Skip to content

Commit 8164ac4

Browse files
shapovalovfacebook-github-bot
authored andcommitted
Fix: tensor vs array type correctness
Summary: For fg-masking depth, we assumed np.array but passed a Tensor; for defining the default depth_mask, vice versa. Note that we change the intended behaviour for the latter, assuming that 0s are areas with empty depth. When loading depth masks, we replace NaNs with zeros, so it is sensible. It is not a BC change as that branch would crash if executed. Since there was no reports, I assume no one cared. Reviewed By: bottler Differential Revision: D47403588 fbshipit-source-id: 1094104176d7d767a5657b5bbc9f5a0cc9da0ede
1 parent 9446d91 commit 8164ac4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pytorch3d/implicitron/dataset/frame_data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,9 @@ def build(
583583
else None,
584584
)
585585

586+
fg_mask_np: Optional[np.ndarray] = None
586587
mask_annotation = frame_annotation.mask
587588
if mask_annotation is not None:
588-
fg_mask_np: Optional[np.ndarray] = None
589589
if load_blobs and self.load_masks:
590590
fg_mask_np, mask_path = self._load_fg_probability(frame_annotation)
591591
frame_data.mask_path = mask_path
@@ -627,7 +627,7 @@ def build(
627627
frame_data.depth_map,
628628
frame_data.depth_path,
629629
frame_data.depth_mask,
630-
) = self._load_mask_depth(frame_annotation, frame_data.fg_probability)
630+
) = self._load_mask_depth(frame_annotation, fg_mask_np)
631631

632632
if load_blobs and self.load_point_clouds and point_cloud is not None:
633633
pcl_path = self._fix_point_cloud_path(point_cloud.path)
@@ -683,7 +683,7 @@ def _postprocess_image(
683683
def _load_mask_depth(
684684
self,
685685
entry: types.FrameAnnotation,
686-
fg_probability: Optional[torch.Tensor],
686+
fg_mask: Optional[np.ndarray],
687687
) -> Tuple[torch.Tensor, str, torch.Tensor]:
688688
entry_depth = entry.depth
689689
dataset_root = self.dataset_root
@@ -693,15 +693,15 @@ def _load_mask_depth(
693693
depth_map = load_depth(self._local_path(path), entry_depth.scale_adjustment)
694694

695695
if self.mask_depths:
696-
assert fg_probability is not None
697-
depth_map *= fg_probability
696+
assert fg_mask is not None
697+
depth_map *= fg_mask
698698

699699
mask_path = entry_depth.mask_path
700700
if self.load_depth_masks and mask_path is not None:
701701
mask_path = os.path.join(dataset_root, mask_path)
702702
depth_mask = load_depth_mask(self._local_path(mask_path))
703703
else:
704-
depth_mask = torch.ones_like(depth_map)
704+
depth_mask = (depth_map > 0.0).astype(np.float32)
705705

706706
return torch.tensor(depth_map), path, torch.tensor(depth_mask)
707707

0 commit comments

Comments
 (0)