Code Monkey home page Code Monkey logo

bsrgan's Introduction

visitors

Kai Zhang, Jingyun Liang, Luc Van Gool, Radu Timofte
Computer Vision Lab, ETH Zurich, Switzerland

[Paper] [Code] [Training Code]

Our new work for real image denoising ---> https://github.com/cszn/SCUNet

Our work is the beginning rather than the end of real image super-resolution.


  • News (2021-08-31): We upload the training code.
  • News (2021-08-24): We upload the BSRGAN degradation model.
from utils import utils_blindsr as blindsr
img_lq, img_hq = blindsr.degradation_bsrgan(img, sf=4, lq_patchsize=72)
  • News (2021-07-23): After rejection by CVPR 2021, our paper is accepted by ICCV 2021. For the sake of fairness, we will not update the trained models in our camera-ready version. However, we may update the trained models in github.
  • News (2021-05-18): Add trained BSRGAN model for scale factor 2.
  • News (2021-04): Our degradation model for face image enhancement: https://github.com/vvictoryuki/BSRGAN_implementation

Training

  1. Download KAIR: git clone https://github.com/cszn/KAIR.git
  2. Put your training high-quality images into trainsets/trainH or set "dataroot_H": "trainsets/trainH"
  3. Train BSRNet
    1. Modify train_bsrgan_x4_psnr.json e.g., "gpu_ids": [0], "dataloader_batch_size": 4
    2. Training with DataParallel
    python main_train_psnr.py --opt options/train_bsrgan_x4_psnr.json
    1. Training with DistributedDataParallel - 4 GPUs
    python -m torch.distributed.launch --nproc_per_node=4 --master_port=1234 main_train_psnr.py --opt options/train_bsrgan_x4_psnr.json  --dist True
  4. Train BSRGAN
    1. Put BSRNet model (e.g., '400000_G.pth') into superresolution/bsrgan_x4_gan/models
    2. Modify train_bsrgan_x4_gan.json e.g., "gpu_ids": [0], "dataloader_batch_size": 4
    3. Training with DataParallel
    python main_train_gan.py --opt options/train_bsrgan_x4_gan.json
    1. Training with DistributedDataParallel - 4 GPUs
    python -m torch.distributed.launch --nproc_per_node=4 --master_port=1234 main_train_gan.py --opt options/train_bsrgan_x4_gan.json  --dist True
  5. Test BSRGAN model 'xxxxxx_E.pth' by modified main_test_bsrgan.py
    1. 'xxxxxx_E.pth' is more stable than 'xxxxxx_G.pth'

Some visual examples: oldphoto2; butterfly; comic; oldphoto3; oldphoto6; comic_01; comic_03; comic_04


Testing code

Main idea

Design a new degradation model to synthesize LR images for training:

  • 1) Make the blur, downsampling and noise more practical
    • Blur: two convolutions with isotropic and anisotropic Gaussian kernels from both the HR space and LR space
    • Downsampling: nearest, bilinear, bicubic, down-up-sampling
    • Noise: Gaussian noise, JPEG compression noise, processed camera sensor noise
  • 2) Degradation shuffle: instead of using the commonly-used blur/downsampling/noise-addition pipeline, we perform randomly shuffled degradations to synthesize LR images

Some notes on the proposed degradation model:

  • The degradation model is mainly designed to synthesize degraded LR images. Its most direct application is to train a deep blind super-resolver with paired LR/HR images. In particular, the degradation model can be performed on a large dataset of HR images to produce unlimited perfectly aligned training images, which typically do not suffer from the limited data issue of laboriously collected paired data and the misalignment issue of unpaired training data.

  • The degradation model tends to be unsuited to model a degraded LR image as it involves too many degradation parameters and also adopts a random shuffle strategy.

  • The degradation model can produce some degradation cases that rarely happen in real-world scenarios, while this can still be expected to improve the generalization ability of the trained deep blind super-resolver.

  • A DNN with large capacity has the ability to handle different degradations via a single model. This has been validated multiple times. For example, DnCNN is able to handle SISR with different scale factors, JPEG compression deblocking with different quality factors and denoising for a wide range of noise levels, while still having a performance comparable to VDSR for SISR. It is worth noting that even when the super-resolver reduces the performance for unrealistic bicubic downsampling, it is still a preferred choice for real SISR.

  • One can conveniently modify the degradation model by changing the degradation parameter settings and adding more reasonable degradation types to improve the practicability for a certain application.

Comparison

