hf_mirrors/edsr
Model Introduction
Files & versions
Analysis

Enhanced Deep Residual Networks for Single Image Super-Resolution (EDSR)

EDSR model pre-trained on DIV2K (800 images training, augmented to 4000 images, 100 images validation) for 2x, 3x and 4x image super resolution. It was introduced in the paper Enhanced Deep Residual Networks for Single Image Super-Resolution by Lim et al. (2017) and first released in this repository.

The goal of image super resolution is to restore a high resolution (HR) image from a single low resolution (LR) image. The image below shows the ground truth (HR), the bicubic upscaling x2 and EDSR upscaling x2.

Comparing Bicubic upscaling against the models x4 upscaling on Set5 Image 4

Model description

EDSR is a model that uses both deeper and wider architecture (32 ResBlocks and 256 channels) to improve performance. It uses both global and local skip connections, and up-scaling is done at the end of the network. It doesn't use batch normalization layers (input and output have similar distributions, normalizing intermediate features may not be desirable) instead it uses constant scaling layers to ensure stable training. An L1 loss function (absolute error) is used instead of L2 (MSE), the authors showed better performance empirically and it requires less computation.

This is a base model (~5mb vs ~100mb) that includes just 16 ResBlocks and 64 channels.

Intended uses & limitations

You can use the pre-trained models for upscaling your images 2x, 3x and 4x. You can also use the trainer to train a model on your own dataset.

How to use

The model can be used with the super_image library:

pip install super-image

Here is how to use a pre-trained model to upscale your image:

import torch
import torch_npu
import argparse
from openmind import pipeline, is_torch_npu_available
from super_image import EdsrModel, ImageLoader
from PIL import Image
import requests

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default=None,
    )
    args = parser.parse_args()
    return args


def main():
    args = parse_args()
    model_path = args.model_name_or_path
    
    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"
    
    url = 'https://paperswithcode.com/media/datasets/Set5-0000002728-07a9793f_zA3bDjj.jpg'
    image = Image.open(requests.get(url, stream=True).raw)

    model = EdsrModel.from_pretrained(model_path, scale=2).to(device)
    inputs = ImageLoader.load_image(image).to(device)
    preds = model(inputs)

    ImageLoader.save_image(preds, './scaled_2x.png')                      
    ImageLoader.save_compare(inputs, preds, './scaled_2x_compare.png') 

if __name__=="__main__":
    main()

Open In Colab

Training data

The models for 2x, 3x and 4x image super resolution were pretrained on DIV2K, a dataset of 800 high-quality (2K resolution) images for training, augmented to 4000 images and uses a dev set of 100 validation images (images numbered 801 to 900).

Training procedure

Preprocessing

We follow the pre-processing and training method of Wang et al.. Low Resolution (LR) images are created by using bicubic interpolation as the resizing method to reduce the size of the High Resolution (HR) images by x2, x3 and x4 times. During training, RGB patches with size of 64×64 from the LR input are used together with their corresponding HR patches. Data augmentation is applied to the training set in the pre-processing stage where five images are created from the four corners and center of the original image.

Open In Colab

Evaluation results

The evaluation metrics include PSNR and SSIM.

The results columns below are represented below as PSNR/SSIM. They are compared against a Bicubic baseline.

DatasetScaleBicubicedsr
Set52x33.64/0.929238.19/0.9612
Set53x30.39/0.867835.31/0.9421
Set54x28.42/0.810132.5/0.8986
Set142x30.22/0.868333.99/0.9215
Set143x27.53/0.773731.18/0.862
Set144x25.99/0.702328.92/0.7899
BSD1002x29.55/0.842533.89/0.9266
BSD1003x27.20/0.738229.77/0.8224
BSD1004x25.96/0.667228.62/0.7689
Urban1002x26.66/0.840832.68/0.9331
Urban1003x29.75/0.8825
Urban1004x23.14/0.657326.53/0.7995

Comparing Bicubic upscaling against the models x4 upscaling on Set5 Image 2

You can find a notebook to easily run evaluation on pretrained models below:

BibTeX entry and citation info

@InProceedings{Lim_2017_CVPR_Workshops,
  author = {Lim, Bee and Son, Sanghyun and Kim, Heewon and Nah, Seungjun and Lee, Kyoung Mu},
  title = {Enhanced Deep Residual Networks for Single Image Super-Resolution},
  booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) Workshops},
  month = {July},
  year = {2017}
}