sharif-apu / BJDD_CVPR21

This is the official implementation of Beyond Joint Demosaicking and Denoising from CVPRW21.
69 stars 20 forks source link

PIPNet training and noise #3

Closed nikopj closed 2 years ago

nikopj commented 3 years ago

In dataTools/customTransform.py, line 13, you have the line

noisyTensor = tensor + torch.randn(tensor.size()).uniform_(0, 1.) * sigma  + self.mean

This looks to be adding uniform random noise (U(0,sigma)) instead of Gaussian random noise (N(0,sigma^2)), as described in the paper (see PyTorch docs). This function is used in dataTools/customDataloader.py (customDatasetReader) which is then used in the main training code (mainModule/BJDD.py, lines 124, 91). Are the numbers reported in the paper derived from this code?

Another question: are the numbers reported in the paper a single model PIPNet model trained over a range of noise-levels, or multiple models trained at each level? If it's a single model, what was the training noise-level range?

Thanks, Nikola

sharif-apu commented 3 years ago

Hi Nikola! Due to implementation constraints, we used an uniform distribution right after the Gaussian distribution. We did it purposefully, thus the sigma can be controlled on the normalized data. However, you may modify that chunk of code as per your requirements. And yes, we used this code to produce all reported results with the same principle.

We used a range of noise (as described in the paper) to train a single model and produced the results accordingly. Please see line 30 of dataTools/customDataloader.py.

nikopj commented 3 years ago

Hi, thanks for the response.

My issue is that torch.Tensor.uniform_() replaces the values in the noise vector with those from a uniform distribution, regardless of what was there before. Your noise is thus not Gaussian. Perhaps I'm missing something, but in any case I feel this was not explained in the paper...

sharif-apu commented 3 years ago

Your speculation is correct. After applying uniform(), the distribution becomes a uniform distribution. Actually, in our initial training, we used OpenCV to read all images and applied Gaussian noise similar to the following link: https://stackoverflow.com/questions/22937589/how-to-add-noise-gaussian-salt-and-pepper-etc-to-image-in-python-with-opencv. However, before making the repo public, we used standard PyTorch APIs for better readability. We found our trained wights can perform similarly with both implementations. It is worth noting, actual sensor noise is substantially different from the synthesized noise. No matter which distribution we used, it won't reflect the performance of any model in the real world. The main goal here is to provide an approximate estimation of model performance. Therefore, you may use both implementations at your convenience.