def test_05(self): Nr = 32 Nc = 31 Nd = 5 M = 4 D = np.random.randn(Nd, Nd, M).astype(np.float32) s = np.random.randn(Nr, Nc).astype(np.float32) lmbda = 1e-1 mu = 1e-2 opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False, 'MaxMainIter': 50, 'AutoRho': {'Enabled': False}}) b = cbpdn.ConvBPDNGradReg(D, s, lmbda, mu, opt) X1 = b.solve() X2 = cucbpdn.cbpdngrd(D, s, lmbda, mu, opt) assert(sm.mse(X1, X2) < 1e-10)
'Verbose': True, 'MaxMainIter': 20, 'HighMemSolve': True, 'LinSolveCheck': False, 'RelStopTol': 2e-3, 'AuxVarObj': False, 'AutoRho': { 'Enabled': False } }) # Initialise and run ConvBPDNGradReg object b = cbpdn.ConvBPDNGradReg(D, sh, lmbda, mu, opt) X1 = b.solve() print("ConvBPDNGradReg solve time: %.2fs" % b.timer.elapsed('solve')) # Time CUDA ConvBPDNGradReg solve t = util.Timer() with util.ContextTimer(t): X2 = cucbpdn.cbpdngrd(D, sh, lmbda, mu, opt) print("GPU ConvBPDNGradReg solve time: %.2fs" % t.elapsed()) print("GPU time improvement factor: %.1f" % (b.timer.elapsed('solve') / t.elapsed())) # Compare CPU and GPU solutions print("CPU solution: min: %.4e max: %.4e l1: %.4e" % (X1.min(), X1.max(), np.sum(np.abs(X1)))) print("GPU solution: min: %.4e max: %.4e l1: %.4e" % (X2.min(), X2.max(), np.sum(np.abs(X2)))) print("CPU/GPU MSE: %.2e SNR: %.2f dB" % (sm.mse(X1, X2), sm.snr(X1, X2)))
wgr[0] = 1.0 # Set up ConvBPDNGradReg options lmbda = 1e-2 mu = 1e1 opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': True, 'MaxMainIter': 200, 'HighMemSolve': True, 'RelStopTol': 5e-3, 'AuxVarObj': False, 'AutoRho': {'Enabled': False}, 'rho': 0.2, 'L1Weight': wl1, 'GradWeight': wgr}) # Time CUDA cbpdn solve t = util.Timer() with util.ContextTimer(t): X = cucbpdn.cbpdngrd(D, img, lmbda, mu, opt) print("Image size: %d x %d" % img.shape) print("GPU ConvBPDNGradReg solve time: %.2fs" % t.elapsed()) # Reconstruct the image from the sparse representation imgr = np.sum(spl.fftconv(D, X), axis=2) #Display representation and reconstructed image. fig = plot.figure(figsize=(14, 14)) plot.subplot(2, 2, 1) plot.imview(X[..., 0].squeeze(), fig=fig, title='Lowpass component') plot.subplot(2, 2, 2) plot.imview(np.sum(abs(X[..., 1:]), axis=2).squeeze(), fig=fig, cmap=plot.cm.Blues, title='Main representation')