Giter Site home page Giter Site logo

mipnerf_pl's Introduction

mipnerf_pl

Unofficial pytorch-lightning implement of Mip-NeRF, Here are some results generated by this repository (pre-trained models are provided below):

Multi-scale render result

Multi Scale Train And Multi Scale Test Single Scale
PNSR SSIM PSNR SSIM
Full Res 1/2 Res 1/4 Res 1/8 Res Aveage
(PyTorch)
Aveage
(Jax)
Full Res 1/2 Res 1/4 Res 1/8 Res Average
(PyTorch)
Average
(Jax)
Full Res
lego 34.412 35.640 36.074 35.482 35.402 35.736 0.9719 0.9843 0.9897 0.9912 0.9843 0.9843 35.198 0.985

The top image of each column is groundtruth and the bottom image is Mip-NeRF render in different resolutions.

The above results are trained on the lego dataset with 300k steps for single-scale and multi-scale datasets respectively, and the pre-trained model can be found here. Feel free to contribute more datasets.

Installation

We recommend using Anaconda to set up the environment. Run the following commands:

# Clone the repo
git clone https://github.com/hjxwhy/mipnerf_pl.git; cd mipnerf_pl
# Create a conda environment
conda create --name mipnerf python=3.9.12; conda activate mipnerf
# Prepare pip
conda install pip; pip install --upgrade pip
# Install PyTorch
pip3 install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113
# Install requirements
pip install -r requirements.txt

Dataset

Download the datasets from the NeRF official Google Drive and unzip nerf_synthetic.zip. You can generate the multi-scale dataset used in the paper with the following command:

# Generate all scenes
python datasets/convert_blender_data.py --blender_dir UZIP_DATA_DIR --out_dir OUT_DATA_DIR
# If you only want to generate a scene, you can:
python datasets/convert_blender_data.py --blender_dir UZIP_DATA_DIR --out_dir OUT_DATA_DIR --object_name lego

Running

Train

To train a single-scale lego Mip-NeRF:

# You can specify the GPU numbers and batch size at the end of command,
# such as num_gpus 2 train.batch_size 4096 val.batch_size 8192 and so on.
# More parameters can be found in the configs/lego.yaml file. 
python train.py --out_dir OUT_DIR --data_path UZIP_DATA_DIR --dataset_name blender exp_name EXP_NAME

To train a multi-scale lego Mip-NeRF:

python train.py --out_dir OUT_DIR --data_path OUT_DATA_DIR --dataset_name multi_blender exp_name EXP_NAME

Evaluation

You can evaluate both single-scale and multi-scale models under the eval.sh guidance, changing all directories to your directory. Alternatively, you can use the following command for evaluation.

# eval single scale model
python eval.py --ckpt CKPT_PATH --out_dir OUT_DIR --scale 1 --save_image
# eval multi scale model
python eval.py --ckpt CKPT_PATH --out_dir OUT_DIR --scale 4 --save_image
# summarize the result again if you have saved the pnsr.txt and ssim.txt
python eval.py --ckpt CKPT_PATH --out_dir OUT_DIR --scale 4 --summa_only

Render Spheric Path Video

It also provide a script for rendering spheric path video

# Render spheric video
python render_video.py --ckpt CKPT_PATH --out_dir OUT_DIR --scale 4
# generate video if you already have images
python render_video.py --gen_video_only --render_images_dir IMG_DIR_RENDER

Visualize All Poses

The script modified from nerfplusplus supports visualize all poses which have been reorganized to right-down-forward coordinate. Multi-scale have different camera focal length which is equivalent to different resolutions.

Citation

Kudos to the authors for their amazing results:

