mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-21 15:15:43 +08:00
1 parent
5a76b955cd
commit
d7c34ca2bd
68 files changed
+87
-148
No files matched your search
@@ -0,0 +1,352 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"# Creating Custom Methods\n",
|
||||
"\n",
|
||||
"> Our goal is to enable nerfstudio users to implement an entire NeRF method by only editing one file.\n",
|
||||
"\n",
|
||||
"Here we explain how to create custom pipelines with nerfstudio. Pipelines are composed of two components, namely a DataManager and a Model. The pipeline is responsible for routing RayBundle instances returned from the DataManager into the Model.\n",
|
||||
"\n",
|
||||
"A NeRF method is implemented as a Pipeline. Users can create a Pipeline with a DataManager and Model. We provide default implementations for these components prefixed with the name Vanilla (e.g., `VanillaPipeline`, `VanillaDataManager` which inherit from the `Pipeline` and `DataManager` class, respectively) and specific Models (e.g., `InstantNGPModel` or `TensoRFModel` which inherit from the `Model` class). With most NeRF methods, `VanillaPipeline` and `VanillaDataManager` can be used and only the model needs to be changed. We provide many already implmented Models for people to get started with 3D reconstruction. However, in this tutorial we will demonstrate how to customize each of the Pipeline, DataManager, and Model with an example.\n",
|
||||
"\n",
|
||||
"We'll show how to make an incremental DataManager where we progressively add cameras to train with from multiple scenes and importance sample rays from pixels with a high loss. The extensible features that we show in this tutorial are the following:\n",
|
||||
"- a DataManager that incrementally adds cameras\n",
|
||||
"- a DataManager that uses multiple scenes\n",
|
||||
"- a Model that is conditioned on the scene\n",
|
||||
"- a Pipeline that modifies the DataManager's PixelSampler to sample more rays in regions with high loss"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"#### Model Components\n",
|
||||
"\n",
|
||||
"> The model renders values from 3D line segments defined by a RayBundle.\n",
|
||||
"\n",
|
||||
"We provide Models and Model Components (i.e., Fields and Field Modules) which can be strung together to create a custom model.\n",
|
||||
"\n",
|
||||
"<details closed>\n",
|
||||
"<summary>Models</summary>\n",
|
||||
"<br>\n",
|
||||
"<li>Vanilla NeRF Model</li>\n",
|
||||
"<li>Mip NeRF Model</li>\n",
|
||||
"<li>Mip NeRF 360 Model</li>\n",
|
||||
"<li>Instant NGP Model</li>\n",
|
||||
"<li>NeRF-W Model</li>\n",
|
||||
"<li>Semantic NeRF Model</li>\n",
|
||||
"</details>\n",
|
||||
"\n",
|
||||
"<br>\n",
|
||||
"\n",
|
||||
"<details closed>\n",
|
||||
"<summary>Model Components</summary>\n",
|
||||
"<br>\n",
|
||||
"Fields:\n",
|
||||
"<li>Vanilla NeRF Field</li>\n",
|
||||
"<li>Instant NGP Field</li>\n",
|
||||
"<br>\n",
|
||||
"Field Modules:\n",
|
||||
"<li>Encodings</li>\n",
|
||||
"<li>Embeddings</li>\n",
|
||||
"<li>Field Heads</li>\n",
|
||||
"<li>Field Losses</li>\n",
|
||||
"<li>MLP</li>\n",
|
||||
"<li>Spatial Distortions</li>\n",
|
||||
"</details>\n",
|
||||
"\n",
|
||||
"#### DataManager Components\n",
|
||||
"\n",
|
||||
"> The DataManager provides a RayBundle (3D line segments with metadata needed to run the forward pass) and a dictionary of information needed at train-time to supervise the pipeline components.\n",
|
||||
"\n",
|
||||
"Similar to the Model components, we provide DataManager components that are strung together to generate RayBundle instances. A RayBundle contains everything needed to generate a ray (e.g., origin and direction, near and far planes) as well as any additional metadata that the Model requires (e.g., camera index, scene index, etc.).\n",
|
||||
"\n",
|
||||
"<details closed>\n",
|
||||
"<summary>DataManager Components</summary>\n",
|
||||
"<br>\n",
|
||||
"Datasets Parsers:<br>\n",
|
||||
" <em style=\"padding-left:2em\">Takes a data location and returns a DatsetInputs instance. A DatsetInputs will contain all data needed throughout the pipeline.</em>\n",
|
||||
"<li>Vanilla Image DataParser</li>\n",
|
||||
"<br>\n",
|
||||
"Image Datasets:<br>\n",
|
||||
" <em style=\"padding-left:2em\">Takes image filename information and can return images.</em>\n",
|
||||
"<li>Vanilla Image Dataset</li>\n",
|
||||
"<br>\n",
|
||||
"Image Dataloader:<br>\n",
|
||||
" <em style=\"padding-left:2em\">Takes an Image Dataset and samples images from it.</em>\n",
|
||||
"<li>Vanilla Image Dataloader</li>\n",
|
||||
"<li>Cache Image Dataloader</li>\n",
|
||||
"<br>\n",
|
||||
"Pixel Samplers:<br>\n",
|
||||
" <em style=\"padding-left:2em\">Takes sampled images and returns pixel locations.</em>\n",
|
||||
"<li>Vanilla Pixel Sampler</li>\n",
|
||||
"<br>\n",
|
||||
"Ray Generators:<br>\n",
|
||||
" <em style=\"padding-left:2em\">Takes cameras and pixel locations and returns RayBundle objects.</em>\n",
|
||||
"<br>\n",
|
||||
"\n",
|
||||
"Colliders:<br>\n",
|
||||
" <em style=\"padding-left:2em\">Takes RayBundles and clips them according .</em>\n",
|
||||
"</details>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"tags": [
|
||||
"hide-input"
|
||||
]
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# COLLAPSED\n",
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2\n",
|
||||
"\n",
|
||||
"from __future__ import annotations\n",
|
||||
"\n",
|
||||
"from typing import Dict, Optional, Tuple, List\n",
|
||||
"import torch\n",
|
||||
"\n",
|
||||
"from nerfstudio.utils.config import DataManagerConfig, ModelConfig, PipelineConfig, ViewerConfig\n",
|
||||
"from nerfstudio.data.base import DataManager\n",
|
||||
"from nerfstudio.data.structs import DatasetInputs\n",
|
||||
"from nerfstudio.models.base import Model\n",
|
||||
"from nerfstudio.pipelines.base_pipeline import Pipeline\n",
|
||||
"from nerfstudio.models.instant_ngp import NGPModel\n",
|
||||
"from nerfstudio.cameras.rays import RayBundle"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class CustomDataManagerConfig(DataManagerConfig):\n",
|
||||
" _target = \"CustomDataManager\"\n",
|
||||
" scene_names: List[str] = [\"chair\", \"drums\", \"fern\", \"lego\"]\n",
|
||||
" steps_per_add_cameras: int = 100 # every X iterations, add more cameras\n",
|
||||
" num_cameras_per_add: int = 10 # number of cameras to add\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class CustomDataManager(DataManager):\n",
|
||||
" \"\"\"A custom dataloader that incrementally adds cameras and has multiple scenes.\"\"\"\n",
|
||||
"\n",
|
||||
" config: CustomDataManagerConfig\n",
|
||||
"\n",
|
||||
" def populate_train_modules(self):\n",
|
||||
" \"\"\"Populate the train dataloader modules.\"\"\"\n",
|
||||
" self.scene_name_to_image_sampler = {}\n",
|
||||
" self.scene_name_to_collider = {} # TODO(ethan): move colliders to the dataloader\n",
|
||||
" for scene_name in self.config.scene_names:\n",
|
||||
" dataset_inputs: DatasetInputs = None # TODO\n",
|
||||
" image_dataset = ImageDataset(dataset_inputs)\n",
|
||||
" image_sampler = CacheImageDataloader(image_dataset=image_dataset) # a torch dataloader\n",
|
||||
" self.scene_name_to_image_sampler[scene_name] = image_sampler\n",
|
||||
" self.train_pixel_sampler = PixelSampler\n",
|
||||
" self.train_ray_generator = RayGenerator # nn.Module\n",
|
||||
"\n",
|
||||
" def populate_eval_modules(self):\n",
|
||||
" \"\"\"Populate the eval dataloader modules.\"\"\"\n",
|
||||
" # we'll mostly rely on the train dataloader modules\n",
|
||||
" self.eval_pixel_sampler = EvalPixelSampler # this will sample entire images\n",
|
||||
"\n",
|
||||
" def sample_images(self) -> List[Image]:\n",
|
||||
" images = []\n",
|
||||
" for scene_name in self.scene_name_to_image_sampler.keys():\n",
|
||||
" image_sampler = self.scene_name_to_image_sampler[scene_name]\n",
|
||||
" x = image_sampler.forward() # note that empty forward calls next()\n",
|
||||
" images.append(x)\n",
|
||||
" return images\n",
|
||||
"\n",
|
||||
" def next_train(self, step: int) -> Tuple[RayBundle, Dict]:\n",
|
||||
" \"\"\"Get the next batch of training data by stringing together the train modules.\"\"\"\n",
|
||||
" # grab some images from each scene\n",
|
||||
" images = self.sample_images()\n",
|
||||
" pixels = self.train_pixel_sampler.forward(images)\n",
|
||||
" ray_bundle = self.train_ray_generator(pixels)\n",
|
||||
" # shape should be (H, W, :)\n",
|
||||
" ray_bundle.metadata[\"scene_indices\"] = None # TODO(ethan): populate this with a tensor of scene indices\n",
|
||||
" dict_ = {}\n",
|
||||
" return ray_bundle, dict_\n",
|
||||
"\n",
|
||||
" def next_eval(self, step: int) -> Tuple[RayBundle, Dict]:\n",
|
||||
" \"\"\"Get the next batch of eval data by stringing together the eval modules.\"\"\"\n",
|
||||
" # grab some images from each scene\n",
|
||||
" images = self.sample_images()\n",
|
||||
" pixels = self.train_pixel_sampler.forward(images)\n",
|
||||
" ray_bundle = self.eval_ray_generator(pixels) # notice this is eval and not train\n",
|
||||
" # shape should be (H, W, :)\n",
|
||||
" ray_bundle.metadata[\"scene_indices\"] = None # TODO(ethan): populate this with a tensor of scene indices\n",
|
||||
" dict_ = {}\n",
|
||||
" return ray_bundle, dict_\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class CustomNGPModelConfig(ModelConfig):\n",
|
||||
" _target = \"CustomNGPModel\"\n",
|
||||
" coarse_field: str = \"temp\"\n",
|
||||
" fine_field: str = \"temp2\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class CustomNGPModel(Model):\n",
|
||||
" \"\"\"An instant ngp model modified slightly to output semantics.\"\"\"\n",
|
||||
"\n",
|
||||
" config: SceneConditionNGPModelConfig\n",
|
||||
"\n",
|
||||
" def populate_modules(self):\n",
|
||||
" self.ngp_model = NGPModel(coarse_field=self.config.coarse_field, fine_field=self.config.fine_field)\n",
|
||||
"\n",
|
||||
" def get_outputs(self, ray_bundle: RayBundle) -> Dict[str, torch.Tensor]:\n",
|
||||
" # TODO(ethan): pass in batch from the forward function\n",
|
||||
" # TODO(ethan): rename batch to something else\n",
|
||||
" outputs = self.ngp_model.forward(ray_bundle)\n",
|
||||
" outputs[\"semantics\"] = torch.rand_like(outputs[\"rgb\"])\n",
|
||||
" return outputs\n",
|
||||
"\n",
|
||||
" def get_loss_dict(self):\n",
|
||||
" return {}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class CustomPipeline(Pipeline):\n",
|
||||
" \"\"\"The Instant NGP pipeline.\"\"\"\n",
|
||||
"\n",
|
||||
" config: PipelineConfig\n",
|
||||
"\n",
|
||||
" def train_step(self, step: int):\n",
|
||||
" ray_bundle, batch = self.dataloader.next_train(step=step)\n",
|
||||
" # TODO: maybe run a CNN on the data before passing into model\n",
|
||||
" model_outputs, loss_dict, metrics_dict = self.model(ray_bundle, batch)\n",
|
||||
" # TODO: update pixel sampler state with loss map to show the flexibilty of our Pipeline\n",
|
||||
" self.dataloader.pixel_sampler.update_loss_map()\n",
|
||||
" return model_outputs, loss_dict, metrics_dict\n",
|
||||
"\n",
|
||||
" def eval_step(self):\n",
|
||||
" ray_bundle, batch = self.dataloader.next_eval(step=step)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dataloader = DataManager()\n",
|
||||
"model = SceneConditionNGPModel()\n",
|
||||
"pipeline = CustomPipeline.from_dataloader_and_model(dataloader=dataloader, model=model)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"Now we show how to create a pipeline from a config, which has the following form:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"@dataclass\n",
|
||||
"class PipelineConfig:\n",
|
||||
" \"\"\"Configuration for pipeline instantiation\"\"\"\n",
|
||||
"\n",
|
||||
" _target: ClassVar[Type] = Pipeline\n",
|
||||
" dataloader: DataloaderConfig = MISSING\n",
|
||||
" model: ModelConfig = MISSING\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"See `nerfstudio/utils/config.py` for more details. In this example, we will simply load from an existing configuration from `configs/graph_instant_ngp.yaml`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pprint\n",
|
||||
"import hydra\n",
|
||||
"\n",
|
||||
"hydra.core.global_hydra.GlobalHydra.instance().clear()\n",
|
||||
"from hydra import compose, initialize\n",
|
||||
"\n",
|
||||
"initialize(version_base=\"1.2\", config_path=\"../configs/\")\n",
|
||||
"config_name = \"graph_instant_ngp.yaml\"\n",
|
||||
"config = compose(config_name)\n",
|
||||
"pipeline_config = config.pipeline\n",
|
||||
"pprint.pprint(pipeline_config)\n",
|
||||
"print(\"----------------------------------------------------\")\n",
|
||||
"\n",
|
||||
"# from nerfstudio.pipelines.base_pipeline import setup_pipeline\n",
|
||||
"# pipeline = setup_pipeline(pipeline_config, device=\"cuda\")\n",
|
||||
"pipeline = pipeline_config.setup()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"pipeline.get_train_loss_dict()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.13 ('nerfactory')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.13"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "b7b86c17c0dfd6b313529972d424f2e075cc198a46cda005757126afe8133c7b"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# DataManagers\n",
|
||||
"\n",
|
||||
"```{image} imgs/datamanagers.png\n",
|
||||
":align: center\n",
|
||||
"```"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.13 ('nerfactory')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.8.13"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "b7b86c17c0dfd6b313529972d424f2e075cc198a46cda005757126afe8133c7b"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# DataParsers\n",
|
||||
"\n",
|
||||
"```{image} imgs/dataparsers.png\n",
|
||||
":align: center\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## What is a DataParser?\n",
|
||||
"\n",
|
||||
"The dataparser returns `DataparserOutputs`, which puts all the various datasets into a common format.\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"@dataclass\n",
|
||||
"class DataparserOutputs:\n",
|
||||
" \"\"\"Dataparser outputs for the image dataset and the ray generator.\"\"\"\n",
|
||||
"\n",
|
||||
" image_filenames: List[Path]\n",
|
||||
" \"\"\"Filenames for the images.\"\"\"\n",
|
||||
" cameras: Cameras\n",
|
||||
" \"\"\"Camera object storing collection of camera information in dataset\"\"\"\n",
|
||||
" alpha_color: Optional[TensorType[3]] = None\n",
|
||||
" \"\"\"color of dataset background\"\"\"\n",
|
||||
" scene_box: SceneBox = SceneBox()\n",
|
||||
" \"\"\"scene box of dataset. Could be used to bound the scene, or to provide the scene scale depending on model.\"\"\"\n",
|
||||
" ...\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class DataParser:\n",
|
||||
"\n",
|
||||
" @abstractmethod\n",
|
||||
" def _generate_datapaser_outputs(self, split: str = \"train\") -> DataparserOutputs:\n",
|
||||
" \"\"\"Abstract method that returns the dataparser outputs for the given split.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" split: Which dataset split to generate data for (train/eval/test).\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" DataparserOutputs for the specified dataset and split.\n",
|
||||
" \"\"\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Example\n",
|
||||
"\n",
|
||||
"Here is an example where we implement a DataParser for our Nerfstudio data format.\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"@dataclass\n",
|
||||
"class NerfstudioDataParserConfig(DataParserConfig):\n",
|
||||
" \"\"\"Nerfstudio dataset config\"\"\"\n",
|
||||
"\n",
|
||||
" _target: Type = field(default_factory=lambda: Nerfstudio)\n",
|
||||
" \"\"\"Target class to instantiate.\"\"\"\n",
|
||||
" data_directory: Path = Path(\"data/nerfstudio/poster\")\n",
|
||||
" \"\"\"Directory specifying location of data.\"\"\"\n",
|
||||
" scale_factor: float = 1.0\n",
|
||||
" \"\"\"How much to scale the camera origins by.\"\"\"\n",
|
||||
" downscale_factor: int = 1\n",
|
||||
" \"\"\"How much to downscale images.\"\"\"\n",
|
||||
" scene_scale: float = 1.0\n",
|
||||
" \"\"\"How much to scale the region of interest by.\"\"\"\n",
|
||||
" orientation_method: Literal[\"pca\", \"up\"] = \"up\"\n",
|
||||
" \"\"\"The method to use for orientation.\"\"\"\n",
|
||||
" train_split_percentage: float = 0.9\n",
|
||||
" \"\"\"The percent of images to use for training. The remaining images are for eval.\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class Nerfstudio(DataParser):\n",
|
||||
" \"\"\"Nerfstudio Dataset\"\"\"\n",
|
||||
"\n",
|
||||
" config: NerfstudioDataParserConfig\n",
|
||||
"\n",
|
||||
" def _generate_datapaser_outputs(self, split=\"train\") -> DataParserOutputs:\n",
|
||||
" \"\"\"Returns DataParserOutputs.\"\"\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Our Implementations\n",
|
||||
"\n",
|
||||
"###### Nerfstudio\n",
|
||||
"\n",
|
||||
"This is our custom dataparser.\n",
|
||||
"\n",
|
||||
"```{button-link} https://github.com/nerfstudio-project/nerfstudio/blob/master/nerfstudio/data/dataparsers/nerfstudio_dataparser.py\n",
|
||||
":color: primary\n",
|
||||
":outline:\n",
|
||||
"See the code!\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"###### Blender\n",
|
||||
"\n",
|
||||
"We support the synthetic Blender dataset from the original NeRF paper.\n",
|
||||
"\n",
|
||||
"```{button-link} https://github.com/nerfstudio-project/nerfstudio/blob/master/nerfstudio/data/dataparsers/blender_dataparser.py\n",
|
||||
":color: primary\n",
|
||||
":outline:\n",
|
||||
"See the code!\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"###### Instant NGP\n",
|
||||
"\n",
|
||||
"This supports the Instant NGP dataset.\n",
|
||||
"\n",
|
||||
"```{button-link} https://github.com/nerfstudio-project/nerfstudio/blob/master/nerfstudio/data/dataparsers/instant_ngp_dataparser.py\n",
|
||||
":color: primary\n",
|
||||
":outline:\n",
|
||||
"See the code!\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"###### MipNeRF 360\n",
|
||||
"\n",
|
||||
"```{button-link} https://github.com/nerfstudio-project/nerfstudio/blob/master/nerfstudio/data/dataparsers/mipnerf_dataparser.py\n",
|
||||
":color: primary\n",
|
||||
":outline:\n",
|
||||
"See the code!\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"###### Record3D\n",
|
||||
"\n",
|
||||
"This dataparser can use recorded data from a >= iPhone 12 Pro using the Record3D app. Record a video and export with the `EXR + JPG sequence` format. Unzip export and `rgb` folder before training.\n",
|
||||
"\n",
|
||||
"```{button-link} https://github.com/nerfstudio-project/nerfstudio/blob/master/nerfstudio/data/dataparsers/record3d_dataparser.py\n",
|
||||
":color: primary\n",
|
||||
":outline:\n",
|
||||
"See the code!\n",
|
||||
"```\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.12 ('nerfactory')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.8.12"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "34c28001ff35fb390494047002768a8182dcf55b1b11415165e62ea61557ab83"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 119 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
@@ -0,0 +1,19 @@
|
||||
Pipelines Overview
|
||||
-------------------------
|
||||
|
||||
Here we show you how to create a custom pipeline.
|
||||
|
||||
# TODO: show a figure of what a pipeline is here
|
||||
|
||||
.. image:: imgs/pipelines_overview.png
|
||||
:width: 400
|
||||
:align: center
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
dataparsers.ipynb
|
||||
datamanagers.ipynb
|
||||
models.ipynb
|
||||
pipelines.ipynb
|
||||
creating_new_methods.ipynb
|
||||
@@ -0,0 +1,229 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Models\n",
|
||||
"\n",
|
||||
"```{image} imgs/models.png\n",
|
||||
":align: center\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"In this quick tour, we will walk you through the core of training and building any NeRFs with nerfstudio.\n",
|
||||
"\n",
|
||||
"The entry point for training starts at `scripts/train.py`, which spawns instances of our `Trainer()` class (in `engine/trainer.py`). The `Trainer()` is responsible for setting up the datasets and NeRF graph depending on the config specified. It will then run the usual train/val routine for a config-specified number of iterations. If you are planning on using our codebase to build a new NeRF method or to use an existing implementation, we've abstracted away the training routine in these two files and chances are you will not need to think of them again.\n",
|
||||
"\n",
|
||||
"### Graphs, Modules, and Fields\n",
|
||||
"\n",
|
||||
"If you are looking to implemnet a new NeRF method or extend an existing one, you may need to set up a new graph (in `graphs/`).\n",
|
||||
"\n",
|
||||
"All NeRF graph definitions can be found in `graphs/`. The graph encapsulates all the modules in the NeRF method- from the MLP's to the samplers to the losses and optimizers. All graphs are composed of modules and fields.\n",
|
||||
"\n",
|
||||
"### Modules\n",
|
||||
"\n",
|
||||
"We can decompose all graphs into respective modules. For instance, we have `optimizers` which contains modules related to the loss, `renderers` which contains all rendering modules, {`graph/modules/`}, which includes samplers and ray generators. Additionally, we have `field_modules`, which will be discussed below.\n",
|
||||
"In general, modules can be thought of as individual component parts of the graph that can be swapped in/out. We provide most of the standard modules, but if you are creating a new NeRF graph, you may have to define new modules.\n",
|
||||
"\n",
|
||||
"### Fields\n",
|
||||
"\n",
|
||||
"`fields` represents the \"space\", aka. the radiance field of the NeRF. Here, we define the field as the part of the network that takes in point samples and any other conditioning, and outputs any of the `FieldHeadNames` (`nerf/field_modules/field_heads.py`).\n",
|
||||
"\n",
|
||||
"All fields are composed of modules continained within the `fields/` directory (e.g. `fields/modules/`). We can think of field modules as modules that actually define or interact with the field.\n",
|
||||
"\n",
|
||||
"To build a NeRF field, we therefore follow these steps:\n",
|
||||
"\n",
|
||||
"1. define any relevant field modules\n",
|
||||
"2. create a new class that extends the `fields` base class and use these field modules to compose the full field\n",
|
||||
"3. implement the abstract functions `get_density()` and `get_outputs()`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "SyntaxError",
|
||||
"evalue": "invalid syntax (383175768.py, line 4)",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;36m Input \u001b[0;32mIn [1]\u001b[0;36m\u001b[0m\n\u001b[0;31m def __init__(self, ...) -> None:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"class NeRFField(Field):\n",
|
||||
" \"\"\"NeRF Field\"\"\"\n",
|
||||
"\n",
|
||||
" def __init__(self, ...) -> None:\n",
|
||||
" \"\"\"Create boilerplate NeRF field.\"\"\"\n",
|
||||
"\n",
|
||||
" super().__init__()\n",
|
||||
"\n",
|
||||
" # In the init method, we are instantiating all relevant field modules\n",
|
||||
" self.position_encoding = position_encoding\n",
|
||||
" self.direction_encoding = direction_encoding\n",
|
||||
"\n",
|
||||
" self.mlp_base = MLP(\n",
|
||||
" in_dim=self.position_encoding.get_out_dim(),\n",
|
||||
" num_layers=base_mlp_num_layers,\n",
|
||||
" layer_width=base_mlp_layer_width,\n",
|
||||
" skip_connections=skip_connections,\n",
|
||||
" )\n",
|
||||
" ...\n",
|
||||
"\n",
|
||||
" def get_density(self, point_samples: PointSamples):\n",
|
||||
" \"\"\"\n",
|
||||
" Computes and returns the densities.\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def get_outputs(\n",
|
||||
" self, point_samples: PointSamples, density_embedding: Optional[TensorType] = None\n",
|
||||
" ) -> Dict[FieldHeadNames, TensorType]:\n",
|
||||
" \"\"\"\n",
|
||||
" Computes and returns the outputs.\n",
|
||||
" \"\"\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Putting it together\n",
|
||||
"\n",
|
||||
"Now that we've gone over what modules and fields are, we are ready to create the graph!\n",
|
||||
"\n",
|
||||
"To implement the vanilla NeRF, we create a new class that inherits the abstract Graph class. Similar to composing a new field, we can pull from all pre-defined fields and modules and use them to compose a new Graph.\n",
|
||||
"We will then need to define the following abstract methods as seen in the skeleton code below. See also `graphs/vanilla_nerf.py` for the full implementation."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "NameError",
|
||||
"evalue": "name 'Graph' is not defined",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m/shared/ethanweber/nerfactory/docs/tutorials/pipelines/creating_models.ipynb Cell 4\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> <a href='vscode-notebook-cell://ssh-remote%2Bbirman/shared/ethanweber/nerfactory/docs/tutorials/pipelines/creating_models.ipynb#W6sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39mNeRFGraph\u001b[39;00m(Graph):\n\u001b[1;32m <a href='vscode-notebook-cell://ssh-remote%2Bbirman/shared/ethanweber/nerfactory/docs/tutorials/pipelines/creating_models.ipynb#W6sdnNjb2RlLXJlbW90ZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39m\"\"\"Vanilla NeRF graph\"\"\"\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell://ssh-remote%2Bbirman/shared/ethanweber/nerfactory/docs/tutorials/pipelines/creating_models.ipynb#W6sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3'>4</a>\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__init__\u001b[39m(\u001b[39mself\u001b[39m, intrinsics\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, camera_to_world\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mNone\u001b[39;00m:\n",
|
||||
"\u001b[0;31mNameError\u001b[0m: name 'Graph' is not defined"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"class NeRFGraph(Graph):\n",
|
||||
" \"\"\"Vanilla NeRF graph\"\"\"\n",
|
||||
"\n",
|
||||
" def __init__(self, intrinsics=None, camera_to_world=None, **kwargs) -> None:\n",
|
||||
" super().__init__(intrinsics=intrinsics, camera_to_world=camera_to_world, **kwargs)\n",
|
||||
"\n",
|
||||
" def populate_fields(self):\n",
|
||||
" \"\"\"\n",
|
||||
" Set all field related modules here\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def populate_misc_modules(self):\n",
|
||||
" \"\"\"\n",
|
||||
" Set all remaining modules here including: samplers, renderers, losses, and metrics\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def get_param_groups(self) -> Dict[str, List[Parameter]]:\n",
|
||||
" \"\"\"\n",
|
||||
" Create a dictionary of parameters that are grouped according to different optimizers\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def get_outputs(self, ray_bundle: RayBundle):\n",
|
||||
" \"\"\"\n",
|
||||
" Takes in a Ray Bundle and returns a dictionary of outputs.\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def get_loss_dict(self, outputs, batch):\n",
|
||||
" \"\"\"\n",
|
||||
" Computes and returns the losses.\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def log_test_image_outputs(self, image_idx, step, batch, outputs):\n",
|
||||
" \"\"\"\n",
|
||||
" Writes the test image outputs.\n",
|
||||
" \"\"\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Creating the config\n",
|
||||
"\n",
|
||||
"Now that you have the graph and dataset all set up, you'll need to create the config that you pass into our run train routine. Our config system is powered by [Hydra](https://hydra.cc/). All Hydra and machine related arguments are stored in `configs/default_setup.yaml`, as well as the defaults list.\n",
|
||||
"To set up the graph config, create a new yaml under `configs/`.\n",
|
||||
"\n",
|
||||
"```yaml\n",
|
||||
"# configs/vanilla_nerf.yaml\n",
|
||||
"\n",
|
||||
"defaults:\n",
|
||||
" - graph_default # inherit the basic yaml heirarchy\n",
|
||||
" - _self_\n",
|
||||
"\n",
|
||||
"logging:\n",
|
||||
" # <insert logging definitions here>\n",
|
||||
"\n",
|
||||
"trainer:\n",
|
||||
" # <override configurations for loading/training/saving model here>\n",
|
||||
"\n",
|
||||
"experiment_name: blender_lego\n",
|
||||
"method_name: vanilla_nerf\n",
|
||||
"\n",
|
||||
"data:\n",
|
||||
" # <insert any dataset related overrides here>\n",
|
||||
"\n",
|
||||
"graph:\n",
|
||||
" _target_: nerfstudio.graph.vanilla_nerf.NeRFGraph # set the target to the graph you defined\n",
|
||||
" # <insert any graph related overrides here>\n",
|
||||
"\n",
|
||||
"optimizers:\n",
|
||||
" # <insert any optimizer related overrides here>\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### Training and testing\n",
|
||||
"\n",
|
||||
"Once you have the config properly set up, you can begin training! To begin the training process, just pass in the name of your new config to the training script:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"python scripts/train.py --config-name vanilla_nerf\n",
|
||||
"```"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.12 ('nerfactory')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.12"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "34c28001ff35fb390494047002768a8182dcf55b1b11415165e62ea61557ab83"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Pipelines\n",
|
||||
"\n",
|
||||
"```{image} imgs/pipelines.png\n",
|
||||
":align: center\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.13 ('nerfactory')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.8.13"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "b7b86c17c0dfd6b313529972d424f2e075cc198a46cda005757126afe8133c7b"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in new issue
Block a user