These no-reference IQA metrics, i.e., NIQE, NRQM and PI, do not always match perceptual visual quality [1] and the IQA metric should be updated with new SISR methods [2]. We further argue that the IQA metric for SISR should also be updated with new image degradation types, which we leave for future work.

[1] "NTIRE 2020 challenge on real-world image super-resolution: Methods and results." CVPRW, 2020.
[2] "PIPAL: a large-scale image quality assessment dataset for perceptual image restoration." ECCV, 2020.

More visual results on RealSRSet dataset

Left: real images | Right: super-resolved images with scale factor 4

Visual results on DPED dataset

Without using any prior information of DPED dataset for training, our BSRGAN still performs well.

Citation

@inproceedings{zhang2021designing,
    title={Designing a Practical Degradation Model for Deep Blind Image Super-Resolution},
    author={Zhang, Kai and Liang, Jingyun and Van Gool, Luc and Timofte, Radu},
    booktitle={IEEE International Conference on Computer Vision},
    pages={4791--4800},
    year={2021}
}

Acknowledgments

This work was partly supported by the ETH Zurich Fund (OK), a Huawei Technologies Oy (Finland) project, and an Amazon AWS grant.

bsrgan's People

Contributors

airesearch22 avatar cszn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bsrgan's Issues

Can you share 2x model in another form?

Is it possible for you to post the 2x pretrained model in the architecture of your 4x model? Other than that thanks for this great work. Are you thinking about improving the face restoration quality in later projects?

Also I was wondering if you have any experimental models you would like to share for bsrgan without any denoising but with the ability of face restoration,motion blur removal etc? I mean bsrgan model but just without denoise

Model for x2 BSRNet

Thank you for sharing the code and model.

Could you please share the trained model of x2 BSRNet? Thanks

About PSNR value in papers

Hi,
Great works! Is the PSNR from table 1 in papers calculated in RGB space or on the luminance channel in YCbCr color space?

Training details

Hi, great work the results look really good. I had few questions regarding training

  1. How long did you train the BSRNet?
  2. Did you apply the proposed data degradation pipeline on the fly as a data-augmentation technique or you applied it on images beforehand and stored them?

关于模型训练的一些疑问

大佬,有几个问题想请教下:

  1. 如果从头训练,需要准备多少张高清训练样本?(数据主要为电商平台的商品主图)
  2. BSRNET和BSRGAN分别需要训练多少个epoch/iter,训练时长大概是多久?
  3. 为什么要先训练BSRNET再训练BSRGAN?训练BSRGAN的时候只需要导入训好的BSRNET的XXX_G.pth吗?
    麻烦大佬得空的时候解答下,万分感谢!

Run on mobile devices

Thanks for the interesting work. I like to run it on a mobile device in android. Is it possible to do that? I guess we need a .tflite model file?

i can't find path

Hi. I want to train this model with my own data. In one of the steps, it says, "Put BSRNet model (e.g., '400000_G.pth') into superresolution/bsrgan_x4_gan/models." Where are BSRNet model and superresolution/bsrgan_x4_gan located? and How can I do this step?

[Feature Request] Any planning/progress on publishing QualityScaler for Linux?

I like this tool from the looks and general preview a lot and could not find a similar tool for Linux on itch.io so I wanted to ask if there is a progress or starting for Linux? I just own Linux Arch and don't use windows anymore sadly and I don't know how I could upscale images but I want to, I'd like to support the project at patreon or through another subscription because I think there should be more tools like this out there.
Not really an issue but a feature request or question, delete if unwanted

请问LPIPS指标如何计算?

在测试代码以及训练代码KAIA中,暂时没有找到该指标的计算方式,请问您是如何计算的?代码中有计算LPIPS的方法吗?

Question about the utils_blindsr

why did you write the "util.imresize_np" function? Is there a difference between cv2.resize and util.imresize_np?

.....
if sf == 4 and random.random() < scale2_prob: # downsample1
if np.random.rand() < 0.5:
img = cv2.resize(img, (int(1/2img.shape[1]), int(1/2img.shape[0])), interpolation=random.choice([1,2,3]))
else:
img = util.imresize_np(img, 1/2, True)
img = np.clip(img, 0.0, 1.0)
sf = 2
......

Your Results in New Super-Resolution Benchmarks

Hello,

MSU Graphics & Media Lab Video Group has recently launched two new Super-Resolution Benchmarks.

Your method achieved 3rd place in Video Upscalers Benchmark: Quality Enhancement in 'Camera 4x' category. We congratulate you on your result and look forward to your future work!

