Shortcuts

nerfacc.unpack_data

nerfacc.unpack_data(packed_info, data, n_samples=None, pad_value=0.0)

Unpack packed data (all_samples, D) to per-ray data (n_rays, n_samples, D).

Parameters:
  • packed_info (Tensor) – Stores information on which samples belong to the same ray. See nerfacc.ray_marching() for details. Tensor with shape (n_rays, 2).

  • data (Tensor) – Packed data to unpack. Tensor with shape (n_samples, D).

  • n_samples (int) – Optional Number of samples per ray. If not provided, it will be inferred from the packed_info.

  • pad_value (float) – Value to pad the unpacked data.

Returns:

Unpacked data (n_rays, n_samples, D).

Return type:

Tensor

Examples:

rays_o = torch.rand((128, 3), device="cuda:0")
rays_d = torch.randn((128, 3), device="cuda:0")
rays_d = rays_d / rays_d.norm(dim=-1, keepdim=True)

# Ray marching with aabb.
scene_aabb = torch.tensor([0.0, 0.0, 0.0, 1.0, 1.0, 1.0], device="cuda:0")
packed_info, t_starts, t_ends = ray_marching(
    rays_o, rays_d, scene_aabb=scene_aabb, render_step_size=1e-2
)
print(t_starts.shape)  # torch.Size([all_samples, 1])

t_starts = unpack_data(packed_info, t_starts, n_samples=1024)
print(t_starts.shape)  # torch.Size([128, 1024, 1])