Add progress display during the inference phase
Browse files
app.py
CHANGED
@@ -745,14 +745,14 @@ class Upscale:
|
|
745 |
self.realesrganer = upscaler
|
746 |
|
747 |
|
748 |
-
def initFaceEnhancerModel(self, face_restoration, face_detection
|
749 |
-
|
|
|
|
|
750 |
|
751 |
-
resolution = 512
|
752 |
self.modelInUse = f"_{os.path.splitext(face_restoration)[0]}" + self.modelInUse
|
753 |
from gfpgan.utils import GFPGANer
|
754 |
-
|
755 |
-
model_path = os.path.join(model_rootpath, face_restoration)
|
756 |
channel_multiplier = None
|
757 |
|
758 |
if face_restoration and face_restoration.startswith("GFPGANv1."):
|
@@ -775,24 +775,34 @@ class Upscale:
|
|
775 |
self.face_enhancer = GFPGANer(model_path=model_path, upscale=self.scale, arch=arch, channel_multiplier=channel_multiplier, model_rootpath=model_rootpath, det_model=face_detection, resolution=resolution)
|
776 |
|
777 |
|
778 |
-
def inference(self, gallery, face_restoration, upscale_model, scale: float, face_detection, face_detection_threshold: any, face_detection_only_center: bool, outputWithModelName: bool):
|
779 |
try:
|
780 |
if not gallery or (not face_restoration and not upscale_model):
|
781 |
raise ValueError("Invalid parameter setting")
|
782 |
|
783 |
-
|
|
|
784 |
|
785 |
timer = Timer() # Create a timer
|
786 |
self.scale = scale
|
787 |
-
|
|
|
|
|
|
|
|
|
|
|
788 |
if upscale_model:
|
789 |
self.initBGUpscaleModel(upscale_model)
|
790 |
-
|
|
|
|
|
791 |
|
792 |
if face_restoration:
|
793 |
-
self.initFaceEnhancerModel(face_restoration, face_detection
|
794 |
-
|
795 |
-
|
|
|
|
|
796 |
timer.report()
|
797 |
|
798 |
if not outputWithModelName:
|
@@ -822,6 +832,8 @@ class Upscale:
|
|
822 |
bg_upsample_img = None
|
823 |
if self.realesrganer and hasattr(self.realesrganer, "enhance"):
|
824 |
bg_upsample_img, _ = auto_split_upscale(img_cv2, self.realesrganer.enhance, self.scale) if is_auto_split_upscale else self.realesrganer.enhance(img_cv2, outscale=self.scale)
|
|
|
|
|
825 |
timer.checkpoint(f"image{gallery_idx:02d}, Background upscale Section")
|
826 |
|
827 |
if self.face_enhancer:
|
@@ -843,6 +855,8 @@ class Upscale:
|
|
843 |
files.append(save_crop_path)
|
844 |
files.append(save_restore_path)
|
845 |
files.append(save_cmp_path)
|
|
|
|
|
846 |
timer.checkpoint(f"image{gallery_idx:02d}, Face enhancer Section")
|
847 |
|
848 |
restored_img = bg_upsample_img
|
@@ -859,6 +873,7 @@ class Upscale:
|
|
859 |
print(traceback.format_exc())
|
860 |
print('Error', error)
|
861 |
|
|
|
862 |
timer.report_all() # Print all recorded times
|
863 |
except Exception as error:
|
864 |
print(traceback.format_exc())
|
@@ -1100,6 +1115,10 @@ def main():
|
|
1100 |
max-height: 500px !important; /* Set the maximum height of the dropdown menu */
|
1101 |
overflow-y: auto !important; /* Enable vertical scrolling if the content exceeds the height */
|
1102 |
}
|
|
|
|
|
|
|
|
|
1103 |
"""
|
1104 |
|
1105 |
upscale = Upscale()
|
|
|
745 |
self.realesrganer = upscaler
|
746 |
|
747 |
|
748 |
+
def initFaceEnhancerModel(self, face_restoration, face_detection):
|
749 |
+
model_rootpath = os.path.join("weights", "face")
|
750 |
+
model_path = os.path.join(model_rootpath, face_restoration)
|
751 |
+
download_from_url(face_models[face_restoration][0], face_restoration, model_rootpath)
|
752 |
|
|
|
753 |
self.modelInUse = f"_{os.path.splitext(face_restoration)[0]}" + self.modelInUse
|
754 |
from gfpgan.utils import GFPGANer
|
755 |
+
resolution = 512
|
|
|
756 |
channel_multiplier = None
|
757 |
|
758 |
if face_restoration and face_restoration.startswith("GFPGANv1."):
|
|
|
775 |
self.face_enhancer = GFPGANer(model_path=model_path, upscale=self.scale, arch=arch, channel_multiplier=channel_multiplier, model_rootpath=model_rootpath, det_model=face_detection, resolution=resolution)
|
776 |
|
777 |
|
778 |
+
def inference(self, gallery, face_restoration, upscale_model, scale: float, face_detection, face_detection_threshold: any, face_detection_only_center: bool, outputWithModelName: bool, progress=gr.Progress()):
|
779 |
try:
|
780 |
if not gallery or (not face_restoration and not upscale_model):
|
781 |
raise ValueError("Invalid parameter setting")
|
782 |
|
783 |
+
gallery_len = len(gallery)
|
784 |
+
print(face_restoration, upscale_model, scale, f"gallery length: {gallery_len}")
|
785 |
|
786 |
timer = Timer() # Create a timer
|
787 |
self.scale = scale
|
788 |
+
|
789 |
+
progressTotal = gallery_len + 1
|
790 |
+
progressRatio = 0.5 if upscale_model and face_restoration else 1
|
791 |
+
print(f"progressRatio: {progressRatio}")
|
792 |
+
current_progress = 0
|
793 |
+
progress(0, desc="Initialize model start")
|
794 |
if upscale_model:
|
795 |
self.initBGUpscaleModel(upscale_model)
|
796 |
+
current_progress += progressRatio/progressTotal;
|
797 |
+
progress(current_progress, desc="Initialize BG upscale model finished")
|
798 |
+
timer.checkpoint(f"Initialize BG upscale model")
|
799 |
|
800 |
if face_restoration:
|
801 |
+
self.initFaceEnhancerModel(face_restoration, face_detection)
|
802 |
+
current_progress += progressRatio/progressTotal;
|
803 |
+
progress(current_progress, desc="Initialize face enhancer model finished")
|
804 |
+
timer.checkpoint(f"Initialize face enhancer model")
|
805 |
+
|
806 |
timer.report()
|
807 |
|
808 |
if not outputWithModelName:
|
|
|
832 |
bg_upsample_img = None
|
833 |
if self.realesrganer and hasattr(self.realesrganer, "enhance"):
|
834 |
bg_upsample_img, _ = auto_split_upscale(img_cv2, self.realesrganer.enhance, self.scale) if is_auto_split_upscale else self.realesrganer.enhance(img_cv2, outscale=self.scale)
|
835 |
+
current_progress += progressRatio/progressTotal;
|
836 |
+
progress(current_progress, desc=f"image{gallery_idx:02d}, Background upscale Section")
|
837 |
timer.checkpoint(f"image{gallery_idx:02d}, Background upscale Section")
|
838 |
|
839 |
if self.face_enhancer:
|
|
|
855 |
files.append(save_crop_path)
|
856 |
files.append(save_restore_path)
|
857 |
files.append(save_cmp_path)
|
858 |
+
current_progress += progressRatio/progressTotal;
|
859 |
+
progress(current_progress, desc=f"image{gallery_idx:02d}, Face enhancer Section")
|
860 |
timer.checkpoint(f"image{gallery_idx:02d}, Face enhancer Section")
|
861 |
|
862 |
restored_img = bg_upsample_img
|
|
|
873 |
print(traceback.format_exc())
|
874 |
print('Error', error)
|
875 |
|
876 |
+
progress(1, desc=f"Execution completed")
|
877 |
timer.report_all() # Print all recorded times
|
878 |
except Exception as error:
|
879 |
print(traceback.format_exc())
|
|
|
1115 |
max-height: 500px !important; /* Set the maximum height of the dropdown menu */
|
1116 |
overflow-y: auto !important; /* Enable vertical scrolling if the content exceeds the height */
|
1117 |
}
|
1118 |
+
div.progress-level div.progress-level-inner {
|
1119 |
+
text-align: left !important;
|
1120 |
+
width: 55.5% !important;
|
1121 |
+
}
|
1122 |
"""
|
1123 |
|
1124 |
upscale = Upscale()
|