Spaces:
Runtime error
Runtime error
support input image path.
Browse files- README.md +1 -1
- inference_codeformer.py +13 -6
README.md
CHANGED
@@ -103,7 +103,7 @@ python inference_codeformer.py --w 0.5 --has_aligned --test_path [input folder]
|
|
103 |
# For the whole images
|
104 |
# Add '--bg_upsampler realesrgan' to enhance the background regions with Real-ESRGAN
|
105 |
# Add '--face_upsample' to further upsample restorated face with Real-ESRGAN
|
106 |
-
python inference_codeformer.py --w 0.7 --test_path [input folder]
|
107 |
```
|
108 |
|
109 |
Fidelity weight *w* lays in [0, 1]. Generally, smaller *w* tends to produce a higher-quality result, while larger *w* yields a higher-fidelity result.
|
|
|
103 |
# For the whole images
|
104 |
# Add '--bg_upsampler realesrgan' to enhance the background regions with Real-ESRGAN
|
105 |
# Add '--face_upsample' to further upsample restorated face with Real-ESRGAN
|
106 |
+
python inference_codeformer.py --w 0.7 --test_path [input folder/image path]
|
107 |
```
|
108 |
|
109 |
Fidelity weight *w* lays in [0, 1]. Generally, smaller *w* tends to produce a higher-quality result, while larger *w* yields a higher-fidelity result.
|
inference_codeformer.py
CHANGED
@@ -42,7 +42,7 @@ def set_realesrgan():
|
|
42 |
|
43 |
if not cuda_is_available: # CPU
|
44 |
import warnings
|
45 |
-
warnings.warn('
|
46 |
'The unoptimized RealESRGAN is slow on CPU. '
|
47 |
'If you want to disable it, please remove `--bg_upsampler` and `--face_upsample` in command.',
|
48 |
category=RuntimeWarning)
|
@@ -68,11 +68,18 @@ if __name__ == '__main__':
|
|
68 |
args = parser.parse_args()
|
69 |
|
70 |
# ------------------------ input & output ------------------------
|
71 |
-
if args.test_path.endswith('/'): # solve when path ends with /
|
72 |
-
args.test_path = args.test_path[:-1]
|
73 |
-
|
74 |
w = args.w
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
# ------------------ set up background upsampler ------------------
|
78 |
if args.bg_upsampler == 'realesrgan':
|
@@ -122,7 +129,7 @@ if __name__ == '__main__':
|
|
122 |
|
123 |
# -------------------- start to processing ---------------------
|
124 |
# scan all the jpg and png images
|
125 |
-
for img_path in
|
126 |
# clean all the intermediate results to process the next image
|
127 |
face_helper.clean_all()
|
128 |
|
|
|
42 |
|
43 |
if not cuda_is_available: # CPU
|
44 |
import warnings
|
45 |
+
warnings.warn('Running on CPU now! Make sure your PyTorch version matches your CUDA.'
|
46 |
'The unoptimized RealESRGAN is slow on CPU. '
|
47 |
'If you want to disable it, please remove `--bg_upsampler` and `--face_upsample` in command.',
|
48 |
category=RuntimeWarning)
|
|
|
68 |
args = parser.parse_args()
|
69 |
|
70 |
# ------------------------ input & output ------------------------
|
|
|
|
|
|
|
71 |
w = args.w
|
72 |
+
if args.test_path.endswith(('jpg', 'png')): # input single img path
|
73 |
+
input_img_list = [args.test_path]
|
74 |
+
result_root = f'results/test_img_{w}'
|
75 |
+
|
76 |
+
else: # input img folder
|
77 |
+
if args.test_path.endswith('/'): # solve when path ends with /
|
78 |
+
args.test_path = args.test_path[:-1]
|
79 |
+
|
80 |
+
input_img_list = sorted(glob.glob(os.path.join(args.test_path, '*.[jp][pn]g')))
|
81 |
+
result_root = f'results/{os.path.basename(args.test_path)}_{w}'
|
82 |
+
|
83 |
|
84 |
# ------------------ set up background upsampler ------------------
|
85 |
if args.bg_upsampler == 'realesrgan':
|
|
|
129 |
|
130 |
# -------------------- start to processing ---------------------
|
131 |
# scan all the jpg and png images
|
132 |
+
for img_path in input_img_list:
|
133 |
# clean all the intermediate results to process the next image
|
134 |
face_helper.clean_all()
|
135 |
|