def dexp_lr_decon(image, psf, num_iterations, padding, internal_dtype): """ Lucy-Richardson deconvolution using dexp library :param image: ndarray data tile generated by dask :param skewed_psf: ndarray theoretical PSF :param padding: int internal padding for deconvolution :param internal_dtype: dtype data type to use on GPU :return result: ndarray deconvolved data tile """ # LR deconvolution on GPU deconvolved = lucy_richardson_deconvolution(image.astype(np.float16), psf.astype(np.float16), num_iterations=num_iterations, padding=padding, blind_spot=3, internal_dtype=internal_dtype) deconvolved = _c( dehaze(deconvolved, in_place=True, internal_dtype=internal_dtype)) # clean up memory del image, psf cp.clear_memo() gc.collect() return deconvolved.astype(np.uint16)
def clear_memo(): """Clears the memoized results for all functions decorated by memoize. This function works like :func:`cupy.clear_memo` as a counterpart for :func:`chainer.cuda.memoize`. It can be used even if CUDA is not available. In such a case, this function does nothing. """ if available: cupy.clear_memo()
def clear_memo(): """Clears the memoized results for all functions decorated by memoize. This function works like :func:`cupy.clear_memo` as a counterpart for :func:`chainer.cuda.memoize`. It can be used even if CUDA is not available. In such a case, this function does nothing. """ if available: cupy.clear_memo()
def lr_deconvolution(image,psf,iterations=50): """ Tiled Lucy-Richardson deconvolution using DECON_LIBRARY :param image: ndarray raw data :param psf: ndarray theoretical PSF :param iterations: int number of iterations to run :return deconvolved: ndarray deconvolved image """ # create dask array scan_chunk_size = 512 if image.shape[0]<scan_chunk_size: dask_raw = da.from_array(image,chunks=(image.shape[0],image.shape[1],image.shape[2])) overlap_depth = (0,2*psf.shape[1],2*psf.shape[1]) else: dask_raw = da.from_array(image,chunks=(scan_chunk_size,image.shape[1],image.shape[2])) overlap_depth = 2*psf.shape[0] del image gc.collect() if DECON_LIBRARY=='dexp': # define dask dexp partial function for GPU LR deconvolution lr_dask = partial(dexp_lr_decon,psf=psf,num_iterations=iterations,padding=2*psf.shape[0],internal_dtype=np.float16) else: lr_dask = partial(mv_lr_decon,psf=psf,num_iterations=iterations) # create dask plan for overlapped blocks dask_decon = da.map_overlap(lr_dask,dask_raw,depth=overlap_depth,boundary=None,trim=True,meta=np.array((), dtype=np.uint16)) # perform LR deconvolution in blocks if DECON_LIBRARY=='dexp': with CupyBackend(enable_cutensor=True,enable_cub=True,enable_fft_planning=True): with ProgressBar(): decon_data = dask_decon.compute(scheduler='single-threaded') else: with ProgressBar(): decon_data = dask_decon.compute(scheduler='single-threaded') # clean up memory cp.clear_memo() del dask_decon gc.collect() return decon_data.astype(np.uint16)
def _check_get_arch(self, device_cc, expected_arch): with mock.patch('cupy.cuda.device.Device') as device_class: device_class.return_value.compute_capability = device_cc assert compiler._get_arch() == expected_arch cupy.clear_memo() # _get_arch result is cached
def setUp(self): cupy.clear_memo() # _get_arch result is cached
S, C, H, W = subj.shape # Rotate ksp img_sli = np.fft.ifftshift(np.fft.ifft2(np.fft.ifftshift(subj, axes=(2, 3)), axes=(2, 3)), axes=(2, 3)) subj = np.fft.fftshift(np.fft.fft2(img_sli, axes=(2, 3)), axes=(2, 3)) for i in range(S): try: est_coilmap = np.load(sensemaps_path + subj_file + str(i) + '.npy') except: est_coilmap_gpu = mr.app.EspiritCalib(subj[i], calib_width=W // 2, thresh=0.02, kernel_width=6, crop=0.01, max_iter=100, show_pbar=False, device=0).run().get() est_coilmap = np.fft.fftshift(est_coilmap_gpu, axes=(1, 2)) np.save(sensemaps_path + subj_file + str(i), est_coilmap) del est_coilmap del est_coilmap_gpu cupy.clear_memo() print(j, i)