Skip to content

Commit

Permalink
Merge branch 'brent/external_method_help' of github.com:nerfstudio-pr…
Browse files Browse the repository at this point in the history
…oject/nerfstudio into brent/external_method_help
  • Loading branch information
brentyi committed Jan 20, 2024
2 parents cad244f + bfb20e9 commit d5ca320
Show file tree
Hide file tree
Showing 83 changed files with 360 additions and 528 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/core_code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
- name: Check notebook cell metadata
run: |
python ./nerfstudio/scripts/docs/add_nb_tags.py --check
- name: Run Ruff
run: ruff docs/ nerfstudio/ tests/
- name: Run Black
run: black docs/ nerfstudio/ tests/ --check
- name: Run Ruff Linter
run: ruff check docs/ nerfstudio/ tests/
- name: Run Ruff Formatter
run: ruff format docs/ nerfstudio/ tests/ --check
- name: Run Pyright
run: |
pyright
Expand Down
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ repos:
files: '.*'
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.267'
rev: v0.1.13
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: '23.3.0'
hooks:
- id: black
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
"typescript.suggestionActions.enabled": false,
"javascript.suggestionActions.enabled": false,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
}
},
"editor.formatOnSave": true,
"editor.rulers": [120],
"python.envFile": "${workspaceFolder}/.env",
"python.formatting.provider": "none",
"black-formatter.args": ["--line-length=120"],
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": false,
"python.linting.enabled": true,
Expand Down
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -119,44 +119,44 @@ ENV PATH="${PATH}:/home/user/.local/bin"
SHELL ["/bin/bash", "-c"]

