Commit a9b51b74 authored by Noury Robin's avatar Noury Robin
Browse files

Version initiale Robin NOURY

parent 916aa980
This diff is collapsed.
......@@ -36,9 +36,10 @@ __status__ = "Production"
# Default hyperparameters:
hparams = tf.contrib.training.HParams(
#to train on HOLODEEP tiff images
noise_src_dir = '/lium/raid01_c/tahon/holography/HOLODEEP/',
clean_src_dir = '/lium/raid01_c/tahon/holography/NOISEFREEHOLODEEP/',
eval_dir = '/lium/raid01_c/tahon/holography/HOLODEEPmat/',
noise_src_dir = '/info/etu/slbm/e161513/dncnn-tensorflow-holography/DB_Train2/',
clean_src_dir = '/info/etu/slbm/e161513/dncnn-tensorflow-holography/DB_Train2/',
eval_dir = '/info/etu/slbm/e161513/dncnn-tensorflow-holography/HOLODEEPmat/',
train_dir='/info/etu/slbm/e161513/dncnn-tensorflow-holography/DB_Train2/',
#to train on matlab images
#eval_dir = '/lium/raid01_c/tahon/holography/HOLODEEPmat/',
#to train on natural images
......@@ -52,14 +53,14 @@ hparams = tf.contrib.training.HParams(
originalsize = (1024,1024), #1024 for matlab database, 128 for holodeep database, 180 for natural images
phase_type = 'two', #keep phase between -pi and pi (phi), convert into cosinus (cos) or sinus (sin)
#select images for training
train_patterns = [1, 2, 3, 4, 5], #number of images from 1 to 5
train_noise = '0', #[0, 1, 1.5, 2, 2.5],
train_patterns = [1, 2, 3, 4, 5,6,7], #number of images from 1 to 5
train_noise = '1-1.5-2-2.5-3', # [0.5, 1, 1.5, 2, 2.5,3],
#select images for evaluation (during training)
eval_patterns = [1, 2, 3, 4, 5],
eval_patterns = [1, 2, 3, 4, 5],
eval_noise = '0-1-1.5-2-2.5',
#select images for testing
test_patterns = [1, 2, 3, 4, 5],
test_noise = '0-1-1.5-2-2.5',
test_noise = '0.5-1-1.5-2-2.5-3',
noise_type = 'spkl', #type of noise: speckle or gaussian (spkl|gauss)
sigma = 25, #noise level for gaussian denoising
......
......@@ -104,7 +104,7 @@ class denoiser(object):
psnr_sum = 0
dev_sum = 0
clean_ref = test_data[0].copy() #between -pi and pi
fres.write('clean ref for evaluation max %.2f; min %.2f\n' %(np.max(clean_ref), np.min(clean_ref)))
fres.write('clean ref for evaluation max %.5f; min %.5f\n' %(np.max(clean_ref), np.min(clean_ref)))
print('clean ref eval', np.max(clean_ref), np.min(clean_ref))
noisy_ref = test_data[1].copy()
for idx in range(len(clean_ref)):
......@@ -129,11 +129,11 @@ class denoiser(object):
clean_pred_rad = np.angle(clean_pred_cos + clean_pred_sin * 1j) #phase obtained between -pi and pi
#old version where noisy X is generated by adding gaussian noise to Y_
#output_clean_image, noisy_image, psnr_summary = self.sess.run([self.Y, self.X, summary_merged], feed_dict={self.Y_: clean_image, self.is_training: False})
fres.write('std phase between clean and noisy ref: %.2f\n' %(cal_std_phase(clean_ref_rad, noisy_ref_rad)))
fres.write('std phase between clean and noisy ref: %.5f\n' %(cal_std_phase(clean_ref_rad, noisy_ref_rad)))
print('clean ref radian:', np.max(clean_ref_rad), np.min(clean_ref_rad))
fres.write('clean ref radians: %.2f %.2f\n' %(np.max(clean_ref_rad), np.min(clean_ref_rad)))
fres.write('clean ref radians: %.5f %.5f\n' %(np.max(clean_ref_rad), np.min(clean_ref_rad)))
print('clean pred rad', np.max(clean_pred_rad), np.min(clean_pred_rad))
fres.write('clean pred rad: %.2f %.2f\n' %(np.max(clean_pred_rad), np.min(clean_pred_rad)))
fres.write('clean pred rad: %.5f %.5f\n' %(np.max(clean_pred_rad), np.min(clean_pred_rad)))
#groundtruth = np.clip(255 * clean_ref_phi, 0, 255).astype('uint8')
#noisyimage = np.clip(255* noisy_ref_phi, 0, 255).astype('uint8')
#outputimage = np.clip(255 * clean_pred_phi, 0, 255).astype('uint8')
......@@ -142,19 +142,19 @@ class denoiser(object):
psnr = cal_psnr(clean_ref_rad, clean_pred_rad)
# calculate std on phase
dev = cal_std_phase(clean_ref_rad, clean_pred_rad)
fres.write("img%d PSNR: %.2f, STD: %.2f\n" % (idx + 1, psnr, dev))
print("img%d PSNR: %.2f, STD: %.2f" % (idx + 1, psnr, dev))
fres.write("img%d PSNR: %.5f, STD: %.5f\n" % (idx + 1, psnr, dev))
print("img%d PSNR: %.5f, STD: %.5f" % (idx + 1, psnr, dev))
psnr_sum += psnr
dev_sum += dev
if idx < 10:
save_images(os.path.join(sample_dir, 'test%d_%d.tiff' % (idx + 1, iter_num)), clean_ref_rad, noisy_ref_rad, clean_pred_rad)
avg_psnr = psnr_sum / len(clean_ref)
avg_dev = dev_sum / len(clean_ref)
fres.write("--- Test ---- Average PSNR %.2f ---\n" % avg_psnr)
fres.write("--- Test ---- Average STD %.2f ---\n" % avg_dev)
fres.write("--- Test ---- Average PSNR %.5f ---\n" % avg_psnr)
fres.write("--- Test ---- Average STD %.5f ---\n" % avg_dev)
fres.close()
print("--- Test ---- Average PSNR %.2f ---" % avg_psnr)
print("--- Test ---- Average STD %.2f ---" % avg_dev)
print("--- Test ---- Average PSNR %.5f ---" % avg_psnr)
print("--- Test ---- Average STD %.5f ---" % avg_dev)
def denoise(self, data):
data_clean = data[0]
......@@ -165,7 +165,7 @@ class denoiser(object):
clean_pred, psnr = self.sess.run([self.Y, self.eva_psnr], feed_dict={self.Y_: data_clean, self.X: data_noisy, self.is_training: False})
return output_clean_image, noisy_image, psnr
def train(self, data, eval_data, batch_size, ckpt_dir, epoch, lr, sample_dir, phase_type, nb_layers, eval_every_epoch=5):
def train(self, data, eval_data, batch_size, ckpt_dir, epoch, lr, sample_dir, phase_type, nb_layers, eval_every_epoch=3):
phase_augmentation = True
#ckpt_dir_ = ckpt_dir
sess_name = 'run-test' + str(datetime.now()).replace(' ', '_')
......@@ -249,7 +249,7 @@ class denoiser(object):
fres = open(sample_dir + '/res', 'a')
batch_images_clean = data_clean[batch_id * batch_size:(batch_id + 1) * batch_size, :, :, :]
batch_images_noisy = data_noisy[batch_id * batch_size:(batch_id + 1) * batch_size, :, :, :]
fres.write('max/min train: %.2f %.2f (clean), %.2f %.2f (noisy)\n' %(np.max(batch_images_clean), np.min(batch_images_clean), np.max(batch_images_noisy), np.min(batch_images_noisy)))
fres.write('max/min train: %.5f %.5f (clean), %.5f %.5f (noisy)\n' %(np.max(batch_images_clean), np.min(batch_images_clean), np.max(batch_images_noisy), np.min(batch_images_noisy)))
# batch_images = batch_images.astype(np.float32) / 255.0 # normalize the data to 0-1
_, loss, summary = self.sess.run([self.train_op, self.loss, merged], feed_dict={self.X: batch_images_noisy, self.Y_: batch_images_clean, self.lr: lr[epoch], self.is_training: True})
fres.write("Epoch: [%2d] [%4d/%4d] time: %4.4f, loss: %.6f\n"% (epoch + 1, batch_id + 1, numBatch, time.time() - start_time, loss))
......@@ -361,8 +361,8 @@ class denoiser(object):
psnr = cal_psnr(clean_ref_rad, clean_pred_rad)
# calculate std on phase
dev = cal_std_phase(clean_ref_rad, clean_pred_rad)
ftest.write("test img PSNR: %.3f, STD: %.3f\n" % (psnr, dev))
print("test img %s PSNR: %.3f, STD: %.3f" % (save_name, psnr, dev))
ftest.write("test img PSNR: %.5f, STD: %.5f\n" % (psnr, dev))
print("test img %s PSNR: %.5f, STD: %.5f" % (save_name, psnr, dev))
save_images(os.path.join(save_dir, '%s.tiff' % (save_name + '-' + str(global_step))), clean_pred_rad)
save_MAT_images(os.path.join(save_dir, '%s.mat' %(save_name + '-' + str(global_step))), clean_pred_rad)
ftest.close()
......
File mode changed from 100644 to 100755
import numpy as np
import sys
import re
epochPattern = re.compile(r'^Epoch: \[(.*)\] \[')
sessName = sys.argv[1]
imStd = {}
imPsnr = {}
nepochs = 0
imEpoch = []
with open(sessName) as f:
for line in f:
#im = 'img' + str(i)
m = epochPattern.match(line)
if m:
nepochs = m.group(1)
for i in range(1,36):
pattern = re.compile(r'img' + str(i) + ' ')
if pattern.search(line):
if i == 1:
imEpoch.append(nepochs)
tab = line.split(' ')
std_ = float(tab[4])
psnr_ = float(tab[2][:-2])
# print(i, std_, psnr_)
if i in imStd:
imStd[i].append(std_)
imPsnr[i].append(psnr_)
else:
imStd[i] = [std_]
imPsnr[i] = [psnr_]
# else:#if image imgi is not find
# sys.exit('this image is not find check res file: img' + str(i))
#print(imEpoch)
noise = {1.0: [1, 6, 11, 16, 21, 26, 31],
1.5: [2, 7, 12, 17, 22, 27, 32],
2.0: [3, 8, 13, 18, 23, 28, 33],
2.5: [4, 9, 14, 19, 24, 29, 34],
3.0: [5, 10, 15, 20, 25, 30, 35]}
stdt = np.array([imStd[i] for i in range(1,36)]).mean(axis=0)
psnrt = np.array([imPsnr[i] for i in range(1, 36)]).mean(axis=0)
minEpoch = np.argmin(stdt)
print('NumEpochs:', imEpoch[-1])
print('BestEpoch ', imEpoch[minEpoch])
x_avg = 'avg %.3f %.3f' %(stdt[minEpoch], psnrt[minEpoch])
print(x_avg.replace('.',','))
for n in noise:
stdn = np.array([imStd[i] for i in noise[n]]).mean(axis=0)
psnrn = np.array([imPsnr[i] for i in noise[n]]).mean(axis=0)
#print(stdn.shape)
#print(stdn)
#minEpoch = np.argmin(stdn)
x = '%.1f %.3f %.3f' %(n, stdn[minEpoch], psnrn[minEpoch])
print(x.replace('.',','))
......@@ -2,30 +2,37 @@
#SBATCH -p gpu
#SBATCH --gres gpu:1
#SBATCH --mem 40G
#SBATCH --mail-type=ALL
#SBATCH --mail-user=robin.noury.etu@univ-lemans.fr
#SBATCH -o test_debruitage.out
#SBATCH --time 20-00
#noisyImg=$1
#cleanImg=$2
#runTest=/lium/raid01_c/tahon/holography/checkpoints/run-test2020-04-12_12\:14\:29.082341/
runTest=$1
for num in 1 2 3 4 5; do
for lambda in 0 1 1p5 2 2p5; do
noisyImg=/lium/raid01_c/tahon/holography/HOLODEEPmat/PATTERN$num/MFH_$lambda/NoisyPhase.mat
for lambda in 0 1 1.5 2 2.5 ; do
noisyImg=./HOLODEEPmat/Pattern$num/MFH_$lambda/NoisyPhase.mat
#noisyImg=/lium/raid01_c/tahon/holography/HOLODEEPmat/PATTERN$num/MFH_$lambda/run-test2020-04-12_12\:14\:29.082341/run-test2020-04-12_12\:14\:29.082341/NoisyPhase.mat-27000.mat-27000.mat
cleanImg=/lium/raid01_c/tahon/holography/HOLODEEPmat/PATTERN$num/PhaseDATA.mat
echo $noisyImg >> DL-Py6-epoch.res
python main_holo.py --test_noisy_img $noisyImg --test_noisy_key 'NoisyPhase' --test_clean_img $cleanImg --test_clean_key 'Phase' --test_flip False --test_ckpt_index $runTest --params "phase=test, lr=0.001, train_noise=0, nb_layers=4" >> DL-Py6-epoch.res
cleanImg=./HOLODEEPmat/Pattern$num/PhaseDATA.mat
echo $noisyImg >> TEST-TRAIN_1.res
python main_holo.py --test_noisy_img $noisyImg --test_noisy_key 'NoisyPhase' --test_clean_img $cleanImg --test_clean_key 'Phase' --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
done
done
test1=/lium/raid01_c/tahon/holography/DATAEVAL/DATA_1_Phase_Type1_2_0.25_1.5_4_50.mat
test2=/lium/raid01_c/tahon/holography/DATAEVAL/DATA_20_Phase_Type4_2_0.25_2.5_4_100.mat
test3=/lium/raid01_c/tahon/holography/DATAEVAL/VibPhaseDATA_masked.mat
test1=./DATAEVAL/DATA_1_Phase_Type1_2_0.25_1.5_4_50.mat
test2=./DATAEVAL/DATA_20_Phase_Type4_2_0.25_2.5_4_100.mat
test3=./DATAEVAL/VibPhaseDATA.mat
test4=./Base_exp_test_double_impact/Temps_200/NoisyPhase.mat
keyNoisy='Phaseb'
keyClean='Phase'
echo $test1
python main_holo.py --test_noisy_img $test1 --test_noisy_key $keyNoisy --test_clean_img $test1 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest --params "phase=test, lr=0.0001, train_noise=0-1-1.5, nb_layers=4" >> DL-Py6-epoch.res
python main_holo.py --test_noisy_img $test1 --test_noisy_key $keyNoisy --test_clean_img $test1 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
echo $test2
python main_holo.py --test_noisy_img $test2 --test_noisy_key $keyNoisy --test_clean_img $test2 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest --params "phase=test, lr=0.0001, train_noise=0-1-1.5, nb_layers=4" >> DL-Py6-epoch.res
python main_holo.py --test_noisy_img $test2 --test_noisy_key $keyNoisy --test_clean_img $test2 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
echo $test3
python main_holo.py --test_noisy_img $test3 --test_noisy_key $keyNoisy --test_clean_img $test3 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest --params "phase=test, lr=0.0001, train_noise=0-1-1.5, nb_layers=4" >> DL-Py6-epoch.res
python main_holo.py --test_noisy_img $test3 --test_noisy_key $keyNoisy --test_clean_img $test3 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
echo $test4
python main_holo.py --test_noisy_img $test4 --test_noisy_key $keyNoisy --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
#!/bin/bash
#SBATCH -p gpu
#SBATCH --gres gpu:1
#SBATCH --mem 40G
#SBATCH --mail-type=ALL
#SBATCH --mail-user=robin.noury.etu@univ-lemans.fr
#SBATCH -o test_debruitage.out
#SBATCH --time 20-00
#noisyImg=$1
#cleanImg=$2
#runTest=/lium/raid01_c/tahon/holography/checkpoints/run-test2020-04-12_12\:14\:29.082341/
runTest=$1
for num in 1 2 3 4 5; do
for lambda in 0 1 1.5 2 2.5 ; do
noisyImg=./HOLODEEPmat/Pattern$num/MFH_$lambda/NoisyPhase.mat
#noisyImg=/lium/raid01_c/tahon/holography/HOLODEEPmat/PATTERN$num/MFH_$lambda/run-test2020-04-12_12\:14\:29.082341/run-test2020-04-12_12\:14\:29.082341/NoisyPhase.mat-27000.mat-27000.mat
cleanImg=./HOLODEEPmat/Pattern$num/PhaseDATA.mat
echo $noisyImg >> TEST-TRAIN_1.res
python main_holo.py --test_noisy_img $noisyImg --test_noisy_key 'NoisyPhase' --test_clean_img $cleanImg --test_clean_key 'Phase' --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
done
done
test1=./DATAEVAL/DATA_1_Phase_Type1_2_0.25_1.5_4_50.mat
test2=./DATAEVAL/DATA_20_Phase_Type4_2_0.25_2.5_4_100.mat
test3=./DATAEVAL/VibPhaseDATA.mat
for t in range(1,212) ; do
noisyImg = ./Base_exp_test_double_impact/Temps_$t/NoisyPhase.mat
#WFT2FImg =
echo $noisyImg >> TEST-TRAIN_1.res
python main_holo.py --test_noisy_img $test4 --test_noisy_key $keyNoisy --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
done
keyNoisy='Phaseb'
keyClean='Phase'
echo $test1
python main_holo.py --test_noisy_img $test1 --test_noisy_key $keyNoisy --test_clean_img $test1 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
echo $test2
python main_holo.py --test_noisy_img $test2 --test_noisy_key $keyNoisy --test_clean_img $test2 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
echo $test3
python main_holo.py --test_noisy_img $test3 --test_noisy_key $keyNoisy --test_clean_img $test3 --test_clean_key $keyClean --test_flip False --test_ckpt_index $runTest >> TEST-TRAIN_1.res
#!/bin/bash
#SBATCH -p gpu
#SBATCH --gres gpu:1
#SBATCH --mem 40G
#SBATCH --mail-type=ALL
#SBATCH --mail-user=robin.noury.etu@univ-lemans.fr
#SBATCH -o holo_two_train_noise0-1.5.out
#SBATCH --time 20-00
source activate hologaphy
#python generate_patches_holo_fromMAT.py --params "phase_type=two"
#deja lance avec run_holo.sh
python main_holo.py --checkpoint_dir $HOME/holography/checkpoints/ --sample_dir $HOME/holography/eval_samples/ --params "phase=train" --save_dir "./data1/"
......@@ -132,9 +132,10 @@ def from_HOLODEEP(dir_noise, dir_clean, noise_eval, img_eval, path_only):
def from_DATABASE(dir_data, noise_eval, img_eval, flipupdown = False):
select_noisy = []
select_clean = []
nois_pat = [str(n).replace('.','p') for n in noise_eval.split('-')]
nois_pat = [str(n) for n in noise_eval.split('-')]
#nois_pat = [str(n).replace('.','p') for n in noise_eval.split('-')]
for p in img_eval:
pat = dir_data + 'PATTERN' + str(p) + '/'
pat = dir_data + 'Pattern' + str(p) + '/'
for n in nois_pat:
select_noisy.append(pat + 'MFH_' + n + '/NoisyPhase.mat')
select_clean.append(pat + 'PhaseDATA.mat')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment