Giter VIP home page Giter VIP logo

nerfiller's Introduction

NeRFiller: Completing Scenes via Generative 3D Inpainting

TLDR: NeRFiller completes missing regions in 3D scenes via an off-the-shelf 2D generative inpainter.

Project page at https://ethanweber.me/nerfiller/. Paper at https://arxiv.org/abs/2312.04560.

animated

Setup the environment

Here are the steps for installing all dependencies.

Clone this repo.

git clone [email protected]:ethanweber/nerfiller.git

Create a conda environment that has Nerfstudio installed. We tested with nerfstudio greater than version 1.0.0. Then run,

pip install -e .

Download and process data

Download the NeRF synthetic data

python nerfiller/scripts/download.py blender

Download the meshes that we will complete with NeRFiller

python nerfiller/scripts/download.py meshes

Download the backpack capture from SPIn-NeRF, formatted as a Nerfstudio dataset

python nerfiller/scripts/download.py nerfstudio

Download the novel-view camera paths.

python nerfiller/scripts/download.py camera-paths

Download the LaMa inpainter weights

python nerfiller/scripts/download.py models

Convert the blender datasets to Nerfstudio format.

Use blender_to_nerfstudio.py for converting blender data to nerfstudio datasets. Run ns-launch blender-to-nerfstudio --dry-run to to see all the commands you need to run, one per dataset, for a total of 8. Running it without --dry-run will run all the commands. I prefer to run all commands in a tmux session in case they take a while to run.

ns-launch blender-to-nerfstudio

Use create_nerfstudio_dataset.ipynb to render the meshes into nerfstudio datasets. This will require going into the notebook and running it from start to completition, where you modify the variable dataset_name each time. The dataset variables should be the name of the meshes in the folder data/meshes. This is where you'd want to add your own custom data. For example, let's look at the dataset cat with an explanation for each file.

cat/
  |- jerrypillow.jpg    # texture file
  |- model.mtl          # model material file
  |- model.obj          # model obj (name is important)
  |- occlusion.obj      # occlusion obj (name is important)

The filenames for model.obj and occlusion.obj are important, and should be the same for each dataset so the notebook can properly process it based on the specified dataset_name. The model will reference it's material and texture files, and the occlusion file will be used to mark regions of the mesh in 3D which we want to inpaint. We call the texture file jerrypillow.jpg because the cat plushie is named Jerry. πŸ™‚

Cat mesh
Cat mesh
Occlusion mesh
Occlusion mesh (manually made)
Cat composited
Cat mesh & occlusion

The cat mesh was created by scanning a scene with Polycam, exporting the mesh and loading it into Blender, and then deleting vertices and faces. The occluder wsa manually created in Blender too. Both the mesh (left) and occluder (middle) were explored to the files model.obj and occlusion.obj, respectively, where we keep the material and texture files for the model. The composited result is on the right.

Using your own data

If you want to use your own data, you can make a folder like specified above. Blender is useful is you want to export to OBJ files, which is what we require. In the notebook, you'll need to add another entry for your dataset in the dataset_configs dictionary.

Experiments

Run ns-launch --help for replicating our experiments. Run commands with --dry-run to see what the individual jobs will be. Edit nerfiller/experiments/data.py if you'd like to run on your own data! You'll need to modify the beginning lines of the file.

Next, we will show how to run experiments on all of our data for completing large unknown 3D regions. We refer to these experiments as the "occluder" experiments. This will involve editing the file nerfiller/experiments/occluder.py. You'd first uncomment as follows and run ns-launch train-occluder. This will train models on the visible regions.

methods = [
    ("nerfacto-nerfiller-visualize", "none"),
    ("nerfacto-nerfiller", "none"), # this must be trained first, as the following depend on it
    # ("individual-inpaint-once", "individual-sd-image"),
    # ("individual-inpaint-once", "individual-lama"),
    # ("grid-prior-du-no-depth", "none"),
    # ("grid-prior-du", "none"),
    # ("individual-inpaint-du", "none"),
    # ("grid-prior-du-random-noise", "none"), # this is extra for an ablation
]

Next, you'd uncomment as follows, omitting the first two methods. These methods will start from the nerfacto-nerfiller method checkpoint, which was trained in the previous step. grid-prior-du is our main method, and the rest are baselines.

If you want to run the individual-inpaint-once baselines, first run ns-launch inpaint-occluder. This will inpaint the missing regions once, and before we train the NeRF. The du methods will inpaint iteratively with the dataset update strategy. The inpaints will be in the folders data/nerfstudio/<dataset_name>-inpaint/<inpaint_method>/<timestamp>.

methods = [
    # ("nerfacto-nerfiller-visualize", "none"),
    # ("nerfacto-nerfiller", "none"), # this must be trained first, as the following depend on it
    ("individual-inpaint-once", "individual-sd-image"),
    ("individual-inpaint-once", "individual-lama"),
    ("grid-prior-du-no-depth", "none"),
    ("grid-prior-du", "none"),
    ("individual-inpaint-du", "none"),
    ("grid-prior-du-random-noise", "none"), # this is extra for an ablation
]

Finally, you can run ns-launch render-occluder --help and ns-launch metrics-occluder --help (in order, without --help or --dry-run). In general, we following a convention of training, rendering out the result, and finally, computing metrics. We use the notebook notebooks/inpainting_consistency_table.ipynb for aggregating results and generating LaTeX tables.

If you want to create side-by-side comparison videos, use the notebook notebooks/video_comparison.ipynb.

Experimenting with inpaints

Use notebooks/inpaint.ipynb to play around with inpainting a dataset in a notebook.

Synthetic experiments

For the experiments on the Blender dataset, the series of commands will be ns-launch inpaint-blender, ns-launch train-blender, ns-launch render-blender, and ns-launch metrics-blender. In this case, "blender" is used instead of "occluder" (as used previously). These are our one-word nicknames we use in the code to distinguish the different types of experiments performed in the paper.

Using a reference inpaint

In order to do reference inpainting, you can place a reference image named reference.png inside a Nerfstudio dataset folder. E.g., if you look at data/nerfstudio/cat, you'll see the file data/nerfstudio/cat/reference.png. You can inpaint images with notebooks/inpaint.ipynb until finding an example image that you like and then place it inside the Nerfstudio dataset folder. Then, you'll need to run the method for inpainting with a reference. Edit nerfiller/experiments/data.py as follows. Comment out lines of the occluder_dataset_names set such that only the datasets you care about are present. Mark if they are synthetic datasets or not in the variable synthetic_dataset_names as done with other datasets. This will change settings of Nerfacto, such as turning off scene contraction or setting a white or black background during training. Modify dataset_name_method_modifications as done for other examples if you want to use a text prompt with the reference inpaint. Finally, call ns-launch train-reference --dry-run to see the commands that would run. If you're happy with it, run without --dry-run or simply copy and paste the printed command and run on your own.

Misc

Some files are included that aren't used in the main pipeline, but could be useful to reference. Here is a high-level overview of this miscellaneous code.
  • nerfiller/dreambooth/dataset.py - Dataset code used for fine-tuning the SD inpainting models.

  • nerfiller/guidance/ - Experimental code for classifier-guidance when iterately denoising a diffusion model.

  • nerfiller/utils/ - Utils, including some extra code which may be useful to people.

  • scripts/blendernerf_to_nerfstudio.py.py - Convert the BlenderNeRF dataset format to Nerfstudio dataset format.

  • scripts/train_dreambooth_lora.py (ns-dreambooth) - Fine-tune an SD inpainting model on our data.

  • scripts/visualize_nerfstudio_dataset.py - Visualize a Nerfstudio dataset.

  • notebooks/inpaint.ipynb - If you want to play around with inpainting.

  • notebooks/novel_view_metrics.ipynb - Notebook to test computing the novel-view metrics.

  • notebooks/spinnerf_to_nerfstudio.ipynb - Code to convert from spinnerf to nerfstudio.

  • notebooks/upscale.ipynb - Code to play with a SD upscaler in a notebook.

