INNER CODE UNIT · Python
LazyDetections2D
allenai/ai2thor · ai2thor/server.py:211
class LazyDetections2D(Mapping):
def __init__(self, instance_masks: LazyInstanceSegmentationMasks):
self.instance_masks = instance_masks
def mask_bounding_box(self, mask: np.ndarray) -> Optional[Tuple[int, int, int, int]]:
rows = np.any(mask, axis=1)
cols = np.any(mask, axis=0)
rw = np.where(rows)
if len(rw[0]) == 0:
return None
rmin, rmax = map(int, rw[0][[0, -1]])
cmin, cmax = map(int, np.where(cols)[0][[0, -1]])
return cmin, rmin, cmax, rmax
def __contains__(self, key: object) -> bool:
return key in self.instance_masks