mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-29 20:39:48 +08:00
merge w main
This commit is contained in:
commit
e343ea0b07
237 files changed
+3986
-1961
No files matched your search
@@ -1,4 +1,4 @@
|
||||
# Copyright 2022 The Nerfstudio Team. All rights reserved.
|
||||
# Copyright 2022 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2022 The Nerfstudio Team. All rights reserved.
|
||||
# Copyright 2022 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
"""Base Configs"""
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -30,7 +29,7 @@ warnings.filterwarnings("ignore", module="torchvision")
|
||||
|
||||
|
||||
# Pretty printing class
|
||||
class PrintableConfig: # pylint: disable=too-few-public-methods
|
||||
class PrintableConfig:
|
||||
"""Printable Config defining str function"""
|
||||
|
||||
def __str__(self):
|
||||
@@ -48,7 +47,7 @@ class PrintableConfig: # pylint: disable=too-few-public-methods
|
||||
|
||||
# Base instantiate configs
|
||||
@dataclass
|
||||
class InstantiateConfig(PrintableConfig): # pylint: disable=too-few-public-methods
|
||||
class InstantiateConfig(PrintableConfig):
|
||||
"""Config class for instantiating an the class specified in the _target attribute."""
|
||||
|
||||
_target: Type
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2022 The Nerfstudio Team. All rights reserved.
|
||||
# Copyright 2022 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -21,10 +21,7 @@ from __future__ import annotations
|
||||
from dataclasses import field
|
||||
from typing import Any, Dict
|
||||
|
||||
from rich.console import Console
|
||||
|
||||
CONSOLE = Console()
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from nerfstudio.utils.rich_utils import CONSOLE
|
||||
|
||||
|
||||
# cannot use mutable types directly within dataclass; abstracting default factory calls
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
# Copyright 2022 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Aggregate all the dataparser configs in one location.
|
||||
"""
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import tyro
|
||||
|
||||
from nerfstudio.data.dataparsers.arkitscenes_dataparser import (
|
||||
ARKitScenesDataParserConfig,
|
||||
)
|
||||
from nerfstudio.data.dataparsers.base_dataparser import DataParserConfig
|
||||
from nerfstudio.data.dataparsers.blender_dataparser import BlenderDataParserConfig
|
||||
from nerfstudio.data.dataparsers.dnerf_dataparser import DNeRFDataParserConfig
|
||||
from nerfstudio.data.dataparsers.dycheck_dataparser import DycheckDataParserConfig
|
||||
from nerfstudio.data.dataparsers.instant_ngp_dataparser import (
|
||||
InstantNGPDataParserConfig,
|
||||
)
|
||||
from nerfstudio.data.dataparsers.minimal_dataparser import MinimalDataParserConfig
|
||||
from nerfstudio.data.dataparsers.nerfosr_dataparser import NeRFOSRDataParserConfig
|
||||
from nerfstudio.data.dataparsers.nerfstudio_dataparser import NerfstudioDataParserConfig
|
||||
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.sdfstudio_dataparser import SDFStudioDataParserConfig
|
||||
from nerfstudio.data.dataparsers.sitcoms3d_dataparser import Sitcoms3DDataParserConfig
|
||||
from nerfstudio.plugins.registry_dataparser import discover_dataparsers
|
||||
|
||||
dataparsers = {
|
||||
"nerfstudio-data": NerfstudioDataParserConfig(),
|
||||
"minimal-parser": MinimalDataParserConfig(),
|
||||
"arkit-data": ARKitScenesDataParserConfig(),
|
||||
"blender-data": BlenderDataParserConfig(),
|
||||
"instant-ngp-data": InstantNGPDataParserConfig(),
|
||||
"nuscenes-data": NuScenesDataParserConfig(),
|
||||
"dnerf-data": DNeRFDataParserConfig(),
|
||||
"phototourism-data": PhototourismDataParserConfig(),
|
||||
"dycheck-data": DycheckDataParserConfig(),
|
||||
"scannet-data": ScanNetDataParserConfig(),
|
||||
"sdfstudio-data": SDFStudioDataParserConfig(),
|
||||
"nerfosr-data": NeRFOSRDataParserConfig(),
|
||||
"sitcoms3d-data": Sitcoms3DDataParserConfig(),
|
||||
}
|
||||
|
||||
external_dataparsers = discover_dataparsers()
|
||||
all_dataparsers = {**dataparsers, **external_dataparsers}
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# For static analysis (tab completion, type checking, etc), just use the base
|
||||
# dataparser config.
|
||||
DataParserUnion = DataParserConfig
|
||||
else:
|
||||
# At runtime, populate a Union type dynamically. This is used by `tyro` to generate
|
||||
# subcommands in the CLI.
|
||||
DataParserUnion = tyro.extras.subcommand_type_from_defaults(
|
||||
all_dataparsers,
|
||||
prefix_names=False, # Omit prefixes in subcommands themselves.
|
||||
)
|
||||
|
||||
AnnotatedDataParserUnion = tyro.conf.OmitSubcommandPrefixes[DataParserUnion] # Omit prefixes of flags in subcommands.
|
||||
"""Union over possible dataparser types, annotated with metadata for tyro. This is
|
||||
the same as the vanilla union, but results in shorter subcommand names."""
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2022 The Nerfstudio Team. All rights reserved.
|
||||
# Copyright 2022 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,6 @@ from pathlib import Path
|
||||
from typing import Any, Dict, Literal, Optional
|
||||
|
||||
import yaml
|
||||
from rich.console import Console
|
||||
|
||||
from nerfstudio.configs.base_config import (
|
||||
InstantiateConfig,
|
||||
@@ -34,8 +33,7 @@ from nerfstudio.configs.config_utils import to_immutable_dict
|
||||
from nerfstudio.engine.optimizers import OptimizerConfig
|
||||
from nerfstudio.engine.schedulers import SchedulerConfig
|
||||
from nerfstudio.pipelines.base_pipeline import VanillaPipelineConfig
|
||||
|
||||
CONSOLE = Console(width=120)
|
||||
from nerfstudio.utils.rich_utils import CONSOLE
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -70,7 +68,7 @@ class ExperimentConfig(InstantiateConfig):
|
||||
}
|
||||
)
|
||||
"""Dictionary of optimizer groups and their schedulers"""
|
||||
vis: Literal["viewer", "wandb", "tensorboard", "viewer+wandb", "viewer+tensorboard"] = "wandb"
|
||||
vis: Literal["viewer", "wandb", "tensorboard", "viewer+wandb", "viewer+tensorboard", "viewer_beta"] = "wandb"
|
||||
"""Which visualizer to use."""
|
||||
data: Optional[Path] = None
|
||||
"""Alias for --pipeline.datamanager.data"""
|
||||
@@ -83,6 +81,10 @@ class ExperimentConfig(InstantiateConfig):
|
||||
"""Checks if a viewer is enabled."""
|
||||
return ("viewer" == self.vis) | ("viewer+wandb" == self.vis) | ("viewer+tensorboard" == self.vis)
|
||||
|
||||
def is_viewer_beta_enabled(self) -> bool:
|
||||
"""Checks if a viewer beta is enabled."""
|
||||
return "viewer_beta" == self.vis
|
||||
|
||||
def is_wandb_enabled(self) -> bool:
|
||||
"""Checks if wandb is enabled."""
|
||||
return ("wandb" == self.vis) | ("viewer+wandb" == self.vis)
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
# Copyright 2022 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""This file contains the configuration for external methods which are not included in this repository."""
|
||||
import subprocess
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Dict, List, Optional, Tuple, cast
|
||||
|
||||
from rich.prompt import Confirm
|
||||
|
||||
from nerfstudio.engine.trainer import TrainerConfig
|
||||
from nerfstudio.utils.rich_utils import CONSOLE
|
||||
|
||||
|
||||
@dataclass
|
||||
class ExternalMethod:
|
||||
"""External method class. Represents a link to a nerfstudio-compatible method not included in this repository."""
|
||||
|
||||
instructions: str
|
||||
"""Instructions for installing the method. This will be printed to
|
||||
the console when the user tries to use the method."""
|
||||
configurations: List[Tuple[str, str]]
|
||||
"""List of configurations for the method. Each configuration is a tuple of (registered slug, description)
|
||||
as it will be printed in --help."""
|
||||
pip_package: Optional[str] = None
|
||||
"""Specifies a pip package if the method can be installed by running `pip install <pip_package>`."""
|
||||
|
||||
|
||||
external_methods = []
|
||||
|
||||
# Instruct-NeRF2NeRF
|
||||
external_methods.append(
|
||||
ExternalMethod(
|
||||
"""[bold yellow]Instruct-NeRF2NeRF[/bold yellow]
|
||||
For more information visit: https://docs.nerf.studio/en/latest/nerfology/methods/in2n.html
|
||||
|
||||
To enable Instruct-NeRF2NeRF, you must install it first by running:
|
||||
[grey]pip install git+https://github.com/ayaanzhaque/instruct-nerf2nerf[/grey]""",
|
||||
configurations=[
|
||||
("in2n", "Instruct-NeRF2NeRF. Full model, used in paper"),
|
||||
("in2n-small", "Instruct-NeRF2NeRF. Half precision model"),
|
||||
("in2n-tiny", "Instruct-NeRF2NeRF. Half prevision with no LPIPS"),
|
||||
],
|
||||
pip_package="git+https://github.com/ayaanzhaque/instruct-nerf2nerf",
|
||||
)
|
||||
)
|
||||
|
||||
# K-Planes
|
||||
external_methods.append(
|
||||
ExternalMethod(
|
||||
"""[bold yellow]K-Planes[/bold yellow]
|
||||
For more information visit https://docs.nerf.studio/en/latest/nerfology/methods/kplanes.html
|
||||
|
||||
To enable K-Planes, you must install it first by running:
|
||||
[grey]pip install kplanes-nerfstudio[/grey]""",
|
||||
configurations=[
|
||||
("kplanes", "K-Planes model tuned to static blender scenes"),
|
||||
("kplanes-dynamic", "K-Planes model tuned to dynamic DNeRF scenes"),
|
||||
],
|
||||
pip_package="kplanes-nerfstudio",
|
||||
)
|
||||
)
|
||||
|
||||
# LERF
|
||||
external_methods.append(
|
||||
ExternalMethod(
|
||||
"""[bold yellow]LERF[/bold yellow]
|
||||
For more information visit: https://docs.nerf.studio/en/latest/nerfology/methods/lerf.html
|
||||
|
||||
To enable LERF, you must install it first by running:
|
||||
[grey]pip install git+https://github.com/kerrj/lerf[/grey]""",
|
||||
configurations=[
|
||||
("lerf-big", "LERF with OpenCLIP ViT-L/14"),
|
||||
("lerf", "LERF with OpenCLIP ViT-B/16, used in paper"),
|
||||
("lerf-lite", "LERF with smaller network and less LERF samples"),
|
||||
],
|
||||
pip_package="git+https://github.com/kerrj/lerf",
|
||||
)
|
||||
)
|
||||
|
||||
# Tetra-NeRF
|
||||
external_methods.append(
|
||||
ExternalMethod(
|
||||
"""[bold yellow]Tetra-NeRF[/bold yellow]
|
||||
For more information visit: https://docs.nerf.studio/en/latest/nerfology/methods/tetranerf.html
|
||||
|
||||
To enable Tetra-NeRF, you must install it first. Please follow the instructions here:
|
||||
https://github.com/jkulhanek/tetra-nerf/blob/master/README.md#installation""",
|
||||
configurations=[
|
||||
("tetra-nerf-original", "Tetra-NeRF. Official implementation from the paper"),
|
||||
("tetra-nerf", "Tetra-NeRF. Different sampler - faster and better"),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ExternalMethodTrainerConfig(TrainerConfig):
|
||||
"""
|
||||
Trainer config for external methods which does not have an implementation in this repository.
|
||||
"""
|
||||
|
||||
_method: ExternalMethod = field(default=cast(ExternalMethod, None))
|
||||
|
||||
def handle_print_information(self, *_args, **_kwargs):
|
||||
"""Prints the method information and exits."""
|
||||
CONSOLE.print(self._method.instructions)
|
||||
if self._method.pip_package and Confirm.ask(
|
||||
"\nWould you like to run the install it now?", default=False, console=CONSOLE
|
||||
):
|
||||
# Install the method
|
||||
install_command = f"{sys.executable} -m pip install {self._method.pip_package}"
|
||||
CONSOLE.print(f"Running: [cyan]{install_command}[/cyan]")
|
||||
result = subprocess.run(install_command, shell=True, check=False)
|
||||
if result.returncode != 0:
|
||||
CONSOLE.print("[bold red]Error installing method.[/bold red]")
|
||||
sys.exit(1)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
def __getattribute__(self, __name: str) -> Any:
|
||||
out = object.__getattribute__(self, __name)
|
||||
if callable(out) and __name not in {"handle_print_information"} and not __name.startswith("__"):
|
||||
# We exit early, displaying the message
|
||||
return self.handle_print_information
|
||||
return out
|
||||
|
||||
|
||||
def get_external_methods() -> Tuple[Dict[str, TrainerConfig], Dict[str, str]]:
|
||||
"""Returns the external methods trainer configs and the descriptions."""
|
||||
method_configs = {}
|
||||
descriptions = {}
|
||||
for external_method in external_methods:
|
||||
for config_slug, config_description in external_method.configurations:
|
||||
method_configs[config_slug] = ExternalMethodTrainerConfig(method_name=config_slug, _method=external_method)
|
||||
descriptions[config_slug] = f"""[External] {config_description}"""
|
||||
return method_configs, descriptions
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2022 The Nerfstudio Team. All rights reserved.
|
||||
# Copyright 2022 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -18,12 +18,14 @@ Put all the method implementations in one location.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict
|
||||
from typing import Dict
|
||||
|
||||
import tyro
|
||||
|
||||
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,
|
||||
@@ -133,7 +135,8 @@ method_configs["nerfacto-big"] = TrainerConfig(
|
||||
train_num_rays_per_batch=4096,
|
||||
eval_num_rays_per_batch=4096,
|
||||
camera_optimizer=CameraOptimizerConfig(
|
||||
mode="SO3xR3", optimizer=RAdamOptimizerConfig(lr=6e-4, eps=1e-8, weight_decay=1e-3)
|
||||
mode="SO3xR3",
|
||||
optimizer=RAdamOptimizerConfig(lr=6e-4, eps=1e-8, weight_decay=1e-3),
|
||||
),
|
||||
),
|
||||
model=NerfactoModelConfig(
|
||||
@@ -480,7 +483,6 @@ method_configs["dreamfusion"] = TrainerConfig(
|
||||
"proposal_networks": {
|
||||
"optimizer": AdamOptimizerConfig(lr=1e-2, eps=1e-15),
|
||||
"scheduler": ExponentialDecaySchedulerConfig(lr_final=0.0001, max_steps=200000),
|
||||
"scheduler": None,
|
||||
},
|
||||
"fields": {
|
||||
"optimizer": AdamOptimizerConfig(lr=1e-3, eps=1e-15),
|
||||
@@ -493,6 +495,38 @@ method_configs["dreamfusion"] = TrainerConfig(
|
||||
vis="viewer",
|
||||
)
|
||||
|
||||
method_configs["nerfplayer-nerfacto"] = TrainerConfig(
|
||||
method_name="nerfplayer-nerfacto",
|
||||
steps_per_eval_batch=500,
|
||||
steps_per_save=2000,
|
||||
max_num_iterations=30000,
|
||||
mixed_precision=True,
|
||||
pipeline=VanillaPipelineConfig(
|
||||
datamanager=VanillaDataManagerConfig(
|
||||
_target=VanillaDataManager[DepthDataset],
|
||||
dataparser=DycheckDataParserConfig(),
|
||||
train_num_rays_per_batch=4096,
|
||||
eval_num_rays_per_batch=4096,
|
||||
camera_optimizer=CameraOptimizerConfig(
|
||||
mode="SO3xR3", optimizer=AdamOptimizerConfig(lr=6e-4, eps=1e-8, weight_decay=1e-2)
|
||||
),
|
||||
),
|
||||
model=NerfplayerNerfactoModelConfig(eval_num_rays_per_chunk=1 << 15),
|
||||
),
|
||||
optimizers={
|
||||
"proposal_networks": {
|
||||
"optimizer": AdamOptimizerConfig(lr=1e-2, eps=1e-15),
|
||||
"scheduler": None,
|
||||
},
|
||||
"fields": {
|
||||
"optimizer": AdamOptimizerConfig(lr=1e-2, eps=1e-15),
|
||||
"scheduler": None,
|
||||
},
|
||||
},
|
||||
viewer=ViewerConfig(num_rays_per_chunk=1 << 15),
|
||||
vis="viewer",
|
||||
)
|
||||
|
||||
method_configs["nerfplayer-ngp"] = TrainerConfig(
|
||||
method_name="nerfplayer-ngp",
|
||||
steps_per_eval_batch=500,
|
||||
@@ -577,7 +611,7 @@ method_configs["neus-facto"] = TrainerConfig(
|
||||
),
|
||||
),
|
||||
model=NeuSFactoModelConfig(
|
||||
# proposal network allows for signifanctly smaller sdf/color network
|
||||
# proposal network allows for significantly smaller sdf/color network
|
||||
sdf_field=SDFFieldConfig(
|
||||
use_grid_feature=True,
|
||||
num_layers=2,
|
||||
@@ -609,9 +643,42 @@ method_configs["neus-facto"] = TrainerConfig(
|
||||
vis="viewer",
|
||||
)
|
||||
|
||||
external_methods, external_descriptions = discover_methods()
|
||||
all_methods = {**method_configs, **external_methods}
|
||||
all_descriptions = {**descriptions, **external_descriptions}
|
||||
|
||||
def merge_methods(methods, method_descriptions, new_methods, new_descriptions, overwrite=True):
|
||||
"""Merge new methods and descriptions into existing methods and descriptions.
|
||||
Args:
|
||||
methods: Existing methods.
|
||||
method_descriptions: Existing descriptions.
|
||||
new_methods: New methods to merge in.
|
||||
new_descriptions: New descriptions to merge in.
|
||||
Returns:
|
||||
Merged methods and descriptions.
|
||||
"""
|
||||
methods = OrderedDict(**methods)
|
||||
method_descriptions = OrderedDict(**method_descriptions)
|
||||
for k, v in new_methods.items():
|
||||
if overwrite or k not in methods:
|
||||
methods[k] = v
|
||||
method_descriptions[k] = new_descriptions.get(k, "")
|
||||
return methods, method_descriptions
|
||||
|
||||
|
||||
def sort_methods(methods, method_descriptions):
|
||||
"""Sort methods and descriptions by method name."""
|
||||
methods = OrderedDict(sorted(methods.items(), key=lambda x: x[0]))
|
||||
method_descriptions = OrderedDict(sorted(method_descriptions.items(), key=lambda x: x[0]))
|
||||
return methods, method_descriptions
|
||||
|
||||
|
||||
all_methods, all_descriptions = method_configs, descriptions
|
||||
# Add discovered external methods
|
||||
all_methods, all_descriptions = merge_methods(all_methods, all_descriptions, *discover_methods())
|
||||
all_methods, all_descriptions = sort_methods(all_methods, all_descriptions)
|
||||
|
||||
# Register all possible external methods which can be installed with Nerfstudio
|
||||
all_methods, all_descriptions = merge_methods(
|
||||
all_methods, all_descriptions, *sort_methods(*get_external_methods()), overwrite=False
|
||||
)
|
||||
|
||||
AnnotatedBaseConfigUnion = tyro.conf.SuppressFixed[ # Don't show unparseable (fixed) arguments in helptext.
|
||||
tyro.conf.FlagConversionOff[
|
||||
|
||||
Reference in new issue
Block a user