From 70a343790f027b8fb6e0de3db80fb43f3e187887 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Tue, 31 Oct 2017 16:40:59 +0000 Subject: progress using abstract device in class squash later --- src/Python/ccpi/reconstruction/AstraDevice.py | 24 +++++++--- .../ccpi/reconstruction/FISTAReconstructor.py | 52 +++++++++++++++------- 2 files changed, 55 insertions(+), 21 deletions(-) (limited to 'src/Python/ccpi') diff --git a/src/Python/ccpi/reconstruction/AstraDevice.py b/src/Python/ccpi/reconstruction/AstraDevice.py index ac9206e..61e95ce 100644 --- a/src/Python/ccpi/reconstruction/AstraDevice.py +++ b/src/Python/ccpi/reconstruction/AstraDevice.py @@ -41,7 +41,7 @@ Uses Astra-toolbox volume, self.proj_geom, self.vol_geom) astra.matlab.data3d('delete', sino_id) return y - except Exception(e): + except Exception as e: print(e) print("Value Error: ", self.proj_geom, self.vol_geom) @@ -59,19 +59,33 @@ Uses Astra-toolbox astra.matlab.data3d('delete', idx) return volume - def createReducedDevice(self): + def createReducedDevice(self, proj_par={'cameraY' : 1} , vol_par={'Z':1}): + '''Change the definition of the current device by changing some parameter + +VERY RISKY''' + for k,v in proj_par.items(): + if k in self.acquisition_data_geometry.keys(): + print ("Reduced device updating " , k , v) + self.acquisition_data_geometry[k] = v + print ("Reduced Device: ", self.acquisition_data_geometry) proj_geom = [ self.acquisition_data_geometry['cameraX'], - 1, + self.acquisition_data_geometry['cameraY'], self.acquisition_data_geometry['detectorSpacingX'], self.acquisition_data_geometry['detectorSpacingY'], self.acquisition_data_geometry['angles'] ] - + + for k,v in vol_par.items(): + if k in self.reconstructed_volume_geometry.keys(): + print ("Reduced device updating " , k , v) + self.reconstructed_volume_geometry[k] = v + print ("Reduced Device: ",self.reconstructed_volume_geometry) + vol_geom = [ self.reconstructed_volume_geometry['X'], self.reconstructed_volume_geometry['Y'], - 1 + self.reconstructed_volume_geometry['Z'] ] return AstraDevice(self.type, proj_geom, vol_geom) diff --git a/src/Python/ccpi/reconstruction/FISTAReconstructor.py b/src/Python/ccpi/reconstruction/FISTAReconstructor.py index b549755..3c576c4 100644 --- a/src/Python/ccpi/reconstruction/FISTAReconstructor.py +++ b/src/Python/ccpi/reconstruction/FISTAReconstructor.py @@ -664,7 +664,7 @@ class FISTAReconstructor(): 'ring_lambda_R_L1', 'Lipschitz_constant', 'number_of_iterations']) - + # errors vector (if the ground truth is given) Resid_error = numpy.zeros((iterFISTA)); # objective function values vector @@ -727,7 +727,12 @@ class FISTAReconstructor(): for j in range(len(CurrSubIndices)): mask[int(CurrSubIndices[j])] = True proj_geomSUB['ProjectionAngles'] = angles[mask] - + if self.use_device: + device = self.getParameter('device_model')\ + .createReducedDevice( + proj_par={'angles':angles[mask]}, + vol_par={}) + shape = list(numpy.shape(self.getParameter('input_sinogram'))) shape[1] = numProjSub sino_updt_Sub = numpy.zeros(shape) @@ -736,17 +741,24 @@ class FISTAReconstructor(): geometry_type == 'fanflat_vec' : for kkk in range(SlicesZ): - sino_id, sinoT = astra.creators.create_sino3d_gpu ( - X_t[kkk:kkk+1] , proj_geomSUB, vol_geom) - sino_updt_Sub[kkk] = sinoT.T.copy() + if self.use_device: + sinoT = device.doForwardProject(X_t[kkk:kkk+1]) + else: + sino_id, sinoT = astra.creators.create_sino3d_gpu ( + X_t[kkk:kkk+1] , proj_geomSUB, vol_geom) + sino_updt_Sub[kkk] = sinoT.T.copy() + astra.matlab.data3d('delete', sino_id) else: # for 3D geometry (watch the GPU memory overflow in # ASTRA < 1.8) - sino_id, sino_updt_Sub = \ - astra.creators.create_sino3d_gpu (X_t, proj_geomSUB, vol_geom) - - astra.matlab.data3d('delete', sino_id) + if self.use_device: + sino_updt_Sub = device.doForwardProject(X_t) + else: + sino_id, sino_updt_Sub = \ + astra.creators.create_sino3d_gpu (X_t, proj_geomSUB, vol_geom) + + astra.matlab.data3d('delete', sino_id) if lambdaR_L1 > 0 : @@ -773,18 +785,26 @@ class FISTAReconstructor(): # routine x_temp = numpy.zeros(numpy.shape(X), dtype=numpy.float32) for kkk in range(SlicesZ): - - x_id, x_temp[kkk] = \ - astra.creators.create_backprojection3d_gpu( - residualSub[kkk:kkk+1], - proj_geomSUB, vol_geom) + if self.use_device: + x_temp[kkk] = device.doBackwardProject( + residualSub[kkk:kkk+1]) + else: + x_id, x_temp[kkk] = \ + astra.creators.create_backprojection3d_gpu( + residualSub[kkk:kkk+1], + proj_geomSUB, vol_geom) + astra.matlab.data3d('delete', x_id) else: - x_id, x_temp = \ + if self.use_device: + x_temp = device.doBackwardProject( + residualSub) + else: + x_id, x_temp = \ astra.creators.create_backprojection3d_gpu( residualSub, proj_geomSUB, vol_geom) - astra.matlab.data3d('delete', x_id) + astra.matlab.data3d('delete', x_id) X = X_t - (1/L_const) * x_temp ## REGULARIZATION X = self.regularize(X) -- cgit v1.2.3