mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-24 00:26:08 +08:00
Add support for Project Aria datasets. (#2617)
* Add support for Project Aria datasets. 1) An export script for processing Project Aria datasets 2) Add support for Fisheye624 cameras 3) Add support for center-crop masking and sampling Example commands for running nerfstudio on Project Aria data: python scripts/datasets/process_project_aria.py --vrs_file=<path_to_vrs> --mps_data_dir=<path to MPS directory> --output_dir=<nerfstudio_data_dir> ns-train nerfacto --data <nerfstudio_data_dir> nerfstudio-data --orientation-method none * Clean up type errors * Fix formatting * Fix linter errors, import, and use absolute file paths * Add aria subcommand to ns-process-data * Appease ruff * Add Aria to docs * Fix docs, add back import try/except * nit: path.as_posix() -> str(path) --------- Co-authored-by: Brent Yi <yibrenth@gmail.com>
This commit is contained in:
1 parent
01d57b90dc
commit
6ccbc2de45
10 files changed
+634
-40
No files matched your search
@@ -47,6 +47,8 @@ class PixelSamplerConfig(InstantiateConfig):
|
||||
"""Whether or not to include a reference to the full image in returned batch."""
|
||||
is_equirectangular: bool = False
|
||||
"""List of whether or not camera i is equirectangular."""
|
||||
fisheye_crop_radius: Optional[float] = None
|
||||
"""Set to the radius (in pixels) for fisheye cameras."""
|
||||
|
||||
|
||||
class PixelSampler:
|
||||
@@ -65,6 +67,7 @@ class PixelSampler:
|
||||
self.config.num_rays_per_batch = self.kwargs.get("num_rays_per_batch", self.config.num_rays_per_batch)
|
||||
self.config.keep_full_image = self.kwargs.get("keep_full_image", self.config.keep_full_image)
|
||||
self.config.is_equirectangular = self.kwargs.get("is_equirectangular", self.config.is_equirectangular)
|
||||
self.config.fisheye_crop_radius = self.kwargs.get("fisheye_crop_radius", self.config.fisheye_crop_radius)
|
||||
self.set_num_rays_per_batch(self.config.num_rays_per_batch)
|
||||
|
||||
def set_num_rays_per_batch(self, num_rays_per_batch: int):
|
||||
@@ -134,6 +137,36 @@ class PixelSampler:
|
||||
|
||||
return indices
|
||||
|
||||
def sample_method_fisheye(
|
||||
self,
|
||||
batch_size: int,
|
||||
num_images: int,
|
||||
image_height: int,
|
||||
image_width: int,
|
||||
mask: Optional[Tensor] = None,
|
||||
device: Union[torch.device, str] = "cpu",
|
||||
) -> Int[Tensor, "batch_size 3"]:
|
||||
if isinstance(mask, torch.Tensor):
|
||||
indices = self.sample_method(batch_size, num_images, image_height, image_width, mask=mask, device=device)
|
||||
else:
|
||||
rand_samples = torch.rand((batch_size, 3), device=device)
|
||||
# convert random samples tto radius and theta
|
||||
radii = self.config.fisheye_crop_radius * torch.sqrt(rand_samples[:, 1])
|
||||
theta = 2.0 * torch.pi * rand_samples[:, 2]
|
||||
|
||||
# convert radius and theta to x and y between -radii and radii
|
||||
x = radii * torch.cos(theta)
|
||||
y = radii * torch.sin(theta)
|
||||
|
||||
# Multiply by the batch size and height/width to get pixel indices.
|
||||
indices = torch.floor(
|
||||
torch.stack([rand_samples[:, 0], y, x], dim=1)
|
||||
* torch.tensor([num_images, image_height // 2, image_width // 2], device=device)
|
||||
+ torch.tensor([0, image_height // 2, image_width // 2], device=device)
|
||||
).long()
|
||||
|
||||
return indices
|
||||
|
||||
def collate_image_dataset_batch(self, batch: Dict, num_rays_per_batch: int, keep_full_image: bool = False):
|
||||
"""
|
||||
Operates on a batch of images and samples pixels to use for generating rays.
|
||||
@@ -154,6 +187,10 @@ class PixelSampler:
|
||||
indices = self.sample_method_equirectangular(
|
||||
num_rays_per_batch, num_images, image_height, image_width, mask=batch["mask"], device=device
|
||||
)
|
||||
elif self.config.fisheye_crop_radius is not None:
|
||||
indices = self.sample_method_fisheye(
|
||||
num_rays_per_batch, num_images, image_height, image_width, mask=batch["mask"], device=device
|
||||
)
|
||||
else:
|
||||
indices = self.sample_method(
|
||||
num_rays_per_batch, num_images, image_height, image_width, mask=batch["mask"], device=device
|
||||
@@ -163,6 +200,10 @@ class PixelSampler:
|
||||
indices = self.sample_method_equirectangular(
|
||||
num_rays_per_batch, num_images, image_height, image_width, device=device
|
||||
)
|
||||
elif self.config.fisheye_crop_radius is not None:
|
||||
indices = self.sample_method_fisheye(
|
||||
num_rays_per_batch, num_images, image_height, image_width, device=device
|
||||
)
|
||||
else:
|
||||
indices = self.sample_method(num_rays_per_batch, num_images, image_height, image_width, device=device)
|
||||
|
||||
|
||||
Reference in new issue
Block a user