Giter Club home page Giter Club logo

pd-denoising-pytorch's Introduction




PD-Denoising

This is the official pytorch implementation of the paper 'When AWGN-based Denoiser Meets Real Noises', and parts of the code are initialized from the pytorch implementation of DnCNN-pytorch. We revised the basis model structure and data generation process, and rewrote the testing procedure to make it work for real noisy images. More details can be found in the code implementation.

Abstract

Discriminative learning based image denoisers have achieved promising performance on synthetic noise such as the additive Gaussian noise. However, their performance on images with real noise is often not satisfactory. The main reason is that real noises are mostly spatially/channel-correlated and spatial/channel-variant. In contrast, the synthetic Additive White Gaussian Noise (AWGN) adopted in most previous work is pixel-independent. In this paper, we propose a novel approach to boost the performance of a real image denoiser which is trained only with synthetic pixel-independent noise data. First, we train a deep model that consists of a noise estimator and a denoiser with mixed AWGN and Random Value Impulse Noise (RVIN). We then investigate Pixel-shuffle Down-sampling (PD) strategy to adapt the trained model to real noises. Extensive experiments demonstrate the effectiveness and generalization ability of the proposed approach. Notably, our method achieves state-of-the-art performance on real sRGB images in the DND benchmark.

Basis Model + PD Adaptation

Basis Model

The proposed blind denoising model G consists of a noise estimator E and a follow-up non-blind denoiser R. It is trained on AWGN and RVIN. It can achieve the disentanglement of the two noises as shown.

PD Adaptation

The proposed Pixel-shuffle Down-sampling (PD) refinement strategy: (1) Compute the smallest stride s, which is 2 in this example and more CCD image cases, to match AWGN following the adaptation process, and pixel-shuffle the image into mosaic y_s; (2) Denoise y_s using G; (3) Refill each sub-image with noisy blocks separately and inversely pixel-shuffle them; (4) Denoise each refilled image again using G and average them to obtain the texture details T; (5) Combine the over-smoothed flat regions F to refine the final result.

Denoising Performance on Real Images

RNI15

DND Benchmark

Self-collected Night Photos

Comparisons with state-of-the-arts

We follow the submission guideline of DND benchmark to achieve the following results.

Requirements and Dependencies

Citation

If you think our model and code useful, please cite

@article{zhou2019awgn,
  title={When AWGN-based Denoiser Meets Real Noises},
  author={Zhou, Yuqian and Jiao, Jianbo and Huang, Haibin and Wang, Yang and Wang, Jue and Shi, Honghui and Huang, Thomas},
  journal={arXiv preprint arXiv:1904.03485},
  year={2019}
}

Train

Data Preparation

  • Please follow DnCNN-pytorch to generate training data of gray image model.
  • For color images, you can save your images inside the train_c folder and process it to train_c.h5 by setting preprocess=1. In the paper, we used CBSD(500-68) as the training data set. Training data can be downloaded here
  • If you've already built the training and validation dataset (i.e. train.h5 & val.h5 files), set preprocess to be False.

Train the Baseline Model

The baseline model is the one without explicit noise estimation. We directly trained the model with AWGN, RVIN and mixed-AWGN-RVIN.

python train.py \
  --preprocess 1\
  --num_of_layers 20\
  --mode B\
  --color 0\
  --outf logs/baseline_model

Train the Basis Model with Noise Estimation

python train.py \
  --preprocess 1\
  --num_of_layers 20 \
  --mode MC\
  --color 0\
  --outf logs/gray_MC_model

You can also directly run

bash run_train.sh

NOTE

  • For color version, directly set the color option to 1, and change the output folder name.
  • The layer number of estimation model is default 3.

Test the Pretrained Model on Patches

We provide the pretrained model saved in the logs folder. To replicate the denoising results on real images in DND benchmark and other real images, simply run

python test.py\
 --scale 1\
 --ps 2 --ps_scale 2\
 --real 1\
 --k 0\
 --mode MC\
 --color 1\
 --output_map 0\
 --zeroout 0 --keep_ind 0\
 --num_of_layers 20\
 --delog logs/logs_color_MC_AWGN_RVIN\
 --cond 1 --refine 0 --refine_opt 1\
 --test_data real_night\
 --out_dir results/real_night

or simiply run,

bash run_test_on_real_patches.sh

NOTE

  • test_data can be changed to other folder name with your own data.
  • ps can be set to 1 to get the adaptive pixel-shuffle stride (ps_scale is computed by algorithm in this case). For CCD camera images, it is better to set ps=2(meaning manually setting the ps_scale) and ps_scale=2.
  • k can be interactively adjusted to balance the details and background, providing a flexibile denoising performance. k=1 for more focusing on flat regions to get a very smoothed results, and k=0 for obtaining more textural details (default).
  • Testing on patch will ensure there is no boundary artifacts, but may cause out-of-memory issues on GPU while testing it on large-scale images.

Test the Pretrained Model on Full-image

For large-scale testing images (>1k), simply run

