mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 14:28:41 +08:00
Remove dataparser dependency (#1529)
This commit is contained in:
1 parent
4a9764d3c4
commit
bfaf11cd72
6 files changed
+103
-49
No files matched your search
@@ -20,6 +20,7 @@ from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||
|
||||
import torch
|
||||
@@ -95,6 +96,21 @@ AnnotatedDataParserUnion = tyro.conf.OmitSubcommandPrefixes[ # Omit prefixes of
|
||||
same as the vanilla union, but results in shorter subcommand names."""
|
||||
|
||||
|
||||
@dataclass
|
||||
class DataManagerConfig(InstantiateConfig):
|
||||
"""Configuration for data manager instantiation; DataManager is in charge of keeping the train/eval dataparsers;
|
||||
After instantiation, data manager holds both train/eval datasets and is in charge of returning unpacked
|
||||
train/eval data at each iteration
|
||||
"""
|
||||
|
||||
_target: Type = field(default_factory=lambda: DataManager)
|
||||
"""Target class to instantiate."""
|
||||
data: Optional[Path] = None
|
||||
"""Source of data, may not be used by all models."""
|
||||
camera_optimizer: Optional[CameraOptimizerConfig] = None
|
||||
"""Specifies the camera pose optimizer used during training. Helpful if poses are noisy."""
|
||||
|
||||
|
||||
class DataManager(nn.Module):
|
||||
"""Generic data manager's abstract class
|
||||
|
||||
@@ -213,12 +229,10 @@ class DataManager(nn.Module):
|
||||
"""Sets up the data manager for training.
|
||||
|
||||
Here you will define any subclass specific object attributes from the attribute"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def setup_eval(self):
|
||||
"""Sets up the data manager for evaluation"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def next_train(self, step: int) -> Tuple:
|
||||
@@ -241,6 +255,20 @@ class DataManager(nn.Module):
|
||||
"""Returns the next eval image."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def get_train_rays_per_batch(self) -> int:
|
||||
"""Returns the number of rays per batch for training."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def get_eval_rays_per_batch(self) -> int:
|
||||
"""Returns the number of rays per batch for evaluation."""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_datapath(self) -> Optional[Path]: # pylint:disable=no-self-use
|
||||
"""Returns the path to the data. This is used to determine where to save camera paths."""
|
||||
return None
|
||||
|
||||
def get_training_callbacks( # pylint:disable=no-self-use
|
||||
self, training_callback_attributes: TrainingCallbackAttributes # pylint: disable=unused-argument
|
||||
) -> List[TrainingCallback]:
|
||||
@@ -258,11 +286,8 @@ class DataManager(nn.Module):
|
||||
|
||||
|
||||
@dataclass
|
||||
class VanillaDataManagerConfig(InstantiateConfig):
|
||||
"""Configuration for data manager instantiation; DataManager is in charge of keeping the train/eval dataparsers;
|
||||
After instantiation, data manager holds both train/eval datasets and is in charge of returning unpacked
|
||||
train/eval data at each iteration
|
||||
"""
|
||||
class VanillaDataManagerConfig(DataManagerConfig):
|
||||
"""A basic data manager"""
|
||||
|
||||
_target: Type = field(default_factory=lambda: VanillaDataManager)
|
||||
"""Target class to instantiate."""
|
||||
@@ -333,7 +358,12 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
|
||||
self.sampler = None
|
||||
self.test_mode = test_mode
|
||||
self.test_split = "test" if test_mode in ["test", "inference"] else "val"
|
||||
self.dataparser = self.config.dataparser.setup()
|
||||
self.dataparser = self.config.dataparser
|
||||
if self.config.data is not None:
|
||||
self.config.dataparser.data = Path(self.config.data)
|
||||
else:
|
||||
self.config.data = self.config.dataparser.data
|
||||
self.dataparser = self.dataparser.setup()
|
||||
self.train_dataparser_outputs = self.dataparser.get_dataparser_outputs(split="train")
|
||||
|
||||
self.train_dataset = self.create_train_dataset()
|
||||
@@ -455,6 +485,15 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
|
||||
return image_idx, camera_ray_bundle, batch
|
||||
raise ValueError("No more eval images")
|
||||
|
||||
def get_train_rays_per_batch(self) -> int:
|
||||
return self.config.train_num_rays_per_batch
|
||||
|
||||
def get_eval_rays_per_batch(self) -> int:
|
||||
return self.config.eval_num_rays_per_batch
|
||||
|
||||
def get_datapath(self) -> Path:
|
||||
return self.config.dataparser.data
|
||||
|
||||
def get_param_groups(self) -> Dict[str, List[Parameter]]: # pylint: disable=no-self-use
|
||||
"""Get the param groups for the data manager.
|
||||
Returns:
|
||||
|
||||
Reference in new issue
Block a user