The folders nerfiller/inpaint/models and nerfiller/inpaint/saicinpainting are taken from the LaMa inpainter codebase. We copied the code over to make it easier to use in our workflow. The LaMa module in nerfiller/inpaint/lama_inpainter.py references these files, and the weights downloaded to data/models/big-lama in the initial README instructions are from a Google Drive folder, where we simply copied their original weights to our own folder for setup convenience.

The MUSIQ metric is removed from our repo since we originally used the Tensorflow version from https://tfhub.dev/google/musiq/ava/1, which is difficult to install and get working within our PyTorch context. We commented the code out of nerfiller/utils/metrics.py and manually return 0s for now. An equivalent PyTorch image quality model should be used instead.


Citing

If you find this code or data useful for your research, please consider citing the following paper:

@inproceedings{weber2023nerfiller,
    title = {NeRFiller: Completing Scenes via Generative 3D Inpainting},
    author = {Ethan Weber and Aleksander Holynski and Varun Jampani and Saurabh Saxena and
        Noah Snavely and Abhishek Kar and Angjoo Kanazawa},
    booktitle = {CVPR},
    year = {2024},
}

nerfiller's People

Contributors

ethanweber avatar mikolajzielinski avatar

Stargazers

 avatar Xinyi Liu avatar Xingrui Wang avatar Seok Joon Kim avatar Jun-Pu (Yi) ZHANG 张珺菩 avatar Yuze Wang avatar Kohei Miura avatar Zesong Yang avatar  avatar Haotong LIN avatar Jie Yang avatar Yinghao Xu avatar Noah Snavely avatar Xueting Yang avatar Ro.Z avatar Tuan-Vu Trinh  avatar  avatar Matthias Fauconneau avatar  avatar Jack Hu avatar  avatar Freax Ruby avatar Yuhong Zhang avatar KIM MINSU avatar Spider Man avatar Xiyi Chen avatar  avatar Ziqi Cai avatar Yiqian Wu avatar Asrar avatar Jangho Park avatar noname avatar Igor Kraglik avatar Zhe Zhu avatar  avatar  avatar Yongjia Ma avatar Jiemin Fang avatar  avatar  avatar Suhas G avatar Braxton Mills avatar Lukas Hoellein avatar Griffin Seonho Lee avatar Yeojeong Park avatar Hu Zhu avatar Zhuoyang Pan avatar Ayaan Haque avatar Huang Binxiao avatar Freeman Cheng avatar Mohit Motwani avatar Evonne Ng avatar Luming Tang avatar Lu Ming avatar  avatar luyues avatar Matt Shaffer avatar Prakhar Kulshreshtha avatar  avatar ε°δΈ‰ηˆ·ζˆ‘ε€§θƒ†εœ°εΎ€ε‰θ΅°θŽ«ε›žε€΄ avatar Jinpeng Liu avatar Haebeom Jung avatar  avatar Gleb Sterkin avatar AI/ML Engineer avatar Renato Sortino avatar Arian Kulp avatar  avatar DoBetter avatar Nikan Doosti avatar 爱可可-ηˆ±η”Ÿζ΄» avatar Haiping Wang avatar YangXiuyu avatar Vincent Ho avatar Leo avatar  avatar Xuan Li avatar Tianyi Xie avatar Sai Kumar Dwivedi avatar  avatar ewrfcas avatar 唐国撁Tommy avatar

Watchers

Matthias Fauconneau avatar Jiaming Sun avatar Rajendra Alluri avatar  avatar  avatar Hu Zhu avatar Matt Shaffer avatar Zhenyu Tang avatar AI/ML Engineer avatar

nerfiller's Issues

