diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_CPU_regularisers.py | 18 | ||||
-rwxr-xr-x | test/test_run_test.py | 558 |
2 files changed, 286 insertions, 290 deletions
diff --git a/test/test_CPU_regularisers.py b/test/test_CPU_regularisers.py index 851569c..5e3f303 100644 --- a/test/test_CPU_regularisers.py +++ b/test/test_CPU_regularisers.py @@ -32,7 +32,7 @@ class TestRegularisers(unittest.TestCase): def test_FGP_TV_CPU(self): Im,input,ref = self.getPars() - fgp_cpu = FGP_TV(input,0.04,1200,1e-5,0,0,0,'cpu'); + fgp_cpu,info = FGP_TV(input,0.02,300,0.0,0,0,'cpu'); rms = rmse(Im, fgp_cpu) @@ -42,7 +42,7 @@ class TestRegularisers(unittest.TestCase): # set parameters Im, input,ref = self.getPars() # call routine - fgp_cpu = ROF_TV(input,0.04,1200,2e-5, 'cpu') + fgp_cpu,info = ROF_TV(input,0.02,1000,0.001,0.0, 'cpu') rms = rmse(Im, fgp_cpu) @@ -53,7 +53,7 @@ class TestRegularisers(unittest.TestCase): # set parameters Im, input,ref = self.getPars() # call routine - sb_cpu = SB_TV(input,0.04,150,1e-5,0,0,'cpu') + sb_cpu,info = SB_TV(input,0.02,150,0.0,0,'cpu') rms = rmse(Im, sb_cpu) @@ -64,9 +64,9 @@ class TestRegularisers(unittest.TestCase): # set parameters Im, input,ref = self.getPars() # call routine - sb_cpu = TGV(input,0.04,1.0,2.0,250,12,'cpu') + tgv_cpu,info = TGV(input,0.02,1.0,2.0,500,12,0.0,'cpu') - rms = rmse(Im, sb_cpu) + rms = rmse(Im, tgv_cpu) # now test that it generates some expected output self.assertAlmostEqual(rms,0.02,delta=0.01) @@ -75,7 +75,7 @@ class TestRegularisers(unittest.TestCase): # set parameters Im, input,ref = self.getPars() # call routine - sb_cpu = LLT_ROF(input,0.04,0.01,1000,1e-4,'cpu') + sb_cpu,info = LLT_ROF(input,0.01,0.008,1000,0.001,0.0,'cpu') rms = rmse(Im, sb_cpu) @@ -86,7 +86,7 @@ class TestRegularisers(unittest.TestCase): # set parameters Im, input,ref = self.getPars() # call routine - sb_cpu = NDF(input, 0.06, 0.04,1000,0.025,1, 'cpu') + sb_cpu,info = NDF(input, 0.02, 0.17,1000,0.01,1,0.0, 'cpu') rms = rmse(Im, sb_cpu) @@ -97,7 +97,7 @@ class TestRegularisers(unittest.TestCase): # set parameters Im, input,ref = self.getPars() # call routine - sb_cpu = Diff4th(input, 3.5,0.02,500,0.001, 'cpu') + sb_cpu,info = Diff4th(input, 0.8,0.02,1000,0.001,0.0, 'cpu') rms = rmse(Im, sb_cpu) @@ -108,7 +108,7 @@ class TestRegularisers(unittest.TestCase): # set parameters Im, input,ref = self.getPars() # call routine - sb_cpu = FGP_dTV(input,ref,0.04,1000,1e-7,0.2,0,0,0, 'cpu') + sb_cpu,info = FGP_dTV(input,ref,0.02,500,0.0,0.2,0,0, 'cpu') rms = rmse(Im, sb_cpu) diff --git a/test/test_run_test.py b/test/test_run_test.py index 5a688c9..1174c5b 100755 --- a/test/test_run_test.py +++ b/test/test_run_test.py @@ -27,14 +27,14 @@ def nrmse(im1, im2): max_val = max(np.max(im1), np.max(im2))
min_val = min(np.min(im1), np.min(im2))
return 1 - (rmse / (max_val - min_val))
-
+
def rmse(im1, im2):
rmse = np.sqrt(np.sum((im1 - im2) ** 2) / float(im1.size))
return rmse
###############################################################################
class TestRegularisers(unittest.TestCase):
-
+
def test_ROF_TV_CPU_vs_GPU(self):
#print ("tomas debug test function")
@@ -42,53 +42,55 @@ class TestRegularisers(unittest.TestCase): filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("____________ROF-TV bench___________________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
+
# set parameters
pars = {'algorithm': ROF_TV, \
'input' : u0,\
- 'regularisation_parameter':0.04,\
- 'number_of_iterations': 2500,\
- 'time_marching_parameter': 0.00002
- }
+ 'regularisation_parameter':0.02,\
+ 'number_of_iterations': 1000,\
+ 'time_marching_parameter': 0.001,\
+ 'tolerance_constant':0.0}
print ("#############ROF TV CPU####################")
start_time = timeit.default_timer()
- rof_cpu = ROF_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'],'cpu')
+ (rof_cpu, infocpu) = ROF_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['tolerance_constant'],'cpu')
rms = rmse(Im, rof_cpu)
pars['rmse'] = rms
-
+
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
print ("##############ROF TV GPU##################")
start_time = timeit.default_timer()
try:
- rof_gpu = ROF_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'],'gpu')
+ (rof_gpu, infogpu) = ROF_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['tolerance_constant'],'gpu')
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
@@ -99,78 +101,74 @@ class TestRegularisers(unittest.TestCase): txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
print ("--------Compare the results--------")
- tolerance = 1e-04
+ tolerance = 1e-05
diff_im = np.zeros(np.shape(rof_cpu))
diff_im = abs(rof_cpu - rof_gpu)
diff_im[diff_im > tolerance] = 1
self.assertLessEqual(diff_im.sum() , 1)
-
+
def test_FGP_TV_CPU_vs_GPU(self):
print(__name__)
filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("____________FGP-TV bench___________________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
-
+
+
# set parameters
pars = {'algorithm' : FGP_TV, \
- 'input' : u0,\
- 'regularisation_parameter':0.04, \
- 'number_of_iterations' :1200 ,\
- 'tolerance_constant':0.00001,\
- 'methodTV': 0 ,\
- 'nonneg': 0 ,\
- 'printingOut': 0
- }
-
+ 'input' : u0,\
+ 'regularisation_parameter':0.02, \
+ 'number_of_iterations' :400 ,\
+ 'tolerance_constant':0.0,\
+ 'methodTV': 0 ,\
+ 'nonneg': 0}
+
print ("#############FGP TV CPU####################")
start_time = timeit.default_timer()
- fgp_cpu = FGP_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['tolerance_constant'],
- pars['methodTV'],
- pars['nonneg'],
- pars['printingOut'],'cpu')
-
-
+ (fgp_cpu,infocpu) = FGP_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'],
+ pars['nonneg'],'cpu')
+
+
rms = rmse(Im, fgp_cpu)
pars['rmse'] = rms
-
+
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
-
+
print ("##############FGP TV GPU##################")
start_time = timeit.default_timer()
try:
- fgp_gpu = FGP_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['tolerance_constant'],
- pars['methodTV'],
- pars['nonneg'],
- pars['printingOut'],'gpu')
+ (fgp_gpu,infogpu) = FGP_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'],
+ pars['nonneg'],'gpu')
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
@@ -181,7 +179,7 @@ class TestRegularisers(unittest.TestCase): txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
-
+
print ("--------Compare the results--------")
tolerance = 1e-05
diff_im = np.zeros(np.shape(fgp_cpu))
@@ -195,65 +193,60 @@ class TestRegularisers(unittest.TestCase): filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("____________SB-TV bench___________________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
-
+
+
# set parameters
pars = {'algorithm' : SB_TV, \
- 'input' : u0,\
- 'regularisation_parameter':0.04, \
- 'number_of_iterations' :150 ,\
- 'tolerance_constant':1e-05,\
- 'methodTV': 0 ,\
- 'printingOut': 0
- }
-
+ 'input' : u0,\
+ 'regularisation_parameter':0.02, \
+ 'number_of_iterations' :250 ,\
+ 'tolerance_constant':0.0,\
+ 'methodTV': 0}
+
print ("#############SB-TV CPU####################")
start_time = timeit.default_timer()
- sb_cpu = SB_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['tolerance_constant'],
- pars['methodTV'],
- pars['printingOut'],'cpu')
-
-
+ (sb_cpu, info_vec_cpu) = SB_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'], 'cpu')
+
+
rms = rmse(Im, sb_cpu)
pars['rmse'] = rms
-
+
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
-
+
print ("##############SB TV GPU##################")
start_time = timeit.default_timer()
try:
-
- sb_gpu = SB_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['tolerance_constant'],
- pars['methodTV'],
- pars['printingOut'],'gpu')
+ (sb_gpu, info_vec_gpu) = SB_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'], 'gpu')
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
@@ -276,64 +269,65 @@ class TestRegularisers(unittest.TestCase): filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("____________TGV bench___________________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
-
+
+
# set parameters
pars = {'algorithm' : TGV, \
- 'input' : u0,\
- 'regularisation_parameter':0.04, \
- 'alpha1':1.0,\
- 'alpha0':2.0,\
- 'number_of_iterations' :250 ,\
- 'LipshitzConstant' :12 ,\
- }
-
+ 'input' : u0,\
+ 'regularisation_parameter':0.02, \
+ 'alpha1':1.0,\
+ 'alpha0':2.0,\
+ 'number_of_iterations' :1000 ,\
+ 'LipshitzConstant' :12 ,\
+ 'tolerance_constant':0.0}
+
print ("#############TGV CPU####################")
start_time = timeit.default_timer()
- tgv_cpu = TGV(pars['input'],
- pars['regularisation_parameter'],
- pars['alpha1'],
- pars['alpha0'],
- pars['number_of_iterations'],
- pars['LipshitzConstant'],'cpu')
-
+ (tgv_cpu, info_vec_cpu) = TGV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['alpha1'],
+ pars['alpha0'],
+ pars['number_of_iterations'],
+ pars['LipshitzConstant'],
+ pars['tolerance_constant'],'cpu')
+
rms = rmse(Im, tgv_cpu)
pars['rmse'] = rms
-
+
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
-
+
print ("##############TGV GPU##################")
start_time = timeit.default_timer()
try:
- tgv_gpu = TGV(pars['input'],
- pars['regularisation_parameter'],
- pars['alpha1'],
- pars['alpha0'],
- pars['number_of_iterations'],
- pars['LipshitzConstant'],'gpu')
-
+ (tgv_gpu, info_vec_gpu) = TGV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['alpha1'],
+ pars['alpha0'],
+ pars['number_of_iterations'],
+ pars['LipshitzConstant'],
+ pars['tolerance_constant'],'gpu')
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
@@ -355,60 +349,62 @@ class TestRegularisers(unittest.TestCase): filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("____________LLT-ROF bench___________________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
-
+
+
# set parameters
pars = {'algorithm' : LLT_ROF, \
- 'input' : u0,\
- 'regularisation_parameterROF':0.04, \
- 'regularisation_parameterLLT':0.01, \
- 'number_of_iterations' :1000 ,\
- 'time_marching_parameter' :0.0001 ,\
- }
-
+ 'input' : u0,\
+ 'regularisation_parameterROF':0.01, \
+ 'regularisation_parameterLLT':0.0085, \
+ 'number_of_iterations' : 1000 ,\
+ 'time_marching_parameter' :0.0001 ,\
+ 'tolerance_constant':0.0}
+
print ("#############LLT- ROF CPU####################")
start_time = timeit.default_timer()
- lltrof_cpu = LLT_ROF(pars['input'],
- pars['regularisation_parameterROF'],
- pars['regularisation_parameterLLT'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'],'cpu')
-
+ (lltrof_cpu, info_vec_cpu) = LLT_ROF(pars['input'],
+ pars['regularisation_parameterROF'],
+ pars['regularisation_parameterLLT'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['tolerance_constant'], 'cpu')
+
rms = rmse(Im, lltrof_cpu)
pars['rmse'] = rms
-
+
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
print ("#############LLT- ROF GPU####################")
start_time = timeit.default_timer()
try:
- lltrof_gpu = LLT_ROF(pars['input'],
- pars['regularisation_parameterROF'],
- pars['regularisation_parameterLLT'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'],'gpu')
-
+ (lltrof_gpu, info_vec_gpu) = LLT_ROF(pars['input'],
+ pars['regularisation_parameterROF'],
+ pars['regularisation_parameterLLT'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['tolerance_constant'], 'gpu')
+
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
@@ -419,7 +415,7 @@ class TestRegularisers(unittest.TestCase): txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
print ("--------Compare the results--------")
- tolerance = 1e-04
+ tolerance = 1e-05
diff_im = np.zeros(np.shape(lltrof_gpu))
diff_im = abs(lltrof_cpu - lltrof_gpu)
diff_im[diff_im > tolerance] = 1
@@ -430,64 +426,66 @@ class TestRegularisers(unittest.TestCase): filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("_______________NDF bench___________________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
-
+
+
# set parameters
pars = {'algorithm' : NDF, \
- 'input' : u0,\
- 'regularisation_parameter':0.06, \
- 'edge_parameter':0.04,\
- 'number_of_iterations' :1000 ,\
- 'time_marching_parameter':0.025,\
- 'penalty_type': 1
- }
-
+ 'input' : u0,\
+ 'regularisation_parameter':0.02, \
+ 'edge_parameter':0.017,\
+ 'number_of_iterations' :1500 ,\
+ 'time_marching_parameter':0.01,\
+ 'penalty_type':1,\
+ 'tolerance_constant':0.0}
+
print ("#############NDF CPU####################")
start_time = timeit.default_timer()
- ndf_cpu = NDF(pars['input'],
- pars['regularisation_parameter'],
- pars['edge_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'],
- pars['penalty_type'],'cpu')
-
+ (ndf_cpu,info_vec_cpu) = NDF(pars['input'],
+ pars['regularisation_parameter'],
+ pars['edge_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['penalty_type'],
+ pars['tolerance_constant'],'cpu')
+
rms = rmse(Im, ndf_cpu)
pars['rmse'] = rms
-
+
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
-
+
print ("##############NDF GPU##################")
start_time = timeit.default_timer()
try:
- ndf_gpu = NDF(pars['input'],
- pars['regularisation_parameter'],
- pars['edge_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'],
- pars['penalty_type'],'gpu')
-
+ (ndf_gpu,info_vec_gpu) = NDF(pars['input'],
+ pars['regularisation_parameter'],
+ pars['edge_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['penalty_type'],
+ pars['tolerance_constant'],'gpu')
+
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
rms = rmse(Im, ndf_gpu)
@@ -503,49 +501,50 @@ class TestRegularisers(unittest.TestCase): diff_im[diff_im > tolerance] = 1
self.assertLessEqual(diff_im.sum(), 1)
-
+
def test_Diff4th_CPU_vs_GPU(self):
filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("___Anisotropic Diffusion 4th Order (2D)____")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
+
# set parameters
pars = {'algorithm' : Diff4th, \
'input' : u0,\
- 'regularisation_parameter':3.5, \
+ 'regularisation_parameter':0.8, \
'edge_parameter':0.02,\
- 'number_of_iterations' :500 ,\
- 'time_marching_parameter':0.001
- }
-
+ 'number_of_iterations' :1000 ,\
+ 'time_marching_parameter':0.0001,\
+ 'tolerance_constant':0.0}
+
print ("#############Diff4th CPU####################")
start_time = timeit.default_timer()
- diff4th_cpu = Diff4th(pars['input'],
- pars['regularisation_parameter'],
- pars['edge_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'],'cpu')
-
+ (diff4th_cpu,info_vec_cpu) = Diff4th(pars['input'],
+ pars['regularisation_parameter'],
+ pars['edge_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['tolerance_constant'],'cpu')
+
rms = rmse(Im, diff4th_cpu)
pars['rmse'] = rms
@@ -555,12 +554,13 @@ class TestRegularisers(unittest.TestCase): print ("##############Diff4th GPU##################")
start_time = timeit.default_timer()
try:
- diff4th_gpu = Diff4th(pars['input'],
- pars['regularisation_parameter'],
- pars['edge_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'], 'gpu')
-
+ (diff4th_gpu,info_vec_gpu) = Diff4th(pars['input'],
+ pars['regularisation_parameter'],
+ pars['edge_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'],
+ pars['tolerance_constant'],'gpu')
+
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
rms = rmse(Im, diff4th_gpu)
@@ -580,72 +580,68 @@ class TestRegularisers(unittest.TestCase): filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
-
+
Im = Im/255
perc = 0.05
u0 = Im + np.random.normal(loc = 0 ,
- scale = perc * Im ,
+ scale = perc * Im ,
size = np.shape(Im))
u_ref = Im + np.random.normal(loc = 0 ,
- scale = 0.01 * Im ,
+ scale = 0.01 * Im ,
size = np.shape(Im))
-
+
# map the u0 u0->u0>0
# f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
u0 = u0.astype('float32')
u_ref = u_ref.astype('float32')
-
+
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("____________FGP-dTV bench___________________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
+
# set parameters
pars = {'algorithm' : FGP_dTV, \
- 'input' : u0,\
- 'refdata' : u_ref,\
- 'regularisation_parameter':0.04, \
- 'number_of_iterations' :1000 ,\
- 'tolerance_constant':1e-07,\
- 'eta_const':0.2,\
- 'methodTV': 0 ,\
- 'nonneg': 0 ,\
- 'printingOut': 0
- }
-
+ 'input' : u0,\
+ 'refdata' : u_ref,\
+ 'regularisation_parameter':0.02, \
+ 'number_of_iterations' :500 ,\
+ 'tolerance_constant':0.0,\
+ 'eta_const':0.2,\
+ 'methodTV': 0 ,\
+ 'nonneg': 0}
+
print ("#############FGP dTV CPU####################")
start_time = timeit.default_timer()
- fgp_dtv_cpu = FGP_dTV(pars['input'],
- pars['refdata'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['tolerance_constant'],
- pars['eta_const'],
- pars['methodTV'],
- pars['nonneg'],
- pars['printingOut'],'cpu')
-
-
+ (fgp_dtv_cpu,info_vec_cpu) = FGP_dTV(pars['input'],
+ pars['refdata'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['eta_const'],
+ pars['methodTV'],
+ pars['nonneg'],'cpu')
+
+
rms = rmse(Im, fgp_dtv_cpu)
pars['rmse'] = rms
-
+
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
print ("##############FGP dTV GPU##################")
start_time = timeit.default_timer()
try:
- fgp_dtv_gpu = FGP_dTV(pars['input'],
- pars['refdata'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['tolerance_constant'],
- pars['eta_const'],
- pars['methodTV'],
- pars['nonneg'],
- pars['printingOut'],'gpu')
+ (fgp_dtv_gpu,info_vec_gpu) = FGP_dTV(pars['input'],
+ pars['refdata'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['eta_const'],
+ pars['methodTV'],
+ pars['nonneg'],'gpu')
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
rms = rmse(Im, fgp_dtv_gpu)
@@ -660,23 +656,23 @@ class TestRegularisers(unittest.TestCase): diff_im = abs(fgp_dtv_cpu - fgp_dtv_gpu)
diff_im[diff_im > tolerance] = 1
self.assertLessEqual(diff_im.sum(), 1)
-
+"""
def test_cpu_ROF_TV(self):
#filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
-
+
filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
Im = Im/255
-
- """
+
+
# read noiseless image
- Im = plt.imread(filename)
- Im = np.asarray(Im, dtype='float32')
- """
+ #Im = plt.imread(filename)
+ #Im = np.asarray(Im, dtype='float32')
+
tolerance = 1e-05
rms_rof_exp = 8.313131464999238e-05 #expected value for ROF model
@@ -695,27 +691,27 @@ class TestRegularisers(unittest.TestCase): 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)
def test_cpu_FGP_TV(self):
#filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
-
+
filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
Im = Im/255
- """
+
# read noiseless image
- Im = plt.imread(filename)
- Im = np.asarray(Im, dtype='float32')
- """
+ # Im = plt.imread(filename)
+ # Im = np.asarray(Im, dtype='float32')
+
tolerance = 1e-05
rms_fgp_exp = 0.019152347 #expected value for FGP model
-
+
pars_fgp_tv = {'algorithm' : FGP_TV, \
'input' : Im,\
'regularisation_parameter':0.04, \
@@ -723,18 +719,18 @@ class TestRegularisers(unittest.TestCase): 'tolerance_constant':1e-06,\
'methodTV': 0 ,\
'nonneg': 0 ,\
- 'printingOut': 0
+ 'printingOut': 0
}
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("_________testing FGP-TV (2D, CPU)__________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
- fgp_cpu = FGP_TV(pars_fgp_tv['input'],
+ 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['tolerance_constant'],
pars_fgp_tv['methodTV'],
pars_fgp_tv['nonneg'],
- pars_fgp_tv['printingOut'],'cpu')
+ 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)
@@ -748,10 +744,10 @@ class TestRegularisers(unittest.TestCase): Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
Im = Im/255
-
+
tolerance = 1e-05
rms_rof_exp = 8.313131464999238e-05 #expected value for ROF model
-
+
# set parameters for ROF-TV
pars_rof_tv = {'algorithm': ROF_TV, \
'input' : Im,\
@@ -773,20 +769,20 @@ class TestRegularisers(unittest.TestCase): rms_rof = rmse(Im, rof_gpu)
# now compare obtained rms with the expected value
self.assertLess(abs(rms_rof-rms_rof_exp) , tolerance)
-
+
def test_gpu_FGP(self):
#filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
filename = os.path.join("test","lena_gray_512.tif")
plt = TiffReader()
# read image
- Im = plt.imread(filename)
+ Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
Im = Im/255
tolerance = 1e-05
-
+
rms_fgp_exp = 0.019152347 #expected value for FGP model
-
+
# set parameters for FGP-TV
pars_fgp_tv = {'algorithm' : FGP_TV, \
'input' : Im,\
@@ -795,19 +791,19 @@ class TestRegularisers(unittest.TestCase): 'tolerance_constant':1e-06,\
'methodTV': 0 ,\
'nonneg': 0 ,\
- 'printingOut': 0
+ 'printingOut': 0
}
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("_________testing FGP-TV (2D, GPU)__________")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
try:
- fgp_gpu = FGP_TV(pars_fgp_tv['input'],
+ 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['tolerance_constant'],
pars_fgp_tv['methodTV'],
pars_fgp_tv['nonneg'],
- pars_fgp_tv['printingOut'],'gpu')
+ pars_fgp_tv['printingOut'],'gpu')
except ValueError as ve:
self.skipTest("Results not comparable. GPU computing error.")
rms_fgp = rmse(Im, fgp_gpu)
@@ -815,7 +811,7 @@ class TestRegularisers(unittest.TestCase): self.assertLess(abs(rms_fgp-rms_fgp_exp) , tolerance)
-
+"""
if __name__ == '__main__':
unittest.main()
|