A PyTorch-based implementation of Neural Radiance Fields (NeRF) optimized for high-fidelity 3D reconstruction of cultural heritage sites. This project integrates COLMAP Structure-from-Motion data to address the challenges of sparse and noisy multi-view documentation.
The 8.5 GB dataset used in this project is excluded from the GitHub repository to maintain a lightweight codebase.
- Download: https://huggingface.co/datasets/Manognaaaaaa/Heritage-NeRF-Data
- Setup: Extract the
data.zipfile into thedata/folder in your root directory.
- Directory Structure: Create a
data/folder in the root directory and extract the files so they match the structure below:data/nerfbk/ βββ heritage/ # Input RGB images βββ sparse/0/ # COLMAP binary files (cameras.bin, images.bin, points3D.bin)
Clone the repository:
git clone https://github.com/your-username/Heritage-NeRF.git
cd Heritage-NeRFCreate local directories: Since these are ignored by Git, you must create them for the code to output results:
mkdir results
mkdir dataSet up Environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtRun the Pipeline:
Open Code_main.ipynb in Jupyter and run all cells.
βββ Code_main.ipynb # Main Jupyter notebook with full pipeline
βββ data/ # (Local only) Project datasets
βββ results/ # (Local only) Model outputs and metrics
βββ .gitignore # Prevents large data uploads
βββ README.md
- COLMAP Binary Parsing: Automatic handling of cameras.bin, images.bin, and points3D.bin
- Heritage-NeRF Model: Enhanced version addressing sparse/noisy view challenges with cross-view color consistency
- Advanced Regularization: Includes reflection-aware normal smoothness and occupancy penalties
- Multi-Metric Evaluation: Quantifies results using PSNR, SSIM, and Chamfer distance
- Optimized for Consumer GPUs: This project was developed and tested on an HP Victus 15
- VRAM Requirements: 8GB+ recommended for batch_size=1024. If you encounter "CUDA Out of Memory," reduce the batch size in the Configuration cell
Open and run Code_main.ipynb in Jupyter Notebook or JupyterLab:
jupyter notebook Code_main.ipynbAll hyperparameters are defined in the notebook's Configuration Parameters section (Cell #2):
# Model parameters
pos_encoding_L = 10 # Positional encoding levels
hidden_dim = 256 # MLP hidden dimension
num_layers = 8 # Number of MLP layers
# Training parameters
num_iterations = 3000 # Training iterations
batch_size = 1024 # Rays per batch
learning_rate = 5e-4 # Learning rate
# Loss weights
w_img = 1.0 # Image reconstruction weight
w_ssim = 0.1 # SSIM loss weight
w_norm = 0.01 # Normal smoothness weight
w_consistency = 0.05 # Cross-view consistency-
Baseline Mode: For dense multi-view scenarios
baseline_mode = True
-
Heritage-NeRF Mode: For sparse/noisy views (default)
baseline_mode = False
data/nerfbk/
βββ heritage/
β βββ frame_0.jpg
β βββ frame_1.jpg
β βββ ... (RGB images)
βββ sparse/0/
βββ cameras.bin
βββ images.bin
βββ points3D.bin
- Run COLMAP structure-from-motion on heritage images
- Export sparse reconstruction to binary format
- Place in
data/nerfbk/sparse/0/
Results are saved to the results/ directory, including:
- metrics.csv: Quantitative evaluation metrics (PSNR, SSIM, Chamfer distance, F-score)
- Rendered images: Novel view synthesis results
- Geometry visualization: 3D mesh and point cloud visualizations
- Loss curves: Training convergence plots
- GPU Memory: Recommended 8GB+ VRAM for batch_size=1024
- Training Time: ~2-4 hours on RTX 3090 for 3000 iterations
- Resolution: Default batch_size assumes 512Γ512 or smaller images
PE(p) = [sin(2^0 * p), cos(2^0 * p), ..., sin(2^9 * p), cos(2^9 * p)]
Input: [PE(position), PE(direction)]
β 8 fully connected layers (256 dims)
β Output: [RGB, Density]
C(r) = β« T(t) Β· Ο(t) Β· c(t) dt
where T(t) = exp(-β« Ο(s) ds), Ο is density, c is color
- NeRF Paper: Mildenhall et al., "NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis", ECCV 2020
- COLMAP: SchΓΆnberger & Frahm, "Structure-from-Motion Revisited", CVPR 2016
- Reduce
batch_sizein configuration - Reduce image resolution
- Use
baseline_mode = True
- Increase
num_iterations - Adjust loss weights (especially
w_consistencyfor sparse views) - Ensure COLMAP reconstruction quality is adequate
- Verify COLMAP binary files are in
data/nerfbk/sparse/0/ - Check file permissions and disk space
- Real-time rendering with WebGL
- Multi-resolution mipmap pyramid
- Appearance flow modeling
- Dynamic scene support
- Interactive refinement UI
The 8.5 GB dataset used in this project is excluded from the repository to maintain a lightweight codebase.
Download: [Insert your Google Drive or OneDrive link here].
Placement: Extract the files into the data/ folder following the structure defined in the Data Format section.