Ahsen Khaliq
commited on
Commit
•
96e897e
1
Parent(s):
9846174
Update app.py
Browse files
app.py
CHANGED
@@ -18,36 +18,32 @@ from basicsr.utils import imwrite
|
|
18 |
from gfpgan import GFPGANer
|
19 |
|
20 |
# background upsampler
|
21 |
-
if
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
'If you really want to use it, please modify the corresponding codes.')
|
26 |
-
bg_upsampler = None
|
27 |
-
else:
|
28 |
-
from basicsr.archs.rrdbnet_arch import RRDBNet
|
29 |
-
from realesrgan import RealESRGANer
|
30 |
-
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
31 |
-
bg_upsampler = RealESRGANer(
|
32 |
-
scale=2,
|
33 |
-
model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
|
34 |
-
model=model,
|
35 |
-
tile=args.bg_tile,
|
36 |
-
tile_pad=10,
|
37 |
-
pre_pad=0,
|
38 |
-
half=True) # need to set False in CPU mode
|
39 |
-
else:
|
40 |
bg_upsampler = None
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# set up GFPGAN restorer
|
43 |
restorer = GFPGANer(
|
44 |
-
model_path=
|
45 |
-
upscale=
|
46 |
-
arch=
|
47 |
-
channel_multiplier=
|
48 |
bg_upsampler=bg_upsampler)
|
49 |
-
img_list = sorted(glob.glob(os.path.join(args.test_path, '*')))
|
50 |
-
|
51 |
|
52 |
|
53 |
|
@@ -57,12 +53,12 @@ def inference(img):
|
|
57 |
input_img = cv2.imread(img, cv2.IMREAD_COLOR)
|
58 |
# restore faces and background if necessary
|
59 |
cropped_faces, restored_faces, restored_img = restorer.enhance(
|
60 |
-
input_img, has_aligned=
|
61 |
# save faces
|
62 |
# save cropped face
|
63 |
|
64 |
# save comparison image
|
65 |
-
cmp_img = np.concatenate((
|
66 |
|
67 |
return Image.fromarray(cmp_img)
|
68 |
|
|
|
18 |
from gfpgan import GFPGANer
|
19 |
|
20 |
# background upsampler
|
21 |
+
if not torch.cuda.is_available(): # CPU
|
22 |
+
import warnings
|
23 |
+
warnings.warn('The unoptimized RealESRGAN is very slow on CPU. We do not use it. '
|
24 |
+
'If you really want to use it, please modify the corresponding codes.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
bg_upsampler = None
|
26 |
+
else:
|
27 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
28 |
+
from realesrgan import RealESRGANer
|
29 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
30 |
+
bg_upsampler = RealESRGANer(
|
31 |
+
scale=2,
|
32 |
+
model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
|
33 |
+
model=model,
|
34 |
+
tile=400,
|
35 |
+
tile_pad=10,
|
36 |
+
pre_pad=0,
|
37 |
+
half=True) # need to set False in CPU mode
|
38 |
+
|
39 |
+
|
40 |
# set up GFPGAN restorer
|
41 |
restorer = GFPGANer(
|
42 |
+
model_path='GFPGANCleanv1-NoCE-C2.pth',
|
43 |
+
upscale=2,
|
44 |
+
arch='clean',
|
45 |
+
channel_multiplier=2,
|
46 |
bg_upsampler=bg_upsampler)
|
|
|
|
|
47 |
|
48 |
|
49 |
|
|
|
53 |
input_img = cv2.imread(img, cv2.IMREAD_COLOR)
|
54 |
# restore faces and background if necessary
|
55 |
cropped_faces, restored_faces, restored_img = restorer.enhance(
|
56 |
+
input_img, has_aligned=False, only_center_face=False, paste_back=True)
|
57 |
# save faces
|
58 |
# save cropped face
|
59 |
|
60 |
# save comparison image
|
61 |
+
cmp_img = np.concatenate((cropped_faces[0], restored_faces[0]), axis=1)
|
62 |
|
63 |
return Image.fromarray(cmp_img)
|
64 |
|