From 2c20a354b6e5acc313d752e336d63496a0d4cded Mon Sep 17 00:00:00 2001 From: Xintao Date: Sat, 28 Aug 2021 13:20:10 +0800 Subject: [PATCH] add check arg --- Training.md | 2 +- scripts/generate_meta_info.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Training.md b/Training.md index 2344f17..a754246 100644 --- a/Training.md +++ b/Training.md @@ -216,7 +216,7 @@ Download pre-trained models into `experiments/pretrained_models`. wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models ``` -**Finetune** +**3. Finetune** Modify [options/finetune_realesrgan_x4plus_pairdata.yml](options/finetune_realesrgan_x4plus_pairdata.yml) accordingly, especially the `datasets` part: diff --git a/scripts/generate_meta_info.py b/scripts/generate_meta_info.py index b5aeabd..b294f7b 100644 --- a/scripts/generate_meta_info.py +++ b/scripts/generate_meta_info.py @@ -1,4 +1,5 @@ import argparse +import cv2 import glob import os @@ -8,9 +9,20 @@ def main(args): for folder, root in zip(args.input, args.root): img_paths = sorted(glob.glob(os.path.join(folder, '*'))) for img_path in img_paths: - img_name = os.path.relpath(img_path, root) - print(img_name) - txt_file.write(f'{img_name}\n') + status = True + if args.check: + try: + img = cv2.imread(img_path) + except Exception as error: + print(f'Read {img_path} error: {error}') + status = False + if img is None: + status = False + print(f'Img is None: {img_path}') + if status: + img_name = os.path.relpath(img_path, root) + print(img_name) + txt_file.write(f'{img_name}\n') if __name__ == '__main__': @@ -34,6 +46,7 @@ if __name__ == '__main__': type=str, default='datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt', help='txt path for meta info') + parser.add_argument('--check', action='store_true', help='Read image to check whether it is ok') args = parser.parse_args() assert len(args.input) == len(args.root), ('Input folder and folder root should have the same length, but got '