mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 13:59:10 +08:00
updating metrics logging (#460)
* integrated changes * update * stratified * black * bump version * upgrade version * improved wandb logging * fix split for eval * comments
This commit is contained in:
1 parent
4c1e443a41
commit
e22eab8c86
22 files changed
+300
-219
No files matched your search
@@ -31,6 +31,7 @@ from nerfactory.configs import base as cfg
|
||||
from nerfactory.datamanagers.dataloaders import (
|
||||
CacheImageDataloader,
|
||||
FixedIndicesEvalDataloader,
|
||||
RandIndicesEvalDataloader,
|
||||
)
|
||||
from nerfactory.datamanagers.datasets import InputDataset
|
||||
from nerfactory.datamanagers.pixel_sampler import PixelSampler
|
||||
@@ -163,7 +164,7 @@ class DataManager(nn.Module):
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def next_train(self) -> Tuple:
|
||||
def next_train(self, step: int) -> Tuple:
|
||||
"""Returns the next batch of data from the train data manager.
|
||||
|
||||
This will be a tuple of all the information that this data manager outputs.
|
||||
@@ -171,13 +172,18 @@ class DataManager(nn.Module):
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def next_eval(self) -> Tuple:
|
||||
def next_eval(self, step: int) -> Tuple:
|
||||
"""Returns the next batch of data from the eval data manager.
|
||||
|
||||
This will be a tuple of all the information that this data manager outputs.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def next_eval_image(self, step: int) -> Tuple:
|
||||
"""Returns the next eval image."""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_training_callbacks( # pylint:disable=no-self-use
|
||||
self, training_callback_attributes: TrainingCallbackAttributes # pylint: disable=unused-argument
|
||||
) -> List[TrainingCallback]:
|
||||
@@ -285,15 +291,22 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
|
||||
self.eval_pixel_sampler = PixelSampler(self.config.eval_num_rays_per_batch)
|
||||
self.eval_ray_generator = RayGenerator(self.eval_input_dataset.dataset_inputs.cameras.to(self.device))
|
||||
# for loading full images
|
||||
self.eval_dataloader = FixedIndicesEvalDataloader(
|
||||
self.fixed_indices_eval_dataloader = FixedIndicesEvalDataloader(
|
||||
input_dataset=self.eval_input_dataset,
|
||||
device=self.device,
|
||||
num_workers=0 if self.world_size == 1 else self.world_size * 4,
|
||||
)
|
||||
self.eval_dataloader = RandIndicesEvalDataloader(
|
||||
input_dataset=self.eval_input_dataset,
|
||||
num_rays_per_chunk=self.config.eval_num_rays_per_chunk,
|
||||
image_indices=self.config.eval_image_indices,
|
||||
device=self.device,
|
||||
num_workers=0 if self.world_size == 1 else self.world_size * 4,
|
||||
)
|
||||
|
||||
def next_train(self) -> Tuple[RayBundle, Dict]:
|
||||
# TODO: eval dataloader should be separate from train
|
||||
self.iter_eval_dataloader = iter(self.eval_image_dataloader)
|
||||
|
||||
def next_train(self, step: int) -> Tuple[RayBundle, Dict]:
|
||||
"""Returns the next batch of data from the train dataloader."""
|
||||
self.train_count += 1
|
||||
image_batch = next(self.iter_train_image_dataloader)
|
||||
@@ -302,7 +315,7 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
|
||||
ray_bundle = self.train_ray_generator(ray_indices)
|
||||
return ray_bundle, batch
|
||||
|
||||
def next_eval(self) -> Tuple[RayBundle, Dict]:
|
||||
def next_eval(self, step: int) -> Tuple[RayBundle, Dict]:
|
||||
"""Returns the next batch of data from the eval dataloader."""
|
||||
self.eval_count += 1
|
||||
image_batch = next(self.iter_eval_image_dataloader)
|
||||
@@ -310,3 +323,8 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
|
||||
ray_indices = batch["indices"]
|
||||
ray_bundle = self.eval_ray_generator(ray_indices)
|
||||
return ray_bundle, batch
|
||||
|
||||
def next_eval_image(self, step: int) -> Tuple[int, RayBundle, Dict]:
|
||||
for camera_ray_bundle, batch in self.eval_dataloader:
|
||||
image_idx = int(camera_ray_bundle.camera_indices[0, 0])
|
||||
return image_idx, camera_ray_bundle, batch
|
||||
@@ -104,20 +104,17 @@ class EvalDataloader(DataLoader):
|
||||
|
||||
Args:
|
||||
input_dataset: InputDataset to load data from
|
||||
num_rays_per_chunk: Number of camera rays to generate per chunk
|
||||
device: Device to load data to
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
input_dataset: InputDataset,
|
||||
num_rays_per_chunk: int,
|
||||
device: Union[torch.device, str] = "cpu",
|
||||
**kwargs,
|
||||
):
|
||||
self.input_dataset = input_dataset
|
||||
self.cameras = input_dataset.dataset_inputs.cameras.to(device)
|
||||
self.num_rays_per_chunk = num_rays_per_chunk
|
||||
self.device = device
|
||||
self.kwargs = kwargs
|
||||
super().__init__(dataset=input_dataset)
|
||||
@@ -159,7 +156,6 @@ class EvalDataloader(DataLoader):
|
||||
image_idx: Camera image index
|
||||
"""
|
||||
ray_bundle = self.cameras.generate_rays(camera_indices=image_idx)
|
||||
ray_bundle.num_rays_per_chunk = self.num_rays_per_chunk
|
||||
ray_bundle.camera_indices = torch.Tensor([image_idx])[..., None].int()
|
||||
batch = self.input_dataset[image_idx]
|
||||
batch = get_dict_to_torch(batch, device=self.device, exclude=["image"])
|
||||
@@ -171,7 +167,6 @@ class FixedIndicesEvalDataloader(EvalDataloader):
|
||||
|
||||
Args:
|
||||
input_dataset: InputDataset to load data from
|
||||
num_rays_per_chunk: Number of camera rays to generate per chunk
|
||||
image_indices: List of image indices to load data from. If None, then use all images.
|
||||
device: Device to load data to
|
||||
"""
|
||||
@@ -179,17 +174,15 @@ class FixedIndicesEvalDataloader(EvalDataloader):
|
||||
def __init__(
|
||||
self,
|
||||
input_dataset: InputDataset,
|
||||
num_rays_per_chunk: int,
|
||||
image_indices: Optional[Tuple[int]] = None,
|
||||
device: Union[torch.device, str] = "cpu",
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(input_dataset, num_rays_per_chunk, device, **kwargs)
|
||||
super().__init__(input_dataset, device, **kwargs)
|
||||
if image_indices is None:
|
||||
self.image_indices = list(range(len(input_dataset)))
|
||||
else:
|
||||
self.image_indices = image_indices
|
||||
self.num_rays_per_chunk = num_rays_per_chunk
|
||||
self.count = 0
|
||||
|
||||
def __iter__(self):
|
||||
@@ -200,7 +193,6 @@ class FixedIndicesEvalDataloader(EvalDataloader):
|
||||
if self.count < len(self.image_indices):
|
||||
image_idx = self.image_indices[self.count]
|
||||
ray_bundle, batch = self.get_data_from_image_idx(image_idx)
|
||||
ray_bundle.num_rays_per_chunk = self.num_rays_per_chunk
|
||||
self.count += 1
|
||||
return ray_bundle, batch
|
||||
raise StopIteration
|
||||
@@ -211,18 +203,16 @@ class RandIndicesEvalDataloader(EvalDataloader):
|
||||
|
||||
Args:
|
||||
input_dataset: InputDataset to load data from
|
||||
num_rays_per_chunk: Number of camera rays to generate per chunk
|
||||
device: Device to load data to
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
input_dataset: InputDataset,
|
||||
num_rays_per_chunk: int,
|
||||
device: Union[torch.device, str] = "cpu",
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(input_dataset, num_rays_per_chunk, device, **kwargs)
|
||||
super().__init__(input_dataset, device, **kwargs)
|
||||
self.count = 0
|
||||
|
||||
def __iter__(self):
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import math
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
@@ -62,6 +63,27 @@ class Nerfactory(DataParser):
|
||||
No image files found.
|
||||
You should check the file_paths in the transforms.json file to make sure they are correct.
|
||||
"""
|
||||
|
||||
# filter image_filenames and poses based on train/eval split percentage
|
||||
num_images = len(image_filenames)
|
||||
num_train_images = math.ceil(num_images * self.config.train_split_percentage)
|
||||
num_eval_images = num_images - num_train_images
|
||||
i_all = np.arange(num_images)
|
||||
i_train = np.linspace(
|
||||
0, num_images - 1, num_train_images, dtype=int
|
||||
) # equally spaced training images starting and ending at 0 and num_images-1
|
||||
i_eval = np.setdiff1d(i_all, i_train) # eval images are the remaining images
|
||||
assert len(i_eval) == num_eval_images
|
||||
if split == "train":
|
||||
indices = i_train
|
||||
elif split == "val" or split == "test":
|
||||
indices = i_eval
|
||||
else:
|
||||
raise ValueError(f"Unknown dataparser split {split}")
|
||||
|
||||
image_filenames = [image_filenames[i] for i in indices]
|
||||
poses = [poses[i] for i in indices]
|
||||
|
||||
poses = torch.from_numpy(np.array(poses).astype(np.float32))
|
||||
poses = camera_utils.auto_orient_poses(poses, method=self.config.orientation_method)
|
||||
|
||||
|
||||
Reference in new issue
Block a user