test_unconditional_image_dataset.py 813 Bytes
Newer Older
limm's avatar
limm committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp

from mmgen.datasets import UnconditionalImageDataset


class TestUnconditionalImageDataset(object):

    @classmethod
    def setup_class(cls):
        cls.imgs_root = osp.join(osp.dirname(__file__), '..', 'data/image')
        cls.default_pipeline = [
            dict(type='LoadImageFromFile', io_backend='disk', key='real_img')
        ]

    def test_unconditional_imgs_dataset(self):
        dataset = UnconditionalImageDataset(
            self.imgs_root, pipeline=self.default_pipeline)
        assert len(dataset) == 6
        img = dataset[2]['real_img']
        assert img.ndim == 3
        assert repr(dataset) == (
            f'dataset_name: {dataset.__class__}, '
            f'total {6} images in imgs_root: {self.imgs_root}')