From 05d264a335a351d2f4f2e6ed936687417cc35c47 Mon Sep 17 00:00:00 2001 From: Brent Yi Date: Thu, 6 Oct 2022 13:33:42 -0700 Subject: [PATCH] Reduced `tyro` overhead + helptext formatting (#719) * `ns-train` helptext formatting for tyro 0.3.23 * Remove unused import --- docs/quickstart/first_nerf.md | 14 +++++----- nerfstudio/configs/method_configs.py | 10 +++----- pyproject.toml | 2 +- scripts/train.py | 38 +++++++++++++++++++++++++--- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/docs/quickstart/first_nerf.md b/docs/quickstart/first_nerf.md index a434899f4..cbf09d0b6 100644 --- a/docs/quickstart/first_nerf.md +++ b/docs/quickstart/first_nerf.md @@ -61,9 +61,9 @@ ns-train nerfacto --vis viewer --data data/nerfstudio/poster --viewer.websocket- ::: ## Intro to nerfstudio CLI and Configs -Nerfstudio allows for customizing your training runs, eval runs, configs from the CLI in a powerful way, but there are some things to understand. +Nerfstudio allows customization of training and eval configs from the CLI in a powerful way, but there are some things to understand. -The most demonstrative and helpful example of this in action is the difference in output between the following commands: +The most demonstrative and helpful example of the CLI structure is the difference in output between the following commands: ```bash ns-train -h ``` @@ -76,13 +76,13 @@ ns-train nerfacto nerfstudio-data -h In each of these examples, the -h applies to the previous subcommand (`ns-train`, `nerfacto`, and `nerfstudio-data`). -In the first example, this shows us the help menu for the `ns-train` script. +In the first example, we get the help menu for the `ns-train` script. -In the second examples, we will get the help menu for the `nerfacto` model. +In the second example, we get the help menu for the `nerfacto` model. -In the third examples, we will get the help menu for the `nerfstudio-data` dataparser. +In the third example, we get the help menu for the `nerfstudio-data` dataparser. -With our scripts, your arguments will apply to the previous subcommand in your command, and thus where you put your arguments matters! Any optional arguments you discover while doing +With our scripts, your arguments will apply to the preceding subcommand in your command, and thus where you put your arguments matters! Any optional arguments you discover from running ```bash ns-train nerfacto -h nerfstudio-data ``` @@ -133,4 +133,4 @@ Calculate the psnr of your trained model and save to a json file. ns-eval --load-config={PATH_TO_CONFIG} --output-path=output.json ``` -We also provide a train and evaluation script that allows you to do benchmarking on the classical Blender dataset (see our [benchmarking workflow](../developer_guides/debugging_tools/benchmarking.md)). \ No newline at end of file +We also provide a train and evaluation script that allows you to do benchmarking on the classical Blender dataset (see our [benchmarking workflow](../developer_guides/debugging_tools/benchmarking.md)). diff --git a/nerfstudio/configs/method_configs.py b/nerfstudio/configs/method_configs.py index a51706b76..003f959e7 100644 --- a/nerfstudio/configs/method_configs.py +++ b/nerfstudio/configs/method_configs.py @@ -23,7 +23,6 @@ from typing import Dict import tyro from nerfstudio.configs.base_config import Config, TrainerConfig, ViewerConfig -from nerfstudio.configs.config_utils import convert_markup_to_ansi from nerfstudio.data.datamanagers import VanillaDataManagerConfig from nerfstudio.data.dataparsers.blender_dataparser import BlenderDataParserConfig from nerfstudio.data.dataparsers.friends_dataparser import FriendsDataParserConfig @@ -40,15 +39,12 @@ from nerfstudio.pipelines.dynamic_batch import DynamicBatchPipelineConfig method_configs: Dict[str, Config] = {} descriptions = { - "nerfacto": "[bold green]Recommended[/bold green] Real-time model tuned for real captures. " - + "This model will be continually updated.", + "nerfacto": "Recommended real-time model tuned for real captures. This model will be continually updated.", "instant-ngp": "Implementation of Instant-NGP. Recommended real-time model for bounded synthetic data.", - "mipnerf": "High quality model for bounded scenes. [red]*slow*", + "mipnerf": "High quality model for bounded scenes. (slow)", "semantic-nerfw": "Predicts semantic segmentations and filters out transient objects.", - "vanilla-nerf": "Original NeRF model. [red]*slow*", + "vanilla-nerf": "Original NeRF model. (slow)", } -descriptions = {k: convert_markup_to_ansi(v) for k, v in descriptions.items()} - method_configs["nerfacto"] = Config( method_name="nerfacto", diff --git a/pyproject.toml b/pyproject.toml index c5defe634..9bfb7c6d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "aiortc==1.3.2", "appdirs>=1.4", "av==9.2.0", - "tyro>=0.3.22", + "tyro>=0.3.23", "gdown==4.5.1", "ninja==1.10.2.3", "functorch==0.2.1", diff --git a/scripts/train.py b/scripts/train.py index 48a223f0b..47afd26b1 100755 --- a/scripts/train.py +++ b/scripts/train.py @@ -1,6 +1,32 @@ #!/usr/bin/env python -""" -train.py +"""Train a radiance field with nerfstudio. +For real captures, we recommend using the [bright_yellow]nerfacto[/bright_yellow] model. + +Nerfstudio allows for customizing your training and eval configs from the CLI in a powerful way, but there are some +things to understand. + +The most demonstrative and helpful example of the CLI structure is the difference in output between the following +commands: + + ns-train -h + ns-train nerfacto -h nerfstudio-data + ns-train nerfacto nerfstudio-data -h + +In each of these examples, the -h applies to the previous subcommand (ns-train, nerfacto, and nerfstudio-data). + +In the first example, we get the help menu for the ns-train script. +In the second example, we get the help menu for the nerfacto model. +In the third example, we get the help menu for the nerfstudio-data dataparser. + +With our scripts, your arguments will apply to the preceding subcommand in your command, and thus where you put your +arguments matters! Any optional arguments you discover from running + + ns-train nerfacto -h nerfstudio-data + +need to come directly after the nerfacto subcommand, since these optional arguments only belong to the nerfacto +subcommand: + + ns-train nerfacto {nerfacto optional args} nerfstudio-data """ from __future__ import annotations @@ -20,6 +46,7 @@ import tyro import yaml from nerfstudio.configs import base_config as cfg +from nerfstudio.configs.config_utils import convert_markup_to_ansi from nerfstudio.configs.method_configs import AnnotatedBaseConfigUnion from nerfstudio.engine.trainer import train_loop from nerfstudio.utils import comms, profiler @@ -213,7 +240,12 @@ def entrypoint(): """Entrypoint for use with pyproject scripts.""" # Choose a base configuration and override values. tyro.extras.set_accent_color("bright_yellow") - main(tyro.cli(AnnotatedBaseConfigUnion)) + main( + tyro.cli( + AnnotatedBaseConfigUnion, + description=convert_markup_to_ansi(__doc__), + ) + ) if __name__ == "__main__":