示例#1
0
def test_ImageFolderDataset_depth(image_folder):
    dataset = data.ImageFolderDataset(image_folder, depth=1)

    actual = len(dataset)
    desired = 2
    assert actual == desired

    actual = dataset.image_files
    desired = (
        path.join(image_folder, "image0.jpg"),
        path.join(image_folder, "dir1", "image1.jpg"),
    )
    assert actual == desired
示例#2
0
    def test_ImageFolderDataset_depth(self):
        with self.create_fake_image_folder() as root:
            dataset = data.ImageFolderDataset(root, depth=1)

            actual = len(dataset)
            desired = 2
            self.assertEqual(actual, desired)

            actual = dataset.image_files
            desired = (
                path.join(root, "image0.jpg"),
                path.join(root, "dir1", "image1.jpg"),
            )
            self.assertEqual(actual, desired)
示例#3
0
    def test_main(self, image_folder):
        dataset = data.ImageFolderDataset(image_folder)

        actual = len(dataset)
        desired = 3
        assert actual == desired

        actual = dataset.image_files
        desired = (
            path.join(image_folder, "image0.jpg"),
            path.join(image_folder, "dir1", "image1.jpg"),
            path.join(image_folder, "dir1", "dir2", "image2.jpg"),
        )
        assert actual == desired
示例#4
0
def test_ImageFolderDataset_getitem(image_folder):
    def transform(file):
        return path.join(path.dirname(file),
                         f"transformed_{path.basename(file)}")

    def importer(file):
        return path.join(path.dirname(file), f"imported_{path.basename(file)}")

    dataset = data.ImageFolderDataset(image_folder,
                                      transform=transform,
                                      importer=importer)

    actual = dataset[0]
    desired = path.join(image_folder, "transformed_imported_image0.jpg")
    assert actual == desired
示例#5
0
    def test_ImageFolderDataset_getitem(self):
        def transform(file):
            return path.join(path.dirname(file),
                             f"transformed_{path.basename(file)}")

        def importer(file):
            return path.join(path.dirname(file),
                             f"imported_{path.basename(file)}")

        with self.create_fake_image_folder() as root:
            dataset = data.ImageFolderDataset(root,
                                              transform=transform,
                                              importer=importer)

            actual = dataset[0]
            desired = path.join(root, "transformed_imported_image0.jpg")
            self.assertEqual(actual, desired)