mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
generalize mask collation to other image-like data (#1959)
This commit is contained in:
1 parent
a90602060b
commit
ccdcc3951e
1 file changed
+13
-6
@@ -64,6 +64,7 @@ from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttrib
|
|||||||
from nerfstudio.model_components.ray_generators import RayGenerator
|
from nerfstudio.model_components.ray_generators import RayGenerator
|
||||||
from nerfstudio.utils.misc import IterableWrapper
|
from nerfstudio.utils.misc import IterableWrapper
|
||||||
from nerfstudio.utils.rich_utils import CONSOLE
|
from nerfstudio.utils.rich_utils import CONSOLE
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
def variable_res_collate(batch: List[Dict]) -> Dict:
|
def variable_res_collate(batch: List[Dict]) -> Dict:
|
||||||
@@ -74,18 +75,24 @@ def variable_res_collate(batch: List[Dict]) -> Dict:
|
|||||||
Collated batch.
|
Collated batch.
|
||||||
"""
|
"""
|
||||||
images = []
|
images = []
|
||||||
masks = []
|
imgdata_lists = defaultdict(list)
|
||||||
for data in batch:
|
for data in batch:
|
||||||
image = data.pop("image")
|
image = data.pop("image")
|
||||||
mask = data.pop("mask", None)
|
|
||||||
images.append(image)
|
images.append(image)
|
||||||
if mask is not None:
|
topop = []
|
||||||
masks.append(mask)
|
for key, val in data.items():
|
||||||
|
if isinstance(val, torch.Tensor):
|
||||||
|
# if the value has same height and width as the image, assume that it should be collated accordingly.
|
||||||
|
if len(val.shape) >= 2 and val.shape[:2] == image.shape[:2]:
|
||||||
|
imgdata_lists[key].append(val)
|
||||||
|
topop.append(key)
|
||||||
|
# now that iteration is complete, the image data items can be removed from the batch
|
||||||
|
for key in topop:
|
||||||
|
del data[key]
|
||||||
|
|
||||||
new_batch = nerfstudio_collate(batch)
|
new_batch = nerfstudio_collate(batch)
|
||||||
new_batch["image"] = images
|
new_batch["image"] = images
|
||||||
if masks:
|
new_batch.update(imgdata_lists)
|
||||||
new_batch["mask"] = masks
|
|
||||||
|
|
||||||
return new_batch
|
return new_batch
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user