Add two option parameters: Face eye dist threshold and Face detection only center.
Browse filesAdd several SRVGGNet models created by Phhofm.
Face eye dist threshold: A threshold to filter out faces with too small an eye distance (e.g., side faces).
Face detection only center: If set to True, only the face closest to the center of the image will be kept.
- README.md +1 -1
- app.py +66 -12
- requirements.txt +1 -1
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 📈
|
|
4 |
colorFrom: blue
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: apache-2.0
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.14.0
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: apache-2.0
|
app.py
CHANGED
@@ -63,6 +63,54 @@ upscale_models = {
|
|
63 |
"realesr-animevideov3.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
|
64 |
"https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.5.0",
|
65 |
"""update the RealESRGAN AnimeVideo-v3 model, which can achieve better results with a faster inference speed."""],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
# RRDBNet
|
68 |
"RealESRGAN_x4plus_anime_6B.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
|
@@ -218,7 +266,7 @@ def get_model_type(model_name):
|
|
218 |
model_type = "other"
|
219 |
if any(value in model_name.lower() for value in ("realesrgan", "realesrnet")):
|
220 |
model_type = "RRDB"
|
221 |
-
elif
|
222 |
model_type = "SRVGG"
|
223 |
elif "esrgan" in model_name.lower() or "4x-AnimeSharp.pth" == model_name:
|
224 |
model_type = "ESRGAN"
|
@@ -240,7 +288,7 @@ typed_upscale_models = {get_model_type(key): value[0] for key, value in upscale_
|
|
240 |
|
241 |
|
242 |
class Upscale:
|
243 |
-
def inference(self, img, face_restoration, upscale_model, scale: float, face_detection, outputWithModelName: bool):
|
244 |
print(img)
|
245 |
print(face_restoration, upscale_model, scale)
|
246 |
try:
|
@@ -281,8 +329,8 @@ class Upscale:
|
|
281 |
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=num_block, num_grow_ch=32, scale=netscale)
|
282 |
elif upscale_type == "SRVGG":
|
283 |
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
284 |
-
netscale = 4
|
285 |
-
num_conv = 16 if "animevideov3"
|
286 |
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=num_conv, upscale=netscale, act_type='prelu')
|
287 |
elif upscale_type == "ESRGAN":
|
288 |
netscale = 4
|
@@ -479,7 +527,7 @@ class Upscale:
|
|
479 |
bg_upsample_img, _ = auto_split_upscale(img, self.upsampler.enhance, self.scale) if is_auto_split_upscale else self.upsampler.enhance(img, outscale=self.scale)
|
480 |
|
481 |
if self.face_enhancer:
|
482 |
-
cropped_faces, restored_aligned, bg_upsample_img = self.face_enhancer.enhance(img, has_aligned=False, only_center_face=
|
483 |
# save faces
|
484 |
if cropped_faces and restored_aligned:
|
485 |
for idx, (cropped_face, restored_face) in enumerate(zip(cropped_faces, restored_aligned)):
|
@@ -635,13 +683,15 @@ def main():
|
|
635 |
with gr.Blocks(title = title) as demo:
|
636 |
gr.Markdown(value=f"<h1 style=\"text-align:center;\">{title}</h1><br>{description}")
|
637 |
with gr.Row():
|
638 |
-
with gr.Column(variant="panel"):
|
639 |
-
input_image
|
640 |
-
face_model
|
641 |
-
upscale_model
|
642 |
-
upscale_scale
|
643 |
-
face_detection
|
644 |
-
|
|
|
|
|
645 |
with gr.Row():
|
646 |
submit = gr.Button(value="Submit", variant="primary", size="lg")
|
647 |
clear = gr.ClearButton(
|
@@ -651,6 +701,8 @@ def main():
|
|
651 |
upscale_model,
|
652 |
upscale_scale,
|
653 |
face_detection,
|
|
|
|
|
654 |
with_model_name,
|
655 |
], variant="secondary", size="lg",)
|
656 |
with gr.Column(variant="panel"):
|
@@ -689,6 +741,8 @@ def main():
|
|
689 |
upscale_model,
|
690 |
upscale_scale,
|
691 |
face_detection,
|
|
|
|
|
692 |
with_model_name,
|
693 |
],
|
694 |
outputs=[gallerys, outputs],
|
|
|
63 |
"realesr-animevideov3.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
|
64 |
"https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.5.0",
|
65 |
"""update the RealESRGAN AnimeVideo-v3 model, which can achieve better results with a faster inference speed."""],
|
66 |
+
|
67 |
+
"4xLSDIRCompact.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact/4xLSDIRCompact.pth",
|
68 |
+
"https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact",
|
69 |
+
"""Upscale small good quality photos to 4x their size. This is my first ever released self-trained sisr upscaling model."""],
|
70 |
+
|
71 |
+
"4xLSDIRCompactC.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactC.pth",
|
72 |
+
"https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
|
73 |
+
"""4x photo upscaler that handler jpg compression. Trying to extend my previous model to be able to handle compression (JPG 100-30) by manually altering the training dataset, since 4xLSDIRCompact cant handle compression. Use this instead of 4xLSDIRCompact if your photo has compression (like an image from the web)."""],
|
74 |
+
|
75 |
+
"4xLSDIRCompactR.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactR.pth",
|
76 |
+
"https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
|
77 |
+
"""4x photo uspcaler that handles jpg compression, noise and slight. Extending my last 4xLSDIRCompact model to Real-ESRGAN, meaning trained on synthetic data instead to handle more kinds of degradations, it should be able to handle compression, noise, and slight blur."""],
|
78 |
+
|
79 |
+
"4xLSDIRCompactN.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
|
80 |
+
"https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
|
81 |
+
"""Upscale good quality input photos to x4 their size. The original 4xLSDIRCompact a bit more trained, cannot handle degradation.
|
82 |
+
I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
|
83 |
+
|
84 |
+
"4xLSDIRCompactC3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
|
85 |
+
"https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
|
86 |
+
"""Upscale compressed photos to x4 their size. Able to handle JPG compression (30-100).
|
87 |
+
I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
|
88 |
+
|
89 |
+
"4xLSDIRCompactR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactR3.pth",
|
90 |
+
"https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
|
91 |
+
"""Upscale (degraded) photos to x4 their size. Trained on synthetic data, meant to handle more degradations.
|
92 |
+
I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
|
93 |
+
|
94 |
+
"4xLSDIRCompactCR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactCR3.pth",
|
95 |
+
"https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
|
96 |
+
"""I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
|
97 |
+
|
98 |
+
"2xParimgCompact.pth": ["https://github.com/Phhofm/models/releases/download/2xParimgCompact/2xParimgCompact.pth",
|
99 |
+
"https://github.com/Phhofm/models/releases/tag/2xParimgCompact",
|
100 |
+
"""A 2x photo upscaling compact model based on Microsoft's ImagePairs. This was one of the earliest models I started training and finished it now for release. As can be seen in the examples, this model will affect colors."""],
|
101 |
+
|
102 |
+
"1xExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xExposureCorrection_compact.pth",
|
103 |
+
"https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
|
104 |
+
"""This model is meant as an experiment to see if compact can be used to train on photos to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
|
105 |
+
|
106 |
+
"1xUnderExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xUnderExposureCorrection_compact.pth",
|
107 |
+
"https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
|
108 |
+
"""This model is meant as an experiment to see if compact can be used to train on underexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
|
109 |
+
|
110 |
+
"1xOverExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xOverExposureCorrection_compact.pth",
|
111 |
+
"https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
|
112 |
+
"""This model is meant as an experiment to see if compact can be used to train on overexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
|
113 |
+
|
114 |
|
115 |
# RRDBNet
|
116 |
"RealESRGAN_x4plus_anime_6B.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
|
|
|
266 |
model_type = "other"
|
267 |
if any(value in model_name.lower() for value in ("realesrgan", "realesrnet")):
|
268 |
model_type = "RRDB"
|
269 |
+
elif any(value in model_name.lower() for value in ("realesr", "exposurecorrection", "parimgcompact", "lsdircompact")):
|
270 |
model_type = "SRVGG"
|
271 |
elif "esrgan" in model_name.lower() or "4x-AnimeSharp.pth" == model_name:
|
272 |
model_type = "ESRGAN"
|
|
|
288 |
|
289 |
|
290 |
class Upscale:
|
291 |
+
def inference(self, img, face_restoration, upscale_model, scale: float, face_detection, face_detection_threshold: any, face_detection_only_center: bool, outputWithModelName: bool):
|
292 |
print(img)
|
293 |
print(face_restoration, upscale_model, scale)
|
294 |
try:
|
|
|
329 |
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=num_block, num_grow_ch=32, scale=netscale)
|
330 |
elif upscale_type == "SRVGG":
|
331 |
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
332 |
+
netscale = 1 if "1x" in upscale_model else (2 if "2x" in upscale_model else 4)
|
333 |
+
num_conv = 16 if any(value in upscale_model for value in ("animevideov3", "ExposureCorrection", "ParimgCompact", "LSDIRCompact")) else 32
|
334 |
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=num_conv, upscale=netscale, act_type='prelu')
|
335 |
elif upscale_type == "ESRGAN":
|
336 |
netscale = 4
|
|
|
527 |
bg_upsample_img, _ = auto_split_upscale(img, self.upsampler.enhance, self.scale) if is_auto_split_upscale else self.upsampler.enhance(img, outscale=self.scale)
|
528 |
|
529 |
if self.face_enhancer:
|
530 |
+
cropped_faces, restored_aligned, bg_upsample_img = self.face_enhancer.enhance(img, has_aligned=False, only_center_face=face_detection_only_center, paste_back=True, bg_upsample_img=bg_upsample_img, eye_dist_threshold=face_detection_threshold)
|
531 |
# save faces
|
532 |
if cropped_faces and restored_aligned:
|
533 |
for idx, (cropped_face, restored_face) in enumerate(zip(cropped_faces, restored_aligned)):
|
|
|
683 |
with gr.Blocks(title = title) as demo:
|
684 |
gr.Markdown(value=f"<h1 style=\"text-align:center;\">{title}</h1><br>{description}")
|
685 |
with gr.Row():
|
686 |
+
with gr.Column(variant ="panel"):
|
687 |
+
input_image = gr.Image(type="filepath", label="Input", format="png")
|
688 |
+
face_model = gr.Dropdown(list(face_models.keys())+[None], type="value", value='GFPGANv1.4.pth', label='Face Restoration version', info="Face Restoration and RealESR can be freely combined in different ways, or one can be set to \"None\" to use only the other model. Face Restoration is primarily used for face restoration in real-life images, while RealESR serves as a background restoration model.")
|
689 |
+
upscale_model = gr.Dropdown(list(typed_upscale_models.keys())+[None], type="value", value='SRVGG, realesr-general-x4v3.pth', label='UpScale version')
|
690 |
+
upscale_scale = gr.Number(label="Rescaling factor", value=4)
|
691 |
+
face_detection = gr.Dropdown(["retinaface_resnet50", "YOLOv5l", "YOLOv5n"], type="value", value="retinaface_resnet50", label="Face Detection type")
|
692 |
+
face_detection_threshold = gr.Number(label="Face eye dist threshold", value=10, info="A threshold to filter out faces with too small an eye distance (e.g., side faces).")
|
693 |
+
face_detection_only_center = gr.Checkbox(value=False, label="Face detection only center", info="If set to True, only the face closest to the center of the image will be kept.")
|
694 |
+
with_model_name = gr.Checkbox(label="Output image files name with model name", value=True)
|
695 |
with gr.Row():
|
696 |
submit = gr.Button(value="Submit", variant="primary", size="lg")
|
697 |
clear = gr.ClearButton(
|
|
|
701 |
upscale_model,
|
702 |
upscale_scale,
|
703 |
face_detection,
|
704 |
+
face_detection_threshold,
|
705 |
+
face_detection_only_center,
|
706 |
with_model_name,
|
707 |
], variant="secondary", size="lg",)
|
708 |
with gr.Column(variant="panel"):
|
|
|
741 |
upscale_model,
|
742 |
upscale_scale,
|
743 |
face_detection,
|
744 |
+
face_detection_threshold,
|
745 |
+
face_detection_only_center,
|
746 |
with_model_name,
|
747 |
],
|
748 |
outputs=[gallerys, outputs],
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
--extra-index-url https://download.pytorch.org/whl/cu124
|
2 |
|
3 |
-
gradio==5.
|
4 |
|
5 |
basicsr @ git+https://github.com/avan06/BasicSR
|
6 |
facexlib @ git+https://github.com/avan06/facexlib
|
|
|
1 |
--extra-index-url https://download.pytorch.org/whl/cu124
|
2 |
|
3 |
+
gradio==5.14.0
|
4 |
|
5 |
basicsr @ git+https://github.com/avan06/BasicSR
|
6 |
facexlib @ git+https://github.com/avan06/facexlib
|