def _retrieve_sample(self, annotation):
epsilon = 0.05
high_val = 1 - epsilon
low_val = 0 + epsilon
coco_image = self._coco.loadImgs(annotation['image_id'])[0]
image_path = os.path.join(self._config.data_dir['images'], coco_image['file_name'])
image = utils.load_image(image_path)
ann_mask = self._coco.annToMask(annotation)
mask_categorical = np.full((ann_mask.shape[0], ann_mask.shape[1], self.num_classes()), low_val, dtype=np.float32)
mask_categorical[:, :, 0] = high_val # every pixel begins as background
class_index = self._cid_to_id[annotation['category_id']]
mask_categorical[ann_mask > 0, class_index] = high_val
mask_categorical[ann_mask > 0, 0] = low_val # remove background label from pixels of this (non-bg) category
return image, mask_categorical
评论列表
文章目录