Tutorials
Juyter Logo

TorchVector: going on GPU

Authors
Francesco Picetti
Ettore Biondi

#Compute on CPU/GPU: Torch Vectors and Operators

@Author: Francesco Picetti - picettifrancesco@gmail.com

In this notebook we will show how to define a new vector class based on PyTorch operations.

#Import modules

import numpy as np
import occamypy as o

# Plotting
from matplotlib import rcParams
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt
rcParams.update({
    'image.cmap'     : 'gray',
    'image.aspect'   : 'auto',
    'image.interpolation': None,
    'axes.grid'      : False,
    'figure.figsize' : (10, 6),
    'savefig.dpi'    : 300,
    'axes.labelsize' : 14,
    'axes.titlesize' : 16,
    'font.size'      : 14,
    'legend.fontsize': 14,
    'xtick.labelsize': 14,
    'ytick.labelsize': 14,
    'text.usetex'    : True,
    'font.family'    : 'serif',
    'font.serif'     : 'Latin Modern Roman',
})
WARNING! DATAPATH not found. The folder /tmp will be used to write binary files
/nas/home/fpicetti/miniconda3/envs/occd/lib/python3.10/site-packages/dask_jobqueue/core.py:20: FutureWarning: tmpfile is deprecated and will be removed in a future release. Please use dask.utils.tmpfile instead.
  from distributed.utils import tmpfile

#2D Phantom Deconvolution

In this example we reconstruct a phantom CT image starting from a blurred acquisition. Again, we regularize the inversion by imposing the first derivative to be sparse.

Note: as the vector is instantiated on a GPU, we use the method plot for getting a plottable array

x = o.VectorTorch(np.load('./data/shepp_logan_phantom.npy', allow_pickle=True).astype(np.float32),
                  device=0).scale(1 / 255.)
print(x.deviceName)
GPU 0 - Tesla V100-PCIE-16GB

The blurring operator is based on torch Conv Modules, so that it handles torch.Tensor vector data. The derivative operator instead is backend-agnostic.

G = o.GaussianFilter(x, sigma=(3.,3.))
d = G * x

fig, ax = plt.subplots(1, 2, figsize=(10,6))
ax[0].imshow(x.plot(), cmap='bone', clim=(0,1))
ax[0].grid(False)
ax[0].set_title('Model')
ax[1].imshow(d.plot(), cmap='bone', clim=(0,1))
ax[1].grid(False)
ax[1].set_title('Data')
plt.show()
<Figure size 720x432 with 2 Axes>

As regularizer, we compute the gradient.

D = o.Gradient(x)
Dx = D * x

fig, ax = plt.subplots(1, 2, figsize=(10,6))
ax[0].imshow(Dx.vecs[1].plot(), cmap='bone')
ax[0].grid(False)
ax[0].set_title(r'$\nabla_h(x)$')
ax[1].imshow(Dx.vecs[0].plot(), cmap='bone')
ax[1].grid(False)
ax[1].set_title(r'$\nabla_v(x)$')
plt.show()
<Figure size 720x432 with 2 Axes>

Problem and solver:

problemSB = o.GeneralizedLasso(x.clone().zero(), d, G, reg=D, eps=1e-3)
SB = o.SplitBregman(o.BasicStopper(niter=200), niter_inner=3, niter_solver=10,
                           linear_solver='LSQR', breg_weight=1., warm_start=True)
SB.setDefaults(save_obj=True)
SB.run(problemSB, verbose=True, inner_verbose=False)
##########################################################################################
            SPLIT-BREGMAN Solver
    Restart folder: /tmp/restart_2022-04-22T01-51-02.448344/
    Inner iterations: 3
    Solver iterations: 10
    L1 Regularizer weight: 1.00e-03
    Bregman update weight: 1.00e+00
    Using warm start option for inner problem
##########################################################################################

