From b4f066016ba664b84a55d7894e554db771995187 Mon Sep 17 00:00:00 2001 From: LielinJiang <50691816+LielinJiang@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:17:01 +0800 Subject: [PATCH] Add dped docs (#171) * add dped docs --- data/realsr_preprocess/collect_noise.py | 2 +- data/realsr_preprocess/create_bicubic_dataset.py | 2 +- data/realsr_preprocess/create_kernel_dataset.py | 5 +++-- data/realsr_preprocess/paths.yml | 2 +- docs/en_US/tutorials/super_resolution.md | 16 ++++++++++++++++ ppgan/apps/first_order_predictor.py | 2 +- ppgan/utils/registry.py | 2 +- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/data/realsr_preprocess/collect_noise.py b/data/realsr_preprocess/collect_noise.py index 1520cba..a3558ff 100644 --- a/data/realsr_preprocess/collect_noise.py +++ b/data/realsr_preprocess/collect_noise.py @@ -29,7 +29,7 @@ opt = parser.parse_args() # define input and target directories cur_path = os.path.abspath(os.path.dirname(__file__)) with open(os.path.join(cur_path, './paths.yml'), 'r') as stream: - PATHS = yaml.load(stream) + PATHS = yaml.load(stream, Loader=yaml.SafeLoader) def noise_patch(rgb_img, sp, max_var, min_mean): diff --git a/data/realsr_preprocess/create_bicubic_dataset.py b/data/realsr_preprocess/create_bicubic_dataset.py index a9cb398..bb86bce 100644 --- a/data/realsr_preprocess/create_bicubic_dataset.py +++ b/data/realsr_preprocess/create_bicubic_dataset.py @@ -50,7 +50,7 @@ opt = parser.parse_args() # define input and target directories cur_path = os.path.abspath(os.path.dirname(__file__)) with open(os.path.join(cur_path, './paths.yml'), 'r') as stream: - PATHS = yaml.load(stream) + PATHS = yaml.load(stream, Loader=yaml.SafeLoader) if opt.dataset == 'df2k': path_sdsr = PATHS['datasets']['df2k'] + '/generated/sdsr/' diff --git a/data/realsr_preprocess/create_kernel_dataset.py b/data/realsr_preprocess/create_kernel_dataset.py index 97c7535..291363a 100644 --- a/data/realsr_preprocess/create_kernel_dataset.py +++ b/data/realsr_preprocess/create_kernel_dataset.py @@ -53,8 +53,9 @@ parser.add_argument('--upscale_factor', opt = parser.parse_args() # define input and target directories -with open('./paths.yml', 'r') as stream: - PATHS = yaml.load(stream) +cur_path = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(cur_path, './paths.yml'), 'r') as stream: + PATHS = yaml.load(stream, Loader=yaml.SafeLoader) if opt.dataset == 'df2k': path_sdsr = PATHS['datasets']['df2k'] + '/generated/sdsr/' diff --git a/data/realsr_preprocess/paths.yml b/data/realsr_preprocess/paths.yml index ce20727..5a7fd42 100644 --- a/data/realsr_preprocess/paths.yml +++ b/data/realsr_preprocess/paths.yml @@ -7,7 +7,7 @@ dped: clean: hr: train: './data/ntire20/DPEDiphone-tr-x' - valid: './data/datasets/ntire20/DPEDiphone-va' + valid: './data/ntire20/DPEDiphone-va' datasets: df2k: 'data/DF2K' dped: 'data/DPED' diff --git a/docs/en_US/tutorials/super_resolution.md b/docs/en_US/tutorials/super_resolution.md index b44469c..c005bd1 100644 --- a/docs/en_US/tutorials/super_resolution.md +++ b/docs/en_US/tutorials/super_resolution.md @@ -81,6 +81,22 @@ python ./data/realsr_preprocess/collect_noise.py --dataset df2k --artifacts tdsr ``` +#### Prepare dataset for realsr dped model + Download dataset from [NTIRE 2020 RWSR](https://competitions.codalab.org/competitions/22220#participate) and unzip it to your path. + Unzip DPEDiphone-tr-x.zip and DPEDiphone-va.zip to ``PaddleGAN/data/ntire20`` directory. + + Use [KernelGAN](https://github.com/sefibk/KernelGAN) to generate kernels from source images. Clone the repo here. Replace SOURCE_PATH with specific path and run: + ``` + python train.py --X4 --input-dir SOURCE_PATH + ``` + for convenient, we provide [DPED_KERNEL.tar](https://paddlegan.bj.bcebos.com/datasets/DPED_KERNEL.tar). You can download it to ``PaddleGAN/data/DPED_KERNEL`` + + Run the following commands: + ``` + python ./data/realsr_preprocess/create_kernel_dataset.py --dataset dped --artifacts clean --kernel_path data/DPED_KERNEL + python ./data/realsr_preprocess/collect_noise.py --dataset dped --artifacts clean + ``` + ### 1.2.2 Train/Test Datasets used in example is df2k, you can change it to your own dataset in the config file. The model used in example is RealSR, you can change other models by replacing the config file. diff --git a/ppgan/apps/first_order_predictor.py b/ppgan/apps/first_order_predictor.py index 7fe981a..7f6072f 100644 --- a/ppgan/apps/first_order_predictor.py +++ b/ppgan/apps/first_order_predictor.py @@ -43,7 +43,7 @@ class FirstOrderPredictor(BasePredictor): find_best_frame=False, best_frame=None): if config is not None and isinstance(config, str): - self.cfg = yaml.load(config) + self.cfg = yaml.load(config, Loader=yaml.SafeLoader) elif isinstance(config, dict): self.cfg = config elif config is None: diff --git a/ppgan/utils/registry.py b/ppgan/utils/registry.py index 3287854..4bf7437 100644 --- a/ppgan/utils/registry.py +++ b/ppgan/utils/registry.py @@ -96,7 +96,7 @@ def build_from_config(cfg, registry, default_args=None): '`cfg` or `default_args` must contain the key "name", ' f'but got {cfg}\n{default_args}') if not isinstance(registry, Registry): - raise TypeError('registry must be an mmcv.Registry object, ' + raise TypeError('registry must be an ppgan.utils.Registry object, ' f'but got {type(registry)}') if not (isinstance(default_args, dict) or default_args is None): raise TypeError('default_args must be a dict or None, ' -- GitLab