Techniqueresearch
Plug-and-play priors
Also called PnP reconstruction, plug-and-play ADMM.
Replace the proximal step of the prior in ADMM or a proximal gradient method by a generic image denoiser, such as a trained network.
Plug-and-play (PnP) priors reconstruct the unknown of an inverse problem with a splitting method, such as ADMM or the proximal gradient method, in which the proximal step of the regularizer is replaced by a call to an image denoiser. Venkatakrishnan, Bouman and Wohlberg (2013) noticed that this step has the form of a denoising problem, so any good denoiser, such as BM3D, non-local means or a trained network, can stand in for it. The data term keeps the physics, and the denoiser supplies the prior. If the denoiser is the proximal map of a convex function, PnP is the original method and converges. For other denoisers there is in general no objective that PnP minimizes; convergence holds only under extra conditions on the denoiser.
In plain words
Many reconstruction methods take turns between two jobs. One job makes the image agree with the measured data. The other job cleans the image, so that it looks like a real image and not like noise. In the classical methods, the cleaning job comes from a formula for what a good image is.
Plug-and-play keeps the turn taking but hands the cleaning job to an existing noise remover. This can be a very good one, for example a network trained to remove noise from photos. You do not need to write down what a good image is; the noise remover already knows it in its own way. The cost is that you lose the guarantee that the method solves a clear problem, unless the noise remover has special properties.
When it applies
Setting. , , and the objective with . Split . ADMM in scaled form with penalty is
where . The step is a denoising problem: find close to the noisy image with a small , at the noise variance . PnP replaces it by for a given denoiser .
Use the technique when the forward model is known and its proximal step (a linear solve for least squares) is cheap, when a good denoiser for the image class exists, and when no explicit prior is convenient. The theory below says when the result is the minimizer of an objective.
Fact 1 (a proximal denoiser gives ADMM). If for a proper closed convex , then PnP-ADMM with penalty is ADMM for . So, when this problem has a minimizer, the iterates converge to one (Boyd et al. 2011, Section 3). The weight of the prior is : with a fixed denoiser, acts as the regularization parameter. This is a theorem; it is the definition of the step. Soft thresholding in an orthonormal basis , , is the proximal map of .
Fact 2 (when a denoiser is a proximal map). Let be continuously differentiable, with a Jacobian that is symmetric and has its eigenvalues in at every point. Then is the proximal map of some proper closed convex function, so Fact 1 applies (Sreehari et al. 2016, from a theorem of Moreau). For a linear denoiser , this means is symmetric with eigenvalues in . If they lie in , then for , and PnP-ADMM solves . Most practical denoisers, such as BM3D, non-local means with its usual normalization, and trained networks, do not have a symmetric Jacobian. Sreehari et al. built a symmetric form of non-local means to meet the condition.
Fact 3 (contractive residual). Ryu et al. (2019) assume that the residual is -Lipschitz: . If is -strongly convex and , PnP-ADMM with the step of the step converges to a unique fixed point when (their Corollary 3); the forward-backward form converges when for an -smooth (their Theorem 1). Strong convexity of needs to have full column rank, which fails for most inverse problems. The fixed point need not minimize any objective. Ryu et al. train networks with a spectral norm control to meet the assumption; whether a trained network meets it is a measurement.
Fact 4 (bounded denoisers). Chan, Wang and Elgendy (2017) prove fixed point convergence for bounded denoisers, whose change is controlled by the noise level, when grows by a fixed rule during the iterations. The growing forces the steps to shrink, so the limit depends on the schedule.
The template
PNP-ADMM(prox_f, D, v_0, K)- 1
v ← v_0, u ← 0 - 2
for k = 1 to K - 3
x ← prox_{f/ρ}(v - u) ▷ data step: (A^T A + ρI) x = A^T y + ρ(v - u) - 4
v ← D(x + u) ▷ hole: the denoiser, a given function - 5
u ← u + x - v ▷ dual update - 6
return x, v, u
The holes are the denoiser (L4), the penalty and the number of steps. Line L3 calls and ; for least squares it is a linear solve, done once by a factorization for a small dense or by conjugate gradients for a large one. Each step calls the denoiser once, so the cost is times one data step plus one denoiser call. Other splittings give other PnP methods: the forward-backward form (PnP-ISTA or PnP-FBS), half-quadratic splitting, and primal-dual forms.
The denoiser is a given function: the code takes and the data step as arguments and runs lines L1 to L6 around them. The tests build by hand, as soft thresholding in the orthonormal Haar basis or as a fixed symmetric matrix, so that the answer is known; no network is trained. They check that the Haar denoiser satisfies the optimality condition of its proximal problem, the hand example below, that PnP with the Haar denoiser reaches the lasso minimizer found by an independent ISTA solver to on a seeded deblurring problem, and Fact 2 for a symmetric linear denoiser.
Classic examples
A proximal denoiser, by hand. Take (pure denoising), , and the Haar denoiser in , with . By Fact 1, PnP minimizes , whose solution is . Here , the soft threshold gives , and so . From , line L3 is :
| step | |||
|---|---|---|---|
| 1 | (1.5, 0.5) | (0.292893, 0.292893) | (1.207107, 0.207107) |
| 2 | (1.042893, 0.542893) | (0.835786, 0.75) | (1.414214, 0) |
| 3 | (1.210786, 0.875) | (1.210786, 0.875) | (1.414214, 0) |
| 4 | (1.398286, 0.9375) | (1.398286, 0.9375) | (1.414214, 0) |
| 10 | (1.582857, 0.999023) | (1.582857, 0.999023) | (1.414214, 0) |
From step 2 on, is fixed at , which is times the subgradient of at the solution, and the error halves at each step.
A symmetric smoother. A linear smoother that is symmetric with eigenvalues in gives the quadratic regularizer (Fact 2). A periodic blur with a sampled Gaussian kernel that sums to 1 is such a , since it is symmetric and its eigenvalues, the DFT of the kernel, lie in ; a non-local means matrix with rows normalized to sum to 1 is not symmetric.
Strong denoisers. With BM3D or a trained network such as DnCNN as , PnP gives high quality results in deblurring, super-resolution, tomography and MRI. These results are measurements on test images, and the methods have no convergence guarantee unless the denoiser meets Fact 3 or Fact 4. In practice the number of steps and are tuned, often with a fixed small .
Variations
- PnP-ISTA and PnP-FISTA. Replace the proximal step of ISTA or FISTA by . Only and are needed, with no linear solve.
- Half-quadratic splitting. Alternate the data step and the denoiser with a growing penalty and no dual variable; Zhang et al. (2017) used this with a set of trained CNN denoisers at decreasing noise levels.
- Consensus equilibrium. Buzzard et al. (2018) describe the PnP fixed point as a balance of forces between the data step and the denoiser, without an objective.
- Regularization by denoising. RED builds an explicit regularizer from and uses the residual as a gradient.
- Learned splitting. Unroll a fixed number of PnP steps and train the denoiser end to end; this is algorithm unrolling, as in learned primal-dual.
- Score-based priors. A denoiser at many noise levels is a score model, and diffusion posterior sampling samples instead of iterating to a fixed point.
Pitfalls
- No objective. Without Fact 1 or Fact 2, the limit is a fixed point, not a minimizer. Its quality cannot be checked by an objective value, and different splittings (, ADMM or ISTA) give different fixed points.
- The noise level of the denoiser. The step denoises at noise variance . A denoiser trained for one noise level must match it, and changing changes the effective weight of the prior.
- Divergence. With an expansive denoiser, PnP can oscillate or diverge. Stop on a fixed number of steps or check , and do not read a stable image as a converged one.
- Strong convexity is rare. The contraction results need a strongly convex data term, so they do not apply to underdetermined problems such as compressed sensing MRI without changes.
- Hidden bias. A denoiser trained on one image class pushes every reconstruction toward that class.
Code
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/plug-and-play-priors/. The authors are listed in prov/S92WZQ.jsonl.
"""Plug-and-play ADMM of Venkatakrishnan, Bouman and Wohlberg.
The denoiser is given: a function denoiser(z) that returns a denoised copy
of z. The data term enters through prox_f(z), the minimizer of
f(x) + (rho / 2) ||x - z||^2. The method alternates the two and a dual
update. Matrices are lists of rows; vectors are lists of floats.
"""
import math
def pnp_admm(prox_f, denoiser, v0, iters):
"""Run iters steps of PnP-ADMM from v = v0, u = 0 and return (x, v, u)."""
v, u = list(v0), [0.0] * len(v0) # @line L1
x = list(v0)
for _ in range(iters): # @line L2
x = prox_f([a - b for a, b in zip(v, u)]) # @line L3
v = denoiser([a + b for a, b in zip(x, u)]) # @line L4
u = [a + b - c for a, b, c in zip(u, x, v)] # @line L5
return x, v, u # @line L6
def solve(m, b):
"""Solve m x = b by Gaussian elimination with partial pivoting."""
n = len(b)
a = [list(row) + [bi] for row, bi in zip(m, b)]
for c in range(n):
p = max(range(c, n), key=lambda r: abs(a[r][c]))
a[c], a[p] = a[p], a[c]
for r in range(c + 1, n):
f = a[r][c] / a[c][c]
for k in range(c, n + 1):
a[r][k] -= f * a[c][k]
x = [0.0] * n
for r in range(n - 1, -1, -1):
x[r] = (a[r][n] - sum(a[r][k] * x[k] for k in range(r + 1, n))) / a[r][r]
return x
def matvec(a, x):
return [sum(p * q for p, q in zip(row, x)) for row in a]
def rmatvec(a, r):
return [sum(a[i][j] * r[i] for i in range(len(a))) for j in range(len(a[0]))]
def least_squares_prox(a, y, rho):
"""z -> argmin (1/2)||A x - y||^2 + (rho/2)||x - z||^2, by a linear solve."""
n = len(a[0])
m = [[sum(a[i][j] * a[i][k] for i in range(len(a))) + (rho if j == k else 0.0)
for k in range(n)] for j in range(n)]
aty = rmatvec(a, y)
return lambda z: solve(m, [p + rho * q for p, q in zip(aty, z)])
def soft(v, theta):
"""Soft thresholding, the proximal map of theta ||.||_1."""
return [math.copysign(max(abs(t) - theta, 0.0), t) for t in v]
def haar_matrix(n):
"""The orthonormal Haar transform of length n (a power of 2), as rows."""
if n == 1:
return [[1.0]]
h = haar_matrix(n // 2)
s = 1.0 / math.sqrt(2.0)
top = [[s * h[i][j // 2] for j in range(n)] for i in range(n // 2)]
bottom = [[s if j == 2 * i else (-s if j == 2 * i + 1 else 0.0) for j in range(n)]
for i in range(n // 2)]
return top + bottom
def haar_soft_denoiser(n, theta):
"""z -> H^T soft(H z, theta), the proximal map of theta ||H .||_1."""
h = haar_matrix(n)
return lambda z: rmatvec(h, soft(matvec(h, z), theta))
def linear_denoiser(w):
"""z -> W z for a given matrix W."""
return lambda z: matvec(w, z)
test_plug_and_play_priors.py 118 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/plug-and-play-priors/. The authors are listed in prov/S92WZQ.jsonl.
import math
import random
from plug_and_play_priors import (
haar_matrix,
haar_soft_denoiser,
least_squares_prox,
linear_denoiser,
matvec,
pnp_admm,
rmatvec,
soft,
solve,
)
def close(u, v, tol):
return max(abs(p - q) for p, q in zip(u, v)) < tol
def ista_in_haar_domain(a, y, lam, iters):
"""Independent reference: minimize (1/2)||A H^T c - y||^2 + lam ||c||_1 by ISTA."""
n = len(a[0])
h = haar_matrix(n)
b = [matvec(h, row) for row in a] # B = A H^T, row by row
lip = 0.0
v = [1.0] * n
for _ in range(200): # power iteration for ||B||^2
w = rmatvec(b, matvec(b, v))
lip = math.sqrt(sum(t * t for t in w))
v = [t / lip for t in w]
step = 1.0 / (1.01 * lip)
c = [0.0] * n
for _ in range(iters):
r = [p - q for p, q in zip(matvec(b, c), y)]
g = rmatvec(b, r)
c = soft([ci - step * gi for ci, gi in zip(c, g)], step * lam)
return rmatvec(h, c)
def seeded_deblurring(seed, n=8):
rng = random.Random(seed)
kernel = [0.5, 0.3, 0.2]
a = [[sum(kernel[k] for k in range(3) if (i + k) % n == j) for j in range(n)]
for i in range(n)]
x = [1.0 if 2 <= j < 6 else 0.0 for j in range(n)]
y = [v + rng.gauss(0.0, 0.05) for v in matvec(a, x)]
return a, y
def test_haar_is_orthonormal():
for n in (2, 4, 8):
h = haar_matrix(n)
for i in range(n):
for j in range(n):
dot = sum(p * q for p, q in zip(h[i], h[j]))
assert abs(dot - (1.0 if i == j else 0.0)) < 1e-12
def test_haar_soft_threshold_is_a_proximal_map():
# v = D(w) satisfies the optimality condition of
# min (1/2)||v - w||^2 + theta ||H v||_1, written in c = H v.
rng = random.Random(1)
n, theta = 8, 0.4
h = haar_matrix(n)
d = haar_soft_denoiser(n, theta)
w = [rng.gauss(0.0, 1.0) for _ in range(n)]
c, hw = matvec(h, d(w)), matvec(h, w)
for ci, hi in zip(c, hw):
if ci != 0.0:
assert abs(hi - ci - theta * math.copysign(1.0, ci)) < 1e-12
else:
assert abs(hi) <= theta + 1e-12
def test_hand_example():
pf = least_squares_prox([[1.0, 0.0], [0.0, 1.0]], [3.0, 1.0], 1.0)
d = haar_soft_denoiser(2, 1.0)
x, v, u = pnp_admm(pf, d, [0.0, 0.0], 1)
assert close(x, [1.5, 0.5], 1e-12)
assert close(v, [1.0 - 1.0 / math.sqrt(2.0)] * 2, 1e-12)
x, v, u = pnp_admm(pf, d, [0.0, 0.0], 2)
assert close(x, [1.042893, 0.542893], 1e-6) and close(v, [0.835786, 0.75], 1e-6)
x, v, u = pnp_admm(pf, d, [0.0, 0.0], 4)
assert close(v, [1.398286, 0.9375], 1e-6)
x, v, u = pnp_admm(pf, d, [0.0, 0.0], 60)
# The limit is H^T soft(H y, 1) = (3 - sqrt(2), 1).
assert close(v, [3.0 - math.sqrt(2.0), 1.0], 1e-12)
def test_pnp_with_a_proximal_denoiser_is_admm_for_the_lasso():
for seed in (2, 3):
a, y = seeded_deblurring(seed)
for rho, theta in ((1.0, 0.05), (0.5, 0.1)):
pf = least_squares_prox(a, y, rho)
x, v, _ = pnp_admm(pf, haar_soft_denoiser(8, theta), [0.0] * 8, 400)
ref = ista_in_haar_domain(a, y, rho * theta, 4000)
assert close(v, ref, 1e-7) and close(x, v, 1e-7)
def test_symmetric_linear_denoiser_solves_a_quadratic_problem():
# W = Q diag(d) Q^T with d in (0, 1] is the prox of g(x) = (1/2) x^T (W^-1 - I) x,
# so PnP solves (A^T A + rho (W^-1 - I)) x = A^T y.
a, y = seeded_deblurring(4)
q = haar_matrix(8)
d = [1.0, 0.9, 0.7, 0.6, 0.4, 0.4, 0.3, 0.3]
w = [[sum(q[k][i] * d[k] * q[k][j] for k in range(8)) for j in range(8)] for i in range(8)]
winv_minus_i = [[sum(q[k][i] * (1.0 / d[k] - 1.0) * q[k][j] for k in range(8))
for j in range(8)] for i in range(8)]
rho = 0.5
pf = least_squares_prox(a, y, rho)
_, v, _ = pnp_admm(pf, linear_denoiser(w), [0.0] * 8, 300)
m = [[sum(a[r][i] * a[r][j] for r in range(8)) + rho * winv_minus_i[i][j]
for j in range(8)] for i in range(8)]
assert close(v, solve(m, rmatvec(a, y)), 1e-9)
Exercises
- Show that is the proximal map of when is orthonormal. Why does this fail for a frame that is not orthonormal?
- Verify the first two rows of the table. Then prove that from step 2 on the error halves at each step.
- Let be symmetric with eigenvalues in . Show that for , and derive the linear system that PnP-ADMM solves.
- Take , which copies the second entry into the first. Is it the proximal map of a convex function? Run PnP-ADMM with and for and , and compare the fixed points.
- For () and a denoiser with , find the range of for which the forward-backward bound of Ryu et al. gives a contraction.
References
- Singanallur V. Venkatakrishnan, Charles A. Bouman and Brendt Wohlberg, Plug-and-play priors for model based reconstruction, IEEE Global Conference on Signal and Information Processing (GlobalSIP), 2013, pages 945 to 948 (the ADMM split and the replacement of the prior step by a denoiser)
- Suhas Sreehari, Singanallur V. Venkatakrishnan, Brendt Wohlberg, Gregery T. Buzzard, Lawrence F. Drummy, Jeffrey P. Simmons and Charles A. Bouman, Plug-and-play priors for bright field electron tomography and sparse interpolation, IEEE Transactions on Computational Imaging 2(4), 2016, pages 408 to 423 (conditions under which a denoiser is a proximal map, and the symmetrized non-local means denoiser)
- Stanley H. Chan, Xiran Wang and Omar A. Elgendy, Plug-and-play ADMM for image restoration, fixed-point convergence and applications, IEEE Transactions on Computational Imaging 3(1), 2017, pages 84 to 98 (bounded denoisers and fixed point convergence with a growing penalty)
- Ernest K. Ryu, Jialin Liu, Sicheng Wang, Xiaohan Chen, Zhangyang Wang and Wotao Yin, Plug-and-play methods provably converge with properly trained denoisers, Proceedings of the 36th International Conference on Machine Learning, PMLR 97, 2019, pages 5546 to 5557 (Assumption A on the residual of the denoiser, Theorem 1 for PnP-FBS, Theorem 2 and Corollary 3 for PnP-DRS and PnP-ADMM)
- Stephen Boyd, Neal Parikh, Eric Chu, Borja Peleato and Jonathan Eckstein, Distributed optimization and statistical learning via the alternating direction method of multipliers, Foundations and Trends in Machine Learning 3(1), 2011, Section 3 (the scaled form of ADMM and its convergence)
Where this leads
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 | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag S92WZQ Edit this page History Report an error Markdown