NeRF-Code

NeRF Code Review

NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis

Ben Mildenhall, Pratul P.Srinivasan, Matthew Tancik

paper :
https://arxiv.org/abs/2003.08934
project website :
https://www.matthewtancik.com/nerf
pytorch code :
https://github.com/yenchenlin/nerf-pytorch
https://github.com/csm-kr/nerf_pytorch?tab=readme-ov-file
tiny tensorflow code :
https://colab.research.google.com/github/bmild/nerf/blob/master/tiny_nerf.ipynb
Overview image reference :
https://yconquesty.github.io/blog/ml/nerf/nerf_ndc.html#dataflow

NeRF code는 빠른 실행을 위해 lower-level framework인 jax와 jit compile로 짜여진 버전도 있는데,
본 포스팅에서는 좀 더 익숙한 numpy, Pytorch framework로 코드 리뷰를 진행하였다

Train Code Flow Overview

Load Data

load_llff_data()

load_blender_data()

load_LINEMOD_data()

load_dv_data()

Create NeRF Model

Positional Encoding

NeRF model

run_network

batchify

Get Ray with batch

get_rays_np

* 오타 정정 : 2. matrix multiplication에서 [u, v, 1; u, v, 1; u, v, 1] 대신 [u; v; 1]

Get Ray without batch

Render

ndc_rays

batchify_rays

render_rays

perturb=False이면 맨 윗줄을 coarse-samples로 쓰고, perturb=True이면 맨 아랫줄을 coarse-samples로 쓴다

sample_pdf

CDF 가로축의 empty circles는 coarse(stratified) samples 사이의 중점(mid-point)의 t값

raw2outputs

Evaluation

img2mse for loss and mse2psnr for psnr

test

render_path

Question