SwinIR Image Restoration Framework

repository·main·Indexed 26 days ago

https://github.com/jingyunliang/swinir

A PyTorch implementation of a high-performance image restoration framework based on the Swin Transformer. SwinIR supports multiple tasks including image super-resolution (classical, lightweight, and real-world), grayscale and color image denoising, and JPEG compression artifact reduction.

Tokens
1.2K
Snippets
2
Records
7
Agent score
41%

What's inside SwinIR

  1. Overview of SwinIR capabilities

    main

    SwinIR is a PyTorch implementation of a Swin Transformer-based model for image restoration. It achieves state-of-the-art performance in the following tasks:

    • Image Super-Resolution (SR): Including bicubic, lightweight, and real-world image SR.
    • Image Denoising: Supporting both grayscale and color images.
    • JPEG Compression Artifact Reduction: Supporting both grayscale and color images.
  2. Test SwinIR for various image restoration tasks

    main

    You can run SwinIR for several restoration tasks using the main_test_swinir.py script. The script supports classical super-resolution, lightweight super-resolution, real-world super-resolution, denoising (grayscale and color), and JPEG artifact reduction.

    Key CLI Arguments:

    • --task: The restoration task (e.g., classical_sr, lightweight_sr, real_sr, gray_dn, color_dn, jpeg_car, color_jpeg_car).
    • --scale: The upscaling factor (for SR tasks).
    • --model_path: Path to the pretrained .pth model file.
    • --folder_lq: Path to the folder containing low-quality input images.
    • --folder_gt: Path to the folder containing ground-truth images (used for evaluation).
    • --tile: Use this flag (e.g., --tile 400) if you encounter out-of-memory errors during real-world SR.
    • --large_model: Use this flag for larger models in real-world SR.
    • --noise: Specify the noise level (for denoising tasks).
    • --jpeg: Specify the JPEG quality factor (for artifact reduction tasks).
  3. Download training and testing datasets for SwinIR

    main

    Datasets required for training and testing vary by task. Below are the primary datasets used for each task:

    Classical/Lightweight Image SR

    • Training: DIV2K (800 images) or DIV2K + Flickr2K (2650 images).
    • Testing: Set5, Set14, BSD100, Urban100, and Manga109.

    Real-World Image SR

    • Training (SwinIR-M): DIV2K + Flickr2K + OST (10,324 images).
    • Training (SwinIR-L): DIV2K + Flickr2K + OST + WED (4,744 images) + FFHQ (first 2000 images) + Manga109 + SCUT-CTW1500 (first 100 images).
    • Testing: RealSRSet+5images.

    Color/Grayscale Image Denoising

    • Training: DIV2K + Flickr2K + BSD500 (400 images) + WED (4,744 images).
    • Testing (Grayscale): Set12, BSD68, Urban100.
    • Testing (Color): CBSD68, Kodak24, McMaster, Urban100.

    JPEG Compression Artifact Reduction

    • Training: DIV2K + Flickr2K + BSD500 + WED.
    • Testing (Grayscale): Classic5, LIVE1.
  4. Run SwinIR via Colab or PlayTorch demos

    main

    If you do not want to set up a local environment, you can use the following interactive demos:

    1. Google Colab: An online demo for real-world image Super-Resolution (SR) that allows you to test your own images.
    2. PlayTorch: A demo showcasing how to run the SwinIR model in mobile applications built with React Native.
  5. Access SwinIR training code via KAIR

    main

    The training code for SwinIR is maintained within the KAIR repository. You can find the specific documentation and implementation details for SwinIR training there.

    https://github.com/cszn/KAIR/blob/master/docs/README_SwinIR.md
  6. Reference: main_test_swinir.py CLI arguments

    main

    The main_test_swinir.py script uses the following arguments to control the testing process across different tasks:

    ArgumentDescription
    --taskRestoration task: classical_sr, lightweight_sr, real_sr, gray_dn, color_dn, jpeg_car, color_jpeg_car
    --scaleUpscaling factor for SR tasks
    --training_patch_sizeUsed to differentiate settings in classical SR
    --model_pathPath to the pretrained model .pth file
    --folder_lqInput folder for low-quality images
    --folder_gtGround-truth folder for evaluation
    --tileEnables tiling to manage memory (useful for real_sr)
    --large_modelFlag for using larger models in real_sr
    --noiseNoise level for denoising tasks
    --jpegJPEG quality factor for artifact reduction
    --large_modelFlag for using larger models in real_sr