mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 13:59:10 +08:00
+5








ddedb920dc
* Adds Gaussian Splatting integration --------- Co-authored-by: Jake Austin jake-austin@berkeley.edu <jake-austin@berkeley.edu> Co-authored-by: Brent Yi <yibrenth@gmail.com> Co-authored-by: Zhuoyang <zhuoyangpan@outlook.com> Co-authored-by: Vickie Ye <vye1116@gmail.com> Co-authored-by: adamrashid96 <abrashid@berkeley.edu> Co-authored-by: Paul Wais <paulwais@gmail.com> Co-authored-by: Gina Wu <ginawu98@gmail.com> Co-authored-by: Alexander Kristoffersen <akristoffersen@berkeley.edu> Co-authored-by: machenmusik <machenmusik@users.noreply.github.com> Co-authored-by: Riley <cardiacmangoes@gmail.com> Co-authored-by: Gina Wu <42229107+ginazhouhuiwu@users.noreply.github.com> Co-authored-by: maturk <matiasturkulainen@gmail.com> Co-authored-by: Guangyun-Xu <38279883+Guangyun-Xu@users.noreply.github.com> Co-authored-by: Zhuoyang Pan <102644383+Zhuoyang-Pan@users.noreply.github.com>
141 lines
4.8 KiB
Python
141 lines
4.8 KiB
Python
# 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.
|
|
|
|
#!/usr/bin/env python
|
|
"""
|
|
Starts viewer in eval mode.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from dataclasses import dataclass, field, fields
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
import tyro
|
|
|
|
from nerfstudio.configs.base_config import ViewerConfig
|
|
from nerfstudio.engine.trainer import TrainerConfig
|
|
from nerfstudio.pipelines.base_pipeline import Pipeline
|
|
from nerfstudio.utils import writer
|
|
from nerfstudio.utils.eval_utils import eval_setup
|
|
from nerfstudio.viewer.server.viewer_state import ViewerState
|
|
from nerfstudio.viewer_beta.viewer import Viewer as ViewerBetaState
|
|
|
|
|
|
@dataclass
|
|
class ViewerConfigWithoutNumRays(ViewerConfig):
|
|
"""Configuration for viewer instantiation"""
|
|
|
|
num_rays_per_chunk: tyro.conf.Suppress[int] = -1
|
|
|
|
def as_viewer_config(self):
|
|
"""Converts the instance to ViewerConfig"""
|
|
return ViewerConfig(**{x.name: getattr(self, x.name) for x in fields(self)})
|
|
|
|
|
|
@dataclass
|
|
class RunViewer:
|
|
"""Load a checkpoint and start the viewer."""
|
|
|
|
load_config: Path
|
|
"""Path to config YAML file."""
|
|
viewer: ViewerConfigWithoutNumRays = field(default_factory=ViewerConfigWithoutNumRays)
|
|
"""Viewer configuration"""
|
|
vis: Literal["viewer", "viewer_beta"] = "viewer"
|
|
"""Type of viewer"""
|
|
make_share_url: bool = False
|
|
"""Viewer beta feature: print a shareable URL. `vis` must be set to viewer_beta; this flag is otherwise ignored."""
|
|
|
|
def main(self) -> None:
|
|
"""Main function."""
|
|
config, pipeline, _, step = eval_setup(
|
|
self.load_config,
|
|
eval_num_rays_per_chunk=None,
|
|
test_mode="test",
|
|
)
|
|
num_rays_per_chunk = config.viewer.num_rays_per_chunk
|
|
assert self.viewer.num_rays_per_chunk == -1
|
|
config.vis = self.vis
|
|
config.viewer.make_share_url = self.make_share_url
|
|
config.viewer = self.viewer.as_viewer_config()
|
|
config.viewer.num_rays_per_chunk = num_rays_per_chunk
|
|
|
|
_start_viewer(config, pipeline, step)
|
|
|
|
def save_checkpoint(self, *args, **kwargs):
|
|
"""
|
|
Mock method because we pass this instance to viewer_state.update_scene
|
|
"""
|
|
|
|
|
|
def _start_viewer(config: TrainerConfig, pipeline: Pipeline, step: int):
|
|
"""Starts the viewer
|
|
|
|
Args:
|
|
config: Configuration of pipeline to load
|
|
pipeline: Pipeline instance of which to load weights
|
|
step: Step at which the pipeline was saved
|
|
"""
|
|
base_dir = config.get_base_dir()
|
|
viewer_log_path = base_dir / config.viewer.relative_log_filename
|
|
banner_messages = None
|
|
viewer_state = None
|
|
if config.vis == "viewer":
|
|
viewer_state = ViewerState(
|
|
config.viewer,
|
|
log_filename=viewer_log_path,
|
|
datapath=pipeline.datamanager.get_datapath(),
|
|
pipeline=pipeline,
|
|
)
|
|
banner_messages = [f"Viewer at: {viewer_state.viewer_url}"]
|
|
if config.vis == "viewer_beta":
|
|
viewer_state = ViewerBetaState(
|
|
config.viewer,
|
|
log_filename=viewer_log_path,
|
|
datapath=pipeline.datamanager.get_datapath(),
|
|
pipeline=pipeline,
|
|
share=config.viewer.make_share_url,
|
|
)
|
|
banner_messages = [f"Viewer Beta at: {viewer_state.viewer_url}"]
|
|
|
|
# We don't need logging, but writer.GLOBAL_BUFFER needs to be populated
|
|
config.logging.local_writer.enable = False
|
|
writer.setup_local_writer(config.logging, max_iter=config.max_num_iterations, banner_messages=banner_messages)
|
|
|
|
assert viewer_state and pipeline.datamanager.train_dataset
|
|
viewer_state.init_scene(
|
|
train_dataset=pipeline.datamanager.train_dataset,
|
|
train_state="completed",
|
|
eval_dataset=pipeline.datamanager.eval_dataset,
|
|
)
|
|
if isinstance(viewer_state, ViewerState):
|
|
viewer_state.viser_server.set_training_state("completed")
|
|
viewer_state.update_scene(step=step)
|
|
while True:
|
|
time.sleep(0.01)
|
|
|
|
|
|
def entrypoint():
|
|
"""Entrypoint for use with pyproject scripts."""
|
|
tyro.extras.set_accent_color("bright_yellow")
|
|
tyro.cli(tyro.conf.FlagConversionOff[RunViewer]).main()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
entrypoint()
|
|
|
|
# For sphinx docs
|
|
get_parser_fn = lambda: tyro.extras.get_parser(tyro.conf.FlagConversionOff[RunViewer]) # noqa
|