ns-launch command

When I run the ns-launch command, I get a bash: ns-launch: command not found error, is it related to the version of nerfstudio?

TrainingCallbackAttributes Error

When I try the ("grid-prior-du-no-depth", "none"), the error occurs.
(I can successfully run the ("nerfacto-nerfiller-visualize", "none") and ("nerfacto-nerfiller", "none"))

Figure 1: Error:
image

Figure 2: TrainingCallbackAttributes in nerfstudio
image

Plan for code release

Hi Ethan,

Thank you for the great work. I wonder if you have an estimated time for code release? I really want to try it out.

ModuleNotFoundError: No module named 'kornia'

Hi,
I was running create_nerfstudio_dataset.ipynb and found that kornia is not installed.

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 11
      9 from nerfiller.utils.mesh_utils import project_mesh_into_perspective_image, dilate, erode, get_mesh_from_perspective_images, get_cube
     10 from nerfiller.utils.camera_utils import c2wh_from_c2w, rot_y, rot_x, rot_z, get_focal_len_from_fov
---> 11 from nerfiller.utils.depth_utils import depth_to_distance
     12 from nerfstudio.cameras.camera_utils import viewmatrix
     13 from nerfiller.utils.image_utils import image_tensor_to_npy, get_inpainted_image_row

      1 import math
      3 import torch
----> 5 from kornia.geometry.conversions import (
      6     convert_points_to_homogeneous,
      7 )
      8 from kornia.geometry.epipolar import (
      9     triangulate_points,
     10 )
     11 from nerfiller.utils.typing import *

ModuleNotFoundError: No module named 'kornia'

OOM Problem

Inpainting batch of images... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0% 0:00:03
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 9.38 GiB (GPU 0; 23.70 GiB total capacity; 8.04 GiB already allocated; 9.27 GiB free; 12.92 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF.

Environment: GPU RTX 3090 24GB

llff dataset question

Hello, thank you very much for your project. I want to ask a question, as far as I understand, the nerfstudio library does not support LLFF type dataset, but I see that you have used the SPIN dataset. Did you perform additional processing on its data?

ERROR: No matching distribution found for pytorch3d

Hi,
I was trying to install this package by following the description in README.md. Here are my steps:

Step 1: Create virtual env

# Create virtual env and update packages
python3.10 -m venv venv_nerfiller \
&& source venv_nerfiller/bin/activate \
&& python3 -m pip install --upgrade pip setuptools wheel

Step 2: Install nerfstuidio. Everything works perfectly.

# Install nerfstudio
python3 -m pip install torch==2.1.2+cu118 torchvision==0.16.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118

python3 -m pip install ninja git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch

python3 -m pip install nerfstudio

Step 3: Install NeRFiller

# Install NeRFiller
pip install -e .

But I encountered the error:

INFO: pip is looking at multiple versions of nerfiller to determine which version is compatible with other requirements. This could take a while.
ERROR: Could not find a version that satisfies the requirement pytorch3d (from nerfiller) (from versions: none)
ERROR: No matching distribution found for pytorch3d

I don't quite understand that since pytorch3d doesn't specify a version, why pip cannot find a version for it.

Here is my system environment:

  • Python:
Python: 3.10
  • CUDA version:
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

Thank you for creating this awesome project.

Occlusion of CAT

I am a little confused, since the occlusion of cat is like this.
1705727973469

Why some images extracted from the meshes have some black blocks (some didn't have) near the carrot as follows:
1705727935688

Version problem

Packages:
nerfstuido : 0.3.4
pytorch-lightning: 2.1.3
torch: 2.0.1+ cu118
torchmetrics: 1.2.1
torchaudio: 2.1.2

After installation and data preparation, when I run ns-launch train-occluder, I still get an error (seems that torchaudio didn't work). So I would like to inquire about the version you used in the above Packages.
Snipaste_2024-01-04_16-21-02

Thanks a lot~

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.