@misc{barron2021mipnerf,
      title={Mip-NeRF: A Multiscale Representation for Anti-Aliasing Neural Radiance Fields},
      author={Jonathan T. Barron and Ben Mildenhall and Matthew Tancik and Peter Hedman and Ricardo Martin-Brualla and Pratul P. Srinivasan},
      year={2021},
      eprint={2103.13415},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

Acknowledgements

Thansks to mipnerf, mipnerf-pytorch, nerfplusplus, nerf_pl

mipnerf_pl's People

Contributors

hjxwhy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mipnerf_pl's Issues

Collaboration

Hello, thanks for sharing this implementation, it is awesome.

I am also implementing this and "mip-nerf 360" into my codebase. Would you like to work on it together?

I had a look at your latest commit and actually this

far_inv = 1 / far
near_inv = 1 / near
t_samples = far_inv * t_samples + (1 - t_samples) * near_inv
t_samples = 1 / t_samples

equals to this
t_samples = 1. / (1. / near * (1. - t_samples) + 1. / far * t_samples)

Data Parse Error

All output after running python train.py --out_dir . --data_path D:\Git_Project\data\nerf\nerf_synthetic\lego --dataset_name blender exp_name lego is shown below:

Sanity Checking: 0it [00:00, ?it/s]C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\connectors\data_connector.py:224: PossibleUserWarning: The dataloader, val_dataloader 0, does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` (try 16 which is the number of cpus on this machine) in the `DataLoader` init to improve performance.
  rank_zero_warn(
Epoch 0:   0%|          | 0/20842 [00:00<?, ?it/s] Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\multiprocessing\spawn.py", line 126, in _main
    self = reduction.pickle.load(from_parent)
_pickle.UnpicklingError: pickle data was truncated
Traceback (most recent call last):
  File "D:\Interesting\NeRF-Relevent\mipnerf_pl\train.py", line 68, in <module>
    main(parse_args(parser))
  File "D:\Interesting\NeRF-Relevent\mipnerf_pl\train.py", line 64, in main
    trainer.fit(system, ckpt_path=hparams['checkpoint.resume_path'])
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 608, in fit
    call._call_and_handle_interrupt(
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\call.py", line 38, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 650, in _fit_impl
    self._run(model, ckpt_path=self.ckpt_path)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 1112, in _run
    results = self._run_stage()
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 1191, in _run_stage
    self._run_train()
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 1214, in _run_train
    self.fit_loop.run()
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\loops\loop.py", line 199, in run
    self.advance(*args, **kwargs)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\loops\fit_loop.py", line 267, in advance
    self._outputs = self.epoch_loop.run(self._data_fetcher)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\loops\loop.py", line 194, in run
    self.on_run_start(*args, **kwargs)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\loops\epoch\training_epoch_loop.py", line 160, in on_run_start
    _ = iter(data_fetcher)  # creates the iterator inside the fetcher
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\utilities\fetching.py", line 179, in __iter__
    self._apply_patch()
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\utilities\fetching.py", line 120, in _apply_patch
    apply_to_collections(self.loaders, self.loader_iters, (Iterator, DataLoader), _apply_patch_fn)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\utilities\fetching.py", line 156, in loader_iters
    return self.dataloader_iter.loader_iters
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\supporters.py", line 556, in loader_iters
    self._loader_iters = self.create_loader_iters(self.loaders)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\pytorch_lightning\trainer\supporters.py", line 596, in create_loader_iters
    return apply_to_collection(loaders, Iterable, iter, wrong_dtype=(Sequence, Mapping))
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\lightning_utilities\core\apply_func.py", line 47, in apply_to_collection
    return function(data, *args, **kwargs)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\torch\utils\data\dataloader.py", line 435, in __iter__
    return self._get_iterator()
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\torch\utils\data\dataloader.py", line 381, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\site-packages\torch\utils\data\dataloader.py", line 1034, in __init__
    w.start()
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\multiprocessing\context.py", line 327, in _Popen
    return Popen(process_obj)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\AAA\anaconda3\envs\nerf-env\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
OSError: [Errno 22] Invalid argument

Eval error: ValueError: too many values to unpack (expected 3)

Traceback (most recent call last):                                                          
  File "/data/aug_code/mipnerf_pl/eval.py", line 90, in <module>                                     
    blender_scenes = main(args)                                                                         
  File "/data/aug_code/mipnerf_pl/eval.py", line 61, in main                                                                                                            
    _, (f_rgb, distance, acc) = model(batch_rays, False, args.white_bkgd)                                                                                                     
ValueError: too many values to unpack (expected 3) 

The Ln62 of eval.py should be changed to:
_, (f_rgb, distance, acc, _, _) = model(batch_rays, False, args.white_bkgd)

Setting batch_type to 'single_image'

Hi,

I'm trying to train a model with the batch_type set to 'single_image', but it seems like this part hasn't been implemented so far.
I tried to set shuffle in dataloader to be False, so that each batch has rays only coming from one image. However, it doesn't seem to work as the novel view are just white images.

Any clue what might be a right implementation for 'single_image' mode?
Appreciate any input you might have.

How to view the number of iterations?

I don't quite understand what you mean by 300k iterations. I ran on the 2060 GPU for nearly 30 hours, and the epoch only reached 1. The psnr reached 31.50. The file I finally got was “epoch=1-step=72499.ckpt”. Should I understand this as one iteration or 72500 iterations?

The inference speed is very slow

I download the pretrained model and start inference on a RTX 8000 GPU, the speed is so slow like 1 minute per frame. Did anyone get this problem?

Debug problem with render_video.py:

Debug problem with render_video.py:

When I try to run render_video.py on pycharm, it produces the following error:

D:\NeRF\mipnerf\mipnerf_pl-dev> python render_video.py --ckpt results/ckpt/lego/multi-epoch=35-step=298835.ckpt --out_dir video --scale 4
Traceback (most recent call last):
File "D:\NeRF\mipnerf\mipnerf_pl-dev\render_video.py", line 197, in
run_render(args)
File "D:\NeRF\mipnerf\mipnerf_pl-dev\render_video.py", line 139, in run_render
_, (f_rgb, distance, acc) = model(batch_rays, False, args.white_bkgd)
^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 3)

I have not made any changes to the code. Is there any solution, please

Why it is so slow

I start training with the dev code on the dataset of lego, multi-scale, 3 3090 GPU, and one epoch takes over 4 or 5 hours, wtf?

Value error

when I train the model , I have some problems
Validation sanity check: 0it [00:00, ?it/s]/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/data_loading.py:110: UserWarning: The dataloader, val_dataloader 0, does not have many workers which may be a bottleneck. Consider increasing the value of the num_workers argument(try 128 which is the number of cpus on this machine) in theDataLoaderinit to improve performance. rank_zero_warn( Traceback (most recent call last): File "train.py", line 68, in <module> main(parse_args(parser)) File "train.py", line 64, in main trainer.fit(system, ckpt_path=hparams['checkpoint.resume_path']) File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 737, in fit self._call_and_handle_interrupt( File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 682, in _call_and_handle_interrupt return trainer_fn(*args, **kwargs) File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 772, in _fit_impl self._run(model, ckpt_path=ckpt_path) File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1195, in _run self._dispatch() File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1274, in _dispatch self.training_type_plugin.start_training(self) File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/plugins/training_type/training_type_plugin.py", line 202, in start_training self._results = trainer.run_stage() File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1284, in run_stage return self._run_train() File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1314, in _run_train self.fit_loop.run() File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/loops/base.py", line 140, in run self.on_run_start(*args, **kwargs) File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/loops/fit_loop.py", line 197, in on_run_start self.trainer.reset_train_val_dataloaders(self.trainer.lightning_module) File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/data_loading.py", line 561, in reset_train_val_dataloaders self.reset_train_dataloader(model=model) File "/root/miniconda3/lib/python3.8/site-packages/pytorch_lightning/trainer/data_loading.py", line 386, in reset_train_dataloader raise ValueError( ValueError:val_check_interval(10000) must be less than or equal to the number of the training batches (1303). If you want to disable validation setlimit_val_batches` to 0.0 instead.

what can I do to solve it

Experiment Result

Hey and Thanks for sharing ur mip-nerf code.
I am currently doing something base on ur code. I wonder whether this code on the same experiment of paper?
See your reply! love u

How do you understand the variance part of Formula 8 in the paper?

(sigma_t^2 and sigma_r^2) in formula 8(2) represent the decomposition of the vector. In the second coefficient, the unit matrix represents the vector itself, and the one that is subtracted represents the projection from the conical frustum coordinate system to the world coordinate system in the direction of the axis, so the second term can only represent the variance perpendicular to the direction of the axis.
So, why are the coefficients of the first term and the subtractive coefficients of the second term different in form? Whether the first term should also be divided by the quadratic power of d?

FileNotFoundError

I am so sorry to disturb you,when I save_image,I have a problem
0%| | 0/200 [00:02<?, ?it/s]
Traceback (most recent call last):
File "/root/miniconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/root/miniconda3/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/root/mipnerf_pl-dev/eval.py", line 90, in
blender_scenes = main(args)
File "/root/mipnerf_pl-dev/eval.py", line 78, in main
save_images(fine_rgb, distances, accs, out_path, n)
File "/root/mipnerf_pl-dev/utils/vis.py", line 70, in save_images
save_image_tensor(rgb, H, W, os.path.join(path, str('{:05d}'.format(idx)) + '_rgb' + '.png'))
File "/root/mipnerf_pl-dev/utils/vis.py", line 56, in save_image_tensor
torchvision.utils.save_image(image, save_path)
File "/root/miniconda3/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/root/miniconda3/lib/python3.8/site-packages/torchvision/utils.py", line 156, in save_image
im.save(fp, format=format)
File "/root/miniconda3/lib/python3.8/site-packages/PIL/Image.py", line 2297, in save
fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: '/root/mipnerf_pl-dev/Viedos/000/test/lego/4/00000_rgb.png'
I don't know how to solve the problem

question about dataset

Hello, thanks for your excellent work, I have noticed the Jax version and your implementation of mip-nerf have only test on blender dataset, and do not test on other datasets, like llff dataset. Is this implementation only works for blender dataset? can you do some experiments on llff dataset?

Training duration

Hi.

How long does it take to train on the Lego scene for 300k epochs? Also, why 300k and not 1M epochs like in the official mipnerf implementation?

A question about environment

I followed the steps in readme file, and when I did the last step(pip install -r requirements.txt), the system automatically reinstalled torch during the installation process, but there were already separate steps to install torch and torch vision("pip3 install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113" of readme file).
image
Also, at the end, the system tried uninstalling torch-1.12.1 and cu113, and after uninstalling them, it said that the torch version was incompatible.
As shown in the figure below
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.