Exemple #1
0
    def test_can_save_and_load_image_with_arbitrary_extension(self):
        dataset = Dataset.from_iterable([
            DatasetItem('no_label/q/1',
                        image=Image(path='q/1.JPEG', data=np.zeros(
                            (4, 3, 3)))),
            DatasetItem('a/b/c/2',
                        image=Image(path='a/b/c/2.bmp',
                                    data=np.zeros((3, 4, 3))),
                        annotations=[
                            Bbox(0, 2, 4, 2, label=0),
                            Points([
                                4.23, 4.32, 5.34, 4.45, 3.54, 3.56, 4.52, 3.51,
                                4.78, 3.34
                            ],
                                   label=0),
                        ]),
        ],
                                        categories=['a'])

        with TestDir() as test_dir:
            VggFace2Converter.convert(dataset, test_dir, save_images=True)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            compare_datasets(self,
                             dataset,
                             parsed_dataset,
                             require_images=True)
Exemple #2
0
    def test_can_save_dataset_with_no_labels(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='no_label/1',
                        image=np.ones((8, 8, 3)),
                        annotations=[
                            Bbox(0, 2, 4, 2),
                            Points([
                                4.23, 4.32, 5.34, 4.45, 3.54, 3.56, 4.52, 3.51,
                                4.78, 3.34
                            ]),
                        ]),
            DatasetItem(id='no_label/2',
                        image=np.ones((8, 8, 3)),
                        annotations=[
                            Bbox(2, 2, 4, 2),
                        ]),
        ],
                                               categories=[])

        with TestDir() as test_dir:
            VggFace2Converter.convert(source_dataset,
                                      test_dir,
                                      save_images=False)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            compare_datasets(self, source_dataset, parsed_dataset)
Exemple #3
0
    def test_can_save_and_load(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='1', subset='train', image=np.ones((8, 8, 3)),
                annotations=[
                    Bbox(0, 2, 4, 2, label=0, group=1),
                    Points([3.2, 3.12, 4.11, 3.2, 2.11,
                        2.5, 3.5, 2.11, 3.8, 2.13], label=0, group=1),
                ]
            ),
            DatasetItem(id='2', subset='train', image=np.ones((10, 10, 3)),
                annotations=[
                    Points([4.23, 4.32, 5.34, 4.45, 3.54,
                        3.56, 4.52, 3.51, 4.78, 3.34], label=1, group=1),
                ]
            ),
            DatasetItem(id='3', subset='train', image=np.ones((8, 8, 3)),
                annotations=[Label(2, group=1)]
            ),
            DatasetItem(id='4', subset='train', image=np.ones((10, 10, 3)),
                annotations=[
                    Bbox(0, 2, 4, 2, label=3, group=1),
                    Points([3.2, 3.12, 4.11, 3.2, 2.11,
                        2.5, 3.5, 2.11, 3.8, 2.13], label=3, group=1),
                ]
            ),
            DatasetItem(id='a/5', subset='train', image=np.ones((8, 8, 3)),
                annotations=[
                    Bbox(2, 2, 2, 2, group=1),
                ]
            ),
            DatasetItem(id='label_0', subset='train', image=np.ones((8, 8, 3)),
            ),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                [('label_%s' % i, 'class_%s' % i) for i in range(5)]),
        })

        with TestDir() as test_dir:
            VggFace2Converter.convert(source_dataset, test_dir, save_images=True)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            compare_datasets(self, source_dataset, parsed_dataset)
Exemple #4
0
    def test_can_save_and_load_with_meta_file(self):
        source_dataset = Dataset.from_iterable(
            [
                DatasetItem(id='class_0/1',
                            subset='train',
                            image=np.ones((8, 8, 3)),
                            annotations=[
                                Bbox(0, 2, 4, 2, label=0),
                                Points([
                                    3.2, 3.12, 4.11, 3.2, 2.11, 2.5, 3.5, 2.11,
                                    3.8, 2.13
                                ],
                                       label=0),
                            ]),
                DatasetItem(id='class_1/2',
                            subset='train',
                            image=np.ones((10, 10, 3)),
                            annotations=[
                                Points([
                                    4.23, 4.32, 5.34, 4.45, 3.54, 3.56, 4.52,
                                    3.51, 4.78, 3.34
                                ],
                                       label=1),
                            ])
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable([('class_%s' % i)
                                               for i in range(5)]),
            })

        with TestDir() as test_dir:
            VggFace2Converter.convert(source_dataset,
                                      test_dir,
                                      save_images=True,
                                      save_dataset_meta=True)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            self.assertTrue(osp.isfile(osp.join(test_dir,
                                                'dataset_meta.json')))
            compare_datasets(self, source_dataset, parsed_dataset)
    def test_can_save_dataset_with_wrong_number_of_points(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='1',
                        image=np.ones((8, 8, 3)),
                        annotations=[
                            Points([4.23, 4.32, 5.34, 3.51, 4.78, 3.34]),
                        ]),
        ],
                                               categories=[])

        target_dataset = Dataset.from_iterable([
            DatasetItem(id='1', image=np.ones((8, 8, 3)), annotations=[]),
        ],
                                               categories=[])

        with TestDir() as test_dir:
            VggFace2Converter.convert(source_dataset,
                                      test_dir,
                                      save_images=True)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            compare_datasets(self, target_dataset, parsed_dataset)
Exemple #6
0
    def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='a/кириллица с пробелом',
                        image=np.ones((8, 8, 3)),
                        annotations=[
                            Points([
                                4.23, 4.32, 5.34, 4.45, 3.54, 3.56, 4.52, 3.51,
                                4.78, 3.34
                            ],
                                   label=0),
                        ]),
        ],
                                               categories=['a'])

        with TestDir() as test_dir:
            VggFace2Converter.convert(source_dataset,
                                      test_dir,
                                      save_images=True)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            compare_datasets(self,
                             source_dataset,
                             parsed_dataset,
                             require_images=True)