ResShift
ResShift: Efficient Diffusion Model for Image Super-resolution by Residual Shifting (NeurIPS@2023 Spotlight, TPAMI@2024)
Install / Use
/learn @zsyOAOA/ResShiftREADME
ResShift: Efficient Diffusion Model for Image Super-resolution by Residual Shifting (NeurIPS 2023, Spotlight, TPAMI@2025)
Zongsheng Yue, Jianyi Wang, Chen Change Loy
Conference Paper | Journal Paper | Project Page | Video
<a href="https://colab.research.google.com/drive/1CL8aJO7a_RA4MetanrCLqQO5H7KWO8KI?usp=sharing"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>
:star: If ResShift is helpful to your images or projects, please help star this repo. Thanks! :hugs:
Diffusion-based image super-resolution (SR) methods are mainly limited by the low inference speed due to the requirements of hundreds or even thousands of sampling steps. Existing acceleration sampling techniques inevitably sacrifice performance to some extent, leading to over-blurry SR results. To address this issue, we propose a novel and efficient diffusion model for SR that significantly reduces the number of diffusion steps, thereby eliminating the need for post-acceleration during inference and its associated performance deterioration. Our method constructs a Markov chain that transfers between the high-resolution image and the low-resolution image by shifting the residual between them, substantially improving the transition efficiency. Additionally, an elaborate noise schedule is developed to flexibly control the shifting speed and the noise strength during the diffusion process. Extensive experiments demonstrate that the proposed method obtains superior or at least comparable performance to current state-of-the-art methods on both synthetic and real-world datasets, even only with 15 sampling steps. <img src="./assets/framework.png" align="middle" width="800">
Update
- 2024.09.13: Our extended journal version has beed accepted by TPAMI@2024. We add the training and testing code for deblurring.
- 2024.03.11: Update the code for the Journal paper
- 2023.12.02: Add configurations for the x2 super-resolution task.
- 2023.08.15: Add Gradio Demo.
- 2023.08.14: Add bicubic (matlab resize) model.
- 2023.08.14: Add Project Page.
- 2023.08.02: Add Replicate demo
.
- 2023.07.31: Add Colab demo <a href="https://colab.research.google.com/drive/1CL8aJO7a_RA4MetanrCLqQO5H7KWO8KI?usp=sharing"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>.
- 2023.07.24: Create this repo.
Requirements
- Python 3.10, Pytorch 2.1.2, xformers 0.0.23
- More detail (See environment.yml)
A suitable conda environment named
resshiftcan be created and activated with:
conda create -n resshift python=3.10
conda activate resshift
pip install -r requirements.txt
or
conda env create -f environment.yml
conda activate resshift
Applications
:point_right: Real-world image super-resolution
<img src="assets/0015.png" height="330px"/> <img src="assets/0030.png" height="330px"/>
<img src="assets/frog.png" height="330px"/> <img src="assets/dog2.png" height="330px">
<img src="assets/cat.png" height="257px"/> <img src="assets/Lincon.png" height="257px"/> <img src="assets/oldphoto6.png" height="257px"/>
:point_right: Image deblurring
<img src="assets/gopro_138.png" height="218"/> <img src="assets/gopro_301.png" height="218px"/> <img src="assets/gopro_537.png" height="217"/> <img src="assets/gopro_838.png" height="217px"/>
:point_right: Image inpainting
<img src="testdata/inpainting/imagenet/lq_mark/ILSVRC2012_val_00001639_mark.png" height="126px"/> <img src="testdata/inpainting/imagenet/results/ILSVRC2012_val_00001639.png" height="126px"/> <img src="testdata/inpainting/imagenet/lq_mark/ILSVRC2012_val_00001810_mark.png" height="126px"/> <img src="testdata/inpainting/imagenet/results/ILSVRC2012_val_00001810.png" height="126px"/> <img src="testdata/inpainting/imagenet/lq_mark/ILSVRC2012_val_00001204_mark.png" height="126px"/> <img src="testdata/inpainting/imagenet/results/ILSVRC2012_val_00001204.png" height="126px"/> <img src="testdata/inpainting/imagenet/lq_mark/ILSVRC2012_val_00002438_mark.png" height="126px"/> <img src="testdata/inpainting/imagenet/results/ILSVRC2012_val_00002438.png" height="126px"/> <img src="testdata/inpainting/imagenet/lq_mark/ILSVRC2012_val_00005693_mark.png" height="126px"/> <img src="testdata/inpainting/imagenet/results/ILSVRC2012_val_00005693.png" height="126px"/> <img src="testdata/inpainting/imagenet/lq_mark/ILSVRC2012_val_00005814_mark.png" height="126px"/> <img src="testdata/inpainting/imagenet/results/ILSVRC2012_val_00005814.png" height="126px"/> <img src="testdata/inpainting/face/lq_mark/94_mark.png" height="126px"/> <img src="testdata/inpainting/face/results/94.png" height="126px"/> <img src="testdata/inpainting/face/lq_mark/410_mark.png" height="126px"/> <img src="testdata/inpainting/face/results/410.png" height="126px"/> <img src="testdata/inpainting/face/lq_mark/269_mark.png" height="126px"/> <img src="testdata/inpainting/face/results/269.png" height="126px"/> <img src="testdata/inpainting/face/lq_mark/321_mark.png" height="126px"/> <img src="testdata/inpainting/face/results/321.png" height="126px"/> <img src="testdata/inpainting/face/lq_mark/5915_mark.png" height="126px"/> <img src="testdata/inpainting/face/results/5915.png" height="126px"/> <img src="testdata/inpainting/face/lq_mark/5489_mark.png" height="126px"/> <img src="testdata/inpainting/face/results/5489.png" height="126px"/>
:point_right: Blind Face Restoration
<img src="testdata/faceir/cropped_faces/lq/0729.png" height="126px"/> <img src="testdata/faceir/cropped_faces/results/0729.png" height="126px"/> <img src="testdata/faceir/cropped_faces/lq/0444.png" height="126px"/> <img src="testdata/faceir/cropped_faces/results/0444.png" height="126px"/> <img src="testdata/faceir/cropped_faces/lq/0885.png" height="126px"/> <img src="testdata/faceir/cropped_faces/results/0885.png" height="126px"/> <img src="testdata/faceir/cropped_faces/lq/0500.png" height="126px"/> <img src="testdata/faceir/cropped_faces/results/0500.png" height="126px"/> <img src="testdata/faceir/cropped_faces/lq/Solvay_conference_1927_2_16.png" height="126px"/> <img src="testdata/faceir/cropped_faces/results/Solvay_conference_1927_0018.png" height="126px"/> <img src="testdata/faceir/cropped_faces/lq/Solvay_conference_1927_2_16.png" height="126px"/> <img src="testdata/faceir/cropped_faces/results/Solvay_conference_1927_2_16.png" height="126px"/>
Online Demo
You can try our method through an online demo:
python app.py
Fast Testing
:tiger: Real-world image super-resolution
python inference_resshift.py -i [image folder/image path] -o [result folder] --task realsr --scale 4 --version v3
:lion: Bicubic (resize by Matlab) image super-resolution
python inference_resshift.py -i [image folder/image path] -o [result folder] --task bicsr --scale 4
:snail: Image deblurring
python inference_resshift.py -i [image folder/image path] -o [result folder] --task deblur --scale 1
:snake: Natural image inpainting
python inference_resshift.py -i [image folder/image path] -o [result folder] --mask_path [mask path] --task inpaint_imagenet --scale 1
:crocodile: Face image inpainting
python inference_resshift.py -i [image folder/image path] -o [result folder] --mask_path [mask path] --task inpaint_face --scale 1
:octopus: Blind Face Restoration
python inference_resshift.py -i [image folder/image path] -o [result folder] --task faceir --scale 1
Training
:turtle: Preparing stage
- Download the pre-trained VQGAN model from this link and put it in the folder of 'weights'
- Adjust the data path in the config file.
- Adjust batchsize according your GPUS.
- configs.train.batch: [training batchsize, validation batchsize]
- configs.train.microbatch: total batchsize = microbatch * #GPUS * num_grad_accumulation
:dolphin: Real-world Image Super-resolution for NeurIPS
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 torchrun --standalone --nproc_per_node=8 --nnodes=1 main.py --cfg_path configs/realsr_swinunet_realesrgan256.yaml --save_dir [Logging Folder]
:whale: Real-world Image Super-resolution for Journal
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 torchrun --standalone --nproc_per_node=8 --nnodes=1 main.py --cfg_path configs/realsr_swinunet_realesrgan256_journal.yaml --save_dir [Logging Folder]
:camel: Image Deblurring for Journal
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 torchrun --standalone --nproc_per_node=8 --nnodes=1 main.py --cfg_path configs/deblur_gopro256.yaml --save_dir [Logging Folder]
:ox: Image inpainting (Natural) for Journal
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 torchrun --standalone --nproc_per_node=8 --nnodes=1 main.py --cfg_path configs/inpaint_lama256_imagenet.yaml --save_dir [Lo
