mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 15:59:16 +08:00
Setting near and far with scene bounds collider. Also LR schedules. (#74)
* some initial cuda code as I learn. using git to save progress. * first cuda kernel for ray sampling that mostly works * cleaning up code. working on lr. structs for scene bounds aabb * added scene bounds collider code * updated setup * setup * setup * black * including some files * exporting env variable * new file * git workflows * github actions * github actions * github actions * removing env var
This commit is contained in:
1 parent
752df417ce
commit
676beebb14
45 files changed
+803
-8354
No files matched your search
Whitespace-only changes.
@@ -10,7 +10,7 @@ import numpy as np
|
||||
import torch
|
||||
from torchtyping import TensorType
|
||||
|
||||
from mattport.nerf.dataset.structs import DatasetInputs
|
||||
from mattport.nerf.dataset.structs import DatasetInputs, SceneBounds
|
||||
from mattport.utils.io import load_from_json
|
||||
|
||||
|
||||
@@ -53,12 +53,15 @@ def load_blender_data(
|
||||
intrinsics = torch.ones((num_cameras, num_intrinsics_params), dtype=torch.float32)
|
||||
intrinsics *= torch.tensor([cx, cy, focal_length])
|
||||
|
||||
scene_bounds = SceneBounds(aabb=torch.tensor([[-1, -1, -1], [1, 1, 1]], dtype=torch.float32))
|
||||
|
||||
dataset_inputs = DatasetInputs(
|
||||
image_filenames=image_filenames,
|
||||
downscale_factor=downscale_factor,
|
||||
alpha_color=alpha_color,
|
||||
intrinsics=intrinsics * 1.0 / downscale_factor, # downscaling the intrinsics here
|
||||
camera_to_world=camera_to_world,
|
||||
scene_bounds=scene_bounds,
|
||||
)
|
||||
|
||||
return dataset_inputs
|
||||
File renamed without changes.
@@ -0,0 +1,4 @@
|
||||
"""
|
||||
Code for loading instant-ngp dataset formats.
|
||||
# TODO
|
||||
"""
|
||||
File renamed without changes.
@@ -27,6 +27,17 @@ class Semantics:
|
||||
thing_filenames: List[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class SceneBounds:
|
||||
"""Data to represent the scene bounds.
|
||||
|
||||
aabb: axis-aligned bounding box
|
||||
aabb[0] is the minimum (x,y,z) point. aabb[1] is the maximum (x,y,z) point.
|
||||
"""
|
||||
|
||||
aabb: TensorType[2, 3] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class DatasetInputs:
|
||||
"""Dataset inputs for the image dataset and the ray generator.
|
||||
@@ -40,9 +51,9 @@ class DatasetInputs:
|
||||
downscale_factor: int = 1
|
||||
intrinsics: torch.tensor = None
|
||||
camera_to_world: torch.tensor = None
|
||||
bounding_box: torch.tensor = None
|
||||
mask_filenames: List[str] = None
|
||||
depth_filenames: List[str] = None
|
||||
scene_bounds: SceneBounds = SceneBounds()
|
||||
semantics: Semantics = Semantics()
|
||||
point_cloud: PointCloud = PointCloud()
|
||||
alpha_color: Optional[TensorType[3]] = None
|
||||
|
||||
@@ -2,38 +2,37 @@
|
||||
For loading the blender dataset format.
|
||||
"""
|
||||
|
||||
from typing import Dict, Optional, Tuple, Union
|
||||
from typing import Optional, Union
|
||||
|
||||
from omegaconf import ListConfig
|
||||
|
||||
from mattport.nerf.dataset.blender import load_blender_data
|
||||
from mattport.nerf.dataset.friends import load_friends_data
|
||||
from mattport.nerf.dataset.format.blender import load_blender_data
|
||||
from mattport.nerf.dataset.format.friends import load_friends_data
|
||||
from mattport.nerf.dataset.structs import DatasetInputs
|
||||
from mattport.structures.colors import get_color
|
||||
from mattport.utils.io import get_absolute_path
|
||||
|
||||
|
||||
def get_dataset_inputs_dict(
|
||||
def get_dataset_inputs(
|
||||
data_directory: str,
|
||||
dataset_type: str,
|
||||
dataset_format: str,
|
||||
split: str,
|
||||
downscale_factor: int = 1,
|
||||
alpha_color: Optional[Union[str, list, ListConfig]] = None,
|
||||
splits: Tuple[str] = ("train", "val"),
|
||||
load_dataset_inputs_from_cache: bool = False,
|
||||
) -> Dict[str, DatasetInputs]:
|
||||
) -> DatasetInputs:
|
||||
"""Returns the dataset inputs, which will be used with an ImageDataset and RayGenerator.
|
||||
# TODO: implement the `test` split, which will have depths and normals, etc.
|
||||
|
||||
Args:
|
||||
data_directory (str): Location of data
|
||||
dataset_type (str): Name of dataset type
|
||||
dataset_format (str): Name of dataset type
|
||||
downscale_factor (int, optional): How much to downscale images. Defaults to 1.0.
|
||||
alpha_color (str, list, optional): Sets transparent regions to specified color, otherwise black.
|
||||
load_from_cache (bool)
|
||||
Returns:
|
||||
Dict[str, DatasetInputs]: The inputs needed for generating rays.
|
||||
DatasetInputs: The inputs needed for generating rays.
|
||||
"""
|
||||
dataset_inputs_dict = {}
|
||||
|
||||
if load_dataset_inputs_from_cache:
|
||||
print("Loading from cache.")
|
||||
@@ -42,16 +41,14 @@ def get_dataset_inputs_dict(
|
||||
if alpha_color is not None:
|
||||
alpha_color = get_color(alpha_color)
|
||||
|
||||
if dataset_type == "blender":
|
||||
for split in splits:
|
||||
dataset_inputs = load_blender_data(
|
||||
get_absolute_path(data_directory),
|
||||
downscale_factor=downscale_factor,
|
||||
split=split,
|
||||
alpha_color=alpha_color,
|
||||
)
|
||||
dataset_inputs_dict[split] = dataset_inputs
|
||||
elif dataset_type == "friends":
|
||||
if dataset_format == "blender":
|
||||
dataset_inputs = load_blender_data(
|
||||
get_absolute_path(data_directory),
|
||||
downscale_factor=downscale_factor,
|
||||
split=split,
|
||||
alpha_color=alpha_color,
|
||||
)
|
||||
elif dataset_format == "friends":
|
||||
# TODO(ethan): change this hack, and do proper splits for the friends dataset
|
||||
# currently we assume that there is only the training set of images
|
||||
dataset_inputs = load_friends_data(
|
||||
@@ -60,15 +57,7 @@ def get_dataset_inputs_dict(
|
||||
split="train",
|
||||
include_point_cloud=False,
|
||||
)
|
||||
for split in splits:
|
||||
dataset_inputs_dict[split] = dataset_inputs
|
||||
else:
|
||||
raise NotImplementedError(f"{dataset_type} is not a valid dataset type")
|
||||
raise NotImplementedError(f"{dataset_format} is not a valid dataset type")
|
||||
|
||||
for split in splits:
|
||||
# save the dataset inputs to cache
|
||||
# TODO:
|
||||
# dataset_inputs_dict[splits].save_to_folder_name()
|
||||
pass
|
||||
|
||||
return dataset_inputs_dict
|
||||
return dataset_inputs
|
||||
Reference in new issue
Block a user