Algorithm Search⌘K

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 xx of an inverse problem y=Ax+ey = Ax + e 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. x∈Rnx \in \mathbb{R}^n, A∈Rm×nA \in \mathbb{R}^{m \times n}, and the objective f(x)+λR(x)f(x) + \lambda R(x) with f(x)=12∥Ax−y∥2f(x) = \tfrac12\|Ax - y\|^2. Split x=vx = v. ADMM in scaled form with penalty ρ>0\rho > 0 is

x←prox⁡f/ρ(v−u),v←prox⁡(λ/ρ)R(x+u),u←u+x−v,x \leftarrow \operatorname{prox}_{f/\rho}(v - u),\qquad v \leftarrow \operatorname{prox}_{(\lambda/\rho)R}(x + u),\qquad u \leftarrow u + x - v,

where prox⁡g(z)=arg⁡min⁡vg(v)+12∥v−z∥2\operatorname{prox}_{g}(z) = \arg\min_v g(v) + \tfrac12\|v - z\|^2. The vv step is a denoising problem: find vv close to the noisy image x+ux + u with a small R(v)R(v), at the noise variance λ/ρ\lambda/\rho. PnP replaces it by v←D(x+u)v \leftarrow D(x + u) for a given denoiser DD.

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 D=prox⁡θRD = \operatorname{prox}_{\theta R} for a proper closed convex RR, then PnP-ADMM with penalty ρ\rho is ADMM for f(x)+ρθR(x)f(x) + \rho\theta R(x). So, when this problem has a minimizer, the iterates converge to one (Boyd et al. 2011, Section 3). The weight of the prior is ρθ\rho\theta: with a fixed denoiser, ρ\rho acts as the regularization parameter. This is a theorem; it is the definition of the step. Soft thresholding in an orthonormal basis HH, D(z)=HTsoft⁡(Hz,θ)D(z) = H^T\operatorname{soft}(Hz, \theta), is the proximal map of θ∥Hx∥1\theta\|Hx\|_1.

