Spaces:
Running
Running
victorisgeek
commited on
Commit
•
2343c73
1
Parent(s):
67c903a
Update face_enhancer.py
Browse files- face_enhancer.py +28 -2
face_enhancer.py
CHANGED
@@ -15,6 +15,18 @@ def realesrgan_runner(img, model):
|
|
15 |
img = model.predict(img)
|
16 |
return img
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def codeformer_runner(img, model):
|
20 |
img = model.enhance(img)
|
@@ -24,6 +36,9 @@ def codeformer_runner(img, model):
|
|
24 |
supported_enhancers = {
|
25 |
"CodeFormer": ("./assets/pretrained_models/codeformer.onnx", codeformer_runner),
|
26 |
"GFPGAN": ("./assets/pretrained_models/GFPGANv1.4.pth", gfpgan_runner),
|
|
|
|
|
|
|
27 |
"REAL-ESRGAN 2x": ("./assets/pretrained_models/RealESRGAN_x2.pth", realesrgan_runner),
|
28 |
"REAL-ESRGAN 4x": ("./assets/pretrained_models/RealESRGAN_x4.pth", realesrgan_runner),
|
29 |
"REAL-ESRGAN 8x": ("./assets/pretrained_models/RealESRGAN_x8.pth", realesrgan_runner)
|
@@ -49,12 +64,23 @@ def load_face_enhancer_model(name='GFPGAN', device="cpu"):
|
|
49 |
model = CodeFormerEnhancer(model_path=model_path, device=device)
|
50 |
elif name == 'GFPGAN':
|
51 |
model = gfpgan.GFPGANer(model_path=model_path, upscale=1, device=device)
|
52 |
-
|
53 |
-
model =
|
54 |
model.load_weights(model_path, download=False)
|
55 |
elif name == 'REAL-ESRGAN 4x':
|
56 |
model = RealESRGAN(device, scale=4)
|
57 |
model.load_weights(model_path, download=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
elif name == 'REAL-ESRGAN 8x':
|
59 |
model = RealESRGAN(device, scale=8)
|
60 |
model.load_weights(model_path, download=False)
|
|
|
15 |
img = model.predict(img)
|
16 |
return img
|
17 |
|
18 |
+
def realhatgan_runner(img, model):
|
19 |
+
img = model.predict(img)
|
20 |
+
return img
|
21 |
+
|
22 |
+
def restoreformer_runner(img, model):
|
23 |
+
img = model.predict(img)
|
24 |
+
return img
|
25 |
+
|
26 |
+
|
27 |
+
def ultrasharp_runner(img, model):
|
28 |
+
img = model.predict(img)
|
29 |
+
return img
|
30 |
|
31 |
def codeformer_runner(img, model):
|
32 |
img = model.enhance(img)
|
|
|
36 |
supported_enhancers = {
|
37 |
"CodeFormer": ("./assets/pretrained_models/codeformer.onnx", codeformer_runner),
|
38 |
"GFPGAN": ("./assets/pretrained_models/GFPGANv1.4.pth", gfpgan_runner),
|
39 |
+
"Real_Hatgan x4": ("./assets/pretrained_models/real_hatgan_x4.onnx", realhatgan_runner),
|
40 |
+
"Ultra_Sharp x4": ("./assets/pretrained_models/ultra_sharp_x4.onnx", ultrasharp_runner),
|
41 |
+
"RestoreFormer": ("./assets/pretrained_models/restoreformer_plus_plus.onnx", restoreformer_runner),"
|
42 |
"REAL-ESRGAN 2x": ("./assets/pretrained_models/RealESRGAN_x2.pth", realesrgan_runner),
|
43 |
"REAL-ESRGAN 4x": ("./assets/pretrained_models/RealESRGAN_x4.pth", realesrgan_runner),
|
44 |
"REAL-ESRGAN 8x": ("./assets/pretrained_models/RealESRGAN_x8.pth", realesrgan_runner)
|
|
|
64 |
model = CodeFormerEnhancer(model_path=model_path, device=device)
|
65 |
elif name == 'GFPGAN':
|
66 |
model = gfpgan.GFPGANer(model_path=model_path, upscale=1, device=device)
|
67 |
+
elif name ='RestoreFormer':
|
68 |
+
model = RestoreFormer(device, scale=1)
|
69 |
model.load_weights(model_path, download=False)
|
70 |
elif name == 'REAL-ESRGAN 4x':
|
71 |
model = RealESRGAN(device, scale=4)
|
72 |
model.load_weights(model_path, download=False)
|
73 |
+
elif name == 'REAL-ESRGAN 2x':
|
74 |
+
model = RealESRGAN(device, scale=2)
|
75 |
+
model.load_weights(model_path, download=False)
|
76 |
+
elif name == 'Real_Hatgan x4':
|
77 |
+
model = RealHatGAN(device, scale=4)
|
78 |
+
elif name == 'Ultra_Sharp x4':
|
79 |
+
model = UltraShap(device, scale=4)
|
80 |
+
model.load_weights(model_path, download=False)
|
81 |
+
elif name == 'REAL-ESRGAN 4x':
|
82 |
+
model = RealHatGAN(device, scale=4)
|
83 |
+
model.load_weights(model_path, download=False)
|
84 |
elif name == 'REAL-ESRGAN 8x':
|
85 |
model = RealESRGAN(device, scale=8)
|
86 |
model.load_weights(model_path, download=False)
|