Refactoring (data loading, semantic-nerf/nerf-w fixes, ...) (#8)

* in progress. camera_indices broken

* faster dataloader. starting on pixel sampler logic

* imagesampler and pixelsampler

* lint and black

* continuing merge

* pytest working

* fixed docs

* docs

* minor changes
This commit is contained in:
Ethan Weber authored and GitHub committed 2022-06-02 14:58:46 -04:00
1 parent 1f189b3e54
commit 146332cfb6
50 files changed
+914 -831

No files matched your search

+35 -8
View File
@@ -1,7 +1,8 @@
"""
For loading the blender dataset format.
Code for loading the dataset inputs and for caching the data for fast loading.
"""
import logging
from typing import Optional, Union
from omegaconf import ListConfig
@@ -11,7 +12,30 @@ from pyrad.nerf.dataset.format.friends import load_friends_data
from pyrad.nerf.dataset.format.instant_ngp import load_instant_ngp_data
from pyrad.nerf.dataset.structs import DatasetInputs
from pyrad.structures.colors import get_color
from pyrad.utils.io import get_absolute_path
from pyrad.utils.io import get_absolute_path, load_from_pkl, make_dir, write_to_pkl
from pyrad.utils.misc import get_hash_str_from_dict
def get_cache_filename_from_kwargs(kwargs: dict, split: str):
"""Creates a cache filename from the dataset inputs arguments."""
dataset_config_hash = get_hash_str_from_dict(kwargs)
dataset_config_hash_filename = make_dir(
get_absolute_path(f"cache/dataset_inputs/{dataset_config_hash}-{split}.pkl")
)
return dataset_config_hash_filename
def save_dataset_inputs_kwargs_to_cache(kwargs: dict, split: str):
"""Saves the dataset inputs to cache."""
dataset_inputs = get_dataset_inputs(**kwargs, split=split)
dataset_config_hash_filename = get_cache_filename_from_kwargs(kwargs, split)
write_to_pkl(dataset_config_hash_filename, dataset_inputs)
def get_dataset_inputs_from_cache(kwargs: dict, split: str):
"""Loads the dataset inputs from cache."""
dataset_config_hash_filename = get_cache_filename_from_kwargs(kwargs, split)
return load_from_pkl(dataset_config_hash_filename)
def get_dataset_inputs(
@@ -20,10 +44,8 @@ def get_dataset_inputs(
split: str,
downscale_factor: int = 1,
alpha_color: Optional[Union[str, list, ListConfig]] = None,
load_dataset_inputs_from_cache: bool = False,
) -> 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
@@ -35,10 +57,6 @@ def get_dataset_inputs(
DatasetInputs: The inputs needed for generating rays.
"""
if load_dataset_inputs_from_cache:
print("Loading from cache.")
return None
if alpha_color is not None:
alpha_color = get_color(alpha_color)
@@ -68,3 +86,12 @@ def get_dataset_inputs(
raise NotImplementedError(f"{dataset_format} is not a valid dataset type")
return dataset_inputs
def get_dataset_inputs_from_dataset_config(*, split: str, use_cache: bool = False, **kwargs):
"""This may optionally use the cache to return the dataset inputs."""
if use_cache:
logging.info("Loading from cache! Be careful with using this when making changes!")
print(kwargs)
return get_dataset_inputs_from_cache(kwargs, split)
return get_dataset_inputs(**kwargs, split=split)