Coder Social home page Coder Social logo

resshift's Introduction

ResShift: Efficient Diffusion Model for Image Super-resolution by Residual Shifting

Zongsheng Yue, Jianyi Wang, Chen Change Loy

Paper | Project Page | Video

google colab logo Replicate OpenXLab visitors

โญ If ResShift is helpful to your images or projects, please help star this repo. Thanks! ๐Ÿค—


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.

Update

  • 2023.08.15: Add OpenXLab.
  • 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 Replicate.
  • 2023.07.31: Add Colab demo google colab logo.
  • 2023.07.24: Create this repo.

Requirements

  • Python 3.9.16, Pytorch 1.12.1, xformers 0.0.20
  • More detail (See environment.yml) A suitable conda environment named ResShift can be created and activated with:
conda env create -f environment.yaml
conda activate ResShift

Applications

๐Ÿ‘‰ Real-world image super-resolution

Online Demo

You can try our method through an online demo:

CUDA_VISIBLE_DEVICES=gpu_id python app.py

Inference

๐Ÿฏ Real-world image super-resolution

CUDA_VISIBLE_DEVICES=gpu_id python inference_resshift.py -i [image folder/image path] -o [result folder] --task realsrx4 --chop_size 512

๐Ÿฆ Bicubic (resize by Opencv) image super-resolution

CUDA_VISIBLE_DEVICES=gpu_id python inference_resshift.py -i [image folder/image path] -o [result folder] --task bicsrx4_cv2 --chop_size 512

๐Ÿฆ Bicubic (resize by Matlab) image super-resolution

CUDA_VISIBLE_DEVICES=gpu_id python inference_resshift.py -i [image folder/image path] -o [result folder] --task bicsrx4_matlab --chop_size 512

Training

๐Ÿข Prepare data

Download the training data and add the data path to the config file (data.train.params.dir_path or data.train.params.txt_file_path). To synthesize the testing dataset utilized in our paper, please refer to these scripts.

  • Real-world and Bicubic image super-resolution: ImageNet and FFHQ (resized to 256x256)

๐Ÿฌ Real-world Image Super-resolution

CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --standalone --nproc_per_node=4 --nnodes=1 main.py --cfg_path configs/realsr_swinunet_realesrgan256.yaml --save_dir [Logging Folder] --steps 15

๐Ÿณ Bicubic Image Super-resolution

CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --standalone --nproc_per_node=4 --nnodes=1 main.py --cfg_path configs/bicubic_swinunet_bicubic256.yaml --save_dir [Logging Folder]  --steps 15

License

This project is licensed under NTU S-Lab License 1.0. Redistribution and use should follow this license.

Acknowledgement

This project is based on Improved Diffusion Model, LDM, and BasicSR. We also adopt Real-ESRGAN to synthesize the training data for real-world super-resolution. Thanks for their awesome works.

Contact

If you have any questions, please feel free to contact me via [email protected].

resshift's People

Contributors

zsyoaoa avatar chenxwh avatar eltociear avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.