pifpaf的mask生成方法
openpifpaf/src/openpifpaf/encoder/annrescaler.py / Jump to
一开始定义了mask全为1然后去寻找annotation中的标注,如果标注is_crow=0不做处理,如果标注is_corw=1则让这个位置的mask为0。
def bg_mask(self, anns, width_height, *, crowd_margin):
"""Create background mask taking crowd annotations into account."""
mask = np.ones((
(width_height[1] - 1) // self.stride + 1,
(width_height[0] - 1) // self.stride + 1,
), dtype=np.bool_)
for ann in anns:
if not ann['iscrowd']:
valid_keypoints = 'keypoints' in ann and np.any(ann['keypoints'][:, 2] > 0)
if valid_keypoints:
continue
if 'mask' not in ann:
bb = ann['bbox'].copy()
bb /= self.stride
bb[2:] += bb[:2] # convert width and height to x2 and y2
# left top
left = np.clip(int(bb[0] - crowd_margin), 0, mask.shape[1] - 1)
top = np.clip(int(bb[1] - crowd_margin), 0, mask.shape[0] - 1)
# right bottom
# ceil: to round up
# +1: because mask upper limit is exclusive
right = np.clip(int(np.ceil(bb[2] + crowd_margin)) + 1,
left + 1, mask.shape[1])
bottom = np.clip(int(np.ceil(bb[3] + crowd_margin)) + 1,
top + 1, mask.shape[0])
mask[top:bottom, left:right] = 0
continue

浙公网安备 33010602011771号