Spaces:
Running
on
T4
Running
on
T4
Ahsen Khaliq
commited on
Commit
•
148a19e
1
Parent(s):
3ef061e
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,14 @@
|
|
1 |
-
import onnxruntime
|
2 |
-
print(onnxruntime.get_device())
|
3 |
-
import os
|
4 |
-
import gradio as gr
|
5 |
-
os.system("pip install gdown")
|
6 |
-
os.system("gdown https://drive.google.com/uc?id=1riNxV1BWMAXfmWZ3LrQbEkvzV8f7lOCp")
|
7 |
-
|
8 |
-
opts = onnxruntime.SessionOptions()
|
9 |
-
opts.intra_op_num_threads = 32
|
10 |
-
onnx_session = onnxruntime.InferenceSession("face_paint_512_v2_0.onnx",sess_options=opts)
|
11 |
-
|
12 |
-
input_name = onnx_session.get_inputs()[0].name
|
13 |
-
output_name = onnx_session.get_outputs()[0].name
|
14 |
-
|
15 |
-
side_length = 512
|
16 |
-
|
17 |
-
import cv2 as cv
|
18 |
-
import numpy as np
|
19 |
from PIL import Image
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
x = cv.cvtColor(image, cv.COLOR_BGR2RGB)
|
26 |
-
|
27 |
-
x = np.array(x, dtype=np.float32)
|
28 |
-
x = x.transpose(2, 0, 1)
|
29 |
-
x = x * 2 - 1
|
30 |
-
x = x.reshape(-1, 3, side_length, side_length)
|
31 |
-
|
32 |
-
onnx_result = onnx_session.run([output_name], {input_name: x})
|
33 |
-
|
34 |
-
onnx_result = np.array(onnx_result).squeeze()
|
35 |
-
onnx_result = (onnx_result * 0.5 + 0.5).clip(0, 1)
|
36 |
-
onnx_result = onnx_result * 255
|
37 |
-
|
38 |
-
onnx_result = onnx_result.transpose(1, 2, 0).astype('uint8')
|
39 |
-
onnx_result = cv.cvtColor(onnx_result, cv.COLOR_RGB2BGR)
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
return
|
45 |
|
46 |
|
47 |
title = "Animeganv2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from PIL import Image
|
2 |
+
import torch
|
3 |
|
4 |
+
face2paint = torch.hub.load(
|
5 |
+
'bryandlee/animegan2-pytorch:main', 'face2paint',
|
6 |
+
size=512, device="cuda"
|
7 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
def inference(img):
|
10 |
+
out = face2paint(model, img)
|
11 |
+
return out
|
12 |
|
13 |
|
14 |
title = "Animeganv2"
|