Skip to content

pytorch implementation of InstantNGP for 2D and 3D scene reconstruction

License

Notifications You must be signed in to change notification settings

HrushikeshBudhale/NGP_from_scratch

Repository files navigation

NGP_from_scratch

This is a pytorch implementation of paper Instant Neural Graphics Primitives with a Multiresolution Hash Encoding.

If you are good at learning concepts from code, this repo is for you!

The codebase is intentionally simplified to facilitate better understanding of the core concepts with comments showing each tensor's shape which I think makes the code much more readable.

In fact, if you are coming from my previous repo NeRF_from_scratch, you will see that this implementation mainly changes just the model.py without changing any ray marching or rendering or training loop. (Try git diff with initial commit)

The elegant part about this pytorch implementation is that to make the model work for 2D or 3D demo, you only need to set value of d in conf.yaml to either 2 or 3 and all functions behave exactly the same.

If you found this repo useful, please leave a star! ⭐️

Features

  • Multiresolution hash encoding
  • Accelerated ray marching
  • Early stopping
  • (2D) image and (3D) scene reconstruction support
  • SDF reconstruction support (in progress)
  • Exponential stepping (to be implemented)

Installation

  1. Clone the repository

    git clone https://github.com/HrushikeshBudhale/NeRF_from_scratch.git
  2. Create conda environment

    conda create -n nerf python=3.10
    conda activate nerf
  3. Install dependencies

    pip install -r requirements.txt
  4. Download dataset

    For 2D image reconstruction you can use megapixel Tokyo image. For 3D scene reconstruction you can use lego scene.

  5. Set the dataset path and other parameters in conf.yaml.

  6. Run the code

    python train_nerf.py
    python test_nerf.py

Results

2D Image Reconstruction

reconstruction of megapixel tokyo

Rendered 2D image from the model (PSNR: 26.12)

comparison

Comparison of ground truth (left) with model's output (right)


psnr score graph

PSNR score of the model

3D Scene Reconstruction

lego_scene

lego_scene

reconstruction of lego scene

psnr score graph

Acknowledgements

About

pytorch implementation of InstantNGP for 2D and 3D scene reconstruction

Topics

Resources

License

Stars

Watchers

Forks

Languages