mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-21 15:15:43 +08:00
update docstrings and random cleanups (#387)
* fixing docstrings and small nits; up to fileds * finished adding and fixing docstrings
This commit is contained in:
1 parent
bd5967461d
commit
d50c71ac43
52 files changed
+846
-646
No files matched your search
@@ -27,8 +27,7 @@ class RayGenerator(nn.Module):
|
||||
This class will store the intrinsics and extrinsics parameters of the cameras.
|
||||
|
||||
Args:
|
||||
intrinsics: The intrinsics parameters.
|
||||
camera_to_world: Camera to world transformation matrix.
|
||||
cameras: Camera objects containing camera info
|
||||
"""
|
||||
|
||||
def __init__(self, cameras: Cameras) -> None:
|
||||
|
||||
@@ -23,7 +23,7 @@ from nerfactory.cameras.rays import RaySamples
|
||||
def distortion_loss(
|
||||
ray_samples: RaySamples, densities: TensorType["bs":..., "num_samples", 1]
|
||||
) -> TensorType["bs":..., 1]:
|
||||
"""Ray baserd distortion loss proposed in MipNeRF-360.
|
||||
"""Ray baserd distortion loss proposed in MipNeRF-360. Returns distortion Loss.
|
||||
|
||||
.. math::
|
||||
|
||||
@@ -36,9 +36,6 @@ def distortion_loss(
|
||||
Args:
|
||||
ray_samples: Ray samples to compute loss over
|
||||
densities: Predicted sample densities
|
||||
|
||||
Returns:
|
||||
Distortion Loss.
|
||||
"""
|
||||
|
||||
# Compute the weight at each sample location
|
||||
|
||||
@@ -29,7 +29,12 @@ from nerfactory.fields.density_fields.density_grid import DensityGrid
|
||||
|
||||
|
||||
class Sampler(nn.Module):
|
||||
"""Generate Samples"""
|
||||
"""Generate Samples
|
||||
|
||||
Args:
|
||||
num_samples: number of samples to take
|
||||
density_field: density grid specifying weighting of
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, num_samples: int, density_field: Optional[DensityGrid] = None, weight_threshold: float = 0.01
|
||||
@@ -56,7 +61,16 @@ class Sampler(nn.Module):
|
||||
|
||||
|
||||
class SpacedSampler(Sampler):
|
||||
"""Sample points according to a function."""
|
||||
"""Sample points according to a function.
|
||||
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
spacing_fn: Function that dictates sample spacing (ie `lambda x : x` is uniform).
|
||||
spacing_fn_inv: The inverse of spacing_fn.
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -67,15 +81,6 @@ class SpacedSampler(Sampler):
|
||||
density_field: Optional[DensityGrid] = None,
|
||||
weight_threshold: float = 1e-2,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
spacing_fn: Function that dictates sample spacing (ie `lambda x : x` is uniform).
|
||||
spacing_fn_inv: The inverse of spacing_fn.
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
super().__init__(num_samples=num_samples, density_field=density_field, weight_threshold=weight_threshold)
|
||||
self.train_stratified = train_stratified
|
||||
self.spacing_fn = spacing_fn
|
||||
@@ -121,7 +126,14 @@ class SpacedSampler(Sampler):
|
||||
|
||||
|
||||
class UniformSampler(SpacedSampler):
|
||||
"""Sample uniformly along a ray"""
|
||||
"""Sample uniformly along a ray
|
||||
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -130,13 +142,6 @@ class UniformSampler(SpacedSampler):
|
||||
density_field: Optional[DensityGrid] = None,
|
||||
weight_threshold: float = 1e-2,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
super().__init__(
|
||||
num_samples=num_samples,
|
||||
spacing_fn=lambda x: x,
|
||||
@@ -148,7 +153,14 @@ class UniformSampler(SpacedSampler):
|
||||
|
||||
|
||||
class LinearDisparitySampler(SpacedSampler):
|
||||
"""Sample linearly in disparity along a ray"""
|
||||
"""Sample linearly in disparity along a ray
|
||||
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -157,13 +169,6 @@ class LinearDisparitySampler(SpacedSampler):
|
||||
density_field: Optional[DensityGrid] = None,
|
||||
weight_threshold: float = 1e-2,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
super().__init__(
|
||||
num_samples=num_samples,
|
||||
spacing_fn=lambda x: 1 / x,
|
||||
@@ -175,7 +180,14 @@ class LinearDisparitySampler(SpacedSampler):
|
||||
|
||||
|
||||
class SqrtSampler(SpacedSampler):
|
||||
"""Square root sampler along a ray"""
|
||||
"""Square root sampler along a ray
|
||||
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -184,13 +196,6 @@ class SqrtSampler(SpacedSampler):
|
||||
density_field: Optional[DensityGrid] = None,
|
||||
weight_threshold: float = 1e-2,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
super().__init__(
|
||||
num_samples=num_samples,
|
||||
spacing_fn=torch.sqrt,
|
||||
@@ -202,7 +207,14 @@ class SqrtSampler(SpacedSampler):
|
||||
|
||||
|
||||
class LogSampler(SpacedSampler):
|
||||
"""Log sampler along a ray"""
|
||||
"""Log sampler along a ray
|
||||
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -211,13 +223,6 @@ class LogSampler(SpacedSampler):
|
||||
density_field: Optional[DensityGrid] = None,
|
||||
weight_threshold: float = 1e-2,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Use stratified sampling during training. Defults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
"""
|
||||
super().__init__(
|
||||
num_samples=num_samples,
|
||||
spacing_fn=torch.log,
|
||||
@@ -229,7 +234,16 @@ class LogSampler(SpacedSampler):
|
||||
|
||||
|
||||
class PDFSampler(Sampler):
|
||||
"""Sample based on probability distribution"""
|
||||
"""Sample based on probability distribution
|
||||
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Randomize location within each bin during training. Defaults to True
|
||||
include_original: Add original samples to ray. Defaults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
histogram_padding: Amount to weights prior to computing PDF. Defaults to 0.01.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -240,15 +254,6 @@ class PDFSampler(Sampler):
|
||||
weight_threshold: float = 1e-2,
|
||||
histogram_padding: float = 0.01,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
num_samples: Number of samples per ray
|
||||
train_stratified: Randomize location within each bin during training. Defaults to True
|
||||
include_original: Add original samples to ray. Defaults to True
|
||||
density_field: Density grid. If provides, samples below weight_threshold as set as invalid.
|
||||
weight_threshold: Removes samples below threshold weight. Only used if density field is provided.
|
||||
histogram_padding: Amount to weights prior to computing PDF. Defaults to 0.01.
|
||||
"""
|
||||
super().__init__(num_samples=num_samples, density_field=density_field, weight_threshold=weight_threshold)
|
||||
self.train_stratified = train_stratified
|
||||
self.include_original = include_original
|
||||
|
||||
@@ -39,7 +39,11 @@ class SceneBoundsCollider(nn.Module):
|
||||
|
||||
|
||||
class AABBBoxCollider(SceneBoundsCollider):
|
||||
"""Module for colliding rays with the scene bounds to compute near and far values."""
|
||||
"""Module for colliding rays with the scene bounds to compute near and far values.
|
||||
|
||||
Args:
|
||||
scene_bounds: scene bounds to apply to dataset
|
||||
"""
|
||||
|
||||
def __init__(self, scene_bounds: SceneBounds, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
@@ -49,12 +53,13 @@ class AABBBoxCollider(SceneBoundsCollider):
|
||||
def intersect_with_aabb(
|
||||
cls, rays_o: TensorType["num_rays", 3], rays_d: TensorType["num_rays", 3], aabb: TensorType[2, 3]
|
||||
):
|
||||
"""_summary_
|
||||
"""Returns collection of valid rays within a specified near/far bounding box along with a mask
|
||||
specifying which rays are valid
|
||||
|
||||
Args:
|
||||
rays_o (torch.tensor): (num_rays, 3)
|
||||
rays_d (torch.tensor): (num_rays, 3)
|
||||
aabb (torch.tensor): (2, 3) This is [min point (x,y,z), max point (x,y,z)]
|
||||
rays_o: (num_rays, 3) ray origins
|
||||
rays_d: (num_rays, 3) ray directions
|
||||
aabb: (2, 3) This is [min point (x,y,z), max point (x,y,z)]
|
||||
"""
|
||||
# avoid divide by zero
|
||||
dir_fraction = 1.0 / (rays_d + 1e-6)
|
||||
@@ -87,6 +92,9 @@ class AABBBoxCollider(SceneBoundsCollider):
|
||||
def forward(self, ray_bundle: RayBundle) -> RayBundle:
|
||||
"""Intersects the rays with the scene bounds and updates the near and far values.
|
||||
Populates nears and fars fields and returns the ray_bundle.
|
||||
|
||||
Args:
|
||||
ray_bundle: specified ray bundle to operate on
|
||||
"""
|
||||
aabb = self.scene_bounds.aabb
|
||||
nears, fars, valid_mask = self.intersect_with_aabb(ray_bundle.origins, ray_bundle.directions, aabb)
|
||||
@@ -97,7 +105,12 @@ class AABBBoxCollider(SceneBoundsCollider):
|
||||
|
||||
|
||||
class NearFarCollider(SceneBoundsCollider):
|
||||
"""Sets the nears and fars with fixed values."""
|
||||
"""Sets the nears and fars with fixed values.
|
||||
|
||||
Args:
|
||||
near_plane: distance to near plane
|
||||
far_plane: distance to far plane
|
||||
"""
|
||||
|
||||
def __init__(self, near_plane: float, far_plane: float, **kwargs) -> None:
|
||||
self.near_plane = near_plane
|
||||
|
||||
Reference in new issue
Block a user