iter = 000, obj = 7.21397e+02, df_obj = 7.21e+02, reg_obj = 0.00e+00, rnorm = 3.80e+01
iter = 001, obj = 1.56842e+00, df_obj = 2.37e-02, reg_obj = 1.54e+00, rnorm = 1.26e+01
iter = 002, obj = 1.59997e+00, df_obj = 7.93e-03, reg_obj = 1.59e+00, rnorm = 1.34e+01
iter = 003, obj = 1.61106e+00, df_obj = 4.38e-03, reg_obj = 1.61e+00, rnorm = 1.37e+01
iter = 004, obj = 1.62317e+00, df_obj = 2.92e-03, reg_obj = 1.62e+00, rnorm = 1.39e+01
iter = 005, obj = 1.62704e+00, df_obj = 2.15e-03, reg_obj = 1.62e+00, rnorm = 1.41e+01
iter = 006, obj = 1.63125e+00, df_obj = 1.68e-03, reg_obj = 1.63e+00, rnorm = 1.42e+01
iter = 007, obj = 1.63111e+00, df_obj = 1.37e-03, reg_obj = 1.63e+00, rnorm = 1.43e+01
iter = 008, obj = 1.63158e+00, df_obj = 1.14e-03, reg_obj = 1.63e+00, rnorm = 1.44e+01
iter = 009, obj = 1.62932e+00, df_obj = 9.81e-04, reg_obj = 1.63e+00, rnorm = 1.45e+01
iter = 010, obj = 1.62776e+00, df_obj = 8.55e-04, reg_obj = 1.63e+00, rnorm = 1.46e+01
iter = 011, obj = 1.62446e+00, df_obj = 7.58e-04, reg_obj = 1.62e+00, rnorm = 1.46e+01
iter = 012, obj = 1.62171e+00, df_obj = 6.78e-04, reg_obj = 1.62e+00, rnorm = 1.47e+01
iter = 013, obj = 1.61783e+00, df_obj = 6.13e-04, reg_obj = 1.62e+00, rnorm = 1.47e+01
iter = 014, obj = 1.61451e+00, df_obj = 5.59e-04, reg_obj = 1.61e+00, rnorm = 1.48e+01
iter = 015, obj = 1.61040e+00, df_obj = 5.14e-04, reg_obj = 1.61e+00, rnorm = 1.48e+01
iter = 016, obj = 1.60674e+00, df_obj = 4.75e-04, reg_obj = 1.61e+00, rnorm = 1.49e+01
iter = 017, obj = 1.60244e+00, df_obj = 4.41e-04, reg_obj = 1.60e+00, rnorm = 1.49e+01
iter = 018, obj = 1.59853e+00, df_obj = 4.12e-04, reg_obj = 1.60e+00, rnorm = 1.49e+01
iter = 019, obj = 1.59412e+00, df_obj = 3.87e-04, reg_obj = 1.59e+00, rnorm = 1.50e+01
iter = 020, obj = 1.59017e+00, df_obj = 3.64e-04, reg_obj = 1.59e+00, rnorm = 1.50e+01
iter = 021, obj = 1.58588e+00, df_obj = 3.44e-04, reg_obj = 1.59e+00, rnorm = 1.50e+01
iter = 022, obj = 1.58201e+00, df_obj = 3.25e-04, reg_obj = 1.58e+00, rnorm = 1.51e+01
iter = 023, obj = 1.57775e+00, df_obj = 3.09e-04, reg_obj = 1.58e+00, rnorm = 1.51e+01
iter = 024, obj = 1.57385e+00, df_obj = 2.95e-04, reg_obj = 1.57e+00, rnorm = 1.51e+01
iter = 025, obj = 1.56966e+00, df_obj = 2.82e-04, reg_obj = 1.57e+00, rnorm = 1.51e+01
iter = 026, obj = 1.56586e+00, df_obj = 2.69e-04, reg_obj = 1.57e+00, rnorm = 1.51e+01
iter = 027, obj = 1.56176e+00, df_obj = 2.58e-04, reg_obj = 1.56e+00, rnorm = 1.52e+01
iter = 028, obj = 1.55804e+00, df_obj = 2.48e-04, reg_obj = 1.56e+00, rnorm = 1.52e+01
iter = 029, obj = 1.55402e+00, df_obj = 2.39e-04, reg_obj = 1.55e+00, rnorm = 1.52e+01
iter = 030, obj = 1.55039e+00, df_obj = 2.30e-04, reg_obj = 1.55e+00, rnorm = 1.52e+01
iter = 031, obj = 1.54648e+00, df_obj = 2.22e-04, reg_obj = 1.55e+00, rnorm = 1.52e+01
iter = 032, obj = 1.54293e+00, df_obj = 2.15e-04, reg_obj = 1.54e+00, rnorm = 1.53e+01
iter = 033, obj = 1.53912e+00, df_obj = 2.08e-04, reg_obj = 1.54e+00, rnorm = 1.53e+01
iter = 034, obj = 1.53566e+00, df_obj = 2.01e-04, reg_obj = 1.54e+00, rnorm = 1.53e+01
iter = 035, obj = 1.53196e+00, df_obj = 1.95e-04, reg_obj = 1.53e+00, rnorm = 1.53e+01
iter = 036, obj = 1.52862e+00, df_obj = 1.90e-04, reg_obj = 1.53e+00, rnorm = 1.53e+01
iter = 037, obj = 1.52505e+00, df_obj = 1.84e-04, reg_obj = 1.52e+00, rnorm = 1.54e+01
iter = 038, obj = 1.52183e+00, df_obj = 1.79e-04, reg_obj = 1.52e+00, rnorm = 1.54e+01
iter = 039, obj = 1.51840e+00, df_obj = 1.75e-04, reg_obj = 1.52e+00, rnorm = 1.54e+01
iter = 040, obj = 1.51529e+00, df_obj = 1.70e-04, reg_obj = 1.52e+00, rnorm = 1.54e+01
iter = 041, obj = 1.51196e+00, df_obj = 1.66e-04, reg_obj = 1.51e+00, rnorm = 1.54e+01
iter = 042, obj = 1.50893e+00, df_obj = 1.62e-04, reg_obj = 1.51e+00, rnorm = 1.54e+01
iter = 043, obj = 1.50573e+00, df_obj = 1.58e-04, reg_obj = 1.51e+00, rnorm = 1.54e+01
iter = 044, obj = 1.50283e+00, df_obj = 1.55e-04, reg_obj = 1.50e+00, rnorm = 1.55e+01
iter = 045, obj = 1.49976e+00, df_obj = 1.51e-04, reg_obj = 1.50e+00, rnorm = 1.55e+01
iter = 046, obj = 1.49695e+00, df_obj = 1.48e-04, reg_obj = 1.50e+00, rnorm = 1.55e+01
iter = 047, obj = 1.49397e+00, df_obj = 1.45e-04, reg_obj = 1.49e+00, rnorm = 1.55e+01
iter = 048, obj = 1.49122e+00, df_obj = 1.42e-04, reg_obj = 1.49e+00, rnorm = 1.55e+01
iter = 049, obj = 1.48835e+00, df_obj = 1.40e-04, reg_obj = 1.49e+00, rnorm = 1.55e+01
iter = 050, obj = 1.48572e+00, df_obj = 1.37e-04, reg_obj = 1.49e+00, rnorm = 1.55e+01
iter = 051, obj = 1.48296e+00, df_obj = 1.34e-04, reg_obj = 1.48e+00, rnorm = 1.56e+01
iter = 052, obj = 1.48041e+00, df_obj = 1.32e-04, reg_obj = 1.48e+00, rnorm = 1.56e+01
iter = 053, obj = 1.47772e+00, df_obj = 1.30e-04, reg_obj = 1.48e+00, rnorm = 1.56e+01
iter = 054, obj = 1.47523e+00, df_obj = 1.27e-04, reg_obj = 1.48e+00, rnorm = 1.56e+01
iter = 055, obj = 1.47262e+00, df_obj = 1.25e-04, reg_obj = 1.47e+00, rnorm = 1.56e+01
iter = 056, obj = 1.47022e+00, df_obj = 1.23e-04, reg_obj = 1.47e+00, rnorm = 1.56e+01
iter = 057, obj = 1.46772e+00, df_obj = 1.21e-04, reg_obj = 1.47e+00, rnorm = 1.56e+01
iter = 058, obj = 1.46539e+00, df_obj = 1.19e-04, reg_obj = 1.47e+00, rnorm = 1.56e+01
iter = 059, obj = 1.46297e+00, df_obj = 1.17e-04, reg_obj = 1.46e+00, rnorm = 1.57e+01
iter = 060, obj = 1.46072e+00, df_obj = 1.16e-04, reg_obj = 1.46e+00, rnorm = 1.57e+01
iter = 061, obj = 1.45840e+00, df_obj = 1.14e-04, reg_obj = 1.46e+00, rnorm = 1.57e+01
iter = 062, obj = 1.45621e+00, df_obj = 1.12e-04, reg_obj = 1.46e+00, rnorm = 1.57e+01
iter = 063, obj = 1.45395e+00, df_obj = 1.11e-04, reg_obj = 1.45e+00, rnorm = 1.57e+01
iter = 064, obj = 1.45185e+00, df_obj = 1.09e-04, reg_obj = 1.45e+00, rnorm = 1.57e+01
iter = 065, obj = 1.44969e+00, df_obj = 1.08e-04, reg_obj = 1.45e+00, rnorm = 1.57e+01
iter = 066, obj = 1.44764e+00, df_obj = 1.06e-04, reg_obj = 1.45e+00, rnorm = 1.57e+01
iter = 067, obj = 1.44552e+00, df_obj = 1.05e-04, reg_obj = 1.45e+00, rnorm = 1.57e+01
iter = 068, obj = 1.44352e+00, df_obj = 1.04e-04, reg_obj = 1.44e+00, rnorm = 1.58e+01
iter = 069, obj = 1.44147e+00, df_obj = 1.02e-04, reg_obj = 1.44e+00, rnorm = 1.58e+01
iter = 070, obj = 1.43955e+00, df_obj = 1.01e-04, reg_obj = 1.44e+00, rnorm = 1.58e+01
iter = 071, obj = 1.43757e+00, df_obj = 1.00e-04, reg_obj = 1.44e+00, rnorm = 1.58e+01
iter = 072, obj = 1.43571e+00, df_obj = 9.89e-05, reg_obj = 1.44e+00, rnorm = 1.58e+01
iter = 073, obj = 1.43379e+00, df_obj = 9.78e-05, reg_obj = 1.43e+00, rnorm = 1.58e+01
iter = 074, obj = 1.43197e+00, df_obj = 9.67e-05, reg_obj = 1.43e+00, rnorm = 1.58e+01
iter = 075, obj = 1.43010e+00, df_obj = 9.57e-05, reg_obj = 1.43e+00, rnorm = 1.58e+01
iter = 076, obj = 1.42835e+00, df_obj = 9.46e-05, reg_obj = 1.43e+00, rnorm = 1.58e+01
iter = 077, obj = 1.42656e+00, df_obj = 9.37e-05, reg_obj = 1.43e+00, rnorm = 1.58e+01
iter = 078, obj = 1.42486e+00, df_obj = 9.27e-05, reg_obj = 1.42e+00, rnorm = 1.59e+01
iter = 079, obj = 1.42311e+00, df_obj = 9.18e-05, reg_obj = 1.42e+00, rnorm = 1.59e+01
iter = 080, obj = 1.42145e+00, df_obj = 9.09e-05, reg_obj = 1.42e+00, rnorm = 1.59e+01
iter = 081, obj = 1.41975e+00, df_obj = 9.00e-05, reg_obj = 1.42e+00, rnorm = 1.59e+01
iter = 082, obj = 1.41814e+00, df_obj = 8.91e-05, reg_obj = 1.42e+00, rnorm = 1.59e+01
iter = 083, obj = 1.41649e+00, df_obj = 8.83e-05, reg_obj = 1.42e+00, rnorm = 1.59e+01
iter = 084, obj = 1.41492e+00, df_obj = 8.75e-05, reg_obj = 1.41e+00, rnorm = 1.59e+01
iter = 085, obj = 1.41331e+00, df_obj = 8.67e-05, reg_obj = 1.41e+00, rnorm = 1.59e+01
iter = 086, obj = 1.41179e+00, df_obj = 8.59e-05, reg_obj = 1.41e+00, rnorm = 1.59e+01
iter = 087, obj = 1.41026e+00, df_obj = 8.51e-05, reg_obj = 1.41e+00, rnorm = 1.59e+01
iter = 088, obj = 1.40879e+00, df_obj = 8.44e-05, reg_obj = 1.41e+00, rnorm = 1.60e+01
iter = 089, obj = 1.40730e+00, df_obj = 8.37e-05, reg_obj = 1.41e+00, rnorm = 1.60e+01
iter = 090, obj = 1.40587e+00, df_obj = 8.29e-05, reg_obj = 1.41e+00, rnorm = 1.60e+01
iter = 091, obj = 1.40443e+00, df_obj = 8.22e-05, reg_obj = 1.40e+00, rnorm = 1.60e+01
iter = 092, obj = 1.40304e+00, df_obj = 8.15e-05, reg_obj = 1.40e+00, rnorm = 1.60e+01
iter = 093, obj = 1.40161e+00, df_obj = 8.09e-05, reg_obj = 1.40e+00, rnorm = 1.60e+01
iter = 094, obj = 1.40024e+00, df_obj = 8.02e-05, reg_obj = 1.40e+00, rnorm = 1.60e+01
iter = 095, obj = 1.39885e+00, df_obj = 7.96e-05, reg_obj = 1.40e+00, rnorm = 1.60e+01
iter = 096, obj = 1.39751e+00, df_obj = 7.89e-05, reg_obj = 1.40e+00, rnorm = 1.60e+01
iter = 097, obj = 1.39615e+00, df_obj = 7.83e-05, reg_obj = 1.40e+00, rnorm = 1.60e+01
iter = 098, obj = 1.39485e+00, df_obj = 7.77e-05, reg_obj = 1.39e+00, rnorm = 1.60e+01
iter = 099, obj = 1.39351e+00, df_obj = 7.71e-05, reg_obj = 1.39e+00, rnorm = 1.61e+01
iter = 100, obj = 1.39223e+00, df_obj = 7.65e-05, reg_obj = 1.39e+00, rnorm = 1.61e+01
iter = 101, obj = 1.39092e+00, df_obj = 7.60e-05, reg_obj = 1.39e+00, rnorm = 1.61e+01
iter = 102, obj = 1.38968e+00, df_obj = 7.54e-05, reg_obj = 1.39e+00, rnorm = 1.61e+01
iter = 103, obj = 1.38842e+00, df_obj = 7.49e-05, reg_obj = 1.39e+00, rnorm = 1.61e+01
iter = 104, obj = 1.38721e+00, df_obj = 7.43e-05, reg_obj = 1.39e+00, rnorm = 1.61e+01
iter = 105, obj = 1.38598e+00, df_obj = 7.38e-05, reg_obj = 1.39e+00, rnorm = 1.61e+01
iter = 106, obj = 1.38481e+00, df_obj = 7.33e-05, reg_obj = 1.38e+00, rnorm = 1.61e+01
iter = 107, obj = 1.38362e+00, df_obj = 7.28e-05, reg_obj = 1.38e+00, rnorm = 1.61e+01
iter = 108, obj = 1.38248e+00, df_obj = 7.23e-05, reg_obj = 1.38e+00, rnorm = 1.61e+01
iter = 109, obj = 1.38130e+00, df_obj = 7.18e-05, reg_obj = 1.38e+00, rnorm = 1.61e+01
iter = 110, obj = 1.38017e+00, df_obj = 7.13e-05, reg_obj = 1.38e+00, rnorm = 1.61e+01
iter = 111, obj = 1.37901e+00, df_obj = 7.08e-05, reg_obj = 1.38e+00, rnorm = 1.62e+01
iter = 112, obj = 1.37792e+00, df_obj = 7.03e-05, reg_obj = 1.38e+00, rnorm = 1.62e+01
iter = 113, obj = 1.37678e+00, df_obj = 6.99e-05, reg_obj = 1.38e+00, rnorm = 1.62e+01
iter = 114, obj = 1.37572e+00, df_obj = 6.94e-05, reg_obj = 1.38e+00, rnorm = 1.62e+01
iter = 115, obj = 1.37462e+00, df_obj = 6.90e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 116, obj = 1.37357e+00, df_obj = 6.85e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 117, obj = 1.37248e+00, df_obj = 6.81e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 118, obj = 1.37145e+00, df_obj = 6.77e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 119, obj = 1.37038e+00, df_obj = 6.72e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 120, obj = 1.36937e+00, df_obj = 6.68e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 121, obj = 1.36831e+00, df_obj = 6.64e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 122, obj = 1.36733e+00, df_obj = 6.60e-05, reg_obj = 1.37e+00, rnorm = 1.62e+01
iter = 123, obj = 1.36630e+00, df_obj = 6.56e-05, reg_obj = 1.37e+00, rnorm = 1.63e+01
iter = 124, obj = 1.36534e+00, df_obj = 6.52e-05, reg_obj = 1.37e+00, rnorm = 1.63e+01
iter = 125, obj = 1.36433e+00, df_obj = 6.49e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 126, obj = 1.36338e+00, df_obj = 6.45e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 127, obj = 1.36239e+00, df_obj = 6.41e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 128, obj = 1.36145e+00, df_obj = 6.38e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 129, obj = 1.36048e+00, df_obj = 6.34e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 130, obj = 1.35957e+00, df_obj = 6.30e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 131, obj = 1.35862e+00, df_obj = 6.27e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 132, obj = 1.35771e+00, df_obj = 6.24e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 133, obj = 1.35678e+00, df_obj = 6.21e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 134, obj = 1.35590e+00, df_obj = 6.17e-05, reg_obj = 1.36e+00, rnorm = 1.63e+01
iter = 135, obj = 1.35500e+00, df_obj = 6.14e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 136, obj = 1.35415e+00, df_obj = 6.11e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 137, obj = 1.35326e+00, df_obj = 6.08e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 138, obj = 1.35242e+00, df_obj = 6.05e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 139, obj = 1.35155e+00, df_obj = 6.02e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 140, obj = 1.35073e+00, df_obj = 5.99e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 141, obj = 1.34987e+00, df_obj = 5.96e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 142, obj = 1.34906e+00, df_obj = 5.93e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 143, obj = 1.34823e+00, df_obj = 5.90e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 144, obj = 1.34745e+00, df_obj = 5.87e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 145, obj = 1.34664e+00, df_obj = 5.84e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 146, obj = 1.34587e+00, df_obj = 5.82e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 147, obj = 1.34507e+00, df_obj = 5.79e-05, reg_obj = 1.35e+00, rnorm = 1.64e+01
iter = 148, obj = 1.34431e+00, df_obj = 5.76e-05, reg_obj = 1.34e+00, rnorm = 1.64e+01
iter = 149, obj = 1.34352e+00, df_obj = 5.74e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 150, obj = 1.34279e+00, df_obj = 5.71e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 151, obj = 1.34202e+00, df_obj = 5.68e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 152, obj = 1.34130e+00, df_obj = 5.66e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 153, obj = 1.34056e+00, df_obj = 5.63e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 154, obj = 1.33988e+00, df_obj = 5.60e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 155, obj = 1.33916e+00, df_obj = 5.58e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 156, obj = 1.33850e+00, df_obj = 5.55e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 157, obj = 1.33779e+00, df_obj = 5.53e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 158, obj = 1.33714e+00, df_obj = 5.51e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 159, obj = 1.33644e+00, df_obj = 5.48e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 160, obj = 1.33580e+00, df_obj = 5.46e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 161, obj = 1.33513e+00, df_obj = 5.44e-05, reg_obj = 1.34e+00, rnorm = 1.65e+01
iter = 162, obj = 1.33451e+00, df_obj = 5.41e-05, reg_obj = 1.33e+00, rnorm = 1.65e+01
iter = 163, obj = 1.33384e+00, df_obj = 5.39e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 164, obj = 1.33323e+00, df_obj = 5.37e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 165, obj = 1.33259e+00, df_obj = 5.35e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 166, obj = 1.33199e+00, df_obj = 5.32e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 167, obj = 1.33136e+00, df_obj = 5.30e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 168, obj = 1.33078e+00, df_obj = 5.28e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 169, obj = 1.33016e+00, df_obj = 5.26e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 170, obj = 1.32959e+00, df_obj = 5.23e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 171, obj = 1.32898e+00, df_obj = 5.21e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 172, obj = 1.32843e+00, df_obj = 5.19e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 173, obj = 1.32783e+00, df_obj = 5.17e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 174, obj = 1.32727e+00, df_obj = 5.15e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 175, obj = 1.32669e+00, df_obj = 5.13e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 176, obj = 1.32615e+00, df_obj = 5.11e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 177, obj = 1.32556e+00, df_obj = 5.09e-05, reg_obj = 1.33e+00, rnorm = 1.66e+01
iter = 178, obj = 1.32503e+00, df_obj = 5.07e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 179, obj = 1.32446e+00, df_obj = 5.05e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 180, obj = 1.32394e+00, df_obj = 5.03e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 181, obj = 1.32337e+00, df_obj = 5.02e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 182, obj = 1.32286e+00, df_obj = 5.00e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 183, obj = 1.32230e+00, df_obj = 4.98e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 184, obj = 1.32179e+00, df_obj = 4.96e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 185, obj = 1.32124e+00, df_obj = 4.94e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 186, obj = 1.32075e+00, df_obj = 4.92e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 187, obj = 1.32021e+00, df_obj = 4.91e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 188, obj = 1.31973e+00, df_obj = 4.89e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 189, obj = 1.31921e+00, df_obj = 4.87e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 190, obj = 1.31873e+00, df_obj = 4.85e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 191, obj = 1.31821e+00, df_obj = 4.84e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 192, obj = 1.31775e+00, df_obj = 4.82e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 193, obj = 1.31725e+00, df_obj = 4.80e-05, reg_obj = 1.32e+00, rnorm = 1.67e+01
iter = 194, obj = 1.31679e+00, df_obj = 4.79e-05, reg_obj = 1.32e+00, rnorm = 1.68e+01
iter = 195, obj = 1.31629e+00, df_obj = 4.77e-05, reg_obj = 1.32e+00, rnorm = 1.68e+01
iter = 196, obj = 1.31583e+00, df_obj = 4.75e-05, reg_obj = 1.32e+00, rnorm = 1.68e+01
iter = 197, obj = 1.31534e+00, df_obj = 4.74e-05, reg_obj = 1.32e+00, rnorm = 1.68e+01
iter = 198, obj = 1.31489e+00, df_obj = 4.72e-05, reg_obj = 1.31e+00, rnorm = 1.68e+01
iter = 199, obj = 1.31439e+00, df_obj = 4.71e-05, reg_obj = 1.31e+00, rnorm = 1.68e+01
iter = 200, obj = 1.31394e+00, df_obj = 4.69e-05, reg_obj = 1.31e+00, rnorm = 1.68e+01
Terminate: maximum number of iterations reached

