mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
pylint and test cases for dataloader
This commit is contained in:
1 parent
391803759e
commit
80ad17700c
10 files changed
+94
-69
No files matched your search
@@ -2,14 +2,15 @@
|
||||
Classes to help with caching data while training.
|
||||
"""
|
||||
|
||||
from typing import Callable
|
||||
import torch
|
||||
import random
|
||||
from typing import Callable
|
||||
|
||||
import torch
|
||||
from torch.utils.data import default_collate
|
||||
|
||||
|
||||
def collate_batch_size_one(batch_list):
|
||||
"""Use the default collate function but then squeze to avoid the batch dimension being added."""
|
||||
assert len(batch_list) == 1
|
||||
collated_batch = default_collate(batch_list)
|
||||
for key in collated_batch:
|
||||
@@ -41,7 +42,11 @@ class CollateIterDataset(torch.utils.data.IterableDataset):
|
||||
self.num_repeated = self.num_times_to_repeat # starting value
|
||||
self.cached_batch_list = None
|
||||
|
||||
def __getitem__(self, idx):
|
||||
return self.dataset.__getitem__(idx)
|
||||
|
||||
def get_batch_list(self):
|
||||
"""Returns a list of batches from the dataset attribute."""
|
||||
# sampling without replacement. TODO(ethan): don't use 'random'
|
||||
indices = random.sample(range(len(self.dataset)), k=self.num_samples_to_collate)
|
||||
batch_list = [self.dataset.__getitem__(idx) for idx in indices]
|
||||
|
||||
@@ -32,9 +32,11 @@ def collate_batch(batch_list, num_rays_per_batch, keep_full_image: bool = False)
|
||||
assert pixels.shape == (num_rays_per_batch, 3), pixels.shape
|
||||
|
||||
# Needed to correct the random indices to their actual camera idx locations.
|
||||
local_indices = indices.clone()
|
||||
indices[:, 0] = batch["image_idx"][c]
|
||||
collated_batch = {
|
||||
"indices": indices,
|
||||
"local_indices": local_indices, # local to the batch returned
|
||||
"indices": indices, # with the abs camera indices
|
||||
"pixels": pixels,
|
||||
"mask": mask,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user