mmagic.models.editors.eg3d.eg3d_utils
¶
Module Contents¶
Functions¶
|
Author: Petr Kellnhofer |
|
Sample N_importance samples from bins with distribution defined by |
|
Creates a tensor of shape [num, *start.shape] whose values are evenly |
- mmagic.models.editors.eg3d.eg3d_utils.get_ray_limits_box(rays_o: torch.Tensor, rays_d: torch.Tensor, box_side_length: float) Tuple[torch.Tensor, torch.Tensor] [source]¶
Author: Petr Kellnhofer Intersects rays with the [-1, 1] NDC volume. Returns min and max distance of entry. Returns -1 for no intersection. https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection # noqa
- Parameters
rays_o (torch.Tensor) – The origin of each ray.
rays_d (torch.Tensor) – The direction vector of each ray.
box_side_length (float) – The side length of axis aligned bounding box (AABB).
- Returns
- Start and end point
for each ray. Both shape like (bz, res, res, 1).
- Return type
Tuple[torch.Tensor, torch.Tensor]
- mmagic.models.editors.eg3d.eg3d_utils.inverse_transform_sampling(bins: torch.Tensor, weights: torch.Tensor, n_importance: int, deterministic: bool = False, eps: float = 1e-05) torch.Tensor [source]¶
Sample N_importance samples from bins with distribution defined by weights.
- Parameters
bins (int) – (N_points, N_samples+1) where N_samples is the number of coarse samples per ray - 2.
weights (torch.Tensor) – Weights shape like (N_points, N_samples-1).
n_importance (int) – The number of samples to draw from the distribution.
deterministic (bool) – Whether use deterministic sampling method. Defaults to False.
eps (float) – a small number to prevent division by zero. Defaults to 1e-5.
- Outputs:
torch.Tensor: the sampled samples.
- mmagic.models.editors.eg3d.eg3d_utils.linspace_batch(start: torch.Tensor, stop: torch.Tensor, num: int) torch.Tensor [source]¶
Creates a tensor of shape [num, *start.shape] whose values are evenly spaced from start to end, inclusive.
Replicates but the multi-dimensional behaviour of numpy.linspace in PyTorch.
- Parameters
start (torch.Tensor) – The start point of each ray. Shape like (bz, res, res, 1).
stop (torch.Tensor) – The end point of each ray. Shape like (bz, res, res, 1).
num (int) – The number of points to sample.
- Returns
The sampled points. Shape like (num, bz, res, res, 1)
- Return type
torch.Tensor