# Upgrade pip and install packages.
RUN python3.10 -m pip install --upgrade pip setuptools pathtools promise pybind11
RUN python3.10 -m pip install --no-cache-dir --upgrade pip setuptools pathtools promise pybind11
# Install pytorch and submodules
RUN CUDA_VER=${CUDA_VERSION%.*} && CUDA_VER=${CUDA_VER//./} && python3.10 -m pip install \
RUN CUDA_VER=${CUDA_VERSION%.*} && CUDA_VER=${CUDA_VER//./} && python3.10 -m pip install --no-cache-dir \
torch==2.0.1+cu${CUDA_VER} \
torchvision==0.15.2+cu${CUDA_VER} \
--extra-index-url https://download.pytorch.org/whl/cu${CUDA_VER}
# Install tynyCUDNN (we need to set the target architectures as environment variable first).
ENV TCNN_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES}
RUN python3.10 -m pip install git+https://github.com/NVlabs/[email protected]#subdirectory=bindings/torch
RUN python3.10 -m pip install --no-cache-dir git+https://github.com/NVlabs/[email protected]#subdirectory=bindings/torch

# Install pycolmap, required by hloc.
RUN git clone --branch v0.4.0 --recursive https://github.com/colmap/pycolmap.git && \
cd pycolmap && \
python3.10 -m pip install . && \
python3.10 -m pip install --no-cache-dir . && \
cd ..

# Install hloc 1.4 as alternative feature detector and matcher option for nerfstudio.
RUN git clone --branch master --recursive https://github.com/cvg/Hierarchical-Localization.git && \
cd Hierarchical-Localization && \
git checkout v1.4 && \
python3.10 -m pip install -e . && \
python3.10 -m pip install --no-cache-dir -e . && \
cd ..

# Install pyceres from source
RUN git clone --branch v1.0 --recursive https://github.com/cvg/pyceres.git && \
cd pyceres && \
python3.10 -m pip install -e . && \
python3.10 -m pip install --no-cache-dir -e . && \
cd ..

# Install pixel perfect sfm.
RUN git clone --recursive https://github.com/cvg/pixel-perfect-sfm.git && \
cd pixel-perfect-sfm && \
git reset --hard 40f7c1339328b2a0c7cf71f76623fb848e0c0357 && \
git clean -df && \
python3.10 -m pip install -e . && \
python3.10 -m pip install --no-cache-dir -e . && \
cd ..

RUN python3.10 -m pip install omegaconf
RUN python3.10 -m pip install --no-cache-dir omegaconf
# Copy nerfstudio folder and give ownership to user.
ADD . /home/user/nerfstudio
USER root
Expand All @@ -165,7 +165,7 @@ USER ${USER_ID}

# Install nerfstudio dependencies.
RUN cd nerfstudio && \
python3.10 -m pip install -e . && \
python3.10 -m pip install --no-cache-dir -e . && \
cd ..

# Change working directory
Expand Down
4 changes: 2 additions & 2 deletions docs/extensions/blender_addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Overview

This Blender add-on allows for compositing with a Nerfstudio render as a background layer by generating a camera path JSON file from the Blender camera path, as well as a way to import Nerfstudio JSON files as a Blender camera baked with the Nerfstudio camera path. This add-on also allows compositing multiple NeRF objects into a NeRF scene. This is achieved by importing a mesh or point-cloud representation of the NeRF scene from Nerfstudio into Blender and getting the camera coordinates relative to the transformations of the NeRF representation. Dynamic FOV from the Blender camera is supported and will match the Nerfstudio render. Perspective, equirectangular, VR180, and omnidirectional stereo (VR 360) cameras are supported.
This Blender add-on allows for compositing with a Nerfstudio render as a background layer by generating a camera path JSON file from the Blender camera path, as well as a way to import Nerfstudio JSON files as a Blender camera baked with the Nerfstudio camera path. This add-on also allows compositing multiple NeRF objects into a NeRF scene. This is achieved by importing a mesh or point-cloud representation of the NeRF scene from Nerfstudio into Blender and getting the camera coordinates relative to the transformations of the NeRF representation. Dynamic FOV from the Blender camera is supported and will match the Nerfstudio render. Perspective, equirectangular, VR180, and omnidirectional stereo (VR 360) cameras are supported. This add-on also supports Gaussian Splatting scenes as well, however equirectangular and VR video rendering is not currently supported.

<center>
<img width="800" alt="image" src="https://user-images.githubusercontent.com/9502341/211442247-99d1ebc7-3ef9-46f7-9bcc-0e18553f19b7.PNG">
Expand All @@ -30,7 +30,7 @@ This Blender add-on allows for compositing with a Nerfstudio render as a backgro

## Scene Setup

1. Export the mesh or point cloud representation of the NeRF from Nerfstudio, which will be used as reference for the actual NeRF in the Blender scene. Mesh export at a good quality is preferred, however, if the export is not clear or the NeRF is large, a detailed point cloud export will also work.
1. Export the mesh or point cloud representation of the NeRF from Nerfstudio, which will be used as reference for the actual NeRF in the Blender scene. Mesh export at a good quality is preferred, however, if the export is not clear or the NeRF is large, a detailed point cloud export will also work. Keep the `save_world_frame` flag as False or in the viewer, de-select the "Save in world frame" checkbox to keep the correct coordinate system for the add-on.

2. Import the mesh or point cloud representation of the NeRF into the scene. You may need to crop the mesh further. Since it is used as a reference and won't be visible in the final render, only the parts that the blender animation will interact with may be necessary to import.

Expand Down
17 changes: 8 additions & 9 deletions docs/reference/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ In addition to code contributions, we also encourage contributors to add their o

Below are the various tooling features our team uses to maintain this codebase.

| Tooling | Support |
| --------------- | ---------------------------------------------------------- |
| Formatting | [Black](https://black.readthedocs.io/en/stable/) |
| Linter | [Ruff](https://beta.ruff.rs/docs/) |
| Type checking | [Pyright](https://github.com/microsoft/pyright) |
| Testing | [pytest](https://docs.pytest.org/en/7.1.x/) |
| Docs | [Sphinx](https://www.sphinx-doc.org/en/master/) |
| Docstring style | [Google](https://google.github.io/styleguide/pyguide.html) |
| JS Linting | [eslint](https://eslint.org/) |
| Tooling | Support |
| -------------------- | ---------------------------------------------------------- |
| Formatting & Linting | [Ruff](https://beta.ruff.rs/docs/) |
| Type checking | [Pyright](https://github.com/microsoft/pyright) |
| Testing | [pytest](https://docs.pytest.org/en/7.1.x/) |
| Docs | [Sphinx](https://www.sphinx-doc.org/en/master/) |
| Docstring style | [Google](https://google.github.io/styleguide/pyguide.html) |
| JS Linting | [eslint](https://eslint.org/) |

## Requirements

Expand Down
6 changes: 4 additions & 2 deletions nerfstudio/cameras/camera_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
from torch import Tensor, nn
from typing_extensions import assert_never

from nerfstudio.cameras.cameras import Cameras
from nerfstudio.cameras.lie_groups import exp_map_SE3, exp_map_SO3xR3
from nerfstudio.cameras.rays import RayBundle
from nerfstudio.configs.base_config import InstantiateConfig
from nerfstudio.utils import poses as pose_utils
from nerfstudio.engine.optimizers import OptimizerConfig
from nerfstudio.engine.schedulers import SchedulerConfig
from nerfstudio.cameras.cameras import Cameras
from nerfstudio.utils import poses as pose_utils


@dataclass
Expand All @@ -60,6 +60,7 @@ class CameraOptimizerConfig(InstantiateConfig):
def __post_init__(self):
if self.optimizer is not None:
import warnings

from nerfstudio.utils.rich_utils import CONSOLE

CONSOLE.print(
Expand All @@ -70,6 +71,7 @@ def __post_init__(self):

if self.scheduler is not None:
import warnings

from nerfstudio.utils.rich_utils import CONSOLE

CONSOLE.print(
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/cameras/camera_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def _compute_residual_and_jacobian(
xd: torch.Tensor,
yd: torch.Tensor,
distortion_params: torch.Tensor,
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor,]:
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
"""Auxiliary function of radial_and_tangential_undistort() that computes residuals and jacobians.
Adapted from MultiNeRF:
https://github.com/google-research/multinerf/blob/b02228160d3179300c7d499dca28cb9ca3677f32/internal/camera_utils.py#L427-L474
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/configs/dataparser_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
from nerfstudio.data.dataparsers.nuscenes_dataparser import NuScenesDataParserConfig
from nerfstudio.data.dataparsers.phototourism_dataparser import PhototourismDataParserConfig
from nerfstudio.data.dataparsers.scannet_dataparser import ScanNetDataParserConfig
from nerfstudio.data.dataparsers.scannetpp_dataparser import ScanNetppDataParserConfig
from nerfstudio.data.dataparsers.sdfstudio_dataparser import SDFStudioDataParserConfig
from nerfstudio.data.dataparsers.sitcoms3d_dataparser import Sitcoms3DDataParserConfig
from nerfstudio.data.dataparsers.scannetpp_dataparser import ScanNetppDataParserConfig
from nerfstudio.plugins.registry_dataparser import discover_dataparsers

dataparsers = {
Expand Down
21 changes: 6 additions & 15 deletions nerfstudio/configs/method_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,16 @@
from nerfstudio.cameras.camera_optimizers import CameraOptimizerConfig
from nerfstudio.configs.base_config import ViewerConfig
from nerfstudio.configs.external_methods import get_external_methods
from nerfstudio.data.datamanagers.base_datamanager import (
VanillaDataManager,
VanillaDataManagerConfig,
)
from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager, VanillaDataManagerConfig
from nerfstudio.data.datamanagers.full_images_datamanager import FullImageDatamanagerConfig
from nerfstudio.data.datamanagers.parallel_datamanager import ParallelDataManagerConfig
from nerfstudio.data.datamanagers.random_cameras_datamanager import (
RandomCamerasDataManagerConfig,
)
from nerfstudio.data.datamanagers.random_cameras_datamanager import RandomCamerasDataManagerConfig
from nerfstudio.data.dataparsers.blender_dataparser import BlenderDataParserConfig
from nerfstudio.data.dataparsers.colmap_dataparser import ColmapDataParserConfig
from nerfstudio.data.dataparsers.dnerf_dataparser import DNeRFDataParserConfig
from nerfstudio.data.dataparsers.instant_ngp_dataparser import (
InstantNGPDataParserConfig,
)
from nerfstudio.data.dataparsers.instant_ngp_dataparser import InstantNGPDataParserConfig
from nerfstudio.data.dataparsers.nerfstudio_dataparser import NerfstudioDataParserConfig
from nerfstudio.data.dataparsers.phototourism_dataparser import (
PhototourismDataParserConfig,
)
from nerfstudio.data.dataparsers.phototourism_dataparser import PhototourismDataParserConfig
from nerfstudio.data.dataparsers.sdfstudio_dataparser import SDFStudioDataParserConfig
from nerfstudio.data.dataparsers.sitcoms3d_dataparser import Sitcoms3DDataParserConfig
from nerfstudio.data.datasets.depth_dataset import DepthDataset
Expand All @@ -62,7 +55,6 @@
from nerfstudio.models.gaussian_splatting import GaussianSplattingModelConfig
from nerfstudio.models.generfacto import GenerfactoModelConfig
from nerfstudio.models.instant_ngp import InstantNGPModelConfig
from nerfstudio.data.dataparsers.colmap_dataparser import ColmapDataParserConfig
from nerfstudio.models.mipnerf import MipNerfModel
from nerfstudio.models.nerfacto import NerfactoModelConfig
from nerfstudio.models.neus import NeuSModelConfig
Expand All @@ -71,7 +63,6 @@
from nerfstudio.models.tensorf import TensoRFModelConfig
from nerfstudio.models.vanilla_nerf import NeRFModel, VanillaModelConfig
from nerfstudio.pipelines.base_pipeline import VanillaPipelineConfig
from nerfstudio.data.datamanagers.full_images_datamanager import FullImageDatamanagerConfig
from nerfstudio.pipelines.dynamic_batch import DynamicBatchPipelineConfig
from nerfstudio.plugins.registry import discover_methods

Expand Down
12 changes: 2 additions & 10 deletions nerfstudio/data/datamanagers/base_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,8 @@
from nerfstudio.data.dataparsers.base_dataparser import DataparserOutputs
from nerfstudio.data.dataparsers.blender_dataparser import BlenderDataParserConfig
from nerfstudio.data.datasets.base_dataset import InputDataset
from nerfstudio.data.pixel_samplers import (
PatchPixelSamplerConfig,
PixelSampler,
PixelSamplerConfig,
)
from nerfstudio.data.utils.dataloaders import (
CacheDataloader,
FixedIndicesEvalDataloader,
RandIndicesEvalDataloader,
)
from nerfstudio.data.pixel_samplers import PatchPixelSamplerConfig, PixelSampler, PixelSamplerConfig
from nerfstudio.data.utils.dataloaders import CacheDataloader, FixedIndicesEvalDataloader, RandIndicesEvalDataloader
from nerfstudio.data.utils.nerfstudio_collate import nerfstudio_collate
from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes
from nerfstudio.model_components.ray_generators import RayGenerator
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/data/datamanagers/random_cameras_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import torch
from rich.progress import Console
from torch.nn import Parameter
from torch import Tensor
from torch.nn import Parameter
from typing_extensions import Literal

from nerfstudio.cameras.cameras import Cameras
Expand Down
6 changes: 1 addition & 5 deletions nerfstudio/data/dataparsers/arkitscenes_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@

from nerfstudio.cameras import camera_utils
from nerfstudio.cameras.cameras import Cameras, CameraType
from nerfstudio.data.dataparsers.base_dataparser import (
DataParser,
DataParserConfig,
DataparserOutputs,
)
from nerfstudio.data.dataparsers.base_dataparser import DataParser, DataParserConfig, DataparserOutputs
from nerfstudio.data.scene_box import SceneBox


Expand Down
6 changes: 1 addition & 5 deletions nerfstudio/data/dataparsers/blender_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
import torch

from nerfstudio.cameras.cameras import Cameras, CameraType
from nerfstudio.data.dataparsers.base_dataparser import (
DataParser,
DataParserConfig,
DataparserOutputs,
)
from nerfstudio.data.dataparsers.base_dataparser import DataParser, DataParserConfig, DataparserOutputs
from nerfstudio.data.scene_box import SceneBox
from nerfstudio.utils.colors import get_color
from nerfstudio.utils.io import load_from_json
Expand Down
20 changes: 8 additions & 12 deletions nerfstudio/data/dataparsers/colmap_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import sys
from dataclasses import dataclass, field
from pathlib import Path
from functools import partial
from pathlib import Path
from typing import List, Literal, Optional, Type

import numpy as np
Expand All @@ -31,15 +31,15 @@
from nerfstudio.data.dataparsers.base_dataparser import DataParser, DataParserConfig, DataparserOutputs
from nerfstudio.data.scene_box import SceneBox
from nerfstudio.data.utils import colmap_parsing_utils as colmap_utils
from nerfstudio.process_data.colmap_utils import parse_colmap_camera_params
from nerfstudio.utils.scripts import run_command
from nerfstudio.utils.rich_utils import CONSOLE, status
from nerfstudio.data.utils.dataparsers_utils import (
get_train_eval_split_all,
get_train_eval_split_filename,
get_train_eval_split_fraction,
get_train_eval_split_interval,
get_train_eval_split_all,
)
from nerfstudio.process_data.colmap_utils import parse_colmap_camera_params
from nerfstudio.utils.rich_utils import CONSOLE, status
from nerfstudio.utils.scripts import run_command

MAX_AUTO_RESOLUTION = 1600

Expand All @@ -66,7 +66,7 @@ class ColmapDataParserConfig(DataParserConfig):
"""Whether to automatically scale the poses to fit in +/- 1 bounding box."""
eval_mode: Literal["fraction", "filename", "interval", "all"] = "interval"
"""
The method to use for splitting the dataset into train and eval.
The method to use for splitting the dataset into train and eval.
Fraction splits based on a percentage for train and the remaining for eval.
Filename splits based on filenames containing train/eval.
Interval uses every nth frame for eval (used by most academic papers, e.g. MipNerf360, GSplat).
Expand Down Expand Up @@ -284,15 +284,11 @@ def _generate_dataparser_outputs(self, split: str = "train", **kwargs):
if "depth_path" in frame:
depth_filenames.append(Path(frame["depth_path"]))

assert len(mask_filenames) == 0 or (
len(mask_filenames) == len(image_filenames)
), """
assert len(mask_filenames) == 0 or (len(mask_filenames) == len(image_filenames)), """
Different number of image and mask filenames.
You should check that mask_path is specified for every frame (or zero frames) in transforms.json.
"""
assert len(depth_filenames) == 0 or (
len(depth_filenames) == len(image_filenames)
), """
assert len(depth_filenames) == 0 or (len(depth_filenames) == len(image_filenames)), """
Different number of image and depth filenames.
You should check that depth_file_path is specified for every frame (or zero frames) in transforms.json.
"""
Expand Down
6 changes: 1 addition & 5 deletions nerfstudio/data/dataparsers/dnerf_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
import torch

from nerfstudio.cameras.cameras import Cameras, CameraType
from nerfstudio.data.dataparsers.base_dataparser import (
DataParser,
DataParserConfig,
DataparserOutputs,
)
from nerfstudio.data.dataparsers.base_dataparser import DataParser, DataParserConfig, DataparserOutputs
from nerfstudio.data.scene_box import SceneBox
from nerfstudio.utils.colors import get_color
from nerfstudio.utils.io import load_from_json
Expand Down
6 changes: 1 addition & 5 deletions nerfstudio/data/dataparsers/dycheck_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
import torch

from nerfstudio.cameras.cameras import Cameras, CameraType
from nerfstudio.data.dataparsers.base_dataparser import (
DataParser,
DataParserConfig,
DataparserOutputs,
)
from nerfstudio.data.dataparsers.base_dataparser import DataParser, DataParserConfig, DataparserOutputs
from nerfstudio.data.scene_box import SceneBox
from nerfstudio.utils.colors import get_color
from nerfstudio.utils.io import load_from_json
Expand Down
Loading

0 comments on commit d5ca320

Please sign in to comment.