Algorithmresearch
Learned primal-dual reconstruction
Also called learned primal-dual.
An unrolled primal-dual scheme for inverse problems in which learned networks replace both proximal steps, and each of a fixed number of steps calls the forward operator and its adjoint once.
- Time
- O(K (a + g)) worst
- Space
- O(p n + d m) extra
- Where
- K = the number of steps; a = the cost of one call to A plus one call to its adjoint; d = the number of dual channels; g = the cost of one call to each of the two learned maps (outside this page); m = the number of data values; n = the number of unknowns; p = the number of primal channels
- Model
- Real RAM
- Properties
- deterministicnot exactiterativelearnedmatrix free
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Jonas Adler, Ozan Oktem, 2018
Learned primal-dual reconstruction is an unrolled version of the Chambolle-Pock algorithm for an inverse problem . It runs a fixed number of steps. In each step a learned dual map takes the dual state, the forward projection and the data , and a learned primal map takes the primal state and the back projection . The maps are small convolutional networks with separate weights in each step, and the primal and dual states have several channels that act as a memory. The whole scheme is trained end to end on pairs of images and data. Adler and Oktem (2018) introduced it for low-dose CT. With the maps set to the two proximal steps it is exactly Chambolle-Pock, and with other fixed maps it is gradient descent. For trained maps there is no convergence or correctness theorem; its accuracy is measured on test data.
In plain words
A classical solver for an imaging problem goes back and forth many times. It compares its current image with the measured data, sends the mismatch back into image space, and corrects the image with a fixed rule. The rules are the same for every patient and every step.
Learned primal-dual keeps the back and forth but lets small networks make the corrections. On the data side, a network looks at the old data-side state, at what the current image predicts, and at the real measurement, and decides on a new data-side state. On the image side, another network looks at the old image and at the sent-back mismatch, and decides on a new image. It does this a fixed number of times, for example ten, and each step has its own networks. The networks are trained on many examples so that the final image is close to the true one.
The problem
The model is with the image, the data and the forward operator, for example a discrete Radon transform. The variational approach minimizes , for example . The learned approach instead looks for a reconstruction operator with parameters that minimizes the empirical risk over training pairs . Learned primal-dual is a choice of that uses and inside.
The input of the algorithm is the data , functions that apply and , and the trained maps and . The output is an image .
The algorithm
The primal state has images, and the dual state has vectors in data space. This is Algorithm 3 of Adler and Oktem for a linear operator, where the adjoint of the derivative is .
LEARNED-PRIMAL-DUAL(y, A, A^T, Γ_1..Γ_K, Λ_1..Λ_K, x_0, h_0)- 1
x ← x_0, h ← h_0 ▷ usually all zero - 2
for i = 1 to K - 3
h ← Γ_i(h, A x^(2), y) ▷ dual update, a given network - 4
x ← Λ_i(x, A^T h^(1)) ▷ primal update, a given network - 5
return x^(1)
Line L3 is the only place where the data enters. The dual map sees the old dual state, the forward projection of the second primal channel and the data. Line L4 is the only place where the adjoint enters: the primal map sees the old primal state and the back projection of the first dual channel. Each line calls the operator once, so a step costs one call to and one call to , as a step of Chambolle-Pock does.
Chambolle-Pock as a special case. Take , , and for every step
Then is the Chambolle-Pock iterate and is the extrapolated point . This is Section III.D of the paper.
Gradient descent as a special case. Take , and . Then each step is , the Landweber iteration.
The trained version. Adler and Oktem use and . Each map is a residual network: the identity plus three convolution layers, with PReLU activations after the first two. The input of a dual map has 7 channels (5 dual channels, and ), and the input of a primal map has 6 (5 primal channels and ). The ten steps have separate weights, about parameters in total. Training minimizes the mean squared error by Adam, with gradients from backpropagation through all steps, including through and .
Example
The scalar problem , , and , that is , has the solution . The optimal dual value is . With (so ), and the soft threshold at . The Chambolle-Pock maps, started from zero, give:
| step | |||
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | 0.2130 | ||
| 4 | 0.3395 | ||
| 10 | 0.5263 |
In step 1, line L3 gives , and line L4 gives . In step 2, and . The iterates converge to . A learned scheme with the same two calls per step could, for example, learn to take larger corrections in the first steps.
With the gradient maps, , and , the scheme gives after steps, which is 0.63397 for : the Landweber filter factor for .
Correctness
For trained maps there is no correctness theorem. The network maps have no convexity, no fixed point and no stopping rule, and the scheme is only as good as its training data. What is proved is in the proof file below. With the Chambolle-Pock maps, the scheme produces the Chambolle-Pock iterates exactly, by induction on the step; so it converges for by the theorem of Chambolle and Pock (2011, Theorem 1). With the gradient maps, it produces the Landweber iterates.
Adler and Oktem conclude that, since the class of schemes contains these methods, a trained scheme should do at least as well as they do with the same number of steps. This is a heuristic: it needs the networks to approximate the proximal maps well, and it needs the nonconvex training to find good weights.
Proof: With the Chambolle-Pock update maps, learned primal-dual is the Chambolle-Pock algorithm, and with the gradient maps it is Landweber iterationfull
Setting. is linear, is the data, and the scheme of lines L1 to L5 runs steps. The primal state is with , and the dual state is with . Step is
and the output is . For the operator is applied to . Because is linear, the adjoint of its derivative at any point is ; this is the case in which Algorithm 3 of Adler and Oktem (2018) uses .
Nothing is proved here about trained maps and . The two statements below are about special choices of the maps. They show that the scheme contains two classical methods, and that the code is correct on these choices.
Chambolle-Pock. Let and be closed proper convex functions, with depending on the data, and fix and . Chambolle-Pock for , started at , and , is
Take , and, for every ,
Claim 1. If the scheme starts at and , then and for every . In particular the output is the Chambolle-Pock iterate .
Proof. By induction on . For the claim is the choice of the start, since . Suppose it holds for . Line L3 computes . Line L4 computes , and the second component . So .
Consequence. With and , if a saddle point exists, the Chambolle-Pock iterates converge to a saddle point and the averages have a primal-dual gap of (Chambolle and Pock 2011, Theorem 1; see Chambolle-Pock algorithm). By Claim 1, learned primal-dual with these maps inherits both results. The test test_cp_maps_give_chambolle_pock_on_a_matrix compares the code with a direct Chambolle-Pock loop and finds equal iterates to .
Gradient descent. Take , and for a step .
Claim 2. The output after steps is the -th iterate of Landweber iteration from the same start.
Proof. Line L3 sets , the residual, and line L4 sets . This is one Landweber step, so induction on gives the claim. Landweber converges to the minimum norm least squares solution for and (see Landweber iteration). With , , and the output is , the Landweber filter factor at ; the test checks this value.
What this does not prove. Adler and Oktem argue that, since the scheme contains these methods, a trained scheme with the same number of steps should do at least as well as they do. This is a heuristic. It needs the network class to contain or approximate the maps above, and it needs training to find the best maps, which a nonconvex training problem does not guarantee. Measured comparisons are reported on the page as measurements.
Complexity
The model is real-ram. Each of the steps calls once, once and each learned map once. So the time is , where is the cost of one call to and one to , and is the cost of the two networks. The cost of the networks depends on their architecture and is outside this page; for convolutional maps on an image of pixels it is linear in times the number of channels and weights. The extra space is for the states. Training needs the gradient through all steps, which by backpropagation costs a constant times the forward pass and stores all intermediate states, memory, unless gradient checkpointing trades time for memory.
For comparison, Chambolle-Pock with the same costs plus two proximal steps per iteration, but it needs hundreds of iterations where the learned scheme uses ten.
Properties
- Uses the physics. Every step calls and , so the network never has to learn the forward model. This is the difference from post-processing networks that only clean up a filtered back projection.
- Fixed cost. The number of steps is fixed before training, so the reconstruction time is known in advance.
- Contains classical schemes. Chambolle-Pock and gradient descent are special cases, as shown above.
- Measured results. Adler and Oktem report two CT tests. The first uses random ellipse phantoms on a grid, a parallel beam geometry with 30 views and 182 detector pixels, and 5 percent Gaussian noise, with the Shepp-Logan phantom for validation. The second uses human abdomen images of pixels from the Mayo Clinic low-dose CT challenge, a fan beam geometry with 1000 angles and Poisson noise with incident photons per pixel. In both tests learned primal-dual had the highest PSNR and SSIM among the methods compared, which included FBP, TV regularization and a learned post-processing network. On the ellipse data the gain over the learned gradient scheme and the post-processing network was more than 6 dB. The learned methods that call the operator were about 6 times slower than FBP plus a network, and at least 100 times faster than TV with 1000 iterations. These are measurements on those data sets, not properties of the algorithm.
Variants and improvements
- Learned PDHG. Keep , the update forms and , and the over-relaxation, and learn only the two proximal maps (Algorithm 2 of the paper). It did about as well as classical methods in their tests.
- Learned primal. Fix the dual map to the residual and learn only the primal map. In the ellipse test it was the closest competitor, 1.3 dB behind.
- Learned gradient (Adler and Oktem 2017). Feed the gradient of the data term to a learned update; this is the earlier scheme.
- Nonlinear forward models. For a nonlinear operator , line L4 uses the adjoint of the derivative . The paper treats the pre-log CT model this way.
- Other unrolled schemes. The variational network unrolls a gradient scheme for MRI, and LISTA unrolls ISTA; see algorithm unrolling.
When to use it
Use learned primal-dual when the forward operator is known and fixed, when many training pairs from the same acquisition setting exist, and when the reconstruction must be fast and better than FBP on undersampled or noisy data, as in low-dose or sparse-view CT. Do not use it when the geometry or the noise level changes from scan to scan without retraining, when no training data exist, or when you need a guarantee such as a bound on the data misfit. Then a variational method or a plug-and-play scheme with an explicit data term is safer.
Pitfalls
- Wrong adjoint. The scheme backpropagates through , and a back projector that is not the exact adjoint of the projector gives wrong training gradients. Check on random vectors.
- Distribution shift. A network trained at one dose, one geometry or one anatomy can produce plausible but wrong structures elsewhere. Evaluate on held-out data from the target setting.
- Memory of training. Backpropagation through steps with large images stores all states; the memory, not the time, is often the limit.
- Reading the PSNR as a guarantee. A higher mean PSNR on a test set does not bound the error on any one image.
- Scaling. The data and the images must be scaled as in training; the network is not invariant to a change of units.
Implementations
The update maps are given functions: the code takes the lists and , and functions for and , as arguments and runs lines L1 to L5 around them. The tests build the maps by hand, as the Chambolle-Pock maps and the gradient maps, or as small residual networks with weights from a fixed seed. No network is trained and no weights are downloaded. The tests check the adjoint of a periodic blur operator, the equality with a direct Chambolle-Pock loop on a matrix and on a blur, the example values above, convergence to the lasso solution of the LISTA example, the Landweber check value 0.63397, and that a step calls and exactly once.
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/learned-primal-dual/. The authors are listed in prov/8N7P4C.jsonl.
"""Learned primal-dual reconstruction (Adler and Oktem 2018, Algorithm 3).
The update maps are given functions. The primal state is a list of N_p
vectors in R^n and the dual state a list of N_d vectors in R^m. In step i:
h <- dual_maps[i](h, A x[1], y) (a list of N_d vectors)
x <- primal_maps[i](x, A^T h[0]) (a list of N_p vectors)
and the result is x[0]. The forward operator is linear here, so the adjoint
of its derivative is A^T. The functions cp_maps and gradient_maps build the
update maps for which the scheme is Chambolle-Pock or gradient descent.
With N_p = 1 the forward operator is applied to x[0].
"""
import math
def learned_primal_dual(y, apply_a, apply_at, dual_maps, primal_maps, x0, h0):
"""Run len(dual_maps) steps of the learned primal-dual scheme.
x0 is a list of N_p primal vectors and h0 a list of N_d dual vectors.
Each step calls apply_a once, apply_at once and each map once.
Returns the first primal component.
"""
x = [list(v) for v in x0] # @line L1
h = [list(v) for v in h0] # @line L1
for gamma, lam in zip(dual_maps, primal_maps): # @line L2
h = gamma(h, apply_a(x[1] if len(x) > 1 else x[0]), y) # @line L3
x = lam(x, apply_at(h[0])) # @line L4
return x[0] # @line L5
def cp_maps(prox_tau_g, prox_sigma_fstar, tau, sigma, theta=1.0):
"""The pair (Gamma, Lambda) for which one step is one Chambolle-Pock step.
N_p = 2 (x and the extrapolated point x_bar) and N_d = 1.
prox_sigma_fstar(v, y) must return prox_{sigma F_y*}(v), and
prox_tau_g(v) must return prox_{tau G}(v).
"""
def gamma(h, a_xbar, y):
return [prox_sigma_fstar([a + sigma * b for a, b in zip(h[0], a_xbar)], y)]
def lam(x, at_h):
new = prox_tau_g([a - tau * b for a, b in zip(x[0], at_h)])
xbar = [(1.0 + theta) * a - theta * b for a, b in zip(new, x[0])]
return [new, xbar]
return gamma, lam
def gradient_maps(step):
"""The pair (Gamma, Lambda) for which one step is a gradient step on (1/2)||A x - y||^2.
N_p = 1 and N_d = 1: the dual state is the residual A x - y, and the
primal map is x - step * A^T h. This is Landweber iteration.
"""
def gamma(h, a_x, y):
return [[a - b for a, b in zip(a_x, y)]]
def lam(x, at_h):
return [[a - step * b for a, b in zip(x[0], at_h)]]
return gamma, lam
def least_squares_dual_prox(sigma):
"""prox_{sigma F_y*} for F_y(z) = (1/2)||z - y||^2, that is (v - sigma y) / (1 + sigma)."""
def prox(v, y):
return [(a - sigma * b) / (1.0 + sigma) for a, b in zip(v, y)]
return prox
def l1_prox(weight):
"""prox of weight * ||x||_1: soft thresholding at weight."""
def prox(v):
return [a - weight if a > weight else a + weight if a < -weight else 0.0 for a in v]
return prox
def residual_network(rng, n_in, n_out, width, scale):
"""A small given network: v -> v[:n_out] + W2 tanh(W1 v + b1), with seeded weights.
It stands in for a trained update map in tests; it is not trained.
"""
w1 = [[rng.gauss(0.0, scale) for _ in range(n_in)] for _ in range(width)]
b1 = [rng.gauss(0.0, scale) for _ in range(width)]
w2 = [[rng.gauss(0.0, scale) for _ in range(width)] for _ in range(n_out)]
def net(v):
hidden = [math.tanh(sum(w * t for w, t in zip(row, v)) + b) for row, b in zip(w1, b1)]
return [v[i] + sum(w * t for w, t in zip(row, hidden)) for i, row in enumerate(w2)]
return net
test_learned_primal_dual.py 147 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/learned-primal-dual/. The authors are listed in prov/8N7P4C.jsonl.
import random
from learned_primal_dual import (
cp_maps,
gradient_maps,
l1_prox,
learned_primal_dual,
least_squares_dual_prox,
residual_network,
)
def matvec(a, x):
return [sum(v * w for v, w in zip(row, x)) for row in a]
def rmatvec(a, y):
return [sum(a[i][j] * y[i] for i in range(len(a))) for j in range(len(a[0]))]
def blur(kernel):
"""Periodic convolution with a kernel centered at index 0, and its adjoint (the correlation)."""
def apply(x):
n = len(x)
return [sum(kernel[k] * x[(i - k) % n] for k in range(len(kernel))) for i in range(n)]
def adjoint(y):
n = len(y)
return [sum(kernel[k] * y[(i + k) % n] for k in range(len(kernel))) for i in range(n)]
return apply, adjoint
def chambolle_pock(apply_a, apply_at, y, lam, tau, sigma, iters, n, m):
"""Chambolle-Pock for (1/2)||A x - y||^2 + lam ||x||_1, written out directly."""
x, xbar, h = [0.0] * n, [0.0] * n, [0.0] * m
for _ in range(iters):
ax = apply_a(xbar)
h = [(hi + sigma * axi - sigma * yi) / (1.0 + sigma) for hi, axi, yi in zip(h, ax, y)]
ath = apply_at(h)
v = [xi - tau * gi for xi, gi in zip(x, ath)]
t = tau * lam
new = [vi - t if vi > t else vi + t if vi < -t else 0.0 for vi in v]
xbar = [2.0 * a - b for a, b in zip(new, x)]
x = new
return x
def lpd_with_cp_maps(apply_a, apply_at, y, lam, tau, sigma, iters, n, m):
gamma, lam_map = cp_maps(l1_prox(tau * lam), least_squares_dual_prox(sigma), tau, sigma)
return learned_primal_dual(y, apply_a, apply_at, [gamma] * iters, [lam_map] * iters,
[[0.0] * n, [0.0] * n], [[0.0] * m])
def test_adjoint_of_the_blur_operator():
rng = random.Random(11)
apply_a, apply_at = blur([0.5, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2])
for _ in range(5):
x = [rng.gauss(0.0, 1.0) for _ in range(16)]
y = [rng.gauss(0.0, 1.0) for _ in range(16)]
ax, aty = apply_a(x), apply_at(y)
gap = abs(sum(a * b for a, b in zip(ax, y)) - sum(a * b for a, b in zip(x, aty)))
norm = sum(a * a for a in ax) ** 0.5 * sum(b * b for b in y) ** 0.5
assert gap <= 1e-10 * norm
def test_cp_maps_give_chambolle_pock_on_a_matrix():
rng = random.Random(5)
m, n = 5, 8
a = [[rng.gauss(0.0, 0.4) for _ in range(n)] for _ in range(m)]
y = [rng.gauss(0.0, 1.0) for _ in range(m)]
def fa(x): return matvec(a, x)
def fat(h): return rmatvec(a, h)
for k in (1, 2, 3, 7, 20):
u = lpd_with_cp_maps(fa, fat, y, 0.1, 0.5, 0.5, k, n, m)
v = chambolle_pock(fa, fat, y, 0.1, 0.5, 0.5, k, n, m)
assert max(abs(p - q) for p, q in zip(u, v)) <= 1e-12
def test_cp_maps_give_chambolle_pock_on_a_blur():
rng = random.Random(6)
apply_a, apply_at = blur([0.5, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25])
y = [rng.gauss(0.0, 1.0) for _ in range(12)]
u = lpd_with_cp_maps(apply_a, apply_at, y, 0.05, 0.9, 0.9, 30, 12, 12)
v = chambolle_pock(apply_a, apply_at, y, 0.05, 0.9, 0.9, 30, 12, 12)
assert max(abs(p - q) for p, q in zip(u, v)) <= 1e-12
def test_scalar_example():
def ident(x): return list(x)
xs = [lpd_with_cp_maps(ident, ident, [1.0], 0.5, 0.5, 0.5, k, 1, 1)[0] for k in (1, 2, 3, 4)]
assert abs(xs[0]) < 1e-15
assert abs(xs[1] - 1 / 36) < 1e-15
assert abs(xs[2] - 13 / 108) < 1e-15
assert abs(xs[3] - 149 / 648) < 1e-15
assert abs(lpd_with_cp_maps(ident, ident, [1.0], 0.5, 0.5, 0.5, 200, 1, 1)[0] - 0.5) < 1e-9
def test_cp_maps_reach_the_lasso_solution_of_the_lista_example():
a = [[1.0, 0.0, 0.6], [0.0, 1.0, 0.8]]
def fa(x): return matvec(a, x)
def fat(h): return rmatvec(a, h)
x = lpd_with_cp_maps(fa, fat, [0.6, 0.8], 0.1, 0.5, 0.5, 3000, 3, 2)
assert max(abs(p - q) for p, q in zip(x, [0.0, 0.0, 0.9])) < 1e-8
def test_gradient_maps_give_landweber():
gamma, lam = gradient_maps(0.01)
def ident(x): return list(x)
x = learned_primal_dual([1.0], ident, ident, [gamma] * 100, [lam] * 100, [[0.0]], [[0.0]])
assert abs(x[0] - (1.0 - 0.99 ** 100)) < 1e-12
assert abs(x[0] - 0.63397) < 5e-6
def test_given_networks_and_call_counts():
rng = random.Random(21)
n_p, n_d, m, n, iters = 3, 2, 6, 6, 4
apply_a, apply_at = blur([0.6, 0.2, 0.0, 0.0, 0.0, 0.2])
calls = {"a": 0, "at": 0}
def counted_a(x):
calls["a"] += 1
return apply_a(x)
def counted_at(h):
calls["at"] += 1
return apply_at(h)
def split(v, parts, size):
return [v[i * size:(i + 1) * size] for i in range(parts)]
dual_maps, primal_maps = [], []
for _ in range(iters):
dnet = residual_network(rng, n_d * m + 2 * m, n_d * m, 8, 0.3)
pnet = residual_network(rng, n_p * n + n, n_p * n, 8, 0.3)
dual_maps.append(lambda h, ax, y, f=dnet: split(f([t for v in h for t in v] + ax + y), n_d, m))
primal_maps.append(lambda x, ath, f=pnet: split(f([t for v in x for t in v] + ath), n_p, n))
y = [rng.gauss(0.0, 1.0) for _ in range(m)]
x0 = [[0.0] * n for _ in range(n_p)]
h0 = [[0.0] * m for _ in range(n_d)]
out1 = learned_primal_dual(y, counted_a, counted_at, dual_maps, primal_maps, x0, h0)
assert calls == {"a": iters, "at": iters}
out2 = learned_primal_dual(y, apply_a, apply_at, dual_maps, primal_maps, x0, h0)
assert out1 == out2 and len(out1) == n
assert any(abs(t) > 1e-6 for t in out1)
History
Gregor and LeCun (2010) unrolled ISTA into a trained network, and Yang, Sun, Li and Xu (2016) and Hammernik et al. (2018) unrolled ADMM and gradient schemes for MRI. Adler and Oktem (2017) proposed a partially learned gradient scheme for nonlinear inverse problems, and in 2018 they introduced learned primal-dual, which replaces both proximal maps of the primal-dual hybrid gradient method by networks and keeps a memory of several channels. It became a common baseline for learned CT reconstruction. The survey of Arridge, Maass, Oktem and Schonlieb (2019) places it among the data-driven methods for inverse problems.
References
- Jonas Adler and Ozan Oktem, Learned primal-dual reconstruction, IEEE Transactions on Medical Imaging 37(6), 2018 (arXiv 1707.06474), pages 1322 to 1332 (Section III.C and Algorithm 3 for the scheme, Section III.D for the reduction to PDHG and to gradient descent, Section IV for the CT data and the networks, Section V for the results)
- Jonas Adler and Ozan Oktem, Solving ill-posed inverse problems using iterative deep neural networks, Inverse Problems 33(12), 2017, article 124007 (the partially learned gradient scheme)
- Antonin Chambolle and Thomas Pock, A first-order primal-dual algorithm for convex problems with applications to imaging, Journal of Mathematical Imaging and Vision 40(1), 2011, pages 120 to 145 (Algorithm 1 and Theorem 1, the method that learned primal-dual contains)
- Simon Arridge, Peter Maass, Ozan Oktem and Carola-Bibiane Schonlieb, Solving inverse problems using data-driven models, Acta Numerica 28, 2019, pages 1 to 174 (survey of learned iterative schemes)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 8N7P4C Edit this page History Report an error Markdown