def load_mask(self, image_id):
    'Mapping annotation images to real Masks(MRCNN needed)\n        image_id: id of mask\n        Returns:\n        masks: A bool array of shape [height, width, instance count] with\n            one mask per instance.\n        class_ids: a 1D array of class IDs of the instance masks.\n        '
    class_label = self.load_class_label(image_id)
    instance_mask = self.load_raw_mask(image_id, 'object_mask')
    max_indice = int(np.max(class_label))
    instance_label = []
    instance_class = []
    for i in range(1, (max_indice + 1)):
        if (not np.any((class_label == i))):
            continue
        gt_indice = i
        object_filter = (class_label == i)
        object_filter = object_filter.astype(np.uint8)
        object_filter = np.dstack((object_filter, object_filter, object_filter))
        filtered = np.multiply(object_filter, instance_mask)
        gray = cv2.cvtColor(filtered, cv2.COLOR_RGB2GRAY)
        max_gray = np.max(gray)
        for sub_index in range(1, (max_gray + 1)):
            if (not np.any((gray == sub_index))):
                continue
            instance_filter = (gray == sub_index)
            instance_label += [instance_filter]
            instance_class += [gt_indice]
    masks = np.asarray(instance_label).transpose((1, 2, 0))
    classes_ids = np.asarray(instance_class)
    return (masks, classes_ids)
Mapping annotation images to real Masks(MRCNN needed)
image_id: id of mask
Returns:
masks: A bool array of shape [height, width, instance count] with
    one mask per instance.
class_ids: a 1D array of class IDs of the instance masks.
def load_mask(self, image_id):
    'Mapping annotation images to real Masks(MRCNN needed)\n        image_id: id of mask\n        Returns:\n        masks: A bool array of shape [height, width, instance count] with\n            one mask per instance.\n        class_ids: a 1D array of class IDs of the instance masks.\n        '
    class_label = self.load_class_label(image_id)
    instance_mask = self.load_raw_mask(image_id, 'object_mask')
    max_indice = int(np.max(class_label))
    instance_label = []
    instance_class = []
    for i in range(1, (max_indice + 1)):
        if (not np.any((class_label == i))):
            continue
        gt_indice = i
        object_filter = (class_label == i)
        object_filter = object_filter.astype(np.uint8)
        object_filter = np.dstack((object_filter, object_filter, object_filter))
        filtered = np.multiply(object_filter, instance_mask)
        gray = cv2.cvtColor(filtered, cv2.COLOR_RGB2GRAY)
        max_gray = np.max(gray)
        for sub_index in range(1, (max_gray + 1)):
            if (not np.any((gray == sub_index))):
                continue
            instance_filter = (gray == sub_index)
            instance_label += [instance_filter]
            instance_class += [gt_indice]
    masks = np.asarray(instance_label).transpose((1, 2, 0))
    classes_ids = np.asarray(instance_class)
    return (masks, classes_ids)