##########################################################################################
            SPLIT-BREGMAN Solver end
##########################################################################################
its = "%d-%d-%d" % (len(SB.obj), SB.niter_inner, SB.niter_solver)

fig, ax = plt.subplots(1, 2, figsize=(10,6))
ax[0].imshow(x.plot(), cmap='bone', clim=(0,1))
ax[0].grid(False)
ax[0].set_title('Model')
ax[1].imshow(problemSB.model.plot(), cmap='bone', clim=(0,1))
ax[1].grid(False)
ax[1].set_title(r'SB %s, $\varepsilon=%.e$' % (its, problemSB.eps))
plt.show()
<Figure size 720x432 with 2 Axes>
fig, ax = plt.subplots(figsize=(10,6))
ax.semilogy(SB.obj / SB.obj[0], 'k', lw=2, label='Obj')
ax.semilogy(SB.obj_terms[:, 0] / SB.obj[0], 'b--', label=r"$0.5 \Vert \mathbf{Gx-d} \Vert_2^2$")
ax.semilogy(SB.obj_terms[:, 1] / SB.obj[0], 'r--', label=r"$\varepsilon \Vert \mathbf{Dx}\Vert_1$")
ax.set_ylim(1e-8, 1), ax.set_xlim(0, SB.stopper.niter)
ax.set_xlabel("Iterations")
ax.legend(loc="right")
ax.grid(True)
plt.suptitle(r'Split-Bregman %s, $\varepsilon=%.e$' % (its, problemSB.eps))
plt.show()
<Figure size 720x432 with 1 Axes>