File size: 1,717 Bytes
2861545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import datasets
import PIL
from datasets import DownloadManager, DatasetInfo

_DESCRIPTION = """\
FBAnimeHQ is a dataset with high-quality full-body anime girl images in a resolution of 1024 × 512.
"""
_HOMEPAGE = "https://huggingface.co/datasets/skytnt/fbanimehq"
_URL_BASE = "https://huggingface.co/datasets/skytnt/fbanimehq/resolve/main/data/"
_URLS = [
    _URL_BASE + "fbanimehq-00.zip",
    _URL_BASE + "fbanimehq-01.zip",
    _URL_BASE + "fbanimehq-02.zip",
    _URL_BASE + "fbanimehq-03.zip",
    _URL_BASE + "fbanimehq-04.zip",
]


class FBAnimeHQ(datasets.GeneratorBasedBuilder):

    def _info(self) -> DatasetInfo:
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "image": datasets.Image(),
                }
            ),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation="",
        )

    def _split_generators(self, dl_manager: DownloadManager):
        downloaded_files = dl_manager.download_and_extract(_URLS)
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files})]

    def _generate_examples(self, filepath):
        for path in filepath:
            all_fnames = {os.path.relpath(os.path.join(root, fname), start=path)
                          for root, _dirs, files in os.walk(path) for fname in files}
            image_fnames = sorted(fname for fname in all_fnames
                                  if os.path.splitext(fname)[1].lower() in PIL.Image.EXTENSION)
            for image_fname in image_fnames:
                yield image_fname, {"image": os.path.join(path, image_fname)}