mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 06:18:44 +08:00
More typing fixes (#1941)
* Fix more types * Fix tests * Minor cleaning * Address comments * Resolve linting errors * Re-ignore pymeshlab type * Add extra assert / error message to mipnerf model
This commit is contained in:
1 parent
8b9574bb5a
commit
814db32ec4
53 files changed
+386
-205
No files matched your search
@@ -30,7 +30,7 @@ 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
|
||||
from nerfstudio.engine.optimizers import AdamOptimizerConfig
|
||||
from nerfstudio.engine.optimizers import AdamOptimizerConfig, OptimizerConfig
|
||||
from nerfstudio.engine.schedulers import (
|
||||
ExponentialDecaySchedulerConfig,
|
||||
SchedulerConfig,
|
||||
@@ -53,7 +53,7 @@ class CameraOptimizerConfig(InstantiateConfig):
|
||||
orientation_noise_std: float = 0.0
|
||||
"""Noise to add to initial orientations. Useful for debugging."""
|
||||
|
||||
optimizer: AdamOptimizerConfig = AdamOptimizerConfig(lr=6e-4, eps=1e-15)
|
||||
optimizer: OptimizerConfig = AdamOptimizerConfig(lr=6e-4, eps=1e-15)
|
||||
"""ADAM parameters for camera optimization."""
|
||||
|
||||
scheduler: SchedulerConfig = ExponentialDecaySchedulerConfig(max_steps=10000)
|
||||
|
||||
@@ -423,7 +423,7 @@ class Cameras(TensorDataclass):
|
||||
if coords is None:
|
||||
index_dim = camera_indices.shape[-1]
|
||||
index = camera_indices.reshape(-1, index_dim)[0]
|
||||
coords: torch.Tensor = cameras.get_image_coords(index=tuple(index)) # (h, w, 2)
|
||||
coords = cameras.get_image_coords(index=tuple(index)) # (h, w, 2)
|
||||
coords = coords.reshape(coords.shape[:2] + (1,) * len(camera_indices.shape[:-1]) + (2,)) # (h, w, 1..., 2)
|
||||
coords = coords.expand(coords.shape[:2] + camera_indices.shape[:-1] + (2,)) # (h, w, num_rays, 2)
|
||||
camera_opt_to_camera = ( # (h, w, num_rays, 3, 4) or None
|
||||
@@ -766,7 +766,7 @@ class Cameras(TensorDataclass):
|
||||
image_uint8 = torchvision.transforms.functional.resize(image_uint8, max_size) # type: ignore
|
||||
image_uint8 = image_uint8.permute(1, 2, 0)
|
||||
image_uint8 = image_uint8.cpu().numpy()
|
||||
data = cv2.imencode(".jpg", image_uint8)[1].tobytes()
|
||||
data = cv2.imencode(".jpg", image_uint8)[1].tobytes() # type: ignore
|
||||
json_["image"] = str("data:image/jpeg;base64," + base64.b64encode(data).decode("ascii"))
|
||||
return json_
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
Some ray datastructures.
|
||||
"""
|
||||
import random
|
||||
from dataclasses import dataclass
|
||||
from typing import Callable, Dict, Optional, Tuple, Union
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Callable, Dict, Literal, Optional, Tuple, Union, overload
|
||||
|
||||
import torch
|
||||
from jaxtyping import Float, Int, Shaped
|
||||
@@ -149,10 +149,27 @@ class RaySamples(TensorDataclass):
|
||||
|
||||
return weights
|
||||
|
||||
@overload
|
||||
@staticmethod
|
||||
def get_weights_and_transmittance_from_alphas(
|
||||
alphas: Float[Tensor, "*batch num_samples 1"], weights_only: Literal[False] = False
|
||||
) -> Tuple[Float[Tensor, "*batch num_samples 1"], Float[Tensor, "*batch num_samples 1"]]:
|
||||
...
|
||||
|
||||
@overload
|
||||
@staticmethod
|
||||
def get_weights_and_transmittance_from_alphas(
|
||||
alphas: Float[Tensor, "*batch num_samples 1"], weights_only: Literal[True]
|
||||
) -> Tuple[Float[Tensor, "*batch num_samples 1"], Float[Tensor, "*batch num_samples 1"]]:
|
||||
...
|
||||
|
||||
@staticmethod
|
||||
def get_weights_and_transmittance_from_alphas(
|
||||
alphas: Float[Tensor, "*batch num_samples 1"], weights_only: bool = False
|
||||
) -> Tuple[Float[Tensor, "*batch num_samples 1"], Float[Tensor, "*batch num_samples 1"]]:
|
||||
) -> Union[
|
||||
Float[Tensor, "*batch num_samples 1"],
|
||||
Tuple[Float[Tensor, "*batch num_samples 1"], Float[Tensor, "*batch num_samples 1"]],
|
||||
]:
|
||||
"""Return weights based on predicted alphas
|
||||
Args:
|
||||
alphas: Predicted alphas (maybe from sdf) for samples along ray
|
||||
@@ -188,7 +205,7 @@ class RayBundle(TensorDataclass):
|
||||
"""Distance along ray to start sampling"""
|
||||
fars: Optional[Float[Tensor, "*batch 1"]] = None
|
||||
"""Rays Distance along ray to stop sampling"""
|
||||
metadata: Optional[Dict[str, Shaped[Tensor, "num_rays latent_dims"]]] = None
|
||||
metadata: Dict[str, Shaped[Tensor, "num_rays latent_dims"]] = field(default_factory=dict)
|
||||
"""Additional metadata or data needed for interpolation, will mimic shape of rays"""
|
||||
times: Optional[Float[Tensor, "*batch 1"]] = None
|
||||
"""Times at which rays are sampled"""
|
||||
|
||||
Reference in new issue
Block a user