Total Variation Optimization Layers for Computer Vision

Raymond A. Yeh, Yuan-Ting Hu, Zhongzheng Ren, Alexander G. SchwingCVPR 2022

Abstract: Optimization within a layer of a deep-net has emerged as a new direction for deep-net layer design. However, there are two main challenges when applying these layers to computer vision tasks: (a) which optimization problem within a layer is useful?; (b) how to ensure that computation within a layer remains efficient? To study question (a), in this work, we propose total variation (TV) minimization as a layer for computer vision. Motivated by the success of total variation in image processing, we hypothesize that TV as a layer provides useful inductive bias for deep-nets too. We study this hypothesis on five computer vision tasks: image classification, weakly supervised object localization, edge-preserving smoothing, edge detection, and image denoising, improving over existing baselines. To achieve these results we had to address question (b): we developed a GPU-based projected-Newton method which is 37× faster than existing solutions.

Introduction

Deep learning success often hinges on "inductive biases"—structural assumptions like the translation invariance of convolutions. Optimization-based layers, where a layer's output is the solution to an internal optimization problem, offer a promising way to inject more sophisticated biases. However, utility and efficiency have limited their use in computer vision. It wasn't clear which optimization problems provide the most value, and solving them for high-dimensional images is computationally expensive.

This work focuses on Total Variation (TV), a classic image processing technique that assumes images are composed of smooth regions separated by sharp edges (piece-wise constant). By integrating TV as a differentiable layer, we provide a powerful structural prior that can be learned and optimized alongside the rest of the network.

The Differentiable TV Layer

The core contribution is a layer that implements the TV proximity operator. It solves for an output $y$ that remains close to the input $x$ while minimizing total variation (the sum of gradients):

$$\text{Prox}_{TV}(x, \lambda) = \arg \min_y \frac{1}{2} \|y - x\|_2^2 + \lambda \|D_N y\|_1$$

The parameter $\lambda$ controls the smoothing strength and is trainable (via a SoftPlus function), allowing the network to learn the optimal amount of "TV-ness" for a given task. This makes the TV layer a "plug-and-play" component that the network can effectively bypass if $\lambda \to 0$.

Comparison of standard low-pass filtering vs. Total Variation (TV) minimization. TV preserves sharp edges while smoothing regions, providing a piece-wise constant inductive bias.

Efficiency: The GPU-Based Solver

To make this practical for deep learning, we developed a custom Projected-Newton solver using 21 specialized CUDA kernels. For 1D TV, we exploit the tridiagonal nature of the dual problem's Hessian to solve in $O(N)$ time. For 2D TV, we utilize the Proximal Dykstra method, parallelizing alternating 1D problems across rows and columns on the GPU. Backpropagation is handled via implicit differentiation, optimized with Cholesky factorization to avoid expensive matrix inversions. This system is 37x faster than specialized CPU solvers and 1770x faster than generic optimization layers.

Experimental Evaluation

We evaluated the TV layer across five diverse computer vision tasks using standard benchmarks:

  • Classification & Robustness: CIFAR-10 and CIFAR-10-C (corrupted images).
  • Weakly Supervised Object Localization (WSOL): ImageNet.
  • Edge Detection: BIPED and MDBD.
  • Edge-Preserving Smoothing: BenchmarkEPS.
  • Image Denoising: CBSD68, Kodak24, and McMaster.

Key Results

  • Robustness: On CIFAR-10-C, TV layers improved accuracy under noise and blur, raising overall performance from 68.4% to 70.6%.
  • Localization: In WSOL, TV layers generated smoother, better-aligned heatmaps, improving localization accuracy across VGG-16, Inception-V3, and ResNet-50 architectures.
  • Edge Detection: Our "DexiNed+TV" model achieved state-of-the-art results on the BIPED dataset (ODS .874), producing cleaner and more defined boundaries.
  • Denoising: Adding TV layers to the DnCNN architecture consistently improved PSNR, particularly at high noise levels ($\sigma=50$).
Edge detection results on the BIPED dataset. Adding a TV layer (DexiNed+TV) results in cleaner, more defined edges compared to the baseline DexiNed model.

Conclusion and Future Work

Total Variation layers provide a valuable structural prior that improves performance in tasks requiring clear boundaries or noise robustness. While very high-capacity models like SwinTransformers may implicitly learn these priors (often setting $\lambda \approx 0$), the TV layer remains a powerful tool for standard architectures. Future work includes exploring different regularizers and extending this fast solver framework to video and 3D data.

The implementation is available at: github.com/raymondyeh07/tv_layers_for_cv

Summary updated

BibTeX
@inproceedings{yeh2022total,
  author = {Raymond A. Yeh and Yuan-Ting Hu and Zhongzheng Ren and Alexander G. Schwing},
  title = {{Total Variation Optimization Layers for Computer Vision}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
  url = {https://openreview.net/forum?id=KvOrMjMnmt},
}
Figure