Pure PyTorch implementation of NVIDIA's Instant Neural Graphics Primitives
Project description
Fast-NGP
A clean, pure PyTorch implementation of NVIDIA's Instant Neural Graphics Primitives with multiresolution hash encoding.
Features
✨ Pure PyTorch - No CUDA extensions required, easy to install and modify
📦 Easy Installation - pip install pyinstant-ngp
🎯 Modular Design - Each component usable independently
🚀 Multiple Tasks - NeRF, SDF, and Gigapixel image support
📊 Visualization Tools - Built-in rendering and metrics
🧪 Well Tested - Comprehensive test suite
📚 Great Docs - Extensive documentation and examples
Installation
From PyPI (recommended)
pip install fast-ngp
From source
git clone https://github.com/Dox45/fast-ngp.git
cd fast-ngp
pip install -e .
Quick Start
Train a NeRF
import torch
from fast_ngp.models.fast_nerf import FastNGP_NeRF
from fast_ngp.utils.dataset import SimpleNeRFDataset
from fast_ngp.utils.trainer import NeRFTrainer
dataset_path = 'path/to/data' # directory containing transforms_train.json or tiny_nerf_data.npz
dataset = SimpleNeRFDataset(root_dir=dataset_path, split='train', img_wh=(128, 128))
print(f"Dataset ready with {len(dataset)} rays")
# inti model
model = FastNGP_NeRF(
encoding_config={
'n_levels': 16,
'n_features_per_level': 2,
'log2_hashmap_size': 19,
'base_resolution': 16,
'finest_resolution': 512
},
mlp_config={
'n_hidden_layers': 2,
'hidden_dim': 64
}
)
print("✅ Model initialized")
# Train
device = 'cuda' if torch.cuda.is_available() else 'cpu'
trainer = NeRFTrainer(
model=model,
train_dataset=dataset,
val_dataset=None, # you can add a validation dataset if available
batch_size=64,
lr=1e-2,
num_epochs=5,
device=device
)
trainer.train()
print("🎉 Training complete!")
# Provide a camera pose as a 3x4 matrix (numpy or torch)
import numpy as np
camera_pose = np.eye(4)[:3, :4] # identity pose for testing
H, W = 128, 128
# The render_image method should be implemented in FastNGP_NeRF
with torch.no_grad():
image = model.render_image(camera_pose, H=H, W=W)
print("Rendered image shape:", image.shape)
Command Line Interface
# Train NeRF
fast-ngp-train --task nerf --data path/to/data --config configs/nerf.yaml
# Render from trained model
fast-ngp-render --checkpoint model.pth --output renders/
Architecture
pyinstant-ngp/
├── encoding/ # Multiresolution hash encoding
├── models/ # MLP networks
├── rendering/ # Ray marching and rendering
├── example/ # Dataset loaders
└── utils/ # Dataset loaders and trainer
Citation
If you use this code in your research, please cite both the original paper and this implementation:
@article{mueller2022instant,
title={Instant Neural Graphics Primitives with a Multiresolution Hash Encoding},
author={M\"uller, Thomas and Evans, Alex and Schied, Christoph and Keller, Alexander},
journal={ACM Transactions on Graphics (ToG)},
volume={41},
number={4},
pages={1--15},
year={2022},
publisher={ACM}
}
@software{fast_ngp,
author = {Chima Emmanuel},
title = {Fast-NGP: Pure PyTorch Implementation of Instant-NGP},
year = {2025},
url = {https://github.com/Dox45/fast-ngp}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Original Instant-NGP by NVIDIA
- Inspired by torch-ngp and HashNeRF-pytorch
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_ngp-0.1.0.tar.gz.
File metadata
- Download URL: fast_ngp-0.1.0.tar.gz
- Upload date:
- Size: 3.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04c275895eb1b5456b7e309fe9dfe11956906e4551f54e945c8df0cdc75dd717
|
|
| MD5 |
a24d3209e398fbfda236183508d7f9f6
|
|
| BLAKE2b-256 |
9b1e0d4ae2602e33dae1f0f8a25f5eae223062427508cae3a14664e80cd20d72
|
File details
Details for the file fast_ngp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fast_ngp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05025e451b41df32cd961c73bd3089e0e7b0277317ef385d8c1afe0b28e92a51
|
|
| MD5 |
855a1b1ff79b0f59b9bb508a1243a36a
|
|
| BLAKE2b-256 |
5678a59d31b727e9493c2f79ac60e05a8b57301a2a1b7473e18eade38916d05c
|