Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
|
|
|
3 |
os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/RetinaFace-R50.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116085&Signature=GlUNW6%2B8FxvxWmE9jKIZYOOciKQ%3D" -O weights/RetinaFace-R50.pth')
|
4 |
os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-512.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116208&Signature=hBgvVvKVSNGeXqT8glG%2Bd2t2OKc%3D" -O weights/GPEN-512.pth')
|
5 |
os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-Colorization-1024.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116315&Signature=9tPavW2h%2F1LhIKiXj73sTQoWqcc%3D" -O weights/GPEN-1024-Color.pth ')
|
@@ -18,24 +19,27 @@ from face_colorization import FaceColorization
|
|
18 |
|
19 |
|
20 |
def inference(file, mode):
|
21 |
-
|
22 |
-
im = cv2.resize(im, (0,0), fx=2, fy=2)
|
23 |
-
faceenhancer = FaceEnhancement(size=512, model='GPEN-512', channel_multiplier=2, device='cuda')
|
24 |
-
img, orig_faces, enhanced_faces = faceenhancer.process(im)
|
25 |
-
|
26 |
if mode == "enhance":
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
cv2.imwrite(os.path.join("output.png"), img)
|
33 |
return os.path.join("output.png")
|
34 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
model = {'name':'GPEN-1024-Color', 'size':1024}
|
36 |
grayf = cv2.imread("enhanced.png", cv2.IMREAD_GRAYSCALE)
|
37 |
grayf = cv2.cvtColor(grayf, cv2.COLOR_GRAY2BGR) # channel: 1->3
|
38 |
-
facecolorizer = FaceColorization(size=model['size'], model=model['name'], channel_multiplier=2, device='
|
39 |
colorf = facecolorizer.process(grayf)
|
40 |
|
41 |
colorf = cv2.resize(colorf, (grayf.shape[1], grayf.shape[0]))
|
|
|
1 |
import os
|
2 |
|
3 |
+
os.system('nvidia-smi')
|
4 |
os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/RetinaFace-R50.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116085&Signature=GlUNW6%2B8FxvxWmE9jKIZYOOciKQ%3D" -O weights/RetinaFace-R50.pth')
|
5 |
os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-512.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116208&Signature=hBgvVvKVSNGeXqT8glG%2Bd2t2OKc%3D" -O weights/GPEN-512.pth')
|
6 |
os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-Colorization-1024.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116315&Signature=9tPavW2h%2F1LhIKiXj73sTQoWqcc%3D" -O weights/GPEN-1024-Color.pth ')
|
|
|
19 |
|
20 |
|
21 |
def inference(file, mode):
|
22 |
+
|
|
|
|
|
|
|
|
|
23 |
if mode == "enhance":
|
24 |
+
model = {'name':'GPEN-512', 'size':512}
|
25 |
+
im = cv2.imread(file, cv2.IMREAD_COLOR)
|
26 |
+
im = cv2.resize(im, (0,0), fx=2, fy=2)
|
27 |
+
faceenhancer = FaceEnhancement(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
28 |
+
img, orig_faces, enhanced_faces = faceenhancer.process(im)
|
29 |
cv2.imwrite(os.path.join("output.png"), img)
|
30 |
return os.path.join("output.png")
|
31 |
else:
|
32 |
+
emodel = {'name':'GPEN-512', 'size':512}
|
33 |
+
im = cv2.imread(file, cv2.IMREAD_COLOR)
|
34 |
+
im = cv2.resize(im, (0,0), fx=2, fy=2)
|
35 |
+
faceenhancer = FaceEnhancement(size=model['size'], model=emodel['name'], channel_multiplier=2, device='cpu')
|
36 |
+
img, orig_faces, enhanced_faces = faceenhancer.process(im)
|
37 |
+
cv2.imwrite(os.path.join("enhanced.png"), img)
|
38 |
+
|
39 |
model = {'name':'GPEN-1024-Color', 'size':1024}
|
40 |
grayf = cv2.imread("enhanced.png", cv2.IMREAD_GRAYSCALE)
|
41 |
grayf = cv2.cvtColor(grayf, cv2.COLOR_GRAY2BGR) # channel: 1->3
|
42 |
+
facecolorizer = FaceColorization(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
43 |
colorf = facecolorizer.process(grayf)
|
44 |
|
45 |
colorf = cv2.resize(colorf, (grayf.shape[1], grayf.shape[0]))
|