# BasicSR
**Repository Path**: liuyh9527/BasicSR
## Basic Information
- **Project Name**: BasicSR
- **Description**: Basic Super-Resolution codes for development. Includes ESRGAN, SFT-GAN for training and testing.
- **Primary Language**: Python
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2019-05-18
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# BasicSR [[ESRGAN]](https://github.com/xinntao/ESRGAN) [[SFTGAN]](https://github.com/xinntao/SFTGAN)
:black_square_button: TODO
- [ ] Use *yaml* instead of *json* for configurations
- [ ] Support distributed training
- [ ] Simplify the network structure file
- [ ] Provide new pre-trained models
- [ ] Update the creating lmdb script to add image one by one
:triangular_flag_on_post: Add saving and loading training state. When resuming training, just pass a option with the name `resume_state`, like , `"resume_state": "../experiments/debug_001_RRDB_PSNR_x4_DIV2K/training_state/200.state"`.
:triangular_flag_on_post: Use Python logging, and support PyTorch 1.0
An image super-resolution toolkit flexible for development. It now provides:
1. **PSNR-oriented SR** models (e.g., SRCNN, SRResNet and etc). You can try different architectures, e.g, ResNet Block, ResNeXt Block, Dense Block, Residual Dense Block, Poly Block, Dual Path Block, Squeeze-and-Excitation Block, Residual-in-Residual Dense Block and etc.
2. [**Enhanced SRGAN**](https://github.com/xinntao/ESRGAN) model (It can also train the **SRGAN** model). Enhanced SRGAN achieves consistently better visual quality with more realistic and natural textures than [SRGAN](https://arxiv.org/abs/1609.04802) and won the first place in the [PIRM2018-SR Challenge](https://www.pirm2018.org/PIRM-SR.html). For more details, please refer to [Paper](https://arxiv.org/abs/1809.00219), [ESRGAN repo](https://github.com/xinntao/ESRGAN). (If you just want to test the model, [ESRGAN repo](https://github.com/xinntao/ESRGAN) provides simpler testing codes.)
3. [**SFTGAN**](https://github.com/xinntao/CVPR18-SFTGAN) model. It adopts Spatial Feature Transform (SFT) to effectively incorporate other conditions/priors, like semantic prior for image SR, representing by segmentation probability maps. For more details, please refer to [Papaer](https://arxiv.org/abs/1804.02815), [SFTGAN repo](https://github.com/xinntao/CVPR18-SFTGAN).
### BibTex
@InProceedings{wang2018esrgan,
author = {Wang, Xintao and Yu, Ke and Wu, Shixiang and Gu, Jinjin and Liu, Yihao and Dong, Chao and Qiao, Yu and Loy, Chen Change},
title = {ESRGAN: Enhanced super-resolution generative adversarial networks},
booktitle = {The European Conference on Computer Vision Workshops (ECCVW)},
month = {September},
year = {2018}
}
@InProceedings{wang2018sftgan,
author = {Wang, Xintao and Yu, Ke and Dong, Chao and Loy, Chen Change},
title = {Recovering realistic texture in image super-resolution by deep spatial feature transform},
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2018}
}
## Table of Contents
1. [Dependencies](#dependencies)
1. [Codes](#codes)
1. [Usage](#usage)
1. [Datasets](#datasets)
1. [Pretrained models](#pretrained-models)
### Dependencies
- Python 3 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux))
- [PyTorch >= 0.4.0](https://pytorch.org/)
- NVIDIA GPU + [CUDA](https://developer.nvidia.com/cuda-downloads)
- Python packages: `pip install numpy opencv-python lmdb`
- [option] Python packages: [`pip install tensorboardX`](https://github.com/lanpa/tensorboardX), for visualizing curves.
# Codes
[`./codes`](https://github.com/xinntao/BasicSR/tree/master/codes). We provide a detailed explaination of the **code framework** in [`./codes`](https://github.com/xinntao/BasicSR/tree/master/codes).
We also provides:
1. Some useful scripts. More details in [`./codes/scripts`](https://github.com/xinntao/BasicSR/tree/master/codes/scripts).
1. [Evaluation codes](https://github.com/xinntao/BasicSR/tree/master/metrics), e.g., PSNR/SSIM metric.
1. [Wiki](https://github.com/xinntao/BasicSR/wiki), e.g., How to make high quality gif with full (true) color, Matlab bicubic imresize and etc.
# Usage
### Data and model preparation
The common **SR datasets** can be found in [Datasets](#datasets). Detailed data preparation can be seen in [`codes/data`](https://github.com/xinntao/BasicSR/tree/master/codes/data).
We provide **pretrained models** in [Pretrained models](#pretrained-models).
## How to Test
### Test ESRGAN (SRGAN) models
1. Modify the configuration file `options/test/test_esrgan.json`
1. Run command: `python test.py -opt options/test/test_esrgan.json`
### Test SR models
1. Modify the configuration file `options/test/test_sr.json`
1. Run command: `python test.py -opt options/test/test_sr.json`
### Test SFTGAN models
1. Obtain the segmentation probability maps: `python test_seg.py`
1. Run command: `python test_sftgan.py`
## How to Train
### Train ESRGAN (SRGAN) models
We use a PSNR-oriented pretrained SR model to initialize the parameters for better quality.
1. Prepare datasets, usually the DIV2K dataset. More details are in [`codes/data`](https://github.com/xinntao/BasicSR/tree/master/codes/data) and [wiki (Faster IO speed)](https://github.com/xinntao/BasicSR/wiki/Faster-IO-speed).
1. Prerapre the PSNR-oriented pretrained model. You can use the `RRDB_PSNR_x4.pth` as the pretrained model.
1. Modify the configuration file `options/train/train_esrgan.json`
1. Run command: `python train.py -opt options/train/train_esrgan.json`
### Train SR models
1. Prepare datasets, usually the DIV2K dataset. More details are in [`codes/data`](https://github.com/xinntao/BasicSR/tree/master/codes/data).
1. Modify the configuration file `options/train/train_sr.json`
1. Run command: `python train.py -opt options/train/train_sr.json`
### Train SFTGAN models
*Pretraining is also important*. We use a PSNR-oriented pretrained SR model (trained on DIV2K) to initialize the SFTGAN model.
1. First prepare the segmentation probability maps for training data: run [`test_seg.py`](https://github.com/xinntao/BasicSR/blob/master/codes/test_seg.py). We provide a pretrained segmentation model for 7 outdoor categories in [Pretrained models](#pretrained-models). We use [Xiaoxiao Li's codes](https://github.com/lxx1991/caffe_mpi) to train our segmentation model and transfer it to a PyTorch model.
1. Put the images and segmentation probability maps in a folder as described in [`codes/data`](https://github.com/xinntao/BasicSR/tree/master/codes/data).
1. Transfer the pretrained model parameters to the SFTGAN model.
1. First train with `debug` mode and obtain a saved model.
1. Run [`transfer_params_sft.py`](https://github.com/xinntao/BasicSR/blob/master/codes/scripts/transfer_params_sft.py) to initialize the model.
1. We provide an initialized model named `sft_net_ini.pth` in [Pretrained models](#pretrained-models)
1. Modify the configuration file in `options/train/train_sftgan.json`
1. Run command: `python train.py -opt options/train/train_sftgan.json`
# Datasets
Several common SR datasets are list below.
| Name |
Datasets |
Short Description |
Google Drive |
Baidu Drive |
| Classical SR Training |
T91 |
91 images for training |
Google Drive |
Baidu Drive |
| BSDS200 |
A subset (train) of BSD500 for training |
| General100 |
100 images for training |
| Classical SR Testing |
Set5 |
Set5 test dataset |
| Set14 |
Set14 test dataset |
| BSDS100 |
A subset (test) of BSD500 for testing |
| urban100 |
100 building images for testing (regular structures) |
| manga109 |
109 images of Japanese manga for testing |
| historical |
10 gray LR images without the ground-truth |
| 2K Resolution |
DIV2K |
proposed in NTIRE17(800 train and 100 validation) |
Google Drive |
Baidu Drive |
| Flickr2K |
2650 2K images from Flickr for training |
| DF2K |
A merged training dataset of DIV2K and Flickr2K |
| OST (Outdoor Scenes) |
OST Training |
7 categories images with rich textures |
Google Drive |
Baidu Drive |
| OST300 |
300 test images of outdoor scences |
| PIRM |
PIRM |
PIRM self-val, val, test datasets |
Google Drive |
Baidu Drive |
# Pretrained models
We provide some pretrained models. More details about the pretrained models, please see [`experiments/pretrained_models`](https://github.com/xinntao/BasicSR/tree/master/experiments/pretrained_models).
You can put the downloaded models in the `experiments/pretrained_models` folder.
| Name |
Modeds |
Short Description |
Google Drive |
Baidu Drive |
| ESRGAN |
RRDB_ESRGAN_x4.pth |
final ESRGAN model we used in our paper |
Google Drive |
Baidu Drive |
| RRDB_PSNR_x4.pth |
model with high PSNR performance |
| SFTGAN |
segmentation_OST_bic.pth |
segmentation model |
Google Drive |
Baidu Drive |
| sft_net_ini.pth |
sft_net for initilization |
| sft_net_torch.pth |
SFTGAN Torch version (paper) |
| SFTGAN_bicx4_noBN_OST_bg.pth |
SFTGAN PyTorch version |
| SRGAN*1 |
SRGAN_bicx4_303_505.pth |
SRGAN(with modification) |
Google Drive |
Baidu Drive |
| SRResNet*2 |
SRResNet_bicx4_in3nf64nb16.pth |
SRResNet(with modification) |
Google Drive |
Baidu Drive |
---
## :satisfied: Image Viewer - [HandyViewer](https://github.com/xinntao/HandyViewer)
May try [HandyViewer](https://github.com/xinntao/HandyViewer) - an image viewer that you can switch image with a fixed zoom ratio, easy for comparing image details.
---
## Acknowledgement
- Code architecture is inspired by [pytorch-cyclegan](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix).
- Thanks to *Wai Ho Kwok*, who contributes to the initial version.