summaryrefslogtreecommitdiffstats
path: root/Wrappers/Python/ccpi
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.pakino@gmail.com>2018-07-04 22:53:24 +0100
committerEdoardo Pasca <edo.pakino@gmail.com>2018-07-04 22:53:24 +0100
commit11199684baba00298c5fab2599c87fc80456ac16 (patch)
tree86b6cca8d00c0e1811630872b2e2c5ff6c6934c5 /Wrappers/Python/ccpi
parent95f9bbac5f70c357a7461b5c3f9a8eab7632687d (diff)
downloadregularization-11199684baba00298c5fab2599c87fc80456ac16.tar.gz
regularization-11199684baba00298c5fab2599c87fc80456ac16.tar.bz2
regularization-11199684baba00298c5fab2599c87fc80456ac16.tar.xz
regularization-11199684baba00298c5fab2599c87fc80456ac16.zip
relaxed requirement of finding GPU bindings
Diffstat (limited to 'Wrappers/Python/ccpi')
-rw-r--r--Wrappers/Python/ccpi/filters/regularisers.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/Wrappers/Python/ccpi/filters/regularisers.py b/Wrappers/Python/ccpi/filters/regularisers.py
index 52c7974..c7ae808 100644
--- a/Wrappers/Python/ccpi/filters/regularisers.py
+++ b/Wrappers/Python/ccpi/filters/regularisers.py
@@ -3,7 +3,11 @@ script which assigns a proper device core function based on a flag ('cpu' or 'gp
"""
from ccpi.filters.cpu_regularisers import TV_ROF_CPU, TV_FGP_CPU, TV_SB_CPU, dTV_FGP_CPU, TNV_CPU, NDF_CPU, Diff4th_CPU, TGV_CPU, LLT_ROF_CPU
-from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, TV_SB_GPU, dTV_FGP_GPU, NDF_GPU, Diff4th_GPU, TGV_GPU, LLT_ROF_GPU
+try:
+ from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, TV_SB_GPU, dTV_FGP_GPU, NDF_GPU, Diff4th_GPU, TGV_GPU, LLT_ROF_GPU
+ gpu_enabled = True
+except ImportError:
+ gpu_enabled = False
from ccpi.filters.cpu_regularisers import NDF_INPAINT_CPU, NVM_INPAINT_CPU
def ROF_TV(inputData, regularisation_parameter, iterations,
@@ -13,12 +17,14 @@ def ROF_TV(inputData, regularisation_parameter, iterations,
regularisation_parameter,
iterations,
time_marching_parameter)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return TV_ROF_GPU(inputData,
regularisation_parameter,
iterations,
time_marching_parameter)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
@@ -32,7 +38,7 @@ def FGP_TV(inputData, regularisation_parameter,iterations,
methodTV,
nonneg,
printM)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return TV_FGP_GPU(inputData,
regularisation_parameter,
iterations,
@@ -41,6 +47,8 @@ def FGP_TV(inputData, regularisation_parameter,iterations,
nonneg,
printM)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
def SB_TV(inputData, regularisation_parameter, iterations,
@@ -52,7 +60,7 @@ def SB_TV(inputData, regularisation_parameter, iterations,
tolerance_param,
methodTV,
printM)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return TV_SB_GPU(inputData,
regularisation_parameter,
iterations,
@@ -60,6 +68,8 @@ def SB_TV(inputData, regularisation_parameter, iterations,
methodTV,
printM)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
def FGP_dTV(inputData, refdata, regularisation_parameter, iterations,
@@ -74,7 +84,7 @@ def FGP_dTV(inputData, refdata, regularisation_parameter, iterations,
methodTV,
nonneg,
printM)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return dTV_FGP_GPU(inputData,
refdata,
regularisation_parameter,
@@ -85,6 +95,8 @@ def FGP_dTV(inputData, refdata, regularisation_parameter, iterations,
nonneg,
printM)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
def TNV(inputData, regularisation_parameter, iterations, tolerance_param):
@@ -101,7 +113,7 @@ def NDF(inputData, regularisation_parameter, edge_parameter, iterations,
iterations,
time_marching_parameter,
penalty_type)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return NDF_GPU(inputData,
regularisation_parameter,
edge_parameter,
@@ -109,6 +121,8 @@ def NDF(inputData, regularisation_parameter, edge_parameter, iterations,
time_marching_parameter,
penalty_type)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
def DIFF4th(inputData, regularisation_parameter, edge_parameter, iterations,
@@ -119,13 +133,15 @@ def DIFF4th(inputData, regularisation_parameter, edge_parameter, iterations,
edge_parameter,
iterations,
time_marching_parameter)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return Diff4th_GPU(inputData,
regularisation_parameter,
edge_parameter,
iterations,
time_marching_parameter)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations,
@@ -137,7 +153,7 @@ def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations,
alpha0,
iterations,
LipshitzConst)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return TGV_GPU(inputData,
regularisation_parameter,
alpha1,
@@ -145,15 +161,19 @@ def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations,
iterations,
LipshitzConst)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
def LLT_ROF(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations,
time_marching_parameter, device='cpu'):
if device == 'cpu':
return LLT_ROF_CPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter)
- elif device == 'gpu':
+ elif device == 'gpu' and gpu_enabled:
return LLT_ROF_GPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter)
else:
+ if not gpu_enabled and device == 'gpu':
+ raise ValueError ('GPU is not available')
raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
.format(device))
def NDF_INP(inputData, maskData, regularisation_parameter, edge_parameter, iterations,