Пример #1
0
    def test_can_save_and_load(self):
        source_dataset = Dataset.from_iterable(
            [
                DatasetItem(id=0,
                            subset='test',
                            image=np.ones((28, 28)),
                            annotations=[Label(0)]),
                DatasetItem(id=1, subset='test', image=np.ones((28, 28))),
                DatasetItem(id=2,
                            subset='test',
                            image=np.ones((28, 28)),
                            annotations=[Label(1)])
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(
                    str(label) for label in range(10)),
            })

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

            compare_datasets(self,
                             source_dataset,
                             parsed_dataset,
                             require_images=True)
Пример #2
0
    def test_can_save_and_load_empty_image(self):
        dataset = Dataset.from_iterable(
            [DatasetItem(id=0, annotations=[Label(0)]),
             DatasetItem(id=1)],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(
                    str(label) for label in range(10)),
            })

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

            compare_datasets(self,
                             dataset,
                             parsed_dataset,
                             require_images=True)
Пример #3
0
    def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):
        source_dataset = Dataset.from_iterable(
            [
                DatasetItem(id="кириллица с пробелом",
                            image=np.ones((28, 28)),
                            annotations=[Label(0)]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(
                    str(label) for label in range(10)),
            })

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

            compare_datasets(self,
                             source_dataset,
                             parsed_dataset,
                             require_images=True)
Пример #4
0
    def test_can_save_and_load_with_other_labels(self):
        dataset = Dataset.from_iterable(
            [
                DatasetItem(
                    id=0, image=np.ones((28, 28)), annotations=[Label(0)]),
                DatasetItem(
                    id=1, image=np.ones((28, 28)), annotations=[Label(1)])
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable('label_%s' % label
                                              for label in range(2)),
            })

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

            compare_datasets(self,
                             dataset,
                             parsed_dataset,
                             require_images=True)
Пример #5
0
    def test_can_save_and_load_image_with_arbitrary_extension(self):
        dataset = Dataset.from_iterable(
            [
                DatasetItem(id='q/1',
                            image=Image(path='q/1.JPEG',
                                        data=np.zeros((28, 28)))),
                DatasetItem(id='a/b/c/2',
                            image=Image(path='a/b/c/2.bmp',
                                        data=np.zeros((28, 28)))),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(
                    str(label) for label in range(10)),
            })

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

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