README.md 5.82 KB
Newer Older
Mano Brabant's avatar
Mano Brabant committed
1
2
# DnCNN-PyTorch
A PyTorch implement of the TIP2017 paper [Beyond a Gaussian Denoiser: Residual Learning of Deep CNN for Image Denoising](http://www4.comp.polyu.edu.hk/~cslzhang/paper/DnCNN.pdf)
Marie Tahon's avatar
Marie Tahon committed
3
This project aims at automatically denoising phase images using a CNN residual filter.
Marie Tahon's avatar
Marie Tahon committed
4
5


Mano Brabant's avatar
Mano Brabant committed
6
## Prerequisites TODO
Marie Tahon's avatar
Marie Tahon committed
7
This project needs the following python3 packages
Marie Tahon's avatar
Marie Tahon committed
8
```
Marie Tahon's avatar
Marie Tahon committed
9
pip3 install arparse pathlib os sys PIL numpy scipy
Marie Tahon's avatar
Marie Tahon committed
10
```
Mano Brabant's avatar
Mano Brabant committed
11
PyTorch == 1.7.1
Marie Tahon's avatar
Marie Tahon committed
12

Marie Tahon's avatar
Marie Tahon committed
13
## Parameters
Mano Brabant's avatar
Mano Brabant committed
14
15
Modifiable parameters are located in argument.py

Marie Tahon's avatar
Marie Tahon committed
16

Marie Tahon's avatar
Marie Tahon committed
17
## Localization of data and generation of patches
Marie Tahon's avatar
update    
Marie Tahon committed
18
19
Data is either .tiff images or .mat MATLAB matrices. Three databases are available for the moment:
* HOLODEEPmat: MATLAB images for training and development purposes: 5 patterns and 5 noise level, 1024x1024
Mano Brabant's avatar
Mano Brabant committed
20
* DATAEVAL: 3 MATLAB images for evaluation purposes: Data1, Data20 and VibMap.
Marie Tahon's avatar
update    
Marie Tahon committed
21
* NATURAL: 400 images in B&W for image denoising, noisy images are obtained with additive Gaussian noise: 180x180
22
23


Mano Brabant's avatar
Mano Brabant committed
24
25
26
Clean reference data is located in argument.clean_src_dir
Noisy input data is located in argument.noisy_src_dir
Images from HOLODEEP are referred by their name according to their pattern number (argument.train_patterns from 1 to 5), their noise level (hparams.train_noises 0, 1, 1.5, 2 or 2.5). Images for train and developpement (or test) and final evaluation (eval) are given by "train", "test" or "eval" suffix.
Marie Tahon's avatar
Marie Tahon committed
27

Marie Tahon's avatar
update    
Marie Tahon committed
28
All phase data is converted using sine or cosine functions and normalized between 0 and 1 for being in agreement with the output of the network. A propotional coefficient is applied on the predicted image to rescale the pahse amplitude between -pi and pi.
Marie Tahon's avatar
Marie Tahon committed
29

Marie Tahon's avatar
Marie Tahon committed
30
Patch size can be given as an argument in the command line either if images .tiff are all in the same directory, or if the .mat files are given in seperated directories. 
Marie Tahon's avatar
Marie Tahon committed
31
```
Mano Brabant's avatar
Mano Brabant committed
32
33
python3 generate_patches_holo.py --patch_size 100
python3 generate_patches_holo_fromMat.py --patch_size 100
Marie Tahon's avatar
Marie Tahon committed
34
```
Marie Tahon's avatar
Marie Tahon committed
35
This command generates two numpy matrices of size (nb_patch, patch_size, patch_size,1) one for noisy images, the other for clean references.
Marie Tahon's avatar
Marie Tahon committed
36
37


Mano Brabant's avatar
Mano Brabant committed
38
39
40
## Manual
You have to manualy download the holography database and put it in the directory.
The database can be found on skinner /info/etu/m1/s171085/Projets/Portage-Keras-PyTorch/Portage-reseau-de-neurones-de-Keras-vers-PyTorch/dncnn-tensorflow-holography-master/Holography (a new link will be available later)
Marie Tahon's avatar
Marie Tahon committed
41

Mano Brabant's avatar
Mano Brabant committed
42
43
44
45
46
47
The application can be used with the main_holo.py script with different arguments from the argument.py script
To start a training with default param you can use the command
```
#launch a training
python3 main_holo.py
```
Marie Tahon's avatar
Marie Tahon committed
48

Mano Brabant's avatar
Mano Brabant committed
49
50
You can precise the training and eval data with the arguments noisy_train, clean_train, noisy_eval and clean_eval
The usable data are generated with the generate_patches_holo.py and generate_patches_holo_fromMAT.py scripts and saved in a directory named "data1".
Marie Tahon's avatar
Marie Tahon committed
51
```
Mano Brabant's avatar
Mano Brabant committed
52
53
#launch a training with the following data
python3 main_holo.py --noisy_train data1/img_noisy_train_1-2-3-4-5_0-1-1.5-2-2.5_two_50_50_384.npy --clean_train data1/img_clean_train_1-2-3-4-5_0-1-1.5-2-2.5_two_50_50_384.npy --noisy_eval data1/img_noisy_train_1-2-3-4-5_0-1-1.5-2-2.5_two_50_50_384.npy --clean_eval data1/img_clean_train_1-2-3-4-5_0-1-1.5-2-2.5_two_50_50_384.npy
Marie Tahon's avatar
Marie Tahon committed
54
```
Marie Tahon's avatar
Marie Tahon committed
55

Mano Brabant's avatar
Mano Brabant committed
56
57
58
59
You can also precise the different hyperparameter for the training
num_epoch is the number of epoch the model will train
D is the number of res block
C is the kernel size for convolutional layer (not tested)
Marie Tahon's avatar
Marie Tahon committed
60
```
Mano Brabant's avatar
Mano Brabant committed
61
62
#launch a training with the following params
python3 main_holo.py --num_epoch 500 --D 16 --C 32
Marie Tahon's avatar
Marie Tahon committed
63
```
Marie Tahon's avatar
Marie Tahon committed
64

Mano Brabant's avatar
Mano Brabant committed
65
66
67
68
For data adapation you have to give the size and the number of channel of the image you will be using in the argument image_size and image_mode (for training or testing).
```
#launch a training in which the image will be 50 by 50 in black and white
python3 main_holo.py --image_size 50 50 --image_mode 1
Marie Tahon's avatar
Marie Tahon committed
69
```
Marie Tahon's avatar
update    
Marie Tahon committed
70

Mano Brabant's avatar
Mano Brabant committed
71
72
73
74
75
76
77
78
79
80
81
82
83
The arguments input_dir and epoch are used for re-training and de-noising operation.
In input_dir give the path to the model you want to use, and in epoch give the number from which you want to re-train or do a de-noising operation.
The model are saved in a directory named "PyTorchExperiments"
```
#re launch a training strating from the model experiment_xxx at the epoch 130 
python3 main_holo.py --input_dir PyTorchExperiments/experiment_xxx --epoch 130
```

To do a de-noising operation you can use the test_mode argument.
You can use the argument test_noisy_img, test_noisy_key, test_clean_img and test_clean_key to precise which image you want to de-noise
```
#launch a denoising operation on the image DATA_1_Phase_Type1_2_0.25_1.5_4_50.mat with the model experiment_xxx at the epoch 130
python3 main_holo.py --test_mode --test_noisy_img Holography/DATAEVAL/DATAEVAL/DATA_1_Phase_Type1_2_0.25_1.5_4_50.mat --test_noisy_key 'Phaseb' --test_clean_img Holography/DATAEVAL/DATAEVAL/DATA_1_Phase_Type1_2_0.25_1.5_4_50.mat --test_clean_key 'Phase' --input_dir PyTorchExperiments/experiment_xxx --epoch 130
Marie Tahon's avatar
Marie Tahon committed
84
85
```

Mano Brabant's avatar
Mano Brabant committed
86
If you do not give an image to de-noise an evaluation of the entire training and testing database you start.
Marie Tahon's avatar
Marie Tahon committed
87
```
Mano Brabant's avatar
Mano Brabant committed
88
89
#launch a denoising operation on the 25 images of Holography/DATABASE and Holography/DATAEVAL/DATAEVAL database with the model experiment_xxx at the epoch 130
python3 main_holo.py --test_mode --input_dir PyTorchExperiments/experiment_xxx --epoch 130
Marie Tahon's avatar
Marie Tahon committed
90
91
```

Mano Brabant's avatar
Mano Brabant committed
92
The results of those de-noising operation can be found in a TestImages directory
Mano Brabant's avatar
Mano Brabant committed
93
94
95
96
97
98
99

## Results
Results obtained with different configurations. Values are given in terms of Phase STD
Durations are given in Day-Hours:Min:Sec with one GPU.
```
                                                                                        | PATTERNS 1-5 || TEST DATA
Epochs |   lr   | train patterns |   train noise   | nb batches   | layers |  duration  | MOY          || DATA1 | DATA20 | VibMap ||
Mano Brabant's avatar
Mano Brabant committed
100
3      | 0.0010 |  [1-2-3-4-5]   | [0,1,1.5,2,2.5] |   384        |   16   | 0-00:27:47 | 0.036        || 0.065 | 0.606  | 0.131  ||
Mano Brabant's avatar
Mano Brabant committed
101
```