summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Wrappers/Python/ccpi/filters/regularisers.py38
-rw-r--r--Wrappers/Python/conda-recipe/meta.yaml4
2 files changed, 31 insertions, 11 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,
diff --git a/Wrappers/Python/conda-recipe/meta.yaml b/Wrappers/Python/conda-recipe/meta.yaml
index 4774563..ca28bae 100644
--- a/Wrappers/Python/conda-recipe/meta.yaml
+++ b/Wrappers/Python/conda-recipe/meta.yaml
@@ -21,7 +21,7 @@ requirements:
- numpy x.x
- setuptools
- cython
- - cil_regulariser
+ - cil_regulariser =={{ environ['CIL_VERSION'] }}
- vc 14 # [win and py36]
- vc 14 # [win and py35]
- vc 9 # [win and py27]
@@ -30,7 +30,7 @@ requirements:
run:
- python
- numpy x.x
- - cil_regulariser
+ - cil_regulariser =={{ environ['CIL_VERSION'] }}
- vc 14 # [win and py36]
- vc 14 # [win and py35]
- vc 9 # [win and py27]