コード例 #1
0
    def test_can_save_and_load_with_multiple_labels(self):
        source_dataset = Dataset.from_iterable(
            [
                DatasetItem(id='1',
                            subset='train',
                            annotations=[Label(1), Label(3)]),
                DatasetItem(id='2',
                            subset='train',
                            image=np.zeros((8, 6, 3)),
                            annotations=[Label(0)]),
                DatasetItem(
                    id='3',
                    subset='train',
                    image=np.zeros((2, 8, 3)),
                ),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable('label_' + str(label)
                                              for label in range(10)),
            })

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(source_dataset,
                                         test_dir,
                                         save_images=True)

            parsed_dataset = ImagenetTxtImporter()(test_dir).make_dataset()

            compare_datasets(self,
                             source_dataset,
                             parsed_dataset,
                             require_images=True)
コード例 #2
0
    def test_can_save_and_load(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='1', subset='train',
                annotations=[Label(0)]
            ),
            DatasetItem(id='2', subset='train',
                annotations=[Label(0)]
            ),
            DatasetItem(id='3', subset='train', image=np.zeros((8, 8, 3)),
                annotations=[Label(0)]
            ),
            DatasetItem(id='4', subset='train',
                annotations=[Label(1)]
            ),
            DatasetItem(id='5', subset='train', image=np.zeros((4, 8, 3)),
                annotations=[Label(1)]
            ),
            DatasetItem(id='6', subset='train',
                annotations=[Label(5)]
            ),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                'label_' + str(label) for label in range(10)),
        })

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(source_dataset, test_dir,
                save_images=True)

            parsed_dataset = Dataset.import_from(test_dir, 'imagenet_txt')

            compare_datasets(self, source_dataset, parsed_dataset,
                require_images=True)
コード例 #3
0
    def test_can_save_and_load_with_no_save_images(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='1', subset='train', annotations=[Label(0)]),
        ],
                                               categories=['label_0'])

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(source_dataset,
                                         test_dir,
                                         save_images=False)

            parsed_dataset = Dataset.import_from(test_dir, 'imagenet_txt')

            compare_datasets(self, source_dataset, parsed_dataset)
コード例 #4
0
    def test_can_save_dataset_with_no_subsets(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='a/b/c', image=np.zeros((8, 4, 3)),
                annotations=[Label(1)]
            ),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                'label_' + str(label) for label in range(10)),
        })

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(source_dataset, test_dir,
                save_images=True)

            parsed_dataset = ImagenetTxtImporter()(test_dir).make_dataset()

            compare_datasets(self, source_dataset, parsed_dataset,
                require_images=True)
コード例 #5
0
    def test_dataset_with_save_dataset_meta_file(self):
        source_dataset = Dataset.from_iterable(
            [
                DatasetItem(id='1', subset='train', annotations=[Label(0)]),
                DatasetItem(id='2', subset='train', annotations=[Label(1)]),
            ],
            categories=['label_0', 'label_1'])

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(source_dataset,
                                         test_dir,
                                         save_images=False,
                                         save_dataset_meta=True)

            parsed_dataset = Dataset.import_from(test_dir, 'imagenet_txt')

            self.assertTrue(osp.isfile(osp.join(test_dir,
                                                'dataset_meta.json')))
            compare_datasets(self, source_dataset, parsed_dataset)
コード例 #6
0
    def test_can_save_and_load_image_with_arbitrary_extension(self):
        dataset = Dataset.from_iterable([
            DatasetItem(id='a/1',
                        image=Image(path='a/1.JPEG', data=np.zeros(
                            (4, 3, 3)))),
            DatasetItem(id='b/c/d/2',
                        image=Image(path='b/c/d/2.bmp',
                                    data=np.zeros((3, 4, 3)))),
        ],
                                        categories=[])

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(dataset, test_dir, save_images=True)

            parsed_dataset = Dataset.import_from(test_dir, 'imagenet_txt')

            compare_datasets(self,
                             dataset,
                             parsed_dataset,
                             require_images=True)
コード例 #7
0
    def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):
        dataset = Dataset.from_iterable(
            [
                DatasetItem(id="кириллица с пробелом",
                            image=np.ones((8, 8, 3)),
                            annotations=[Label(0), Label(1)]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable('label_' + str(label)
                                              for label in range(2)),
            })

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(dataset, test_dir, save_images=True)

            parsed_dataset = Dataset.import_from(test_dir, 'imagenet_txt')

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