예제 #1
0
 def test_dumps(self):
     labeled_rle = LabeledRLE(
         [272, 2, 4, 4, 2, 9],
         category="example",
         attributes={"key": "value"},
         instance="123",
     )
     assert labeled_rle.dumps() == _DATA_LABELEDRLE
예제 #2
0
def _get_instance_label(instances_annotations: Dict[int, Any], image_id: int,
                        categories: Dict[int, str]) -> Label:
    label: Label = Label()
    label.box2d = []
    label.multi_polygon = []
    label.rle = []
    if image_id not in instances_annotations:
        return label

    for annotation in instances_annotations[image_id]:
        category = categories[annotation["category_id"]]
        label.box2d.append(
            LabeledBox2D.from_xywh(*annotation["bbox"], category=category))
        if annotation["iscrowd"] == 0:
            points = [
                chunked(coordinates, 2)
                for coordinates in annotation["segmentation"]
            ]
            label.multi_polygon.append(
                LabeledMultiPolygon(points, category=category))
        else:
            label.rle.append(
                LabeledRLE(annotation["segmentation"]["counts"],
                           category=category))
    return label
예제 #3
0
 def test_init(self):
     labeled_rle = LabeledRLE(
         [272, 2, 4, 4, 2, 9],
         category="example",
         attributes={"key": "value"},
         instance="123",
     )
     assert labeled_rle._data == [272, 2, 4, 4, 2, 9]
     assert labeled_rle.category == "example"
     assert labeled_rle.attributes == {"key": "value"}
     assert labeled_rle.instance == "123"
예제 #4
0
def _get_labeled_rle(
    mask: Dict[str, str],
    category: Optional[str] = None,
    attributes: Optional[Dict[str, str]] = None,
) -> LabeledRLE:
    return LabeledRLE(
        transpose_rle(
            uncompress_rle(bytes.decode(base64.b64decode(mask["counts"]))),
            *mask["size"]),
        category=category,
        attributes=attributes,
    )