Spaces:
Runtime error
Runtime error
Update esr.py
Browse files
esr.py
CHANGED
@@ -8,18 +8,17 @@ from basicsr.utils.download_util import load_file_from_url
|
|
8 |
|
9 |
from realesrgan import RealESRGANer
|
10 |
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
|
|
11 |
|
12 |
|
13 |
last_file = None
|
14 |
img_mode = "RGBA"
|
15 |
-
|
16 |
-
|
17 |
-
def realesrgan1(img, model_name, denoise_strength, face_enhance, outscale):
|
18 |
"""Real-ESRGAN function to restore (and upscale) images.
|
19 |
"""
|
20 |
if not img:
|
21 |
return
|
22 |
-
|
23 |
# Define model parameters
|
24 |
if model_name == 'RealESRGAN_x4plus': # x4 RRDBNet model
|
25 |
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
@@ -45,15 +44,21 @@ def realesrgan1(img, model_name, denoise_strength, face_enhance, outscale):
|
|
45 |
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
|
46 |
]
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# Use dni to control the denoise strength
|
58 |
dni_weight = None
|
59 |
if model_name == 'realesr-general-x4v3' and denoise_strength != 1:
|
@@ -76,7 +81,6 @@ def realesrgan1(img, model_name, denoise_strength, face_enhance, outscale):
|
|
76 |
|
77 |
# Use GFPGAN for face enhancement
|
78 |
if face_enhance:
|
79 |
-
from gfpgan import GFPGANer
|
80 |
face_enhancer = GFPGANer(
|
81 |
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth',
|
82 |
upscale=outscale,
|
|
|
8 |
|
9 |
from realesrgan import RealESRGANer
|
10 |
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
11 |
+
from gfpgan import GFPGANer
|
12 |
|
13 |
|
14 |
last_file = None
|
15 |
img_mode = "RGBA"
|
16 |
+
def dum_fn(model_name):
|
|
|
|
|
17 |
"""Real-ESRGAN function to restore (and upscale) images.
|
18 |
"""
|
19 |
if not img:
|
20 |
return
|
21 |
+
|
22 |
# Define model parameters
|
23 |
if model_name == 'RealESRGAN_x4plus': # x4 RRDBNet model
|
24 |
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
|
|
44 |
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
|
45 |
]
|
46 |
|
47 |
+
model_name = 'realesr-general-x4v3'
|
48 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
49 |
+
netscale = 4
|
50 |
+
file_url = [
|
51 |
+
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth',
|
52 |
+
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
|
53 |
+
]
|
54 |
+
model_path = os.path.join('weights', model_name + '.pth')
|
55 |
+
if not os.path.isfile(model_path):
|
56 |
+
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
57 |
+
for url in file_url:
|
58 |
+
# model_path will be updated
|
59 |
+
model_path = load_file_from_url(
|
60 |
+
url=url, model_dir=os.path.join(ROOT_DIR, 'weights'), progress=True, file_name=None)
|
61 |
+
def realesrgan1(img, model_name, denoise_strength, face_enhance, outscale):
|
62 |
# Use dni to control the denoise strength
|
63 |
dni_weight = None
|
64 |
if model_name == 'realesr-general-x4v3' and denoise_strength != 1:
|
|
|
81 |
|
82 |
# Use GFPGAN for face enhancement
|
83 |
if face_enhance:
|
|
|
84 |
face_enhancer = GFPGANer(
|
85 |
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth',
|
86 |
upscale=outscale,
|