Mehmet Sat | Personal Blog

Neural Radiance Fields A Technical Deep Dive into 3D Scene Representation

· mehmet sat

Neural Radiance Fields: A Technical Deep Dive into 3D Scene

Neural Radiance Fields (NeRF) have revolutionized 3D scene representation and novel view synthesis by leveraging neural networks to model complex scenes with unprecedented detail and flexibility. Let’s explore the technical foundations, key components, and underlying rationale of NeRF.

NeRF represents a 3D scene as a continuous 5D function:

$$ F: (x, y, z, \theta, \phi) \rightarrow (r, g, b, \sigma) $$

Where (x, y, z) represents spatial coordinates, (θ, φ) denotes viewing direction, and (r, g, b, σ) are the emitted color and volume density. This representation allows for smooth interpolation between observed views and handling of complex geometries and lighting effects.

To approximate this function, NeRF employs a Multi-Layer Perceptron (MLP) with typically 8-10 fully connected layers, each containing 256 or 512 neurons. The network architecture incorporates skip connections:

$$ h_l = \phi(W_l \cdot [h_{l-1}, \gamma(x)] + b_l) $$

Where $h_l$ is the output of layer $l$, $W_l$ and $b_l$ are the weights and biases, $φ$ is the activation function (typically ReLU), and $γ(x)$ is the positional encoding of the input.

Skip connections are crucial because they allow the network to preserve fine-grained spatial information and learn both coarse structure and fine details effectively. By concatenating the input to the activations of intermediate layers, the network maintains a strong connection between the input coordinates and the final output, essential for accurately representing complex 3D environments.

A key innovation in NeRF is positional encoding:

$$ \gamma(p) = (\sin(2^0\pi p), \cos(2^0\pi p), \ldots, \sin(2^{L-1}\pi p), \cos(2^{L-1}\pi p)) $$

This encoding transforms input coordinates into a higher-dimensional space, enabling the network to learn high-frequency functions more effectively. The reason behind this is that neural networks often struggle to represent high-frequency details directly from raw input coordinates. By applying sine and cosine functions at different frequencies, positional encoding creates a unique “fingerprint” for each input value, separating nearby points in the high-dimensional space and making them easier for the network to distinguish.

The effectiveness of positional encoding lies in its multi-scale nature. Lower frequencies provide coarse positional information, while higher frequencies allow for encoding of finer details. Together, they create a rich, multi-scale representation of position, analogous to describing a location using maps at different scales.

Volume rendering is employed to generate 2D images from this 3D representation. The expected color C(r) of a camera ray r(t) = o + td is:

$$ C(r) = \int_{t_n}^{t_f} T(t) \sigma(r(t)) c(r(t), d) , dt $$

Where $$ T(t) = \exp\left(-\int_{t_n}^t \sigma(r(s)) , ds\right) $$ is the accumulated transmittance.

In practice, this integral is approximated using quadrature:

$$ \tilde{C} = \sum_{i=1}^N T_i \left(1 - \exp(-\sigma_i \delta_i)\right) c_i $$

Where $δ_i$ is the distance between adjacent samples and $$ T_i = \exp\left(-\sum_{j=1}^{i-1} \sigma_j \delta_j\right) $$

NeRF employs a hierarchical sampling strategy to efficiently allocate samples along each ray. This strategy is motivated by the need to balance computational efficiency with rendering quality. Two networks are used: a coarse network and a fine network. The coarse network samples $N_c$ points uniformly along the ray:

$$ t_i \sim U\left[t_n + \frac{(i-1)(t_f - t_n)}{N_c}, t_n + \frac{i(t_f - t_n)}{N_c}\right] $$

The fine network then samples N_f points according to the piecewise-constant PDF:

$$ \hat{p}(t) = \frac{w_i}{\sum_{j=1}^{N_c} w_j} \quad \text{for } t \in [t_i, t_{i+1}) $$

Where $$ w_i = T_i \left(1 - \exp(-\sigma_i \delta_i)\right) $$

This two-stage approach allows NeRF to focus computational resources on the most relevant parts of the scene, improving rendering quality without dramatically increasing the total number of samples. The coarse network provides a rough estimate of the scene’s structure, while the fine network refines the results in areas identified as important.

Training a NeRF model involves minimizing the mean squared error between the rendered and ground truth pixel colors:

$$ L = \sum_{r \in R} \left| \tilde{C}(r) - C(r) \right|^2_2 $$

Where R is the set of rays in the training images. The optimization process typically uses the Adam optimizer with an initial learning rate of 5e-4, which decays exponentially over the course of training.

A critical aspect of the training process is the differentiability of the entire pipeline. The coarse network’s outputs need to be differentiable with respect to the fine network’s inputs because the sampling process for the fine network depends on the coarse network’s predictions. This allows for end-to-end training of the entire NeRF model, enabling both networks to learn simultaneously and interdependently.

Novel view synthesis is achieved by defining new camera parameters and rendering the scene using the trained model. The quality of synthesized views is often evaluated using metrics such as Peak Signal-to-Noise Ratio (PSNR), Structural Similarity Index (SSIM), and Learned Perceptual Image Patch Similarity (LPIPS).

An important consideration in novel view synthesis is the relationship between the resolution of the training data and the rendered output. While NeRF’s continuous scene representation allows for rendering at arbitrary resolutions, the quality of higher resolution renders is ultimately limited by the information content of the training data. Rendering at higher resolutions than the training data might result in smoother images, but it won’t reveal true details that weren’t present in the original data.

While NeRF produces impressive results, it faces challenges in computational efficiency and handling of complex scene dynamics. The rendering process can be slow, especially for high-resolution images, due to the need to query the neural network multiple times for each ray. Additionally, the original NeRF model assumes static scenes, which limits its applicability to dynamic environments.

Current research focuses on addressing these limitations, with variants exploring real-time rendering, dynamic scene modeling, and improved sampling strategies. These advancements aim to broaden the applicability of NeRF to more diverse and complex scenarios.

In conclusion, Neural Radiance Fields represent a powerful approach to 3D scene representation, combining insights from computer graphics with deep learning techniques. By understanding the underlying principles and motivations behind each component of NeRF, we can appreciate its strengths and limitations, and anticipate future developments in this rapidly evolving field.​​​​​​​​​​​​​​​​