Unoffical implementation about Image Super-Resolution via Iterative Refinement by Pytorch

Overview

Image Super-Resolution via Iterative Refinement

Paper | Project

Brief

This is a unoffical implementation about Image Super-Resolution via Iterative Refinement(SR3) by Pytorch.

There are some implement details with paper description, which maybe different with actual SR3 structure due to details missing.

  • We used the ResNet block and channel concatenation style like vanilla DDPM.
  • We used the attention mechanism in low resolution feature(16×16) like vanilla DDPM.
  • We encoding the $\gamma$ as FilM strcutrue did in WaveGrad, and embedding it without affine transformation.

Status

Conditional generation(super resolution)

  • 16×16 -> 128×128 on FFHQ-CelebaHQ
  • 64×64 -> 512×512 on FFHQ-CelebaHQ

Unconditional generation

  • 128×128 face generation on FFHQ
  • 1024×1024 face generation by a cascade of 3 models

Training Step

  • log / logger
  • metrics evaluation
  • multi-gpu support
  • resume training / pretrained model

Results

We set the maximum reverse steps budget to 2000 now.

Tasks/Metrics SSIM(+) PSNR(+) FID(-) IS(+)
16×16 -> 128×128 0.675 23.26 - -
64×64 -> 512×512 - -
128×128 - -
1024×1024 - -
show show show
show show show

Usage

Pretrained Model

This paper is based on "Denoising Diffusion Probabilistic Models", and we build both DDPM/SR3 network structure, which use timesteps/gama as model embedding input, respectively. In our experiments, SR3 model can achieve better visual results with same reverse steps and learning rate. You can select the json files with annotated suffix names to train different model.

Tasks Google Drive
16×16 -> 128×128 on FFHQ-CelebaHQ SR3
128×128 face generation on FFHQ SR3
# Download the pretrain model and edit [sr|sample]_[ddpm|sr3]_[resolution option].json about "resume_state":
"resume_state": [your pretrain model path]

We have not trained the model until converged for time reason, which means there are a lot room to optimization.

Data Prepare

New Start

If you didn't have the data, you can prepare it by following steps:

Download the dataset and prepare it in LMDB or PNG format using script.

# Resize to get 16×16 LR_IMGS and 128×128 HR_IMGS, then prepare 128×128 Fake SR_IMGS by bicubic interpolation
python prepare.py  --path [dataset root]  --out [output root] --size 16,128 -l

then you need to change the datasets config to your data path and image resolution:

"datasets": {
    "train": {
        "dataroot": "dataset/ffhq_16_128", // [output root] in prepare.py script
        "l_resolution": 16, // low resolution need to super_resolution
        "r_resolution": 128, // high resolution
        "datatype": "lmdb", //lmdb or img, path of img files
    },
    "val": {
        "dataroot": "dataset/celebahq_16_128", // [output root] in prepare.py script
    }
},

Own Data

You also can use your image data by following steps.

At first, you should organize images layout like this:

# set the high/low resolution images, bicubic interpolation images path
dataset/celebahq_16_128/
├── hr_128
├── lr_16
└── sr_16_128

then you need to change the dataset config to your data path and image resolution:

"datasets": {
    "train|val": {
        "dataroot": "dataset/celebahq_16_128",
        "l_resolution": 16, // low resolution need to super_resolution
        "r_resolution": 128, // high resolution
        "datatype": "img", //lmdb or img, path of img files
    }
},

Training/Resume Training

# Use sr.py and sample.py to train the super resolution task and unconditional generation task, respectively.
# Edit json files to adjust network structure and hyperparameters
python sr.py -p train -c config/sr_sr3.json

Test/Evaluation

# Edit json to add pretrain model path and run the evaluation 
python sr.py -p val -c config/sr_sr3.json

Evaluation Alone

# Quantitative evaluation using SSIM/PSNR metrics on given dataset root
python eval.py -p [dataset root]

