diff --git a/.github/workflows/core_code_checks.yml b/.github/workflows/core_code_checks.yml index 86ff5ccca..62128edff 100644 --- a/.github/workflows/core_code_checks.yml +++ b/.github/workflows/core_code_checks.yml @@ -15,10 +15,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python 3.7.13 + - name: Set up Python 3.8.13 uses: actions/setup-python@v4 with: - python-version: '3.7.13' + python-version: '3.8.13' - uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} diff --git a/README.md b/README.md index 4673677fb..a22e281e6 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ You must have an NVIDIA video card with CUDA installed on the system. This libra ### Create environment -Nerfstudio requires `python >= 3.7`. We recommend using conda to manage dependencies. Make sure to install [Conda](https://docs.conda.io/en/latest/miniconda.html) before proceeding. +Nerfstudio requires `python >= 3.8`. We recommend using conda to manage dependencies. Make sure to install [Conda](https://docs.conda.io/en/latest/miniconda.html) before proceeding. ```bash conda create --name nerfstudio -y python=3.8 diff --git a/docs/quickstart/installation.md b/docs/quickstart/installation.md index dafb9f0ee..58f9ffe1d 100644 --- a/docs/quickstart/installation.md +++ b/docs/quickstart/installation.md @@ -33,7 +33,7 @@ Install CUDA 11.7. You can find CUDA download links [here](https://developer.nvi ## Create environment -Nerfstudio requires `python >= 3.7`. We recommend using conda to manage dependencies. Make sure to install [Conda](https://docs.conda.io/en/latest/miniconda.html) before proceeding. +Nerfstudio requires `python >= 3.8`. We recommend using conda to manage dependencies. Make sure to install [Conda](https://docs.conda.io/en/latest/miniconda.html) before proceeding. ```bash conda create --name nerfstudio -y python=3.8 diff --git a/nerfstudio/cameras/camera_optimizers.py b/nerfstudio/cameras/camera_optimizers.py index afd002a71..4b37f2072 100644 --- a/nerfstudio/cameras/camera_optimizers.py +++ b/nerfstudio/cameras/camera_optimizers.py @@ -20,13 +20,13 @@ from __future__ import annotations import functools from dataclasses import dataclass, field -from typing import Type, Union +from typing import Literal, Type, Union import torch import tyro from torch import nn from torchtyping import TensorType -from typing_extensions import Literal, assert_never +from typing_extensions import assert_never from nerfstudio.cameras.lie_groups import exp_map_SE3, exp_map_SO3xR3 from nerfstudio.configs.base_config import InstantiateConfig diff --git a/nerfstudio/cameras/camera_utils.py b/nerfstudio/cameras/camera_utils.py index 8486f1097..7c2364929 100644 --- a/nerfstudio/cameras/camera_utils.py +++ b/nerfstudio/cameras/camera_utils.py @@ -17,13 +17,12 @@ Camera transformation helper code. """ import math -from typing import List, Optional, Tuple +from typing import List, Literal, Optional, Tuple import numpy as np import torch from numpy.typing import ArrayLike from torchtyping import TensorType -from typing_extensions import Literal _EPS = np.finfo(float).eps * 4.0 diff --git a/nerfstudio/configs/base_config.py b/nerfstudio/configs/base_config.py index 5731091ac..2a76c325c 100644 --- a/nerfstudio/configs/base_config.py +++ b/nerfstudio/configs/base_config.py @@ -21,9 +21,7 @@ from __future__ import annotations import warnings from dataclasses import dataclass from pathlib import Path -from typing import Any, List, Optional, Tuple, Type - -from typing_extensions import Literal +from typing import Any, List, Literal, Optional, Tuple, Type # model instances from nerfstudio.utils import writer diff --git a/nerfstudio/configs/config_utils.py b/nerfstudio/configs/config_utils.py index 59b1b252b..42bf7a082 100644 --- a/nerfstudio/configs/config_utils.py +++ b/nerfstudio/configs/config_utils.py @@ -26,6 +26,7 @@ from rich.console import Console CONSOLE = Console() # pylint: disable=import-outside-toplevel + # cannot use mutable types directly within dataclass; abstracting default factory calls def to_immutable_dict(d: Dict[str, Any]): """Method to convert mutable dict to default factory dict diff --git a/nerfstudio/configs/experiment_config.py b/nerfstudio/configs/experiment_config.py index c0da16fef..8e9669a47 100644 --- a/nerfstudio/configs/experiment_config.py +++ b/nerfstudio/configs/experiment_config.py @@ -19,11 +19,10 @@ from __future__ import annotations from dataclasses import dataclass from datetime import datetime from pathlib import Path -from typing import Any, Dict, Optional +from typing import Any, Dict, Literal, Optional import yaml from rich.console import Console -from typing_extensions import Literal from nerfstudio.configs.base_config import ( InstantiateConfig, diff --git a/nerfstudio/data/datamanagers/base_datamanager.py b/nerfstudio/data/datamanagers/base_datamanager.py index 0c495139e..0167ff7fb 100644 --- a/nerfstudio/data/datamanagers/base_datamanager.py +++ b/nerfstudio/data/datamanagers/base_datamanager.py @@ -22,7 +22,7 @@ import functools from abc import abstractmethod from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Dict, Generic, List, Optional, Tuple, Type, Union +from typing import Any, Dict, Generic, List, Literal, Optional, Tuple, Type, Union import torch import tyro @@ -31,7 +31,7 @@ from torch import nn from torch.nn import Parameter from torch.utils.data import Dataset from torch.utils.data.distributed import DistributedSampler -from typing_extensions import Literal, TypeVar +from typing_extensions import TypeVar from nerfstudio.cameras.camera_optimizers import CameraOptimizerConfig from nerfstudio.cameras.cameras import CameraType diff --git a/nerfstudio/data/dataparsers/arkitscenes_dataparser.py b/nerfstudio/data/dataparsers/arkitscenes_dataparser.py index a92745bc6..0ee105196 100644 --- a/nerfstudio/data/dataparsers/arkitscenes_dataparser.py +++ b/nerfstudio/data/dataparsers/arkitscenes_dataparser.py @@ -16,12 +16,11 @@ import math from dataclasses import dataclass, field from pathlib import Path -from typing import Type +from typing import Literal, Type import cv2 import numpy as np import torch -from typing_extensions import Literal from nerfstudio.cameras import camera_utils from nerfstudio.cameras.cameras import Cameras, CameraType diff --git a/nerfstudio/data/dataparsers/base_dataparser.py b/nerfstudio/data/dataparsers/base_dataparser.py index f92b34172..74d934ced 100644 --- a/nerfstudio/data/dataparsers/base_dataparser.py +++ b/nerfstudio/data/dataparsers/base_dataparser.py @@ -20,11 +20,10 @@ import json from abc import abstractmethod from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Dict, List, Optional, Type +from typing import Any, Dict, List, Literal, Optional, Type import torch from torchtyping import TensorType -from typing_extensions import Literal import nerfstudio.configs.base_config as cfg from nerfstudio.cameras.cameras import Cameras diff --git a/nerfstudio/data/dataparsers/nerfosr_dataparser.py b/nerfstudio/data/dataparsers/nerfosr_dataparser.py index f7b84b261..97f430e1a 100644 --- a/nerfstudio/data/dataparsers/nerfosr_dataparser.py +++ b/nerfstudio/data/dataparsers/nerfosr_dataparser.py @@ -23,12 +23,11 @@ import glob import os from dataclasses import dataclass, field from pathlib import Path -from typing import List, Tuple, Type +from typing import List, Literal, Tuple, Type import numpy as np import torch from rich.console import Console -from typing_extensions import Literal from nerfstudio.cameras import camera_utils from nerfstudio.cameras.cameras import Cameras, CameraType diff --git a/nerfstudio/data/dataparsers/nerfstudio_dataparser.py b/nerfstudio/data/dataparsers/nerfstudio_dataparser.py index 7b283d747..d1f19c7fc 100644 --- a/nerfstudio/data/dataparsers/nerfstudio_dataparser.py +++ b/nerfstudio/data/dataparsers/nerfstudio_dataparser.py @@ -18,13 +18,12 @@ from __future__ import annotations import math from dataclasses import dataclass, field from pathlib import Path, PurePath -from typing import Optional, Type +from typing import Literal, Optional, Type import numpy as np import torch from PIL import Image from rich.console import Console -from typing_extensions import Literal from nerfstudio.cameras import camera_utils from nerfstudio.cameras.cameras import CAMERA_MODEL_TO_TYPE, Cameras, CameraType diff --git a/nerfstudio/data/dataparsers/nuscenes_dataparser.py b/nerfstudio/data/dataparsers/nuscenes_dataparser.py index 6b35cf356..ddf15dc8b 100644 --- a/nerfstudio/data/dataparsers/nuscenes_dataparser.py +++ b/nerfstudio/data/dataparsers/nuscenes_dataparser.py @@ -17,13 +17,12 @@ import math import os from dataclasses import dataclass, field from pathlib import Path -from typing import Optional, Tuple, Type +from typing import Literal, Optional, Tuple, Type import numpy as np import pyquaternion import torch from nuscenes.nuscenes import NuScenes as NuScenesDatabase -from typing_extensions import Literal from nerfstudio.cameras.cameras import Cameras, CameraType from nerfstudio.data.dataparsers.base_dataparser import ( diff --git a/nerfstudio/data/dataparsers/phototourism_dataparser.py b/nerfstudio/data/dataparsers/phototourism_dataparser.py index d470215ed..8b6049c64 100644 --- a/nerfstudio/data/dataparsers/phototourism_dataparser.py +++ b/nerfstudio/data/dataparsers/phototourism_dataparser.py @@ -18,12 +18,11 @@ from __future__ import annotations import math from dataclasses import dataclass, field from pathlib import Path -from typing import Type +from typing import Literal, Type import numpy as np import torch from rich.progress import Console -from typing_extensions import Literal from nerfstudio.cameras import camera_utils from nerfstudio.cameras.cameras import Cameras, CameraType diff --git a/nerfstudio/data/dataparsers/scannet_dataparser.py b/nerfstudio/data/dataparsers/scannet_dataparser.py index 5d2702f18..fb863073e 100644 --- a/nerfstudio/data/dataparsers/scannet_dataparser.py +++ b/nerfstudio/data/dataparsers/scannet_dataparser.py @@ -16,12 +16,11 @@ import math from dataclasses import dataclass, field from pathlib import Path -from typing import Type +from typing import Literal, Type import cv2 import numpy as np import torch -from typing_extensions import Literal from nerfstudio.cameras import camera_utils from nerfstudio.cameras.cameras import Cameras, CameraType diff --git a/nerfstudio/data/dataparsers/sitcoms3d_dataparser.py b/nerfstudio/data/dataparsers/sitcoms3d_dataparser.py index b6906ce22..6dfc8896b 100644 --- a/nerfstudio/data/dataparsers/sitcoms3d_dataparser.py +++ b/nerfstudio/data/dataparsers/sitcoms3d_dataparser.py @@ -65,7 +65,6 @@ class Sitcoms3D(DataParser): config: Sitcoms3DDataParserConfig def _generate_dataparser_outputs(self, split="train"): # pylint: disable=unused-argument,too-many-statements - cameras_json = load_from_json(self.config.data / "cameras.json") frames = cameras_json["frames"] bbox = torch.tensor(cameras_json["bbox"]) diff --git a/nerfstudio/data/pixel_samplers.py b/nerfstudio/data/pixel_samplers.py index f3a9bc2f7..74374f381 100644 --- a/nerfstudio/data/pixel_samplers.py +++ b/nerfstudio/data/pixel_samplers.py @@ -137,7 +137,6 @@ class PixelSampler: # pylint: disable=too-few-public-methods if "mask" in batch: num_rays_in_batch = num_rays_per_batch // num_images for i in range(num_images): - image_height, image_width, _ = batch["image"][i].shape if i == num_images - 1: @@ -222,7 +221,6 @@ class EquirectangularPixelSampler(PixelSampler): # pylint: disable=too-few-publ mask: Optional[TensorType] = None, device: Union[torch.device, str] = "cpu", ) -> TensorType["batch_size", 3]: - if isinstance(mask, torch.Tensor): # Note: if there is a mask, sampling reduces back to uniform sampling, which gives more # sampling weight to the poles of the image than the equators. @@ -230,7 +228,6 @@ class EquirectangularPixelSampler(PixelSampler): # pylint: disable=too-few-publ indices = super().sample_method(batch_size, num_images, image_height, image_width, mask=mask, device=device) else: - # We sample theta uniformly in [0, 2*pi] # We sample phi in [0, pi] according to the PDF f(phi) = sin(phi) / 2. # This is done by inverse transform sampling. @@ -280,7 +277,6 @@ class PatchPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods mask: Optional[TensorType] = None, device: Union[torch.device, str] = "cpu", ) -> TensorType["batch_size", 3]: - if mask: # Note: if there is a mask, sampling reduces back to uniform sampling indices = super().sample_method(batch_size, num_images, image_height, image_width, mask=mask, device=device) diff --git a/nerfstudio/engine/schedulers.py b/nerfstudio/engine/schedulers.py index 301d9eb5f..68a459389 100644 --- a/nerfstudio/engine/schedulers.py +++ b/nerfstudio/engine/schedulers.py @@ -18,11 +18,10 @@ from abc import abstractmethod from dataclasses import dataclass, field -from typing import Optional, Tuple, Type +from typing import Literal, Optional, Tuple, Type import numpy as np from torch.optim import Optimizer, lr_scheduler -from typing_extensions import Literal from nerfstudio.configs.base_config import InstantiateConfig diff --git a/nerfstudio/engine/trainer.py b/nerfstudio/engine/trainer.py index 5680bddbe..1c3ed3ad2 100644 --- a/nerfstudio/engine/trainer.py +++ b/nerfstudio/engine/trainer.py @@ -24,7 +24,7 @@ import time from dataclasses import dataclass, field from pathlib import Path from threading import Lock -from typing import Dict, List, Optional, Tuple, Type, Union +from typing import Dict, List, Literal, Optional, Tuple, Type, Union import torch from rich import box, style @@ -32,7 +32,6 @@ from rich.console import Console from rich.panel import Panel from rich.table import Table from torch.cuda.amp.grad_scaler import GradScaler -from typing_extensions import Literal from nerfstudio.configs.experiment_config import ExperimentConfig from nerfstudio.engine.callbacks import ( diff --git a/nerfstudio/exporter/marching_cubes.py b/nerfstudio/exporter/marching_cubes.py index 03cd7da86..a88dc9017 100644 --- a/nerfstudio/exporter/marching_cubes.py +++ b/nerfstudio/exporter/marching_cubes.py @@ -76,7 +76,6 @@ def evaluate_multiresolution_sdf( x_min: float, crop_n: int, ) -> TensorType["batch"]: - """ Evaluate SDF values using a multi-resolution approach with a given point pyramid. diff --git a/nerfstudio/exporter/texture_utils.py b/nerfstudio/exporter/texture_utils.py index d7e08c669..9c0bb0ee0 100644 --- a/nerfstudio/exporter/texture_utils.py +++ b/nerfstudio/exporter/texture_utils.py @@ -22,7 +22,7 @@ from __future__ import annotations import math from pathlib import Path -from typing import Optional, Tuple, Union +from typing import Literal, Optional, Tuple, Union import mediapy as media import numpy as np @@ -30,7 +30,6 @@ import torch import xatlas from rich.console import Console from torchtyping import TensorType -from typing_extensions import Literal from nerfstudio.cameras.rays import RayBundle from nerfstudio.exporter.exporter_utils import Mesh diff --git a/nerfstudio/field_components/encodings.py b/nerfstudio/field_components/encodings.py index ac7cf2aa1..21dacbd0e 100644 --- a/nerfstudio/field_components/encodings.py +++ b/nerfstudio/field_components/encodings.py @@ -18,14 +18,13 @@ Encoding functions import itertools from abc import abstractmethod -from typing import Optional, Sequence +from typing import Literal, Optional, Sequence import numpy as np import torch import torch.nn.functional as F from torch import nn from torchtyping import TensorType -from typing_extensions import Literal from nerfstudio.field_components.base_field_component import FieldComponent from nerfstudio.utils.math import components_from_spherical_harmonics, expected_sin diff --git a/nerfstudio/field_components/field_heads.py b/nerfstudio/field_components/field_heads.py index 6fffb5111..da4e75185 100644 --- a/nerfstudio/field_components/field_heads.py +++ b/nerfstudio/field_components/field_heads.py @@ -59,7 +59,6 @@ class FieldHead(FieldComponent): in_dim: Optional[int] = None, activation: Optional[Union[nn.Module, Callable]] = None, ) -> None: - super().__init__() self.out_dim = out_dim self.activation = activation @@ -131,7 +130,6 @@ class SHFieldHead(FieldHead): def __init__( self, in_dim: Optional[int] = None, levels: int = 3, channels: int = 3, activation: Optional[nn.Module] = None ) -> None: - out_dim = channels * levels**2 super().__init__(in_dim=in_dim, out_dim=out_dim, field_head_name=FieldHeadNames.SH, activation=activation) diff --git a/nerfstudio/field_components/mlp.py b/nerfstudio/field_components/mlp.py index 545f32564..8cc5a73b6 100644 --- a/nerfstudio/field_components/mlp.py +++ b/nerfstudio/field_components/mlp.py @@ -46,7 +46,6 @@ class MLP(FieldComponent): activation: Optional[nn.Module] = nn.ReLU(), out_activation: Optional[nn.Module] = None, ) -> None: - super().__init__() self.in_dim = in_dim assert self.in_dim > 0 diff --git a/nerfstudio/fields/sdf_field.py b/nerfstudio/fields/sdf_field.py index 89274224f..72244a759 100644 --- a/nerfstudio/fields/sdf_field.py +++ b/nerfstudio/fields/sdf_field.py @@ -18,7 +18,7 @@ a signed distance function (SDF) for surface representation is used to help with """ from dataclasses import dataclass, field -from typing import Dict, Optional, Type +from typing import Dict, Literal, Optional, Type import numpy as np import torch @@ -26,7 +26,6 @@ import torch.nn.functional as F from torch import nn from torch.nn.parameter import Parameter from torchtyping import TensorType -from typing_extensions import Literal from nerfstudio.cameras.rays import RaySamples from nerfstudio.field_components.embedding import Embedding diff --git a/nerfstudio/model_components/losses.py b/nerfstudio/model_components/losses.py index d2db011d3..68f11bcc4 100644 --- a/nerfstudio/model_components/losses.py +++ b/nerfstudio/model_components/losses.py @@ -16,11 +16,11 @@ Collection of Losses. """ from enum import Enum +from typing import Literal import torch from torch import nn from torchtyping import TensorType -from typing_extensions import Literal from nerfstudio.cameras.rays import RaySamples from nerfstudio.utils.math import masked_reduction, normalized_depth_scale_and_shift diff --git a/nerfstudio/model_components/ray_samplers.py b/nerfstudio/model_components/ray_samplers.py index 7b7219f15..8112810e6 100644 --- a/nerfstudio/model_components/ray_samplers.py +++ b/nerfstudio/model_components/ray_samplers.py @@ -384,7 +384,6 @@ class VolumetricSampler(Sampler): occupancy_grid: OccGridEstimator, density_fn: Optional[Callable[[TensorType[..., 3]], TensorType[..., 1]]] = None, ) -> None: - super().__init__() assert occupancy_grid is not None self.density_fn = density_fn @@ -651,7 +650,6 @@ class NeuSSampler(Sampler): base_variance = self.base_variance while total_iters < self.num_upsample_steps: - with torch.no_grad(): new_sdf = sdf_fn(new_samples) diff --git a/nerfstudio/model_components/renderers.py b/nerfstudio/model_components/renderers.py index 5bc4be9b1..5deafad74 100644 --- a/nerfstudio/model_components/renderers.py +++ b/nerfstudio/model_components/renderers.py @@ -28,13 +28,12 @@ Example: """ import contextlib import math -from typing import Generator, Optional, Union +from typing import Generator, Literal, Optional, Union import nerfacc import torch from torch import nn from torchtyping import TensorType -from typing_extensions import Literal from nerfstudio.cameras.rays import RaySamples from nerfstudio.utils import colors diff --git a/nerfstudio/models/base_surface_model.py b/nerfstudio/models/base_surface_model.py index c83a07032..857f712ee 100644 --- a/nerfstudio/models/base_surface_model.py +++ b/nerfstudio/models/base_surface_model.py @@ -20,7 +20,7 @@ from __future__ import annotations from abc import abstractmethod from dataclasses import dataclass, field -from typing import Dict, List, Tuple, Type +from typing import Dict, List, Literal, Tuple, Type import torch import torch.nn.functional as F @@ -28,7 +28,6 @@ from torch.nn import Parameter from torchmetrics import PeakSignalNoiseRatio from torchmetrics.functional import structural_similarity_index_measure from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity -from typing_extensions import Literal from nerfstudio.cameras.rays import RayBundle from nerfstudio.field_components.encodings import NeRFEncoding diff --git a/nerfstudio/models/instant_ngp.py b/nerfstudio/models/instant_ngp.py index d8119db5c..f9e89cec3 100644 --- a/nerfstudio/models/instant_ngp.py +++ b/nerfstudio/models/instant_ngp.py @@ -19,7 +19,7 @@ Implementation of Instant NGP. from __future__ import annotations from dataclasses import dataclass, field -from typing import Dict, List, Optional, Tuple, Type +from typing import Dict, List, Literal, Optional, Tuple, Type import nerfacc import torch @@ -27,7 +27,6 @@ from torch.nn import Parameter from torchmetrics import PeakSignalNoiseRatio from torchmetrics.functional import structural_similarity_index_measure from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity -from typing_extensions import Literal from nerfstudio.cameras.rays import RayBundle from nerfstudio.engine.callbacks import ( @@ -233,7 +232,6 @@ class NGPModel(Model): def get_image_metrics_and_images( self, outputs: Dict[str, torch.Tensor], batch: Dict[str, torch.Tensor] ) -> Tuple[Dict[str, float], Dict[str, torch.Tensor]]: - image = batch["image"].to(self.device) rgb = outputs["rgb"] acc = colormaps.apply_colormap(outputs["accumulation"]) diff --git a/nerfstudio/models/mipnerf.py b/nerfstudio/models/mipnerf.py index 31a337d02..0fae0bdac 100644 --- a/nerfstudio/models/mipnerf.py +++ b/nerfstudio/models/mipnerf.py @@ -96,7 +96,6 @@ class MipNerfModel(Model): return param_groups def get_outputs(self, ray_bundle: RayBundle): - if self.field is None: raise ValueError("populate_fields() must be called before get_outputs") diff --git a/nerfstudio/models/nerfacto.py b/nerfstudio/models/nerfacto.py index 53173640a..0a7583ebe 100644 --- a/nerfstudio/models/nerfacto.py +++ b/nerfstudio/models/nerfacto.py @@ -19,7 +19,7 @@ NeRF implementation that combines many recent advancements. from __future__ import annotations from dataclasses import dataclass, field -from typing import Dict, List, Tuple, Type +from typing import Dict, List, Literal, Tuple, Type import numpy as np import torch @@ -27,7 +27,6 @@ from torch.nn import Parameter from torchmetrics import PeakSignalNoiseRatio from torchmetrics.functional import structural_similarity_index_measure from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity -from typing_extensions import Literal from nerfstudio.cameras.rays import RayBundle from nerfstudio.engine.callbacks import ( diff --git a/nerfstudio/models/nerfplayer_nerfacto.py b/nerfstudio/models/nerfplayer_nerfacto.py index e10b3cad2..245d3bac2 100644 --- a/nerfstudio/models/nerfplayer_nerfacto.py +++ b/nerfstudio/models/nerfplayer_nerfacto.py @@ -20,14 +20,13 @@ from __future__ import annotations import functools from dataclasses import dataclass, field -from typing import Dict, List, Type +from typing import Dict, List, Literal, Type import numpy as np import torch from torchmetrics import PeakSignalNoiseRatio from torchmetrics.functional import structural_similarity_index_measure from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity -from typing_extensions import Literal from nerfstudio.cameras.rays import RayBundle from nerfstudio.field_components.field_heads import FieldHeadNames diff --git a/nerfstudio/models/nerfplayer_ngp.py b/nerfstudio/models/nerfplayer_ngp.py index 4f884674f..59390d908 100644 --- a/nerfstudio/models/nerfplayer_ngp.py +++ b/nerfstudio/models/nerfplayer_ngp.py @@ -19,7 +19,7 @@ Implementation of NeRFPlayer (https://arxiv.org/abs/2210.15947) with InstantNGP from __future__ import annotations from dataclasses import dataclass, field -from typing import List, Type +from typing import List, Literal, Type import nerfacc import torch @@ -27,7 +27,6 @@ from torch.nn import Parameter from torchmetrics import PeakSignalNoiseRatio from torchmetrics.functional import structural_similarity_index_measure from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity -from typing_extensions import Literal from nerfstudio.cameras.rays import RayBundle from nerfstudio.engine.callbacks import ( diff --git a/nerfstudio/models/semantic_nerfw.py b/nerfstudio/models/semantic_nerfw.py index 4324e1eeb..c36b2d21c 100644 --- a/nerfstudio/models/semantic_nerfw.py +++ b/nerfstudio/models/semantic_nerfw.py @@ -258,7 +258,6 @@ class SemanticNerfWModel(Model): def get_image_metrics_and_images( self, outputs: Dict[str, torch.Tensor], batch: Dict[str, torch.Tensor] ) -> Tuple[Dict[str, float], Dict[str, torch.Tensor]]: - image = batch["image"].to(self.device) rgb = outputs["rgb"] rgb = torch.clamp(rgb, min=0, max=1) diff --git a/nerfstudio/models/tensorf.py b/nerfstudio/models/tensorf.py index 0a988b111..f94f2ca58 100644 --- a/nerfstudio/models/tensorf.py +++ b/nerfstudio/models/tensorf.py @@ -19,7 +19,7 @@ TensorRF implementation. from __future__ import annotations from dataclasses import dataclass, field -from typing import Dict, List, Tuple, Type +from typing import Dict, List, Literal, Tuple, Type import numpy as np import torch @@ -27,7 +27,6 @@ from torch.nn import Parameter from torchmetrics import PeakSignalNoiseRatio from torchmetrics.functional import structural_similarity_index_measure from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity -from typing_extensions import Literal from nerfstudio.cameras.rays import RayBundle from nerfstudio.configs.config_utils import to_immutable_dict diff --git a/nerfstudio/models/vanilla_nerf.py b/nerfstudio/models/vanilla_nerf.py index b69a35358..e9c74e93d 100644 --- a/nerfstudio/models/vanilla_nerf.py +++ b/nerfstudio/models/vanilla_nerf.py @@ -135,7 +135,6 @@ class NeRFModel(Model): return param_groups def get_outputs(self, ray_bundle: RayBundle): - if self.field_coarse is None or self.field_fine is None: raise ValueError("populate_fields() must be called before get_outputs") diff --git a/nerfstudio/pipelines/base_pipeline.py b/nerfstudio/pipelines/base_pipeline.py index c572bebeb..d1daa348d 100644 --- a/nerfstudio/pipelines/base_pipeline.py +++ b/nerfstudio/pipelines/base_pipeline.py @@ -21,7 +21,7 @@ import typing from abc import abstractmethod from dataclasses import dataclass, field from time import time -from typing import Any, Dict, List, Mapping, Optional, Type, Union, cast +from typing import Any, Dict, List, Literal, Mapping, Optional, Type, Union, cast import torch import torch.distributed as dist @@ -35,7 +35,6 @@ from rich.progress import ( from torch import nn from torch.nn import Parameter from torch.nn.parallel import DistributedDataParallel as DDP -from typing_extensions import Literal from nerfstudio.configs import base_config as cfg from nerfstudio.data.datamanagers.base_datamanager import ( diff --git a/nerfstudio/pipelines/dynamic_batch.py b/nerfstudio/pipelines/dynamic_batch.py index 293ea1706..1b722571a 100644 --- a/nerfstudio/pipelines/dynamic_batch.py +++ b/nerfstudio/pipelines/dynamic_batch.py @@ -17,10 +17,9 @@ A pipeline that dynamically chooses the number of rays to sample. """ from dataclasses import dataclass, field -from typing import Type +from typing import Literal, Type import torch -from typing_extensions import Literal from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager from nerfstudio.pipelines.base_pipeline import VanillaPipeline, VanillaPipelineConfig diff --git a/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py b/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py index 4effdc377..93a123d93 100644 --- a/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py +++ b/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py @@ -16,10 +16,9 @@ from dataclasses import dataclass from pathlib import Path -from typing import Dict, List, Optional, Tuple +from typing import Dict, List, Literal, Optional, Tuple from rich.console import Console -from typing_extensions import Literal from nerfstudio.process_data import colmap_utils, hloc_utils, process_data_utils from nerfstudio.process_data.base_converter_to_nerfstudio_dataset import ( @@ -182,7 +181,11 @@ class ColmapConverterToNerfstudioDataset(BaseConverterToNerfstudioDataset): """ self.absolute_colmap_path.mkdir(parents=True, exist_ok=True) - (sfm_tool, feature_type, matcher_type,) = process_data_utils.find_tool_feature_matcher_combination( + ( + sfm_tool, + feature_type, + matcher_type, + ) = process_data_utils.find_tool_feature_matcher_combination( self.sfm_tool, self.feature_type, self.matcher_type ) # check that sfm_tool is hloc if using refine_pixsfm diff --git a/nerfstudio/process_data/colmap_utils.py b/nerfstudio/process_data/colmap_utils.py index b302762d0..690080771 100644 --- a/nerfstudio/process_data/colmap_utils.py +++ b/nerfstudio/process_data/colmap_utils.py @@ -18,7 +18,7 @@ Tools supporting the execution of COLMAP and preparation of COLMAP-based dataset import json from pathlib import Path -from typing import Any, Dict, Optional +from typing import Any, Dict, Literal, Optional import appdirs import cv2 @@ -27,7 +27,6 @@ import requests import torch from rich.console import Console from rich.progress import track -from typing_extensions import Literal # TODO(1480) use pycolmap instead of colmap_parsing_utils # import pycolmap @@ -115,9 +114,7 @@ def run_colmap( colmap_version = get_colmap_version(colmap_cmd) colmap_database_path = colmap_dir / "database.db" - if colmap_database_path.exists(): - # Can't use missing_ok argument because of Python 3.7 compatibility. - colmap_database_path.unlink() + colmap_database_path.unlink(missing_ok=True) # Feature extraction feature_extractor_cmd = [ diff --git a/nerfstudio/process_data/hloc_utils.py b/nerfstudio/process_data/hloc_utils.py index f04f6c32c..eda02cae1 100644 --- a/nerfstudio/process_data/hloc_utils.py +++ b/nerfstudio/process_data/hloc_utils.py @@ -21,9 +21,9 @@ Requires hloc module from : https://github.com/cvg/Hierarchical-Localization import sys from pathlib import Path +from typing import Literal from rich.console import Console -from typing_extensions import Literal from nerfstudio.process_data.process_data_utils import CameraModel diff --git a/nerfstudio/process_data/process_data_utils.py b/nerfstudio/process_data/process_data_utils.py index 12d440772..74a981826 100644 --- a/nerfstudio/process_data/process_data_utils.py +++ b/nerfstudio/process_data/process_data_utils.py @@ -20,12 +20,11 @@ import shutil import sys from enum import Enum from pathlib import Path -from typing import List, Optional, Tuple +from typing import List, Literal, Optional, OrderedDict, Tuple import cv2 import numpy as np from rich.console import Console -from typing_extensions import Literal, OrderedDict from nerfstudio.utils.rich_utils import status from nerfstudio.utils.scripts import run_command diff --git a/nerfstudio/utils/eval_utils.py b/nerfstudio/utils/eval_utils.py index bd535af7f..5b35c33ff 100644 --- a/nerfstudio/utils/eval_utils.py +++ b/nerfstudio/utils/eval_utils.py @@ -20,12 +20,11 @@ from __future__ import annotations import os import sys from pathlib import Path -from typing import Optional, Tuple +from typing import Literal, Optional, Tuple import torch import yaml from rich.console import Console -from typing_extensions import Literal from nerfstudio.engine.trainer import TrainerConfig from nerfstudio.pipelines.base_pipeline import Pipeline diff --git a/nerfstudio/utils/math.py b/nerfstudio/utils/math.py index 74d4d4c00..924556597 100644 --- a/nerfstudio/utils/math.py +++ b/nerfstudio/utils/math.py @@ -15,11 +15,10 @@ """ Math Helper Functions """ from dataclasses import dataclass -from typing import Tuple +from typing import Literal, Tuple import torch from torchtyping import TensorType -from typing_extensions import Literal def components_from_spherical_harmonics(levels: int, directions: TensorType[..., 3]) -> TensorType[..., "components"]: diff --git a/nerfstudio/viewer/app/run_deploy.py b/nerfstudio/viewer/app/run_deploy.py index 03fd86465..99d5f47a9 100644 --- a/nerfstudio/viewer/app/run_deploy.py +++ b/nerfstudio/viewer/app/run_deploy.py @@ -119,7 +119,6 @@ def main( # update the symlink of latest if branch_name == "main": - # move the build folder to the correct location run_cmd(f"""ssh {host} 'rm -rf {remote_folder}/{version}'""") run_cmd(f"""ssh {host} 'cp -R /home/eweb0124/build {remote_folder}/{version}'""") diff --git a/nerfstudio/viewer/server/gui_utils.py b/nerfstudio/viewer/server/gui_utils.py index 792d3f2b4..a77fc6edb 100644 --- a/nerfstudio/viewer/server/gui_utils.py +++ b/nerfstudio/viewer/server/gui_utils.py @@ -53,7 +53,7 @@ def parse_object( ret = [] # get a list of the properties of the object, sorted by whether things are instances of type_check obj_props = [(k, getattr(obj, k)) for k in dir(obj)] - for (k, v) in obj_props: + for k, v in obj_props: if k[0] == "_": continue new_tree_stub = f"{tree_stub}/{k}" diff --git a/nerfstudio/viewer/server/render_state_machine.py b/nerfstudio/viewer/server/render_state_machine.py index 39c17c1e0..317dd299d 100644 --- a/nerfstudio/viewer/server/render_state_machine.py +++ b/nerfstudio/viewer/server/render_state_machine.py @@ -18,10 +18,9 @@ from __future__ import annotations import contextlib import threading from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple +from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Tuple, get_args import torch -from typing_extensions import Literal, get_args from nerfstudio.cameras.cameras import Cameras, CameraType from nerfstudio.model_components.renderers import background_color_override_context @@ -160,7 +159,7 @@ class RenderStateMachine(threading.Thread): ) camera = camera.to(self.viewer.get_model().device) - with (self.viewer.train_lock if self.viewer.train_lock is not None else contextlib.nullcontext()): + with self.viewer.train_lock if self.viewer.train_lock is not None else contextlib.nullcontext(): camera_ray_bundle = camera.generate_rays(camera_indices=0, aabb_box=self.viewer.get_model().render_aabb) with TimeWriter(None, None, write=False) as vis_t: diff --git a/nerfstudio/viewer/server/viewer_state.py b/nerfstudio/viewer/server/viewer_state.py index 5ecca2944..0d37ee902 100644 --- a/nerfstudio/viewer/server/viewer_state.py +++ b/nerfstudio/viewer/server/viewer_state.py @@ -17,7 +17,7 @@ from __future__ import annotations import threading from pathlib import Path -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List, Literal, Optional import numpy as np import torch @@ -25,7 +25,6 @@ from rich import box, style from rich.console import Console from rich.panel import Panel from rich.table import Table -from typing_extensions import Literal from nerfstudio.configs import base_config as cfg from nerfstudio.data.datasets.base_dataset import InputDataset diff --git a/nerfstudio/viewer/viser/message_api.py b/nerfstudio/viewer/viser/message_api.py index 8034440e6..38faf5d06 100644 --- a/nerfstudio/viewer/viser/message_api.py +++ b/nerfstudio/viewer/viser/message_api.py @@ -31,6 +31,7 @@ from typing import ( Dict, Generator, List, + Literal, Optional, Tuple, TypeVar, @@ -41,7 +42,7 @@ from typing import ( import imageio.v3 as iio import numpy as onp import numpy.typing as onpt -from typing_extensions import Literal, LiteralString, ParamSpec, assert_never +from typing_extensions import LiteralString, ParamSpec, assert_never from nerfstudio.data.scene_box import SceneBox diff --git a/nerfstudio/viewer/viser/messages.py b/nerfstudio/viewer/viser/messages.py index f3227f848..3fcfc7b3a 100644 --- a/nerfstudio/viewer/viser/messages.py +++ b/nerfstudio/viewer/viser/messages.py @@ -18,10 +18,10 @@ from __future__ import annotations import dataclasses -from typing import Any, Tuple +from typing import Any, Literal, Tuple import viser.infra -from typing_extensions import Literal, override +from typing_extensions import override class NerfstudioMessage(viser.infra.Message): diff --git a/pyproject.toml b/pyproject.toml index 968f4e299..3b4d76647 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ version = "0.2.2" description = "All-in-one repository for state-of-the-art NeRFs" readme = "README.md" license = { text="Apache 2.0"} -requires-python = ">=3.7.3" +requires-python = ">=3.8.0" classifiers = [ "Development Status :: 3 - Alpha", "Programming Language :: Python", @@ -74,7 +74,7 @@ gen = [ # Development packages dev = [ - "black[jupyter]==22.3.0", + "black[jupyter]==23.3.0", "pylint==2.13.4", "pytest==7.1.2", "pytest-xdist==2.5.0", @@ -168,5 +168,5 @@ reportMissingTypeStubs = false reportPrivateImportUsage = false reportUndefinedVariable = false -pythonVersion = "3.7" +pythonVersion = "3.8" pythonPlatform = "Linux" diff --git a/scripts/blender/nerfstudio_blender.py b/scripts/blender/nerfstudio_blender.py index dee0b4ab3..6ee80f066 100644 --- a/scripts/blender/nerfstudio_blender.py +++ b/scripts/blender/nerfstudio_blender.py @@ -141,7 +141,6 @@ class CreateJSONCameraPath(bpy.types.Operator): keyframe_list = [] for i, transformed_camera_path_mat_val in enumerate(self.transformed_camera_path_mat): - curr_properties = ( '[["FOV",' + str(self.fov_list[i]) @@ -361,7 +360,7 @@ class NerfstudioBgPanel(bpy.types.Panel): # pylint: disable=too-few-public-meth self.layout.label(text="Camera path for Nerfstudio") col = self.layout.column() - for (prop_name, _) in INPUT_PROPERTIES: + for prop_name, _ in INPUT_PROPERTIES: row = col.row() row.prop(context.scene, prop_name) @@ -385,7 +384,7 @@ class NerfstudioInputPanel(bpy.types.Panel): # pylint: disable=too-few-public-m self.layout.label(text="Create Blender Camera From Nerfstudio JSON") col = self.layout.column() - for (prop_name, _) in INPUT_PROPERTIES_NS_CAMERA: + for prop_name, _ in INPUT_PROPERTIES_NS_CAMERA: row = col.row() row.prop(context.scene, prop_name) @@ -425,10 +424,10 @@ OBJ_PROPERTIES = ["NeRF", "RenderCamera"] def register(): """Register classes for UI panel.""" - for (prop_name, prop_value) in INPUT_PROPERTIES: + for prop_name, prop_value in INPUT_PROPERTIES: setattr(bpy.types.Scene, prop_name, prop_value) - for (prop_name, prop_value) in INPUT_PROPERTIES_NS_CAMERA: + for prop_name, prop_value in INPUT_PROPERTIES_NS_CAMERA: setattr(bpy.types.Scene, prop_name, prop_value) bpy.types.Scene.NeRF = bpy.props.PointerProperty(type=bpy.types.Object) @@ -440,10 +439,10 @@ def register(): def unregister(): """Unregister classes for UI panel.""" - for (prop_name, _) in INPUT_PROPERTIES: + for prop_name, _ in INPUT_PROPERTIES: delattr(bpy.types.Scene, prop_name) - for (prop_name, _) in INPUT_PROPERTIES_NS_CAMERA: + for prop_name, _ in INPUT_PROPERTIES_NS_CAMERA: delattr(bpy.types.Scene, prop_name) del bpy.types.Scene.NeRF diff --git a/scripts/completions/install.py b/scripts/completions/install.py index a7acc862c..67957cf4b 100644 --- a/scripts/completions/install.py +++ b/scripts/completions/install.py @@ -10,13 +10,13 @@ import shutil import stat import subprocess import sys -from typing import List, Optional, Union +from typing import List, Literal, Optional, Union +from typing import get_args as typing_get_args import tyro from rich.console import Console from rich.prompt import Confirm -from typing_extensions import Literal, assert_never -from typing_extensions import get_args as typing_get_args +from typing_extensions import assert_never if sys.version_info < (3, 10): import importlib_metadata diff --git a/scripts/datasets/process_nuscenes_masks.py b/scripts/datasets/process_nuscenes_masks.py index c86baec03..07b5f5e99 100644 --- a/scripts/datasets/process_nuscenes_masks.py +++ b/scripts/datasets/process_nuscenes_masks.py @@ -1,7 +1,7 @@ import os from dataclasses import dataclass from pathlib import Path -from typing import Tuple +from typing import Literal, Tuple import cv2 import numpy as np @@ -10,7 +10,6 @@ from nuscenes.nuscenes import NuScenes as NuScenesDatabase from nuscenes.utils.data_classes import Box from nuscenes.utils.geometry_utils import BoxVisibility, view_points from tqdm import tqdm -from typing_extensions import Literal @dataclass diff --git a/scripts/render.py b/scripts/render.py index 214c5612a..4549a9bdd 100644 --- a/scripts/render.py +++ b/scripts/render.py @@ -11,7 +11,7 @@ import sys from contextlib import ExitStack from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Literal, Optional import mediapy as media import numpy as np @@ -29,7 +29,7 @@ from rich.progress import ( ) from rich.table import Table from torchtyping import TensorType -from typing_extensions import Literal, assert_never +from typing_extensions import assert_never from nerfstudio.cameras.camera_paths import ( get_interpolated_camera_path, diff --git a/scripts/texture.py b/scripts/texture.py index eeb1848cf..2dfbd679b 100644 --- a/scripts/texture.py +++ b/scripts/texture.py @@ -6,11 +6,10 @@ from __future__ import annotations from dataclasses import dataclass from pathlib import Path -from typing import Optional +from typing import Literal, Optional import tyro from rich.console import Console -from typing_extensions import Literal from nerfstudio.exporter import texture_utils from nerfstudio.exporter.exporter_utils import get_mesh_from_filename