Skip to content

Commit

Permalink
Converted many @DataClass assignments to field()s for python 3.11 com…
Browse files Browse the repository at this point in the history
…patibility
  • Loading branch information
jaggzh committed Nov 25, 2023
1 parent 9528a3f commit 0824392
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions nerfstudio/configs/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from __future__ import annotations

from dataclasses import dataclass
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, List, Literal, Optional, Tuple, Type

Expand Down Expand Up @@ -113,7 +113,7 @@ class LoggingConfig(PrintableConfig):
max_buffer_size: int = 20
"""maximum history size to keep for computing running averages of stats.
e.g. if 20, averages will be computed over past 20 occurrences."""
local_writer: LocalWriterConfig = LocalWriterConfig(enable=True)
local_writer: LocalWriterConfig = field(default_factory=lambda: LocalWriterConfig(enable=True))
"""if provided, will print stats locally. if None, will disable printing"""
profiler: Literal["none", "basic", "pytorch"] = "basic"
"""how to profile the code;
Expand Down
10 changes: 5 additions & 5 deletions nerfstudio/configs/experiment_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from __future__ import annotations

from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, Literal, Optional
Expand Down Expand Up @@ -51,13 +51,13 @@ class ExperimentConfig(InstantiateConfig):
"""Project name."""
timestamp: str = "{timestamp}"
"""Experiment timestamp."""
machine: MachineConfig = MachineConfig()
machine: MachineConfig = field(default_factory=lambda: MachineConfig())
"""Machine configuration"""
logging: LoggingConfig = LoggingConfig()
logging: LoggingConfig = field(default_factory=lambda: LoggingConfig())
"""Logging configuration"""
viewer: ViewerConfig = ViewerConfig()
viewer: ViewerConfig = field(default_factory=lambda: ViewerConfig())
"""Viewer configuration"""
pipeline: VanillaPipelineConfig = VanillaPipelineConfig()
pipeline: VanillaPipelineConfig = field(default_factory=lambda: VanillaPipelineConfig())
"""Pipeline configuration"""
optimizers: Dict[str, Any] = to_immutable_dict(
{
Expand Down
4 changes: 2 additions & 2 deletions nerfstudio/data/datamanagers/base_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class VanillaDataManagerConfig(DataManagerConfig):

_target: Type = field(default_factory=lambda: VanillaDataManager)
"""Target class to instantiate."""
dataparser: AnnotatedDataParserUnion = BlenderDataParserConfig()
dataparser: AnnotatedDataParserUnion = field(default_factory=lambda: BlenderDataParserConfig())
"""Specifies the dataparser used to unpack the data."""
train_num_rays_per_batch: int = 1024
"""Number of rays per batch to use per training iteration."""
Expand Down Expand Up @@ -345,7 +345,7 @@ class VanillaDataManagerConfig(DataManagerConfig):
"""Size of patch to sample from. If > 1, patch-based sampling will be used."""
camera_optimizer: Optional[CameraOptimizerConfig] = field(default=None)
"""Deprecated, has been moved to the model config."""
pixel_sampler: PixelSamplerConfig = PixelSamplerConfig()
pixel_sampler: PixelSamplerConfig = field(default_factory=lambda: PixelSamplerConfig())
"""Specifies the pixel sampler used to sample pixels from images."""

def __post_init__(self):
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/data/dataparsers/base_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DataparserOutputs:
"""Camera object storing collection of camera information in dataset."""
alpha_color: Optional[Float[Tensor, "3"]] = None
"""Color of dataset background."""
scene_box: SceneBox = SceneBox(aabb=torch.tensor([[-1, -1, -1], [1, 1, 1]]))
scene_box: SceneBox = field(default_factory=lambda: SceneBox(aabb=torch.tensor([[-1, -1, -1], [1, 1, 1]])))
"""Scene box of dataset. Used to bound the scene or provide the scene scale depending on model."""
mask_filenames: Optional[List[Path]] = None
"""Filenames for any masks that are required"""
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/models/base_surface_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SurfaceModelConfig(ModelConfig):
"""Monocular normal consistency loss multiplier."""
mono_depth_loss_mult: float = 0.0
"""Monocular depth consistency loss multiplier."""
sdf_field: SDFFieldConfig = SDFFieldConfig()
sdf_field: SDFFieldConfig = field(default_factory=lambda: SDFFieldConfig())
"""Config for SDF Field"""
background_model: Literal["grid", "mlp", "none"] = "mlp"
"""background models"""
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/models/nerfacto.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class NerfactoModelConfig(ModelConfig):
"""Which implementation to use for the model."""
appearance_embed_dim: int = 32
"""Dimension of the appearance embedding."""
camera_optimizer: CameraOptimizerConfig = CameraOptimizerConfig(mode="SO3xR3")
camera_optimizer: CameraOptimizerConfig = field(default_factory=lambda: CameraOptimizerConfig(mode="SO3xR3"))
"""Config of the camera optimizer to use"""


Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/models/tensorf.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class TensoRFModelConfig(ModelConfig):
tensorf_encoding: Literal["triplane", "vm", "cp"] = "vm"
regularization: Literal["none", "l1", "tv"] = "l1"
"""Regularization method used in tensorf paper"""
camera_optimizer: CameraOptimizerConfig = CameraOptimizerConfig(mode="SO3xR3")
camera_optimizer: CameraOptimizerConfig = field(default_factory=lambda: CameraOptimizerConfig(mode="SO3xR3"))
"""Config of the camera optimizer to use"""
use_gradient_scaling: bool = False
"""Use gradient scaler where the gradients are lower for points closer to the camera."""
Expand Down
4 changes: 2 additions & 2 deletions nerfstudio/pipelines/base_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ class VanillaPipelineConfig(cfg.InstantiateConfig):

_target: Type = field(default_factory=lambda: VanillaPipeline)
"""target class to instantiate"""
datamanager: DataManagerConfig = DataManagerConfig()
datamanager: DataManagerConfig = field(default_factory=lambda: DataManagerConfig())
"""specifies the datamanager config"""
model: ModelConfig = ModelConfig()
model: ModelConfig = field(default_factory=lambda: ModelConfig())
"""specifies the model config"""


Expand Down

0 comments on commit 0824392

Please sign in to comment.