diff options
author | algol <dkazanc@hotmail.com> | 2018-04-10 16:20:37 +0100 |
---|---|---|
committer | algol <dkazanc@hotmail.com> | 2018-04-10 16:20:37 +0100 |
commit | aa99eb8a9bd47ecd6e4d3d1e8c9f0cfbefb4f7bb (patch) | |
tree | 0552ba5783f3f143cf7bd4bba9620d14f82c9adf /Wrappers | |
parent | abe8e9805bb02e0ec73fd97f43da9f04ce0c6992 (diff) | |
download | regularization-aa99eb8a9bd47ecd6e4d3d1e8c9f0cfbefb4f7bb.tar.gz regularization-aa99eb8a9bd47ecd6e4d3d1e8c9f0cfbefb4f7bb.tar.bz2 regularization-aa99eb8a9bd47ecd6e4d3d1e8c9f0cfbefb4f7bb.tar.xz regularization-aa99eb8a9bd47ecd6e4d3d1e8c9f0cfbefb4f7bb.zip |
implemented with unittest #43
Diffstat (limited to 'Wrappers')
-rw-r--r-- | Wrappers/Python/test/run_test.py | 148 |
1 files changed, 96 insertions, 52 deletions
diff --git a/Wrappers/Python/test/run_test.py b/Wrappers/Python/test/run_test.py index 19af0ec..04bbd40 100644 --- a/Wrappers/Python/test/run_test.py +++ b/Wrappers/Python/test/run_test.py @@ -9,7 +9,11 @@ def rmse(im1, im2): return rmse class TestRegularisers(unittest.TestCase): - def __init__(self): + + def setUp(self): + pass + + def test_cpu_regularisers(self): filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif") # read noiseless image @@ -17,89 +21,129 @@ class TestRegularisers(unittest.TestCase): Im = np.asarray(Im, dtype='float32') Im = Im/255 - self.u0 = Im - self.Im = Im - self.tolerance = 1e-05 - self.rms_rof_exp = 0.006812507 #expected value for ROF model - self.rms_fgp_exp = 0.019152347 #expected value for FGP model + tolerance = 1e-05 + rms_rof_exp = 0.006812507 #expected value for ROF model + rms_fgp_exp = 0.019152347 #expected value for FGP model # set parameters for ROF-TV - self.pars_rof_tv = {'algorithm': ROF_TV, \ - 'input' : self.u0,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 50,\ - 'time_marching_parameter': 0.0025 - } + pars_rof_tv = {'algorithm': ROF_TV, \ + 'input' : Im,\ + 'regularisation_parameter':0.04,\ + 'number_of_iterations': 50,\ + 'time_marching_parameter': 0.0025 + } # set parameters for FGP-TV - self.pars_fgp_tv = {'algorithm' : FGP_TV, \ - 'input' : self.u0,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :50 ,\ - 'tolerance_constant':1e-08,\ - 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } - def test_cpu_regularisers(self): + pars_fgp_tv = {'algorithm' : FGP_TV, \ + 'input' : Im,\ + 'regularisation_parameter':0.04, \ + 'number_of_iterations' :50 ,\ + 'tolerance_constant':1e-08,\ + 'methodTV': 0 ,\ + 'nonneg': 0 ,\ + 'printingOut': 0 + } print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_________testing ROF-TV (2D, CPU)__________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") - rof_cpu = ROF_TV(self.pars_rof_tv['input'], - self.pars_rof_tv['regularisation_parameter'], - self.pars_rof_tv['number_of_iterations'], - self.pars_rof_tv['time_marching_parameter'],'cpu') - rms_rof = rmse(self.Im, rof_cpu) + res = True + rof_cpu = ROF_TV(pars_rof_tv['input'], + pars_rof_tv['regularisation_parameter'], + pars_rof_tv['number_of_iterations'], + pars_rof_tv['time_marching_parameter'],'cpu') + rms_rof = rmse(Im, rof_cpu) # now compare obtained rms with the expected value + self.assertLess(abs(rms_rof-rms_rof_exp) , tolerance) + """ if abs(rms_rof-self.rms_rof_exp) > self.tolerance: raise TypeError('ROF-TV (2D, CPU) test FAILED') else: print ("test PASSED") + """ print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_________testing FGP-TV (2D, CPU)__________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") - fgp_cpu = FGP_TV(self.pars_fgp_tv['input'], - self.pars_fgp_tv['regularisation_parameter'], - self.pars_fgp_tv['number_of_iterations'], - self.pars_fgp_tv['tolerance_constant'], - self.pars_fgp_tv['methodTV'], - self.pars_fgp_tv['nonneg'], - self.pars_fgp_tv['printingOut'],'cpu') - rms_fgp = rmse(self.Im, fgp_cpu) + fgp_cpu = FGP_TV(pars_fgp_tv['input'], + pars_fgp_tv['regularisation_parameter'], + pars_fgp_tv['number_of_iterations'], + pars_fgp_tv['tolerance_constant'], + pars_fgp_tv['methodTV'], + pars_fgp_tv['nonneg'], + pars_fgp_tv['printingOut'],'cpu') + rms_fgp = rmse(Im, fgp_cpu) # now compare obtained rms with the expected value + self.assertLess(abs(rms_fgp-rms_fgp_exp) , tolerance) + """ if abs(rms_fgp-self.rms_fgp_exp) > self.tolerance: raise TypeError('FGP-TV (2D, CPU) test FAILED') else: print ("test PASSED") + """ + self.assertTrue(res) def test_gpu_regularisers(self): + filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif") + + # read noiseless image + Im = plt.imread(filename) + Im = np.asarray(Im, dtype='float32') + + Im = Im/255 + tolerance = 1e-05 + rms_rof_exp = 0.006812507 #expected value for ROF model + rms_fgp_exp = 0.019152347 #expected value for FGP model + + # set parameters for ROF-TV + pars_rof_tv = {'algorithm': ROF_TV, \ + 'input' : Im,\ + 'regularisation_parameter':0.04,\ + 'number_of_iterations': 50,\ + 'time_marching_parameter': 0.0025 + } + # set parameters for FGP-TV + pars_fgp_tv = {'algorithm' : FGP_TV, \ + 'input' : Im,\ + 'regularisation_parameter':0.04, \ + 'number_of_iterations' :50 ,\ + 'tolerance_constant':1e-08,\ + 'methodTV': 0 ,\ + 'nonneg': 0 ,\ + 'printingOut': 0 + } print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_________testing ROF-TV (2D, GPU)__________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") - rof_gpu = ROF_TV(self.pars_rof_tv['input'], - self.pars_rof_tv['regularisation_parameter'], - self.pars_rof_tv['number_of_iterations'], - self.pars_rof_tv['time_marching_parameter'],'gpu') - rms_rof = rmse(self.Im, rof_gpu) + res = True + rof_gpu = ROF_TV(pars_rof_tv['input'], + pars_rof_tv['regularisation_parameter'], + pars_rof_tv['number_of_iterations'], + pars_rof_tv['time_marching_parameter'],'gpu') + rms_rof = rmse(Im, rof_gpu) # now compare obtained rms with the expected value + self.assertLess(abs(rms_rof-rms_rof_exp) , tolerance) + """ if abs(rms_rof-self.rms_rof_exp) > self.tolerance: raise TypeError('ROF-TV (2D, GPU) test FAILED') else: print ("test PASSED") + """ print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_________testing FGP-TV (2D, GPU)__________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") - fgp_gpu = FGP_TV(self.pars_fgp_tv['input'], - self.pars_fgp_tv['regularisation_parameter'], - self.pars_fgp_tv['number_of_iterations'], - self.pars_fgp_tv['tolerance_constant'], - self.pars_fgp_tv['methodTV'], - self.pars_fgp_tv['nonneg'], - self.pars_fgp_tv['printingOut'],'gpu') - rms_fgp = rmse(self.Im, fgp_gpu) + fgp_gpu = FGP_TV(pars_fgp_tv['input'], + pars_fgp_tv['regularisation_parameter'], + pars_fgp_tv['number_of_iterations'], + pars_fgp_tv['tolerance_constant'], + pars_fgp_tv['methodTV'], + pars_fgp_tv['nonneg'], + pars_fgp_tv['printingOut'],'gpu') + rms_fgp = rmse(Im, fgp_gpu) + # now compare obtained rms with the expected value + self.assertLess(abs(rms_fgp-rms_fgp_exp) , tolerance) + """ if abs(rms_fgp-self.rms_fgp_exp) > self.tolerance: raise TypeError('FGP-TV (2D, GPU) test FAILED') else: print ("test PASSED") - # now compare obtained rms with the expected value - #self.assertLess(...) -#if __name__ == '__main__': - #unittest.main()
\ No newline at end of file + """ + self.assertTrue(res) +if __name__ == '__main__': + unittest.main()
\ No newline at end of file |