Fact 2 (when a denoiser is a proximal map). Let D:Rn→RnD : \mathbb{R}^n \to \mathbb{R}^n be continuously differentiable, with a Jacobian that is symmetric and has its eigenvalues in [0,1][0, 1] at every point. Then DD 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 D(z)=WzD(z) = Wz, this means WW is symmetric with eigenvalues in [0,1][0, 1]. If they lie in (0,1](0, 1], then W=prox⁡gW = \operatorname{prox}_g for g(x)=12xT(W−1−I)xg(x) = \tfrac12x^T(W^{-1} - I)x, and PnP-ADMM solves (ATA+ρ(W−1−I))x=ATy(A^TA + \rho(W^{-1} - I))x = A^Ty. 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 D−ID - I is ε\varepsilon-Lipschitz: ∥(D−I)(x)−(D−I)(x′)∥≤ε∥x−x′∥\|(D - I)(x) - (D - I)(x')\| \le \varepsilon\|x - x'\|. If ff is μ\mu-strongly convex and ε<1\varepsilon < 1, PnP-ADMM with the step α=1/ρ\alpha = 1/\rho of the ff step converges to a unique fixed point when ε/((1+ε−2ε2)μ)<α\varepsilon/((1 + \varepsilon - 2\varepsilon^2)\mu) < \alpha (their Corollary 3); the forward-backward form converges when max⁡{∣1−αμ∣,∣1−αL∣}(1+ε)<1\max\{|1 - \alpha\mu|, |1 - \alpha L|\}(1 + \varepsilon) < 1 for an LL-smooth ff (their Theorem 1). Strong convexity of ff needs AA 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 ∥D(z)−z∥\|D(z) - z\| is controlled by the noise level, when ρ\rho grows by a fixed rule during the iterations. The growing ρ\rho forces the steps to shrink, so the limit depends on the schedule.

The template

  1. PNP-ADMM(prox_f, D, v_0, K)
  2. 1v ← v_0, u ← 0
  3. 2for k = 1 to K
  4. 3x ← prox_{f/ρ}(v - u) ▷ data step: (A^T A + ρI) x = A^T y + ρ(v - u)
  5. 4v ← D(x + u) ▷ hole: the denoiser, a given function
  6. 5u ← u + x - v ▷ dual update
  7. 6return x, v, u

The holes are the denoiser (L4), the penalty ρ\rho and the number of steps. Line L3 calls AA and ATA^T; for least squares it is a linear solve, done once by a factorization for a small dense AA or by conjugate gradients for a large one. Each step calls the denoiser once, so the cost is KK times one data step plus one denoiser call. Other splittings give other PnP methods: the forward-backward form x←D(x−γAT(Ax−y))x \leftarrow D(x - \gamma A^T(Ax - y)) (PnP-ISTA or PnP-FBS), half-quadratic splitting, and primal-dual forms.

The denoiser is a given function: the code takes DD and the data step as arguments and runs lines L1 to L6 around them. The tests build DD 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 10−710^{-7} on a seeded deblurring problem, and Fact 2 for a symmetric linear denoiser.

Classic examples

A proximal denoiser, by hand. Take A=IA = I (pure denoising), y=(3,1)y = (3, 1), ρ=1\rho = 1 and the Haar denoiser in R2\mathbb{R}^2, D(z)=HTsoft⁡(Hz,1)D(z) = H^T\operatorname{soft}(Hz, 1) with H=12(111−1)H = \tfrac{1}{\sqrt2}\begin{pmatrix}1 & 1\\ 1 & -1\end{pmatrix}. By Fact 1, PnP minimizes 12∥x−y∥2+∥Hx∥1\tfrac12\|x - y\|^2 + \|Hx\|_1, whose solution is HTsoft⁡(Hy,1)H^T\operatorname{soft}(Hy, 1). Here Hy=(22,2)Hy = (2\sqrt2, \sqrt2), the soft threshold gives (22−1,2−1)(2\sqrt2 - 1, \sqrt2 - 1), and so x⋆=(3−2,1)=(1.585786,1)x^\star = (3 - \sqrt2, 1) = (1.585786, 1). From v=u=0v = u = 0, line L3 is x=(y+v−u)/2x = (y + v - u)/2:

step kk xx vv uu
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, uu is fixed at (2,0)(\sqrt2, 0), which is HTH^T times the subgradient (1,1)(1, 1) of ∥Hx∥1\|Hx\|_1 at the solution, and the error halves at each step.

A symmetric smoother. A linear smoother WW that is symmetric with eigenvalues in (0,1](0, 1] gives the quadratic regularizer ρ2xT(W−1−I)x\tfrac{\rho}{2}x^T(W^{-1} - I)x (Fact 2). A periodic blur with a sampled Gaussian kernel that sums to 1 is such a WW, since it is symmetric and its eigenvalues, the DFT of the kernel, lie in (0,1](0, 1]; 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 DD, 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 ρ\rho are tuned, often with a fixed small KK.

Variations

  • PnP-ISTA and PnP-FISTA. Replace the proximal step of ISTA or FISTA by DD. Only AA and ATA^T 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 DD and uses the residual x−D(x)x - D(x) 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 (ρ\rho, ADMM or ISTA) give different fixed points.
  • The noise level of the denoiser. The vv step denoises at noise variance λ/ρ\lambda/\rho. A denoiser trained for one noise level must match it, and changing ρ\rho 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 ∥x−v∥\|x - v\|, 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.

plug_and_play_priors.pyI0RawGitHub
# 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

  1. Show that D(z)=HTsoft⁡(Hz,θ)D(z) = H^T\operatorname{soft}(Hz, \theta) is the proximal map of θ∥Hx∥1\theta\|Hx\|_1 when HH is orthonormal. Why does this fail for a frame that is not orthonormal?
  2. Verify the first two rows of the table. Then prove that from step 2 on the error xk−x⋆x_k - x^\star halves at each step.
  3. Let WW be symmetric with eigenvalues in (0,1](0, 1]. Show that prox⁡g=W\operatorname{prox}_g = W for g(x)=12xT(W−1−I)xg(x) = \tfrac12x^T(W^{-1} - I)x, and derive the linear system that PnP-ADMM solves.
  4. Take W=(0101)W = \begin{pmatrix}0 & 1\\ 0 & 1\end{pmatrix}, which copies the second entry into the first. Is it the proximal map of a convex function? Run PnP-ADMM with A=IA = I and y=(1,0)y = (1, 0) for ρ=1\rho = 1 and ρ=2\rho = 2, and compare the fixed points.
  5. For f(x)=12∥x−y∥2f(x) = \tfrac12\|x - y\|^2 (μ=L=1\mu = L = 1) and a denoiser with ε=0.2\varepsilon = 0.2, find the range of α\alpha for which the forward-backward bound of Ryu et al. gives a contraction.

References

  1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples