Update app.py
Browse files
app.py
CHANGED
|
@@ -26,22 +26,19 @@ from face_inpainting import FaceInpainting
|
|
| 26 |
|
| 27 |
def inference(file, mode):
|
| 28 |
|
| 29 |
-
im = cv2.imread(file, cv2.IMREAD_COLOR)
|
| 30 |
-
im = cv2.resize(im, (0,0), fx=2, fy=2)
|
| 31 |
-
faceenhancer = FaceEnhancement(size=512, model='GPEN-512', channel_multiplier=2, device='cpu', u=False)
|
| 32 |
-
img, orig_faces, enhanced_faces = faceenhancer.process(im)
|
| 33 |
-
cv2.imwrite(os.path.join("e.png"), img)
|
| 34 |
-
|
| 35 |
|
| 36 |
if mode == "enhance":
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
elif mode == "colorize":
|
| 39 |
model = {'name':'GPEN-1024-Color', 'size':1024}
|
| 40 |
-
grayf = cv2.imread(
|
| 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]))
|
| 46 |
cv2.imwrite(os.path.join("output.png"), colorf)
|
| 47 |
return os.path.join("output.png")
|
|
@@ -49,12 +46,10 @@ def inference(file, mode):
|
|
| 49 |
model = {'name':'GPEN-Inpainting-1024', 'size':1024}
|
| 50 |
faceinpainter = FaceInpainting(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
| 51 |
inpaint = faceinpainter.process(im)
|
| 52 |
-
|
| 53 |
cv2.imwrite(os.path.join("output.png"), inpaint)
|
| 54 |
return os.path.join("output.png")
|
| 55 |
elif mode == "selfie":
|
| 56 |
model = {'name':'GPEN-BFR-2048', 'size':2048}
|
| 57 |
-
im = cv2.resize(im, (0,0), fx=4, fy=4)
|
| 58 |
faceenhancer = FaceEnhancement(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
| 59 |
img, orig_faces, enhanced_faces = faceenhancer.process(im)
|
| 60 |
cv2.imwrite(os.path.join("output.png"), img)
|
|
|
|
| 26 |
|
| 27 |
def inference(file, mode):
|
| 28 |
|
| 29 |
+
im = cv2.imread(file, cv2.IMREAD_COLOR) if mode != "colorize" else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
if mode == "enhance":
|
| 32 |
+
faceenhancer = FaceEnhancement(size=512, model='GPEN-512', channel_multiplier=2, device='cpu', u=False)
|
| 33 |
+
img, orig_faces, enhanced_faces = faceenhancer.process(im)
|
| 34 |
+
cv2.imwrite(os.path.join("output.png"), img)
|
| 35 |
+
return os.path.join("output.png")
|
| 36 |
elif mode == "colorize":
|
| 37 |
model = {'name':'GPEN-1024-Color', 'size':1024}
|
| 38 |
+
grayf = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
|
| 39 |
grayf = cv2.cvtColor(grayf, cv2.COLOR_GRAY2BGR) # channel: 1->3
|
| 40 |
facecolorizer = FaceColorization(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
| 41 |
colorf = facecolorizer.process(grayf)
|
|
|
|
| 42 |
colorf = cv2.resize(colorf, (grayf.shape[1], grayf.shape[0]))
|
| 43 |
cv2.imwrite(os.path.join("output.png"), colorf)
|
| 44 |
return os.path.join("output.png")
|
|
|
|
| 46 |
model = {'name':'GPEN-Inpainting-1024', 'size':1024}
|
| 47 |
faceinpainter = FaceInpainting(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
| 48 |
inpaint = faceinpainter.process(im)
|
|
|
|
| 49 |
cv2.imwrite(os.path.join("output.png"), inpaint)
|
| 50 |
return os.path.join("output.png")
|
| 51 |
elif mode == "selfie":
|
| 52 |
model = {'name':'GPEN-BFR-2048', 'size':2048}
|
|
|
|
| 53 |
faceenhancer = FaceEnhancement(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
| 54 |
img, orig_faces, enhanced_faces = faceenhancer.process(im)
|
| 55 |
cv2.imwrite(os.path.join("output.png"), img)
|