mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 21:39:06 +08:00
feat(fields): Improve Type Hints (#1524)
* feat(fields/tensorf_fields): Improve Type Hints * feat(fields/base_field): Improve Type Hints * feat(fields/density_fields): Improve Type Hints * feat(fields/instant_ngp_field): Improve Type Hints * feat(fields/nerfacto_field): Improve Type Hints * feat(fields/nerplayer_nerfacto_field): Improve Type Hints * fix(fields/nerplayer_nerfacto_field): add typing imports * feat(fields/nerfplayer_ngp_field): Improve Type Hints * feat(fields/nerfw_field): Improve Type Hints * feat(fields/semantic_nerf_field): Improve Type Hints * feat(fields/vanilla_nerf_field): Improve Type Hints * fix(fields/nerfplayer/nerfacto_field): reorder imports * fix(feilds): str -> FieldHeadNames * fix: remove Optionals * fix: add missing comma
This commit is contained in:
1 parent
edb54602da
commit
258ee26983
10 files changed
+60
-53
No files matched your search
@@ -55,7 +55,7 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def get_normalized_directions(directions: TensorType["bs":..., 3]):
|
||||
def get_normalized_directions(directions: TensorType["bs":..., 3]) -> TensorType["bs":..., 3]:
|
||||
"""SH encoding must be in the range [0, 1]
|
||||
|
||||
Args:
|
||||
@@ -92,7 +92,7 @@ class TCNNNerfactoField(Field):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
aabb,
|
||||
aabb: TensorType,
|
||||
num_images: int,
|
||||
num_layers: int = 2,
|
||||
hidden_dim: int = 64,
|
||||
@@ -112,7 +112,7 @@ class TCNNNerfactoField(Field):
|
||||
pass_semantic_gradients: bool = False,
|
||||
use_pred_normals: bool = False,
|
||||
use_average_appearance_embedding: bool = False,
|
||||
spatial_distortion: Optional[SpatialDistortion] = None,
|
||||
spatial_distortion: SpatialDistortion = None,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
|
||||
@@ -133,8 +133,8 @@ class TCNNNerfactoField(Field):
|
||||
self.use_pred_normals = use_pred_normals
|
||||
self.pass_semantic_gradients = pass_semantic_gradients
|
||||
|
||||
base_res = 16
|
||||
features_per_level = 2
|
||||
base_res: int = 16
|
||||
features_per_level: int = 2
|
||||
growth_factor = np.exp((np.log(max_res) - np.log(base_res)) / (num_levels - 1))
|
||||
|
||||
self.direction_encoding = tcnn.Encoding(
|
||||
@@ -233,7 +233,7 @@ class TCNNNerfactoField(Field):
|
||||
},
|
||||
)
|
||||
|
||||
def get_density(self, ray_samples: RaySamples):
|
||||
def get_density(self, ray_samples: RaySamples) -> Tuple[TensorType, TensorType]:
|
||||
"""Computes and returns the densities."""
|
||||
if self.spatial_distortion is not None:
|
||||
positions = ray_samples.frustums.get_positions()
|
||||
@@ -259,7 +259,9 @@ class TCNNNerfactoField(Field):
|
||||
density = density * selector[..., None]
|
||||
return density, base_mlp_out
|
||||
|
||||
def get_outputs(self, ray_samples: RaySamples, density_embedding: Optional[TensorType] = None):
|
||||
def get_outputs(
|
||||
self, ray_samples: RaySamples, density_embedding: Optional[TensorType] = None
|
||||
) -> Dict[FieldHeadNames, TensorType]:
|
||||
assert density_embedding is not None
|
||||
outputs = {}
|
||||
if ray_samples.camera_indices is None:
|
||||
@@ -339,7 +341,7 @@ class TorchNerfactoField(Field):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
aabb,
|
||||
aabb: TensorType,
|
||||
num_images: int,
|
||||
position_encoding: Encoding = HashEncoding(),
|
||||
direction_encoding: Encoding = SHEncoding(),
|
||||
@@ -382,7 +384,7 @@ class TorchNerfactoField(Field):
|
||||
for field_head in self.field_heads:
|
||||
field_head.set_in_dim(self.mlp_head.get_out_dim()) # type: ignore
|
||||
|
||||
def get_density(self, ray_samples: RaySamples):
|
||||
def get_density(self, ray_samples: RaySamples) -> Tuple[TensorType, TensorType]:
|
||||
if self.spatial_distortion is not None:
|
||||
positions = ray_samples.frustums.get_positions()
|
||||
positions = self.spatial_distortion(positions)
|
||||
@@ -396,7 +398,6 @@ class TorchNerfactoField(Field):
|
||||
def get_outputs(
|
||||
self, ray_samples: RaySamples, density_embedding: Optional[TensorType] = None
|
||||
) -> Dict[FieldHeadNames, TensorType]:
|
||||
|
||||
outputs_shape = ray_samples.frustums.directions.shape[:-1]
|
||||
|
||||
if ray_samples.camera_indices is None:
|
||||
@@ -427,4 +428,4 @@ class TorchNerfactoField(Field):
|
||||
return outputs
|
||||
|
||||
|
||||
field_implementation_to_class = {"tcnn": TCNNNerfactoField, "torch": TorchNerfactoField}
|
||||
field_implementation_to_class: Dict[str, Field] = {"tcnn": TCNNNerfactoField, "torch": TorchNerfactoField}
|
||||
Reference in new issue
Block a user