コード例 #1
0
ファイル: test_transforms.py プロジェクト: soparin/datumaro
    def test_mask_to_polygons(self):
        source = Dataset.from_iterable([
            DatasetItem(id=1,
                        image=np.zeros((5, 10, 3)),
                        annotations=[
                            Mask(
                                np.array([
                                    [0, 1, 1, 1, 0, 1, 1, 1, 1, 0],
                                    [0, 0, 1, 1, 0, 1, 1, 1, 0, 0],
                                    [0, 0, 0, 1, 0, 1, 1, 0, 0, 0],
                                    [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                ]), ),
                        ]),
        ])

        expected = Dataset.from_iterable([
            DatasetItem(id=1,
                        image=np.zeros((5, 10, 3)),
                        annotations=[
                            Polygon([3.0, 2.5, 1.0, 0.0, 3.5, 0.0, 3.0, 2.5]),
                            Polygon([5.0, 3.5, 4.5, 0.0, 8.0, 0.0, 5.0, 3.5]),
                        ]),
        ])

        actual = transforms.MasksToPolygons(source)
        compare_datasets(self, expected, actual)
コード例 #2
0
    def test_mask_to_polygons(self):
        class SrcExtractor(Extractor):
            def __iter__(self):
                items = [
                    DatasetItem(id=1,
                                image=np.zeros((5, 10, 3)),
                                annotations=[
                                    Mask(
                                        np.array([
                                            [0, 1, 1, 1, 0, 1, 1, 1, 1, 0],
                                            [0, 0, 1, 1, 0, 1, 1, 1, 0, 0],
                                            [0, 0, 0, 1, 0, 1, 1, 0, 0, 0],
                                            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                                            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                        ]), ),
                                ]),
                ]
                return iter(items)

        class DstExtractor(Extractor):
            def __iter__(self):
                return iter([
                    DatasetItem(
                        id=1,
                        image=np.zeros((5, 10, 3)),
                        annotations=[
                            Polygon([3.0, 2.5, 1.0, 0.0, 3.5, 0.0, 3.0, 2.5]),
                            Polygon([5.0, 3.5, 4.5, 0.0, 8.0, 0.0, 5.0, 3.5]),
                        ]),
                ])

        actual = transforms.MasksToPolygons(SrcExtractor())
        compare_datasets(self, DstExtractor(), actual)
コード例 #3
0
    def test_mask_to_polygons_small_polygons_message(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id=1, image=np.zeros((5, 10, 3)), annotations=[
                Mask(np.array([
                        [0, 0, 0],
                        [0, 1, 0],
                        [0, 0, 0],
                    ]),
                ),
            ]),
        ])

        target_dataset = Dataset.from_iterable([
            DatasetItem(id=1, image=np.zeros((5, 10, 3))), ])

        with self.assertLogs(level=log.DEBUG) as logs:
            actual = transforms.MasksToPolygons(source_dataset)

            compare_datasets(self, target_dataset, actual)
            self.assertRegex('\n'.join(logs.output), 'too small polygons')