We would be grateful for your feedback on our work.

Denoising performance of the model

The model can be image denoised while SR, but in some scenarios, details are lost,has this happened during your test?for example
original image
03877
SR image
03877

Tile texture features missing.

UserWarning: Detected call of `lr_scheduler.step()` before `optimizer.step()`. In PyTorch 1.1.0 and later, you should call them in the opposite order: `optimizer.step()` before `lr_scheduler.step()`. Failure to do this will result in PyTorch skipping the first value of the learning rate schedule. See more details at https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate "https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate", UserWarning)

python main_train_psnr.py --opt options/train_bsrgan_x4_psnr.json 运行至model.update_learning_rate(current_step)报上面错误;pytorch版本为1.7.1

简化模型

您好,您的网络模型很好,可以直接使用,想请问您,,是否有量化或者简化后的模型,可以在一般pc机上运行?谢谢

Possible bug in degradation_bsrgan

It is possible that dimensions are permutated in the cropping operation in degradation_bsrgan_plus, degradation_bsrgan functions in 541, 450 lines.

It should be
img = img.copy()[:h1 - h1 % sf, :w1 - w1 % sf, ...] # mod crop
instead of
img = img.copy()[:w1 - w1 % sf, :h1 - h1 % sf, ...] # mod crop

训练过程的问题

您好,请问为什么先训练BSRNet,再训练BSRGAN呢?请问您的训练数据量、参数以及算力资源是怎样的?训练多久?

import ISP model in the degradation model

Hi Kai,
thank you for your great work.
And I want to know how to import the ISP model in the function "degradation_bsrgan_plus(img, sf=4, shuffle_prob=0.5, use_sharp=True, lq_patchsize=64, isp_model=None)" to process the RGB images.
Thank you again for your time and attention.

Replication of BSRGAN results

Dear authors,

I am more than interested in your work and would very much appreciate if you answer the following questions:

  • Have you used the blindsr.degradation_bsrgan script to generate test dataset? I inferenced BSRNet and RRDB from type-I to type-3 (of proposed DIV2K4D) and achieved almost the same results as reported in the paper. However, results on type-4 (generated by abovementioned script) led to significantly worse results: BSRNet 24.40 +- 0.14 dB (over 10 realizations) and RRDB: 22.50 +- 0.14 dB. Metrics are calculated in Y channel.
  • Do you use the same script to generate a training dataset? Also, are the training parameters (learning rate, patch shape (72x72), num. of iterations, etc.) of BSRNet the same as BSRGAN?

Sincerely,
Magauiya

ISP degradation code

Thank you release the degradation model code, will ISP degradation code be published in the future?

3x3 and 5x5 Gaussian kernel sizes?

Hi @cszn,

Great work on the paper, the results are really fascinating.

Is there any reason why you haven't included 3x3 and 5x5 Gaussian blur kernels? They seem to be pretty standard so I was wondering why they aren't included.

My line of reasoning is that including them could expand the augmentation space and thus help with generalization.

如何制作自己的训练集

from utils import utils_blindsr as blindsr
img_lq, img_hq = blindsr.degradation_bsrgan(img, sf=4, lq_patchsize=72)

但是报错,这这这咋办
h1, w1 = img.shape[:2]
AttributeError: 'str' object has no attribute 'shape'

What does 'axis length' mean?

As section 3.1 of your paper said, the length of each axis for scale factors 2 and 4 uniformly from [0.5, 6] and [0.5, 8], respectively. However, I am not sure what does that mean. In my understanding, gaussian kernel needs only 1. kernel size, 2. eigen-vals, and 3. rotation angle.

I will appreciate it if you can reply at any time you are available.
Thank you!

pretrained_netE 和pretrained_netD的关系

请问pretrained_netE 和pretrained_netD是同一个东西吗? 我填写如下 是否有问题
"root": "superresolution" // "denoising" | "superresolution"
, "pretrained_netG": "bsrgan_x4_gan/models/BSRNet.pth" // path of pretrained model
, "pretrained_netD": "bsrgan_x4_gan/models/vgg19-dcbb9e9d.pth" // path of pretrained model
, "pretrained_netE": "bsrgan_x4_gan/models/vgg19-dcbb9e9d.pth" // path of pretrained model

Paper

would you mind sharing the paper?

0.2 multiplier in RRDB output

I only wanted to know why do you multiply times 0.2 the output of the redo's single blocks and entire block.

What is the reasoning? the advantages? How did you arrived at this solution?

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.