Acknowledge

Our work is based on the following theoretical works:

and we are benefit a lot from following projects:

Comments
  • No such file or directory: 'I830000_E32_gen.pth'

    No such file or directory: 'I830000_E32_gen.pth'

    I tried upscaling a simple picture using the colab notebook but instead getting this "No such file.." error on running the last cell download

    21-11-13 09:59:49.904 - INFO: Dataset [LRHRDataset - CelebaHQ] is created. 21-11-13 09:59:49.904 - INFO: Initial Dataset Finished 21-11-13 10:00:06.355 - INFO: Loading pretrained model for G [I830000_E32] ... Traceback (most recent call last): File "infer.py", line 46, in diffusion = Model.create_model(opt) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/init.py", line 7, in create_model m = M(opt) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 42, in init self.load_network() File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 158, in load_network gen_path), strict=(not self.opt['model']['finetune_norm'])) File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 594, in load with _open_file_like(f, 'rb') as opened_file: File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 230, in _open_file_like return _open_file(name_or_buffer, mode) File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 211, in init super(_open_file, self).init(open(name, mode)) FileNotFoundError: [Errno 2] No such file or directory: 'I830000_E32_gen.pth'

    opened by iitjee 25
  • 1024x1024 model question

    1024x1024 model question

    Hi. Do you plan to release 1024x1024 model? Or it can be done modifying code to cascade all models? Cause, I think it is better to not downscale images to 128Pixels. Thank you very much in advance

    question 
    opened by zelenooki87 17
  • No difference

    No difference

    I have tried using my own images, but I have not got any difference between hr (which is just upscaled lr) and inf. My photos are black and white though, I don't know if that would have any effect on it. I seems to me, this is only copying whatever is in the hr folder. Because it doesn't matter if I use actual ground truths or upscaled low res images, the inference looks the same as it.

    opened by hjrobins 9
  • Bug in Image Augmentations

    Bug in Image Augmentations

    Hi, When reading and augment the data we call: https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-Refinement/blob/0f31547f3d0429dcae23cf528059b7a69e0e7fca/data/util.py#L64-L71

    The bugs:

    1. This line iterate over the first dimension of the numpy image (because the function augment(img, split) called with single image) https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-Refinement/blob/0f31547f3d0429dcae23cf528059b7a69e0e7fca/data/util.py#L41

    2. the hflip get the split value. ( We should call it augment(img, split=split) ) https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-Refinement/blob/0f31547f3d0429dcae23cf528059b7a69e0e7fca/data/util.py#L26

    Suggested solution:

    def transform_augment(img_list, split='val', min_max=(0, 1)):
        imgs = [transform2numpy(img) for img in img_list]
        imgs = augment(imgs, split=split)
        ret_img = [transform2tensor(img, min_max) for img in imgs]
        return ret_img
    

    Please let me know if it's correct.

    enhancement 
    opened by ErezYosef 7
  • Mobile version possible&practical?

    Mobile version possible&practical?

    Hello,

    I just watched a video demonstrating this : https://youtu.be/WCAF3PNEc_c

    It seems like an amazing&incredible work!

    Would it be possible to offer this as a library for mobile, such as Android? Could be great to import it to use on Java/Kotlin based apps...

    Or it's already possible?

    I requested it in the past: https://issuetracker.google.com/issues/198311063

    Also, I don't see the license information. OK to use for any purpose?

    opened by AndroidDeveloperLB 6
  • Training on another big datasets

    Training on another big datasets

    Have you plans training this network on ImageNet, COCO, or another datasets? Can model demonstrate good results in common objects photo (nature, city) after that?

    opened by attashe 6
  • Memory leak in multiprocessing pool

    Memory leak in multiprocessing pool

    (windows10 / python3.6 / conda:latest / all-other-packages:latest)

    There is a memory leak somewhere in the multiprocessing section: https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-Refinement/blob/de9d0b1bb7f4a85d958fb2800c4f56881b279697/data/prepare_data.py#L65

    Running 8 workers on a system with 16GB of ram will lead to a crash within ~1-2mins and a nasty pagefile increase to 40GB! I re-wrote the script using the older Process() api and no shared variables between instances which fixed the issue so its probably something to do with data passing.

    All of my tests were done on the full celebahq dataset.

    enhancement 
    opened by drew6017 5
  • What params should I use for the 128 to 1024 task, and for the 512 to 1024 task? How should I choose the Unet architecture?

    What params should I use for the 128 to 1024 task, and for the 512 to 1024 task? How should I choose the Unet architecture?

    Specifaclly, I'm asking about the following section in the config file:

    "unet": {
        "in_channel": 6,
        "out_channel": 3,
        "inner_channel": 64,
        "channel_multiplier": [?????????],
        "attn_res": [?????????],
        "res_blocks": ?????????,
        "dropout": ?????????
    },
    
    opened by roey1rg 4
  • Custom input issue

    Custom input issue

    Please pardon my inexperience using SR GANs, I wondering if you could clarify what is the role of the data input folders:

    1. Should thel_resolution/h_resolution folders contain the same images (with different sizes)? I assume so for testing/validation steps.
    2. What sort of images does the sr_16_64 contains initially?
    3. Where should I put the images for which I want to increase the resolution?

    Thank you in advance for your answer and thank you for sharing your awesome work!

    opened by curiousQuestions 4
  • UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.

    UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.

    So, when running the command: python data/prepare_data.py --path /content/Image-Super-Resolution-via-Iterative-Refinement/input/ --size 64,512 --out ./dataset/celebahq

    I get the following output:

    0/1 images processed
    /usr/local/lib/python3.7/dist-packages/torchvision/transforms/functional.py:405: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
      "Argument interpolation should be of type InterpolationMode instead of int. "
    0/1 images processed
    

    I tried manually changing all instances of Image.BICUBIC with InterpolationMode.BICUBIC and it didn't work. In this case I got 0/1 images processed and that was it.

    Also tried running both in the Google Collab project, and also locally an Ubuntu, and got the same problem both times.

    Any directions on what i could do to fix it? Thanks a lot!

    opened by saadbruno 4
  • Can you give me an example?

    Can you give me an example?

    Can you give me an example , like I have a low resolution images picture ,how i run out a super resolution images? python sr.py -p val -c config/sr_sr3_64_512.json and python eval.py not work

    opened by feng1990liu 4
  • poor image quality for my own SR dataset from scratch?

    poor image quality for my own SR dataset from scratch?

    Training the model from scratch on my superresolution dataset, and the result becomes very bad, i have test for many parameter setting for unet, learning rate schedule, init_method etc, so how to train a good enough model for my own dataset? could you give me some advise for your experience? Thank you a lot

    312480_1_sr_process

    opened by codgodtao 1
  • Poor image quality

    Poor image quality

    Thanks for you code, it's a great job. I use python sr.py -p val -c config/sr_sr3_64_512.json and your pretrained models to perform super-resolution. But I get poor results which are noisy and blury. step=2000. Could you give some advice? 0_1_sr 0_2_sr

    opened by Zhentao-Liu 4
  • get no results when run infer.py

    get no results when run infer.py

    https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-Refinement/blob/ef9b943b573328d7a5ddb1a0c2abd168b91610dc/infer.py#L12 Thanks for the shared project, but some problems happens to me when I try to produce HR images from LR items. The infer.py can run without any errors, but I get no thing from it. Could you tell me what the problem is, and how can I fix it. Thanks again!

    opened by ZhiyiHe1997 1
  • RuntimeError: CUDA error: CUBLAS_STATUS_NOT_SUPPORTED

    RuntimeError: CUDA error: CUBLAS_STATUS_NOT_SUPPORTED

    I got the "RuntimeError: CUDA error: CUBLAS_STATUS_NOT_SUPPORTED when calling `cublasSgemmStridedBatched" error when running the infer.py. Is there anyone else who's had this problem. Thanks

    opened by stu-GYULA 0
  • Sampling throws the following error:

    Sampling throws the following error:

    Thank you for sharing the project.

    I'm getting the following error, I thought it had to do with the pyTorch version but after trying the minimum in the requirements file I still get the error. I'm not that familiar with Torch and would appreciate some help:

    22-11-07 19:04:58.564 - INFO: Model [DDPM] is created. 22-11-07 19:04:58.564 - INFO: Initial Model Finished 22-11-07 19:04:58.565 - INFO: Begin Model Inference. Traceback (most recent call last): File "infer.py", line 70, in diffusion.test(continous=True) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 68, in test self.data['SR'], continous) File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 15, in decorate_context return func(*args, **kwargs) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/sr3_modules/diffusion.py", line 210, in super_resolution return self.p_sample_loop(x_in, continous) File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 15, in decorate_context return func(*args, **kwargs) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/sr3_modules/diffusion.py", line 182, in p_sample_loop img = torch.randn(shape, device=device) TypeError: randn() received an invalid combination of arguments - got (Tensor, device=torch.device), but expected one of:> 22-11-07 19:04:58.564 - INFO: Model [DDPM] is created. 22-11-07 19:04:58.564 - INFO: Initial Model Finished 22-11-07 19:04:58.565 - INFO: Begin Model Inference. Traceback (most recent call last): File "infer.py", line 70, in diffusion.test(continous=True) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 68, in test self.data['SR'], continous) File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 15, in decorate_context return func(*args, **kwargs) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/sr3_modules/diffusion.py", line 210, in super_resolution return self.p_sample_loop(x_in, continous) File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 15, in decorate_context return func(*args, **kwargs) File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/sr3_modules/diffusion.py", line 182, in p_sample_loop img = torch.randn(shape, device=device) TypeError: randn() received an invalid combination of arguments - got (Tensor, device=torch.device), but expected one of:

    • (tuple of ints size, *, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    • (tuple of ints size, *, torch.Generator generator, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    • (tuple of ints size, *, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    • (tuple of ints size, *, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    • (tuple of ints size, *, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    • (tuple of ints size, *, torch.Generator generator, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    • (tuple of ints size, *, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    • (tuple of ints size, *, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

    opened by hizzlehoff 2
Owner
LiangWei Jiang
LiangWei Jiang
PyTorch Implementation of Google Brain's WaveGrad 2: Iterative Refinement for Text-to-Speech Synthesis

WaveGrad2 - PyTorch Implementation PyTorch Implementation of Google Brain's WaveGrad 2: Iterative Refinement for Text-to-Speech Synthesis. Status (202

Keon Lee 59 Dec 6, 2022
Pytorch implementation of “Recursive Non-Autoregressive Graph-to-Graph Transformer for Dependency Parsing with Iterative Refinement”

Graph-to-Graph Transformers Self-attention models, such as Transformer, have been hugely successful in a wide range of natural language processing (NL

Idiap Research Institute 40 Aug 14, 2022
This repository is an unoffical PyTorch implementation of Medical segmentation in 3D and 2D.

Pytorch Medical Segmentation Read Chinese Introduction:Here! Recent Updates 2021.1.8 The train and test codes are released. 2021.2.6 A bug in dice was

EasyCV-Ellis 618 Dec 27, 2022
Code repo for "RBSRICNN: Raw Burst Super-Resolution through Iterative Convolutional Neural Network" (Machine Learning and the Physical Sciences workshop in NeurIPS 2021).

RBSRICNN: Raw Burst Super-Resolution through Iterative Convolutional Neural Network An official PyTorch implementation of the RBSRICNN network as desc

Rao Muhammad Umer 6 Nov 14, 2022
Official repository for "PAIR: Planning and Iterative Refinement in Pre-trained Transformers for Long Text Generation"

pair-emnlp2020 Official repository for the paper: Xinyu Hua and Lu Wang: PAIR: Planning and Iterative Refinement in Pre-trained Transformers for Long

Xinyu Hua 31 Oct 13, 2022
RefineGNN - Iterative refinement graph neural network for antibody sequence-structure co-design (RefineGNN)

Iterative refinement graph neural network for antibody sequence-structure co-des

Wengong Jin 83 Dec 31, 2022
Unoffical reMarkable AddOn for Firefox.

reMarkable for Firefox (Download) This repo converts the offical reMarkable Chrome Extension into a Firefox AddOn published here under the name "Unoff

Jelle Schutter 45 Nov 28, 2022
PyTorch code for our ECCV 2020 paper "Single Image Super-Resolution via a Holistic Attention Network"

HAN PyTorch code for our ECCV 2020 paper "Single Image Super-Resolution via a Holistic Attention Network" This repository is for HAN introduced in the

五维空间 140 Nov 23, 2022
Official PyTorch code for Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021)

Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021) This repository is the official P

Jingyun Liang 159 Dec 30, 2022
Official PyTorch code for Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021)

Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021) This repository is the official P

Jingyun Liang 159 Dec 30, 2022
PyTorch implementation of Graph Convolutional Networks in Feature Space for Image Deblurring and Super-resolution, IJCNN 2021.

GCResNet PyTorch implementation of Graph Convolutional Networks in Feature Space for Image Deblurring and Super-resolution, IJCNN 2021. The code will

null 11 May 19, 2022
Implementation of paper: "Image Super-Resolution Using Dense Skip Connections" in PyTorch

SRDenseNet-pytorch Implementation of paper: "Image Super-Resolution Using Dense Skip Connections" in PyTorch (http://openaccess.thecvf.com/content_ICC

wxy 114 Nov 26, 2022
pytorch implementation for Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network arXiv:1609.04802

PyTorch SRResNet Implementation of Paper: "Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network"(https://arxiv.org/abs

Jiu XU 436 Jan 9, 2023
PyTorch Implementation of "Light Field Image Super-Resolution with Transformers"

LFT PyTorch implementation of "Light Field Image Super-Resolution with Transformers", arXiv 2021. [pdf]. Contributions: We make the first attempt to a

Squidward 62 Nov 28, 2022
Unofficial pytorch implementation of the paper "Dynamic High-Pass Filtering and Multi-Spectral Attention for Image Super-Resolution"

DFSA Unofficial pytorch implementation of the ICCV 2021 paper "Dynamic High-Pass Filtering and Multi-Spectral Attention for Image Super-Resolution" (p

null 2 Nov 15, 2021
Official PyTorch implementation of the paper "Deep Constrained Least Squares for Blind Image Super-Resolution", CVPR 2022.

Deep Constrained Least Squares for Blind Image Super-Resolution [Paper] This is the official implementation of 'Deep Constrained Least Squares for Bli

MEGVII Research 141 Dec 30, 2022
[CVPR 2021] Official PyTorch Implementation for "Iterative Filter Adaptive Network for Single Image Defocus Deblurring"

IFAN: Iterative Filter Adaptive Network for Single Image Defocus Deblurring Checkout for the demo (GUI/Google Colab)! The GUI version might occasional

Junyong Lee 173 Dec 30, 2022
PyTorch code for our paper "Attention in Attention Network for Image Super-Resolution"

Under construction... Attention in Attention Network for Image Super-Resolution (A2N) This repository is an PyTorch implementation of the paper "Atten

Haoyu Chen 71 Dec 30, 2022
PyTorch code for our paper "Image Super-Resolution with Non-Local Sparse Attention" (CVPR2021).

Image Super-Resolution with Non-Local Sparse Attention This repository is for NLSN introduced in the following paper "Image Super-Resolution with Non-

null 143 Dec 28, 2022