Exemple #1
0
    def test_can_import_points(self):
        expected_dataset = Dataset.from_iterable([
            DatasetItem(id=1, subset='train',
                image=Image(path='1.jpg', size=(5, 5)),
                annotations=[
                    Points([0, 0, 0, 2, 4, 1], [0, 1, 2],
                        label=1, group=1, id=1,
                        attributes={'is_crowd': False}),
                    Polygon([0, 0, 4, 0, 4, 4],
                        label=1, group=1, id=1,
                        attributes={'is_crowd': False}),

                    Points([1, 2, 3, 4, 2, 3],
                        group=2, id=2,
                        attributes={'is_crowd': False}),
                    Bbox(1, 2, 2, 2,
                        group=2, id=2,
                        attributes={'is_crowd': False}),

                    Points([1, 2, 0, 2, 4, 1],
                        label=0, group=3, id=3,
                        attributes={'is_crowd': False}),
                    Bbox(0, 1, 4, 1,
                        label=0, group=3, id=3,
                        attributes={'is_crowd': False}),

                    Points([0, 0, 1, 2, 3, 4], [0, 1, 2],
                        group=5, id=5,
                        attributes={'is_crowd': False}),
                    Bbox(1, 2, 2, 2,
                        group=5, id=5,
                        attributes={'is_crowd': False}),
                ], attributes={'id': 1}),
            ], categories={
                AnnotationType.label: LabelCategories.from_iterable(['a', 'b']),
                AnnotationType.points: PointsCategories.from_iterable(
                    (i, None, [[0, 1], [1, 2]]) for i in range(2)
                ),
            })

        dataset = Dataset.import_from(
            osp.join(DUMMY_DATASET_DIR, 'coco_person_keypoints'), 'coco')

        compare_datasets(self, expected_dataset, dataset)
Exemple #2
0
    def test_can_save_and_load_keypoints(self):
        source_dataset = Dataset.from_iterable(
            [
                DatasetItem(
                    id=1,
                    subset='train',
                    image=np.zeros((5, 5, 3)),
                    annotations=[
                        # Full instance annotations: polygon + keypoints
                        Points([0, 0, 0, 2, 4, 1], [0, 1, 2],
                               label=3,
                               group=1,
                               id=1),
                        Polygon([0, 0, 4, 0, 4, 4], label=3, group=1, id=1),

                        # Full instance annotations: bbox + keypoints
                        Points([1, 2, 3, 4, 2, 3], group=2, id=2),
                        Bbox(1, 2, 2, 2, group=2, id=2),

                        # Solitary keypoints
                        Points([1, 2, 0, 2, 4, 1], label=5, id=3),

                        # Some other solitary annotations (bug #1387)
                        Polygon([0, 0, 4, 0, 4, 4], label=3, id=4),

                        # Solitary keypoints with no label
                        Points([0, 0, 1, 2, 3, 4], [0, 1, 2], id=5),
                    ]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(str(i) for i in range(10)),
                AnnotationType.points:
                PointsCategories.from_iterable(
                    (i, None, [[0, 1], [1, 2]]) for i in range(10)),
            })

        target_dataset = Dataset.from_iterable(
            [
                DatasetItem(id=1,
                            subset='train',
                            image=np.zeros((5, 5, 3)),
                            annotations=[
                                Points([0, 0, 0, 2, 4, 1], [0, 1, 2],
                                       label=3,
                                       group=1,
                                       id=1,
                                       attributes={'is_crowd': False}),
                                Polygon([0, 0, 4, 0, 4, 4],
                                        label=3,
                                        group=1,
                                        id=1,
                                        attributes={'is_crowd': False}),
                                Points([1, 2, 3, 4, 2, 3],
                                       group=2,
                                       id=2,
                                       attributes={'is_crowd': False}),
                                Bbox(1,
                                     2,
                                     2,
                                     2,
                                     group=2,
                                     id=2,
                                     attributes={'is_crowd': False}),
                                Points([1, 2, 0, 2, 4, 1],
                                       label=5,
                                       group=3,
                                       id=3,
                                       attributes={'is_crowd': False}),
                                Bbox(0,
                                     1,
                                     4,
                                     1,
                                     label=5,
                                     group=3,
                                     id=3,
                                     attributes={'is_crowd': False}),
                                Points([0, 0, 1, 2, 3, 4], [0, 1, 2],
                                       group=5,
                                       id=5,
                                       attributes={'is_crowd': False}),
                                Bbox(1,
                                     2,
                                     2,
                                     2,
                                     group=5,
                                     id=5,
                                     attributes={'is_crowd': False}),
                            ],
                            attributes={'id': 1}),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(str(i) for i in range(10)),
                AnnotationType.points:
                PointsCategories.from_iterable(
                    (i, None, [[0, 1], [1, 2]]) for i in range(10)),
            })

        with TestDir() as test_dir:
            self._test_save_and_load(source_dataset,
                                     CocoPersonKeypointsConverter.convert,
                                     test_dir,
                                     target_dataset=target_dataset)
Exemple #3
0
    def test_can_merge_categories(self):
        source0 = Dataset.from_iterable(
            [
                DatasetItem(1, annotations=[
                    Label(0),
                ]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(['a', 'b']),
                AnnotationType.points:
                PointsCategories.from_iterable([
                    (0, ['l0', 'l1']),
                    (1, ['l2', 'l3']),
                ]),
                AnnotationType.mask:
                MaskCategories({
                    0: (0, 1, 2),
                    1: (1, 2, 3),
                }),
            })

        source1 = Dataset.from_iterable(
            [
                DatasetItem(1, annotations=[
                    Label(0),
                ]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(['c', 'b']),
                AnnotationType.points:
                PointsCategories.from_iterable([
                    (0, []),
                    (1, ['l2', 'l3']),
                ]),
                AnnotationType.mask:
                MaskCategories({
                    0: (0, 2, 4),
                    1: (1, 2, 3),
                }),
            })

        expected = Dataset.from_iterable(
            [
                DatasetItem(1, annotations=[
                    Label(0),
                    Label(2),
                ]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(['a', 'b', 'c']),
                AnnotationType.points:
                PointsCategories.from_iterable([
                    (0, ['l0', 'l1']),
                    (1, ['l2', 'l3']),
                    (2, []),
                ]),
                AnnotationType.mask:
                MaskCategories({
                    0: (0, 1, 2),
                    1: (1, 2, 3),
                    2: (0, 2, 4),
                }),
            })

        merger = IntersectMerge()
        merged = merger([source0, source1])

        compare_datasets(self, expected, merged, ignored_attrs={'score'})