Refactor Data Pipeline (#896)

* add none check

* black formatting

* cleanup

* cleanup

* fix tests

* remove new line

* init

* toy example working

* semantic nerf working

* simplify pixel samplers

* cleanup + fix tests

* comments

* fix tests

* fix tests
This commit is contained in:
Nikhil Mohan authored and GitHub committed 2022-11-06 07:40:43 -08:00
1 parent 761645de05
commit 1a24f3e58c
19 files changed
+229 -197

No files matched your search

+4 -21
View File
@@ -48,30 +48,13 @@ def collate_image_dataset_batch(batch: Dict, num_rays_per_batch: int, keep_full_
).long()
c, y, x = (i.flatten() for i in torch.split(indices, 1, dim=-1))
image = batch["image"][c, y, x]
mask, semantics_stuff, semantics_thing = None, None, None
if "mask" in batch:
mask = batch["mask"][c, y, x]
if "semantics_stuff" in batch:
semantics_stuff = batch["semantics_stuff"][c, y, x]
if "semantics_thing" in batch:
semantics_thing = batch["semantics_thing"][c, y, x]
assert image.shape == (num_rays_per_batch, 3), image.shape
collated_batch = {key: value[c, y, x] for key, value in batch.items() if key != "image_idx" and value is not None}
assert collated_batch["image"].shape == (num_rays_per_batch, 3), collated_batch["image"].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 = {
"local_indices": local_indices, # local to the batch returned
"indices": indices, # with the abs camera indices
"image": image,
}
if mask is not None:
collated_batch["mask"] = mask
if semantics_stuff is not None:
collated_batch["semantics_stuff"] = semantics_stuff
if semantics_thing is not None:
collated_batch["semantics_thing"] = semantics_thing
collated_batch["indices"] = indices # with the abs camera indices
if keep_full_image:
collated_batch["full_image"] = batch["image"]