3D生成:DreamFusion Part 4: Algorithm

圖學玩家
6 min readDec 28, 2023

--

<圖學玩家 第033篇 原創文>

ALGORITHM

Diffusion Model的部分,DreamFusion採用Imagen,而3D Model的生成則採用NeRF的架構。演算法首先隨機初始一NeRF,接著重複地從隨機相機位置去Render,再將Render出來的影像與Imagen計算與優化SDS Loss。整個流程如上圖所示。

we initialize a NeRF-like model with random weights, then repeatedly render views of that NeRF from random camera positions and angles, using these renderings as the input to our score distillation loss function that wraps around Imagen

Neural Rendering of a 3D Model

NeRF採用Volume Rendering。由相機位置向各Pixel方向發射Ray,Ray經過的3D位置µ,會得到不透明度τ與RGB顏色c。最終Pixel的值即為該Ray一路從Camera過來所經過的所有µ之加權總合。

DreamFusion中,針對原始NeRF有以下幾個修改:

SHADING
傳統的NeRF針對每個3D Position計算不透明度τ與RGB顏色c,而在DreamFusion則是計算3D Model的每個表面如何著色,也就是著色器 (Shader) 的概念。該Shader MLP會以3D位置µ與相機位置參數θ作為Input,輸出不透明度τ與物體表面的RGB反照率ρ (可視為材質的顏色):

有了τρ,我們需要物體表面的法向量n,去計算3D Position在該物體表面最終的顏色。n可以透過3D位置µ上之τ的反向Gradient計算出來:

接著假設點光源位置與顏色ℓρ,採用Diffuse Reflection模型,即可對3D位置µ進行著色:

SCENE STRUCTURE
DreamFusion將整個NeRF的範圍限制在一球體內,並且該球體的背景是透過另一組MLP參數生成。

use an environment map generated from a second MLP that takes positionally-encoded ray direction as input to compute a background color

GEOMETRY REGULARIZAERS
DreamFusion針對Ray經過的3D Position所計算出的不透明度,會有額外的Regularization Penalty,這麼做是為了避免在空間中塞錯3D資訊。

We include a regularization penalty on the opacity along each ray…… to prevent unneccesarily filling in of empty space.

Text-to-3D Synthesis

文字到3D的生成可以拆解為以下四個步驟:

(1) randomly sample a camera and light
(2) render an image of the NeRF from that camera and shade with the light
(3) compute gradients of the SDS loss with respect to the NeRF parameters
(4) update the NeRF parameters using an optimizer

以下針對這四個步驟詳細解釋:

1. Random camera and light sampling
在每個Training的循環中,相機的極坐標參數會從以下範圍隨機取出:

1. 仰角 φ ∈ [−10°, 90°]
2. 水平角 θ ∈ [0°, 360°]
3. 與原點距離 r ∈ [1, 1.5]

另外,焦距λ與點光源位置則從以下範圍得到

4. 焦距 λ ∈ U(0.7, 1.35)
5. 從以相機位置為均值 (Mean) 的分布中抽樣

2. Rendering
NeRF Render的解析度為64 × 64,搭配Pretrained的Text-to-Image Model。

3. Diffusion loss with view-dependent conditioning
在文字的提示上,DreamFusion會提供針對相機參數的額外提示,比如仰角> 60°時,會加上"overhead view"的字眼。

另外,DreamFusion採用的是T5-XXL Text Embeddings

4. Optimization

針對Training環境進行描述,這裡直接貼上原文內容不贅述

Our 3D scenes are optimized on a TPUv4 machine with 4 chips. Each chip renders a separate view and evaluates the diffusion U-Net with per-device batch size of 1. We optimize for 15,000 iterations which takes around 1.5 hours. Compute time is split evenly between rendering the NeRF and evaluating the diffusion model. Parameters are optimized using the Distributed Shampoo optimizer.

EXPERIMENTS

關於DreamFusion的實驗,上圖展示了一個滿有趣的結果。隨著Text Promt的變更,DreamFusion可以隨Iteration的增加去修改3D Model的生成。

系列文章

  1. 3D生成:DreamFusion Part 1: Diffusion Model
  2. 3D生成:DreamFusion Part 2: Score Function
  3. 3D生成:DreamFusion Part 3: Score Distillation Sampling

Ref

  1. DreamFusion
  2. Understanding Diffusion Models

--

--