From 49423f47c7282672fea979cd122c063c0f5ee465 Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Wed, 21 Feb 2018 12:06:12 +0000 Subject: ROF_TV demo --- Wrappers/Python/test/test_gpu_regularizers.py | 44 +++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index 735a25d..3346fb2 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -6,14 +6,12 @@ Created on Tue Jan 30 10:24:26 2018 @author: ofn77899 """ - - import matplotlib.pyplot as plt import numpy as np import os from enum import Enum import timeit -from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML +from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, ROF_TV_GPU ############################################################################### def printParametersToString(pars): txt = r'' @@ -146,3 +144,43 @@ imgplot = plt.imshow((nml - u0)**2, cmap="gray") plt.show() + +## Rudin-Osher-Fatemi (ROF) TV regularization +start_time = timeit.default_timer() + +pars = { + 'input' : u0, + 'regularization_parameter': 1,\ + 'time_marching_parameter': 0.003, \ + 'number_of_iterations':300 + } + +rof_tv = ROF_TV_GPU(pars['input'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['number_of_iterations']) + +rms = rmse(Im, rof_tv) +pars['rmse'] = rms +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(2,4,1) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) +# place a text box in upper left in axes coords +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=12, + verticalalignment='top', bbox=props) +imgplot = plt.imshow(nml, cmap="gray") + +a=fig.add_subplot(2,4,2) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) +# place a text box in upper left in axes coords +a.text(0.05, 0.95, 'rof_tv - u0', transform=a.transAxes, fontsize=14, + verticalalignment='top', bbox=props) +imgplot = plt.imshow((rof_tv - u0)**2, cmap="gray") + +plt.show() -- cgit v1.2.3 From 75917255b4f0b8aae2e6ce9492a75e0f749bfb3e Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Wed, 21 Feb 2018 12:49:59 +0000 Subject: added TV_ROF --- Wrappers/Python/test/test_gpu_regularizers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index 735a25d..75127a6 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -13,7 +13,7 @@ import numpy as np import os from enum import Enum import timeit -from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML +from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, GPU_ROF_TV ############################################################################### def printParametersToString(pars): txt = r'' -- cgit v1.2.3 From ce313c7dcf45edaf4c824690d8caa7df5df90120 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Wed, 21 Feb 2018 14:43:35 +0000 Subject: modified gpu regularizers build --- Wrappers/Python/test/test_gpu_regularizers.py | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index ff8af44..9e37627 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -50,14 +50,15 @@ u0 = f(u0).astype('float32') ## plot fig = plt.figure() -a=fig.add_subplot(2,3,1) +a=fig.add_subplot(2,4,1) a.set_title('noise') imgplot = plt.imshow(u0,cmap="gray") ## Diff4thHajiaboli start_time = timeit.default_timer() -pars = {'algorithm' : Diff4thHajiaboli , \ +pars = { +'algorithm' : Diff4thHajiaboli , \ 'input' : u0, 'edge_preserv_parameter':0.1 , \ 'number_of_iterations' :250 ,\ @@ -76,7 +77,7 @@ pars['rmse'] = rms txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) -a=fig.add_subplot(2,3,2) +a=fig.add_subplot(2,4,2) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) @@ -85,14 +86,14 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) imgplot = plt.imshow(d4h, cmap="gray") -a=fig.add_subplot(2,3,5) +a=fig.add_subplot(2,4,6) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords a.text(0.05, 0.95, 'd4h - u0', transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) -imgplot = plt.imshow((d4h - u0)**2, cmap="gray") +imgplot = plt.imshow((d4h - u0), cmap="gray") ## Patch Based Regul NML @@ -107,6 +108,7 @@ pars = {'algorithm' : NML , \ } """ pars = { +'algorithm' : NML , \ 'input' : u0, 'regularization_parameter': 0.01,\ 'searching_window_ratio':3, \ @@ -124,7 +126,7 @@ pars['rmse'] = rms txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) -a=fig.add_subplot(2,3,3) +a=fig.add_subplot(2,4,3) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) @@ -133,22 +135,22 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) imgplot = plt.imshow(nml, cmap="gray") -a=fig.add_subplot(2,3,6) +a=fig.add_subplot(2,4,7) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords a.text(0.05, 0.95, 'nml - u0', transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) -imgplot = plt.imshow((nml - u0)**2, cmap="gray") +imgplot = plt.imshow((nml - u0), cmap="gray") -plt.show() ## Rudin-Osher-Fatemi (ROF) TV regularization start_time = timeit.default_timer() pars = { +'algorithm' : GPU_ROF_TV , \ 'input' : u0, 'regularization_parameter': 1,\ 'time_marching_parameter': 0.003, \ @@ -158,29 +160,29 @@ pars = { rof_tv = GPU_ROF_TV(pars['input'], pars['number_of_iterations'], pars['time_marching_parameter'], - pars['number_of_iterations']) + pars['regularization_parameter']) rms = rmse(Im, rof_tv) pars['rmse'] = rms txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) -a=fig.add_subplot(2,4,1) +a=fig.add_subplot(2,4,4) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) # place a text box in upper left in axes coords a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) -imgplot = plt.imshow(nml, cmap="gray") +imgplot = plt.imshow(rof_tv, cmap="gray") -a=fig.add_subplot(2,4,2) +a=fig.add_subplot(2,4,8) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords a.text(0.05, 0.95, 'rof_tv - u0', transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) -imgplot = plt.imshow((rof_tv - u0)**2, cmap="gray") +imgplot = plt.imshow((rof_tv - u0), cmap="gray") plt.show() -- cgit v1.2.3 From d4d12945f5396b10259fdeeb2b09f99b0e2c6afd Mon Sep 17 00:00:00 2001 From: algol Date: Thu, 22 Feb 2018 12:34:39 +0000 Subject: GPU test fixed, cpu vs gpu test added for ROF-TV --- .../Python/test/test_cpu_vs_gpu_regularizers.py | 123 +++++++++++++++++++++ Wrappers/Python/test/test_gpu_regularizers.py | 16 +-- 2 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py new file mode 100644 index 0000000..8c91c73 --- /dev/null +++ b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 22 11:39:43 2018 + +Testing CPU implementation against GPU one + +@author: algol +""" + +import matplotlib.pyplot as plt +import numpy as np +import os +import timeit +from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, GPU_ROF_TV +from ccpi.filters.cpu_regularizers_cython import ROF_TV +############################################################################### +def printParametersToString(pars): + txt = r'' + for key, value in pars.items(): + if key== 'algorithm' : + txt += "{0} = {1}".format(key, value.__name__) + elif key == 'input': + txt += "{0} = {1}".format(key, np.shape(value)) + else: + txt += "{0} = {1}".format(key, value) + txt += '\n' + return txt +############################################################################### +def rmse(im1, im2): + a, b = im1.shape + rmse = np.sqrt(np.sum((im1 - im2) ** 2) / float(a * b)) + return rmse + +filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif") + +# read image +Im = plt.imread(filename) +Im = np.asarray(Im, dtype='float32') + +Im = Im/255 +perc = 0.075 +u0 = Im + np.random.normal(loc = Im , + scale = perc * 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 = f(u0).astype('float32') + +## plot +fig = plt.figure(1) +plt.suptitle('Comparison of ROF-TV regularizer using CPU and GPU implementations') +a=fig.add_subplot(1,4,1) +a.set_title('Noisy Image') +imgplot = plt.imshow(u0,cmap="gray") + + +# set parameters +pars = {'algorithm': ROF_TV , \ + 'input' : u0,\ + 'regularization_parameter':12,\ + 'time_marching_parameter': 0.001,\ + 'number_of_iterations': 600 + } +print ("#################ROF TV CPU#####################") +start_time = timeit.default_timer() +rof_cpu = ROF_TV(pars['input'], + pars['number_of_iterations'], + pars['regularization_parameter'], + pars['time_marching_parameter'] + ) +#tgv = out +rms = rmse(Im, rof_cpu) +pars['rmse'] = rms + +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(1,4,2) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) +# place a text box in upper left in axes coords +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, + verticalalignment='top', bbox=props) +imgplot = plt.imshow(rof_cpu, cmap="gray") +plt.title('{}'.format('CPU results')) + + +print ("#################ROF TV GPU#####################") +start_time = timeit.default_timer() +rof_gpu = GPU_ROF_TV(pars['input'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['regularization_parameter']) + +rms = rmse(Im, rof_gpu) +pars['rmse'] = rms +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(1,4,3) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) +# place a text box in upper left in axes coords +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, + verticalalignment='top', bbox=props) +imgplot = plt.imshow(rof_gpu, cmap="gray") +plt.title('{}'.format('GPU results')) + + +print ("--------Compare the results--------") +tolerance = 1e-06 +diff_im = abs(rof_cpu - rof_gpu) +diff_im[diff_im > tolerance] = 1 +a=fig.add_subplot(1,4,4) +imgplot = plt.imshow(diff_im, vmin=0, vmax=1, cmap="gray") +plt.title('{}'.format('Pixels larger threshold difference')) +if (diff_im.sum() > 1): + print ("Arrays do not match!") +else: + print ("Arrays match") \ No newline at end of file diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index 9e37627..29f5bad 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -93,7 +93,8 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords a.text(0.05, 0.95, 'd4h - u0', transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) -imgplot = plt.imshow((d4h - u0), cmap="gray") +imgplot = plt.imshow((d4h - u0)**2, vmin=0, vmax=0.03, cmap="gray") +plt.colorbar(ticks=[0, 0.03], orientation='vertical') ## Patch Based Regul NML @@ -142,7 +143,8 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords a.text(0.05, 0.95, 'nml - u0', transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) -imgplot = plt.imshow((nml - u0), cmap="gray") +imgplot = plt.imshow((nml - u0)**2, vmin=0, vmax=0.03, cmap="gray") +plt.colorbar(ticks=[0, 0.03], orientation='vertical') @@ -152,9 +154,9 @@ start_time = timeit.default_timer() pars = { 'algorithm' : GPU_ROF_TV , \ 'input' : u0, - 'regularization_parameter': 1,\ - 'time_marching_parameter': 0.003, \ - 'number_of_iterations':300 + 'regularization_parameter': 25,\ + 'time_marching_parameter': 0.001, \ + 'number_of_iterations':350 } rof_tv = GPU_ROF_TV(pars['input'], @@ -183,6 +185,6 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords a.text(0.05, 0.95, 'rof_tv - u0', transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) -imgplot = plt.imshow((rof_tv - u0), cmap="gray") - +imgplot = plt.imshow((rof_tv - u0)**2, vmin=0, vmax=0.03, cmap="gray") +plt.colorbar(ticks=[0, 0.03], orientation='vertical') plt.show() -- cgit v1.2.3 From 0ebf1f949b7150692e356627c455e905b642af97 Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Sun, 25 Feb 2018 17:54:03 +0000 Subject: updates to CPU/GPU core for ROF and demos --- Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py | 6 +++--- Wrappers/Python/test/test_gpu_regularizers.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py index 8c91c73..d742a7f 100644 --- a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py +++ b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py @@ -58,8 +58,8 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm': ROF_TV , \ 'input' : u0,\ - 'regularization_parameter':12,\ - 'time_marching_parameter': 0.001,\ + 'regularization_parameter':0.04,\ + 'time_marching_parameter': 0.0025,\ 'number_of_iterations': 600 } print ("#################ROF TV CPU#####################") @@ -120,4 +120,4 @@ plt.title('{}'.format('Pixels larger threshold difference')) if (diff_im.sum() > 1): print ("Arrays do not match!") else: - print ("Arrays match") \ No newline at end of file + print ("Arrays match") diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index 29f5bad..c473270 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -154,9 +154,9 @@ start_time = timeit.default_timer() pars = { 'algorithm' : GPU_ROF_TV , \ 'input' : u0, - 'regularization_parameter': 25,\ - 'time_marching_parameter': 0.001, \ - 'number_of_iterations':350 + 'regularization_parameter': 0.04,\ + 'time_marching_parameter': 0.0025, \ + 'number_of_iterations':300 } rof_tv = GPU_ROF_TV(pars['input'], -- cgit v1.2.3 From bcdf186ccdca54a3df383512ad5a117004500a60 Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Mon, 26 Feb 2018 12:50:58 +0000 Subject: CPU-GPU naming consistency --- Wrappers/Python/test/test_cpu_vs_gpu.py | 10 ++++++++++ Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 Wrappers/Python/test/test_cpu_vs_gpu.py (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_cpu_vs_gpu.py b/Wrappers/Python/test/test_cpu_vs_gpu.py new file mode 100644 index 0000000..74d65dd --- /dev/null +++ b/Wrappers/Python/test/test_cpu_vs_gpu.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Feb 21 12:12:22 2018 + +# CPU vs GPU comparison tests + +@author: algol +""" + diff --git a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py index d742a7f..6344021 100644 --- a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py +++ b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py @@ -12,8 +12,8 @@ import matplotlib.pyplot as plt import numpy as np import os import timeit -from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, GPU_ROF_TV -from ccpi.filters.cpu_regularizers_cython import ROF_TV +from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, TV_ROF_GPU +from ccpi.filters.cpu_regularizers_cython import TV_ROF_CPU ############################################################################### def printParametersToString(pars): txt = r'' @@ -64,7 +64,7 @@ pars = {'algorithm': ROF_TV , \ } print ("#################ROF TV CPU#####################") start_time = timeit.default_timer() -rof_cpu = ROF_TV(pars['input'], +rof_cpu = TV_ROF_CPU(pars['input'], pars['number_of_iterations'], pars['regularization_parameter'], pars['time_marching_parameter'] @@ -89,7 +89,7 @@ plt.title('{}'.format('CPU results')) print ("#################ROF TV GPU#####################") start_time = timeit.default_timer() -rof_gpu = GPU_ROF_TV(pars['input'], +rof_gpu = TV_ROF_GPU(pars['input'], pars['number_of_iterations'], pars['time_marching_parameter'], pars['regularization_parameter']) -- cgit v1.2.3 From 74ff5b5f319b2f7ea3e078c62041ec8a1bb28335 Mon Sep 17 00:00:00 2001 From: algol Date: Mon, 5 Mar 2018 18:12:01 +0000 Subject: Cmake/Cython fixes to compile ROF-FGP --- Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py index 6344021..e162afa 100644 --- a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py +++ b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py @@ -12,7 +12,7 @@ import matplotlib.pyplot as plt import numpy as np import os import timeit -from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, TV_ROF_GPU +from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, GPU_ROF_TV from ccpi.filters.cpu_regularizers_cython import TV_ROF_CPU ############################################################################### def printParametersToString(pars): @@ -56,11 +56,11 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters -pars = {'algorithm': ROF_TV , \ +pars = {'algorithm': TV_ROF_CPU , \ 'input' : u0,\ 'regularization_parameter':0.04,\ 'time_marching_parameter': 0.0025,\ - 'number_of_iterations': 600 + 'number_of_iterations': 1200 } print ("#################ROF TV CPU#####################") start_time = timeit.default_timer() @@ -89,13 +89,14 @@ plt.title('{}'.format('CPU results')) print ("#################ROF TV GPU#####################") start_time = timeit.default_timer() -rof_gpu = TV_ROF_GPU(pars['input'], +rof_gpu = GPU_ROF_TV(pars['input'], pars['number_of_iterations'], pars['time_marching_parameter'], pars['regularization_parameter']) rms = rmse(Im, rof_gpu) pars['rmse'] = rms +pars['algorithm'] = GPU_ROF_TV txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) -- cgit v1.2.3 From 63ad8306c261a90c572d95084bf1dd8db2b3dce7 Mon Sep 17 00:00:00 2001 From: algol Date: Tue, 6 Mar 2018 16:18:20 +0000 Subject: FGP/ROF-CPU/GPU fully working with new interfaces and regularizers.py script. This closes #39 and #38 --- Wrappers/Python/test/test_cpu_vs_gpu.py | 10 -- .../Python/test/test_cpu_vs_gpu_regularizers.py | 137 ++++++++++++++++++--- Wrappers/Python/test/test_gpu_regularizers.py | 16 +-- 3 files changed, 126 insertions(+), 37 deletions(-) delete mode 100644 Wrappers/Python/test/test_cpu_vs_gpu.py (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_cpu_vs_gpu.py b/Wrappers/Python/test/test_cpu_vs_gpu.py deleted file mode 100644 index 74d65dd..0000000 --- a/Wrappers/Python/test/test_cpu_vs_gpu.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Wed Feb 21 12:12:22 2018 - -# CPU vs GPU comparison tests - -@author: algol -""" - diff --git a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py index e162afa..a9d0f31 100644 --- a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py +++ b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py @@ -5,15 +5,17 @@ Created on Thu Feb 22 11:39:43 2018 Testing CPU implementation against GPU one -@author: algol +@author: Daniil Kazantsev """ import matplotlib.pyplot as plt import numpy as np -import os +import os import timeit -from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, GPU_ROF_TV -from ccpi.filters.cpu_regularizers_cython import TV_ROF_CPU +#from ccpi.filters.cpu_regularizers_cython import TV_ROF_CPU, TV_FGP_CPU +#from ccpi.filters.gpu_regularizers import TV_ROF_GPU, TV_FGP_GPU +from ccpi.filters.regularizers import ROF_TV, FGP_TV + ############################################################################### def printParametersToString(pars): txt = r'' @@ -47,6 +49,11 @@ u0 = Im + np.random.normal(loc = Im , f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1) u0 = f(u0).astype('float32') + +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") +print ("____________ROF-TV bench___________________") +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") + ## plot fig = plt.figure(1) plt.suptitle('Comparison of ROF-TV regularizer using CPU and GPU implementations') @@ -54,22 +61,19 @@ a=fig.add_subplot(1,4,1) a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") - # set parameters -pars = {'algorithm': TV_ROF_CPU , \ +pars = {'algorithm': ROF_TV, \ 'input' : u0,\ 'regularization_parameter':0.04,\ - 'time_marching_parameter': 0.0025,\ - 'number_of_iterations': 1200 + 'number_of_iterations': 1200,\ + 'time_marching_parameter': 0.0025 } -print ("#################ROF TV CPU#####################") +print ("#############ROF TV CPU####################") start_time = timeit.default_timer() -rof_cpu = TV_ROF_CPU(pars['input'], - pars['number_of_iterations'], +rof_cpu = ROF_TV(pars['input'], pars['regularization_parameter'], - pars['time_marching_parameter'] - ) -#tgv = out + pars['number_of_iterations'], + pars['time_marching_parameter'],'cpu') rms = rmse(Im, rof_cpu) pars['rmse'] = rms @@ -87,16 +91,16 @@ imgplot = plt.imshow(rof_cpu, cmap="gray") plt.title('{}'.format('CPU results')) -print ("#################ROF TV GPU#####################") +print ("##############ROF TV GPU##################") start_time = timeit.default_timer() -rof_gpu = GPU_ROF_TV(pars['input'], +rof_gpu = ROF_TV(pars['input'], + pars['regularization_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'], - pars['regularization_parameter']) + pars['time_marching_parameter'],'gpu') rms = rmse(Im, rof_gpu) pars['rmse'] = rms -pars['algorithm'] = GPU_ROF_TV +pars['algorithm'] = ROF_TV txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) @@ -112,7 +116,8 @@ plt.title('{}'.format('GPU results')) print ("--------Compare the results--------") -tolerance = 1e-06 +tolerance = 1e-05 +diff_im = np.zeros(np.shape(rof_cpu)) diff_im = abs(rof_cpu - rof_gpu) diff_im[diff_im > tolerance] = 1 a=fig.add_subplot(1,4,4) @@ -122,3 +127,95 @@ if (diff_im.sum() > 1): print ("Arrays do not match!") else: print ("Arrays match") + +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") +print ("____________FGP-TV bench___________________") +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") + +## plot +fig = plt.figure(2) +plt.suptitle('Comparison of FGP-TV regularizer using CPU and GPU implementations') +a=fig.add_subplot(1,4,1) +a.set_title('Noisy Image') +imgplot = plt.imshow(u0,cmap="gray") + +# set parameters +pars = {'algorithm' : FGP_TV, \ + 'input' : u0,\ + 'regularization_parameter':0.04, \ + 'number_of_iterations' :1200 ,\ + 'tolerance_constant':0.00001,\ + 'methodTV': 0 ,\ + 'nonneg': 0 ,\ + 'printingOut': 0 + } + +print ("#############FGP TV CPU####################") +start_time = timeit.default_timer() +fgp_cpu = FGP_TV(pars['input'], + pars['regularization_parameter'], + pars['number_of_iterations'], + pars['tolerance_constant'], + pars['methodTV'], + pars['nonneg'], + pars['printingOut'],'cpu') + + +rms = rmse(Im, fgp_cpu) +pars['rmse'] = rms + +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(1,4,2) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) +# place a text box in upper left in axes coords +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, + verticalalignment='top', bbox=props) +imgplot = plt.imshow(fgp_cpu, cmap="gray") +plt.title('{}'.format('CPU results')) + + +print ("##############FGP TV GPU##################") +start_time = timeit.default_timer() +fgp_gpu = FGP_TV(pars['input'], + pars['regularization_parameter'], + pars['number_of_iterations'], + pars['tolerance_constant'], + pars['methodTV'], + pars['nonneg'], + pars['printingOut'],'gpu') + +rms = rmse(Im, fgp_gpu) +pars['rmse'] = rms +pars['algorithm'] = FGP_TV +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(1,4,3) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) +# place a text box in upper left in axes coords +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, + verticalalignment='top', bbox=props) +imgplot = plt.imshow(fgp_gpu, cmap="gray") +plt.title('{}'.format('GPU results')) + + +print ("--------Compare the results--------") +tolerance = 1e-05 +diff_im = np.zeros(np.shape(rof_cpu)) +diff_im = abs(fgp_cpu - fgp_gpu) +diff_im[diff_im > tolerance] = 1 +a=fig.add_subplot(1,4,4) +imgplot = plt.imshow(diff_im, vmin=0, vmax=1, cmap="gray") +plt.title('{}'.format('Pixels larger threshold difference')) +if (diff_im.sum() > 1): + print ("Arrays do not match!") +else: + print ("Arrays match") + + diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index c473270..04aeeb4 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -11,7 +11,8 @@ import numpy as np import os from enum import Enum import timeit -from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, GPU_ROF_TV +from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, TV_ROF_GPU + ############################################################################### def printParametersToString(pars): txt = r'' @@ -152,17 +153,18 @@ plt.colorbar(ticks=[0, 0.03], orientation='vertical') start_time = timeit.default_timer() pars = { -'algorithm' : GPU_ROF_TV , \ +'algorithm' : TV_ROF_GPU , \ 'input' : u0, 'regularization_parameter': 0.04,\ - 'time_marching_parameter': 0.0025, \ - 'number_of_iterations':300 + 'number_of_iterations':300,\ + 'time_marching_parameter': 0.0025 + } -rof_tv = GPU_ROF_TV(pars['input'], +rof_tv = TV_ROF_GPU(pars['input'], + pars['regularization_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'], - pars['regularization_parameter']) + pars['time_marching_parameter']) rms = rmse(Im, rof_tv) pars['rmse'] = rms -- cgit v1.2.3 From 4593040d228fec5ef1f1a301e511708d47f0d55e Mon Sep 17 00:00:00 2001 From: algol Date: Tue, 6 Mar 2018 16:51:31 +0000 Subject: demos fixed #40 --- .../Python/test/test_cpu_vs_gpu_regularizers.py | 4 +- Wrappers/Python/test/test_gpu_regularizers.py | 59 +++++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) (limited to 'Wrappers/Python/test') diff --git a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py index a9d0f31..63be1a0 100644 --- a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py +++ b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py @@ -3,7 +3,7 @@ """ Created on Thu Feb 22 11:39:43 2018 -Testing CPU implementation against GPU one +Testing CPU implementation against the GPU one @author: Daniil Kazantsev """ @@ -12,8 +12,6 @@ import matplotlib.pyplot as plt import numpy as np import os import timeit -#from ccpi.filters.cpu_regularizers_cython import TV_ROF_CPU, TV_FGP_CPU -#from ccpi.filters.gpu_regularizers import TV_ROF_GPU, TV_FGP_GPU from ccpi.filters.regularizers import ROF_TV, FGP_TV ############################################################################### diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index 04aeeb4..640b3f9 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -11,8 +11,8 @@ import numpy as np import os from enum import Enum import timeit -from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, TV_ROF_GPU - +from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML +from ccpi.filters.regularizers import ROF_TV, FGP_TV ############################################################################### def printParametersToString(pars): txt = r'' @@ -151,20 +151,19 @@ plt.colorbar(ticks=[0, 0.03], orientation='vertical') ## Rudin-Osher-Fatemi (ROF) TV regularization start_time = timeit.default_timer() - pars = { -'algorithm' : TV_ROF_GPU , \ +'algorithm' : ROF_TV , \ 'input' : u0, 'regularization_parameter': 0.04,\ 'number_of_iterations':300,\ 'time_marching_parameter': 0.0025 } - + rof_tv = TV_ROF_GPU(pars['input'], pars['regularization_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter']) + pars['time_marching_parameter'],'gpu') rms = rmse(Im, rof_tv) pars['rmse'] = rms @@ -190,3 +189,51 @@ a.text(0.05, 0.95, 'rof_tv - u0', transform=a.transAxes, fontsize=14, imgplot = plt.imshow((rof_tv - u0)**2, vmin=0, vmax=0.03, cmap="gray") plt.colorbar(ticks=[0, 0.03], orientation='vertical') plt.show() + +## Fast-Gradient Projection TV regularization +""" +start_time = timeit.default_timer() + +pars = {'algorithm' : FGP_TV, \ + 'input' : u0,\ + 'regularization_parameter':0.04, \ + 'number_of_iterations' :1200 ,\ + 'tolerance_constant':0.00001,\ + 'methodTV': 0 ,\ + 'nonneg': 0 ,\ + 'printingOut': 0 + } + +fgp_gpu = FGP_TV(pars['input'], + pars['regularization_parameter'], + pars['number_of_iterations'], + pars['tolerance_constant'], + pars['methodTV'], + pars['nonneg'], + pars['printingOut'],'gpu') + +rms = rmse(Im, fgp_gpu) +pars['rmse'] = rms +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(2,4,4) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) +# place a text box in upper left in axes coords +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=12, + verticalalignment='top', bbox=props) +imgplot = plt.imshow(fgp_gpu, cmap="gray") + +a=fig.add_subplot(2,4,8) + +# these are matplotlib.patch.Patch properties +props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) +# place a text box in upper left in axes coords +a.text(0.05, 0.95, 'fgp_gpu - u0', transform=a.transAxes, fontsize=14, + verticalalignment='top', bbox=props) +imgplot = plt.imshow((fgp_gpu - u0)**2, vmin=0, vmax=0.03, cmap="gray") +plt.colorbar(ticks=[0, 0.03], orientation='vertical') +plt.show() +""" -- cgit v1.2.3