Differentiable Visual Computing

Tzu-Mao LiarXiv 2019

Abstract

Derivatives of computer graphics, image processing, and deep learning algorithms are essential for guiding parameter space searches and solving complex inverse problems. However, as algorithms evolve to encode sophisticated data transformations, practitioners have traditionally been limited to simple mathematical functions or hand-derived gradients. This paper presents three tools designed to address the challenges of obtaining and applying derivatives for complex graphics pipelines. We extend the Halide language with reverse-mode automatic differentiation and automated optimization, introduce a general-purpose differentiable ray tracer that accounts for geometric discontinuities, and demonstrate a Markov Chain Monte Carlo (MCMC) rendering algorithm that utilizes second-order derivatives to adapt to local integrands. These contributions enable high-performance gradient computation and efficient sampling in both image processing and 3D rendering.

Introduction

Historically, a significant divide has existed between "traditional" computer graphics—grounded in physics, geometry, and hand-tuned algorithms—and "modern" deep learning, which relies on data-driven optimization and derivatives. The field of differentiable visual computing seeks to bridge this gap by making complex graphics pipelines differentiable. By doing so, computers can "reason" about the generation process, optimizing parameters such as camera angles, material properties, and light transport through gradient-based methods.

The Challenges of Differentiability in Graphics

Most modern optimization frameworks, including those used to train neural networks, rely on derivatives to understand how small changes in input affect the final output. Applying these techniques to graphics is difficult for two primary reasons:

  1. System Complexity: General-purpose automatic differentiation (AD) tools often lack the performance required for high-throughput image processing. Conversely, deep learning frameworks like PyTorch are often too inflexible to express the complex, non-linear logic inherent in graphics algorithms efficiently.
  2. Mathematical Discontinuity: 3D rendering involves visibility. When an object moves, it may suddenly occlude or reveal a background element. This creates a mathematical discontinuity (a "jump") that traditional calculus cannot handle, making standard AD tools ineffective for computing gradients with respect to geometry.

Technical Contributions

1. Differentiable Halide

To address performance bottlenecks, we extended the Halide programming language to support reverse-mode automatic differentiation. A key innovation in this implementation is the scatter-to-gather conversion. In gradient mathematics, updates are often "scattered" to memory, which can lead to race conditions in parallel environments. Our compiler automatically transforms these into "gather" operations, which are inherently parallelizable, allowing for high-performance gradient computation with minimal programmer effort.

2. Edge Sampling for Differentiable Ray Tracing

To solve the visibility problem, we developed a general-purpose differentiable ray tracer. We observed that while the image itself is discontinuous at object boundaries, the gradient of the image can be represented as a Dirac delta function along the edges. By explicitly sampling these triangle edges, our renderer can compute unbiased gradients even in the presence of complex shadows and reflections, enabling the solution of the full rendering equation in an inverse context.

3. Hessian-Hamiltonian Monte Carlo (H2MC)

Beyond inverse problems, derivatives can also improve forward rendering. We introduced H2MC, a sampler that uses second-order derivatives (the Hessian) to guide light particles. By simulating Hamiltonian dynamics on a landscape shaped by the Hessian, the sampler can adapt its search to the local integrand. This allows it to efficiently navigate "narrow paths" of high-contribution light, such as those found in complex caustics or motion blur, which traditional isotropic samplers often miss.

Evaluation and Results

Performance and Efficiency

Evaluation on image processing tasks (using the MIT5k and ImageNet datasets) demonstrated that custom deep learning layers written in Differentiable Halide were 10x faster than hand-written CUDA code and 20x faster than PyTorch implementations. Furthermore, these results were achieved with roughly 90% fewer lines of code, significantly reducing development overhead.

Inverse Rendering and Quality

In 3D rendering, the differentiable ray tracer successfully performed complex inverse rendering, automatically adjusting 177 parameters—including camera pose, materials, and lighting—to match real-world photographs. In the domain of image reconstruction, using gradients to tune a traditional demosaicking algorithm (AHD) improved accuracy by 1 dB, demonstrating that classical algorithms can be significantly enhanced through gradient-based optimization.

Sampling Robustness

The H2MC method resolved difficult moving caustics that previous state-of-the-art methods failed to capture. By utilizing the "shape" of the local terrain provided by the Hessian, the sampler achieved higher efficiency with an order of magnitude fewer function evaluations.

Conclusion and Future Work

This work establishes a foundation for a fully differentiable 3D pipeline, moving toward a vision of "analysis-by-synthesis" where computers learn 3D geometry and scene properties directly from 2D images. While current limitations include a focus on grid-based data structures in Halide and the need for better handling of participating media (like smoke) in rendering, these tools represent a major step in making graphics algorithms as flexible and optimizable as neural networks.

Summary updated

BibTeX
@misc{li2019differentiable,
  author = {Tzu-Mao Li},
  title = {{Differentiable Visual Computing}},
  year = {2019},
  eprint = {1904.12228},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1904.12228},
}
Figure