python Demo_on_full_image.py\
 --scale 1\
 --wbin 512\
 --ps 2 --ps_scale 2\
 --real 1\
 --k 0\
 --mode MC\
 --color 1\
 --output_map 0\
 --zeroout 0 --keep_ind 0\
 --num_of_layers 20\
 --delog logs/logs_color_MC_AWGN_RVIN\
 --cond 1 --refine 0 --refine_opt 1\
 --test_data beijing\
 --out_dir results/beijing

or simiply run,

bash run_test_on_full_images.sh

NOTE

  • test_data can be changed to other folder name with your own data.
  • ps can be set to 1 to get the adaptive pixel-shuffle stride (ps_scale is computed by algorithm in this case). For CCD camera images, it is better to set ps=2(meaning manually setting the ps_scale) and ps_scale=2.
  • k can be interactively adjusted to balance the details and background, providing a flexibile denoising performance. k=1 for more focusing on flat regions to get a very smoothed results, and k=0 for obtaining more textural details (default).
  • wbin is the cropped window size for denoising (defaultly set to 512). One can adjust this value to 300 or 256 to ensure there is no out-of-memory issues. But it will both decrease the efficiency and may cause boundary artifacts.
  • To ensure the uniform effect of the whole images, we assume all the patches share the same denoisng settings.
  • We provide the self-collected beijing dataset for evaluation.

Embeded PD idea to Existing Denoisers

PD methods can be embedded into other deep learning based AWGN-trained denoiser, or other traditional denoising methds. It will further improve the performance of them. The codes (pytorch and matlab) will be released soon.

Acknowledgments

Code borrows from DnCNN-pytorch.

pd-denoising-pytorch's People

Contributors

yzhouas 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

pd-denoising-pytorch's Issues

Test on Pretrained model got diferent results with paper's

I want to verify the results in Table 2 of paper, so i want to know the parameters in test.py.
my settings for the model, logs_color_MC_AWGN_RVIN, are
python test.py --scale 1 --ps 2 --ps_scale 2 --real_n 0 --spat_n 1 --k 0 --mode MC --color 1 --output_map 0 --zeroout 0 --keep_ind 0 --num_of_layers 20 --delog logs/logs_color_MC_AWGN_RVIN --cond 1 --refine 0 --refine_opt 1 --test_data CBSD68 --out_dir results/CBSD68
my result is 29.1037 when s=20 and c=10

for cpu

can you please let me know how to test the model on cpu because it asks for a gpu everytime i run the script

PD refinement strategy

Hi, I have read your paper. It' cool to use this pd denoiser. But I cannot understand the edffect of the 3,4 step, you just use this and say these steps can get the texture regions. Can you explain the effect of 3,4 step. Thanks

On the problem of no image generation.

I ran test.py without reporting an error. I set it exactly as the README says. It is normal to read the model and pictures, but only the result saving path is generated, but there is no picture generated in the path. Can you tell me what is the reason?

Validation in training loop - dimensionality problems

Hi! I uncommented the "eval" part in the training loop, and want to use it for validation during training (with color images).
However, I get one of two errors:

Because of the line:
noise_map_val = np.zeros((1, 2*c, img_w, img_h))

In the code
image
The marked line causes a dimension error, as it tries to input a 3 channel image into a 6 channel tensor (as defined above with 2*c).

Otherwise, if I change the above line to
noise_map_val = np.zeros((1, 1*c, img_w, img_h))

The line
out_val_nb = torch.clamp( imgn_val - model(imgn_val, NM_tensor_val), 0., 1.)
Fails, because NM_tensor val has 3 channels and not 6.

What is the right way to input 6 channels into the generated noise map from 3 channels?

Thanks,
Tom

CUDA out of memory

I realize that:

"This version of testing script may cause exceeding memory issues in GPU while testing on large images. A testing_on_full image version will be released soon."

But I encountered this issue on an 8GB RTX 2070 on ubuntu 18.04 while trying run_test_on_real_patches.sh

I can confirm that it runs just fine when I resize the provided sample images to 300x300px.

Does this seem right? Will a new version of the script solve this problem? Any idea how soon that might be released?

Thanks!

bugs while using k>0 and pre-set stride mode(ps=2)

Hi,

Thanks for your great work on the real-world denoising!
It gives me lots of intuitions.

It's a simple bug while using non-zero k and pre-set stride mode(ps=2).
The oversmoothed image does not be reverse pixel-shuffled.

I think the problem on the N173 in test.py
: max_out_numpy = visual_va2np(max_Out, opt.color, opt.ps, pss, 1, opt.rescale, w, h, c)

I changed it to:
max_out_numpy = visual_va2np(max_Out, opt.color, opt.ps==1 or opt.ps==2, pss, 1, opt.rescale, w, h, c)

Is this right modification for your intend?

Thank you

differences between the proposed base model and the CBDNet?

Hi,
In Figure 3, the basic model is very similar to the CBDNet architecture, but in Table 3 there is a big gap of the PSNR values between CBDNet and "our basic model". I want to know what difference causes this phenomenon. Can you help me find some clues?

Thanks!

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.