def __init__(self, D0, lmbda=None, opt=None, dimK=None, dimN=2): """ Parameters ---------- D0 : array_like Initial dictionary array lmbda : float Regularisation parameter opt : :class:`OnlineConvBPDNDictLearn.Options` object Algorithm options dimK : 0, 1, or None, optional (default None) Number of signal dimensions in signal array passed to :meth:`solve`. If there will only be a single input signal (e.g. if `S` is a 2D array representing a single image) `dimK` must be set to 0. dimN : int, optional (default 2) Number of spatial/temporal dimensions """ if opt is None: opt = OnlineConvBPDNDictLearn.Options() if not isinstance(opt, OnlineConvBPDNDictLearn.Options): raise TypeError('Parameter opt must be an instance of ' 'OnlineConvBPDNDictLearn.Options') self.opt = opt if dimN != 2 and opt['CUDA_CBPDN']: raise ValueError('CUDA CBPDN solver can only be used when dimN=2') if opt['CUDA_CBPDN'] and cuda.device_count() == 0: raise ValueError('SPORCO-CUDA not installed or no GPU available') self.dimK = dimK self.dimN = dimN # DataType option overrides data type inferred from __init__ # parameters of derived class self.set_dtype(opt, D0.dtype) # Initialise attributes representing algorithm parameter self.lmbda = lmbda self.eta_a = opt['eta_a'] self.eta_b = opt['eta_b'] self.set_attr('eta', opt['eta_a'] / opt['eta_b'], dval=2.0, dtype=self.dtype) # Get dictionary size if self.opt['DictSize'] is None: self.dsz = D0.shape else: self.dsz = self.opt['DictSize'] # Construct object representing problem dimensions self.cri = None # Normalise dictionary ds = cr.DictionarySize(self.dsz, dimN) dimCd = ds.ndim - dimN - 1 D0 = cr.stdformD(D0, ds.nchn, ds.nflt, dimN).astype(self.dtype) self.D = cr.Pcn(D0, self.dsz, (), dimN, dimCd, crp=True, zm=opt['ZeroMean']) self.Dprv = self.D.copy() # Create constraint set projection function self.Pcn = cr.getPcn(self.dsz, (), dimN, dimCd, crp=True, zm=opt['ZeroMean']) # Initalise iterations stats list and iteration index self.itstat = [] self.j = 0 # Configure status display self.display_config()
'RelStopTol': 5e-3, 'AuxVarObj': False, 'RelaxParam': 1.8, 'rho': 5e1 * lmbda + 1e-1, 'L1Weight': wl1, 'GradWeight': wgr, 'AutoRho': { 'Enabled': False, 'StdResiduals': False } }) """ Construct :class:`.admm.cbpdn.AddMaskSim` wrapper for :class:`.admm.cbpdn.ConvBPDNGradReg` and solve via wrapper. If the ``sporco-cuda`` extension is installed and a GPU is available, use the CUDA implementation of this combination. """ if cuda.device_count() > 0: opt['L1Weight'] = wl1 opt['GradWeight'] = wgr ams = None print('%s GPU found: running CUDA solver' % cuda.device_name()) tm = util.Timer() with sys_pipes(), util.ContextTimer(tm): X = cuda.cbpdngrdmsk(Di, imgwp, mskp, lmbda, mu, opt) t = tm.elapsed() imgr = crop(np.sum(linalg.fftconv(Di, X), axis=-1)) else: opt['L1Weight'] = wl1i opt['GradWeight'] = wgri ams = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, Di, imgwp,
Set up :class:`.admm.cbpdn.ConvBPDNGradReg` options. """ lmbda = 1e-2 mu = 5e-1 opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': True, 'MaxMainIter': 250, 'HighMemSolve': True, 'RelStopTol': 5e-3, 'AuxVarObj': False, 'AutoRho': {'Enabled': False}, 'rho': 0.5, 'L1Weight': wl1, 'GradWeight': wgr}) """ If GPU available, run CUDA ConvBPDNGradReg solver, otherwise run standard Python version. """ if cuda.device_count() > 0: print('%s GPU found: running CUDA solver' % cuda.device_name()) tm = util.Timer() with sys_pipes(), util.ContextTimer(tm): X = cuda.cbpdngrd(D, img, lmbda, mu, opt) t = tm.elapsed() else: print('GPU not found: running Python solver') c = cbpdn.ConvBPDNGradReg(D, img, lmbda, mu, opt) X = c.solve().squeeze() t = c.timer.elapsed('solve') print('Solve time: %.2f s' % t) """ Reconstruct the image from the sparse representation.