wanglishan commited on
Commit
7b5798a
1 Parent(s): e25cd65

Add application file

Browse files
GFPGANv1.2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29e25ee90c170f4231163f4c83df6b59c968b73f3ce00cb884015ae005db083c
3
+ size 348632874
GFPGANv1.3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c953a88f2727c85c3d9ae72e2bd4846bbaf59fe6972ad94130e23e7017524a70
3
+ size 348632874
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import cv2
4
+ import gradio as gr
5
+ import torch
6
+ from basicsr.archs.srvgg_arch import SRVGGNetCompact
7
+ from gfpgan.utils import GFPGANer
8
+ from realesrgan.utils import RealESRGANer
9
+
10
+ os.system("pip freeze")
11
+ #os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth -P .")
12
+ #os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.2.pth -P .")
13
+ #os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P .")
14
+
15
+
16
+
17
+ # background enhancer with RealESRGAN
18
+ model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
19
+ model_path = 'realesr-general-x4v3.pth'
20
+ half = True if torch.cuda.is_available() else False
21
+ upsampler = RealESRGANer(scale=4, model_path=model_path, model=model, tile=0, tile_pad=10, pre_pad=0, half=half)
22
+
23
+ # Use GFPGAN for face enhancement
24
+ face_enhancer_v3 = GFPGANer(
25
+ model_path='GFPGANv1.3.pth', upscale=2, arch='clean', channel_multiplier=2, bg_upsampler=upsampler)
26
+ face_enhancer_v2 = GFPGANer(
27
+ model_path='GFPGANv1.2.pth', upscale=2, arch='clean', channel_multiplier=2, bg_upsampler=upsampler)
28
+ os.makedirs('output', exist_ok=True)
29
+
30
+
31
+ def inference(img, version, scale):
32
+ print(img, version, scale)
33
+ try:
34
+ img = cv2.imread(img, cv2.IMREAD_UNCHANGED)
35
+ if len(img.shape) == 3 and img.shape[2] == 4:
36
+ img_mode = 'RGBA'
37
+ else:
38
+ img_mode = None
39
+
40
+ h, w = img.shape[0:2]
41
+ if h < 300:
42
+ img = cv2.resize(img, (w * 2, h * 2), interpolation=cv2.INTER_LANCZOS4)
43
+
44
+ if version == 'v1.2':
45
+ face_enhancer = face_enhancer_v2
46
+ else:
47
+ face_enhancer = face_enhancer_v3
48
+ try:
49
+ _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
50
+ except RuntimeError as error:
51
+ print('Error', error)
52
+ else:
53
+ extension = 'png'
54
+
55
+ try:
56
+ if scale != 2:
57
+ interpolation = cv2.INTER_AREA if scale < 2 else cv2.INTER_LANCZOS4
58
+ h, w = img.shape[0:2]
59
+ output = cv2.resize(output, (int(w * scale / 2), int(h * scale / 2)), interpolation=interpolation)
60
+ except Exception as error:
61
+ print('wrong scale input.', error)
62
+ if img_mode == 'RGBA': # RGBA images should be saved in png format
63
+ extension = 'png'
64
+ else:
65
+ extension = 'jpg'
66
+ save_path = f'output/out.{extension}'
67
+ cv2.imwrite(save_path, output)
68
+
69
+ output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
70
+ return output, save_path
71
+ except Exception as error:
72
+ print('global exception', error)
73
+ return None, None
74
+
75
+
76
+
77
+
78
+ gr.Interface(
79
+ inference, [
80
+ gr.inputs.Image(type="filepath", label="Input"),
81
+
82
+ ], [
83
+ gr.outputs.Image(type="numpy", label="Output (The whole image)"),
84
+ gr.outputs.File(label="Download the output image")
85
+ ],
86
+
87
+
88
+
89
+ examples=[['1.jpg', 'v1.3', 2]]).launch()
detection_Resnet50_Final.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d1de9c2944f2ccddca5f5e010ea5ae64a39845a86311af6fdf30841b0a5a16d
3
+ size 109497761
gfpgan/weights/detection_Resnet50_Final.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d1de9c2944f2ccddca5f5e010ea5ae64a39845a86311af6fdf30841b0a5a16d
3
+ size 109497761
gfpgan/weights/parsing_parsenet.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d558d8d0e42c20224f13cf5a29c79eba2d59913419f945545d8cf7b72920de2
3
+ size 85331193
packages.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ffmpeg
2
+ libsm6
3
+ libxext6
pyvenv.cfg ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ home = /home/ll/anaconda3/bin
2
+ include-system-site-packages = false
3
+ version = 3.9.12
realesr-general-x4v3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8dc7edb9ac80ccdc30c3a5dca6616509367f05fbc184ad95b731f05bece96292
3
+ size 4885111
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch>=1.7
2
+ basicsr>=1.4.2
3
+ facexlib>=0.2.5
4
+ gfpgan>=1.3.4
5
+ realesrgan>=0.2.5
6
+ numpy
7
+ opencv-python
8
+ torchvision
9
+ scipy
10
+ tqdm
11
+ lmdb
12
+ pyyaml
13
+ yapf