File size: 1,942 Bytes
2861545
 
 
 
 
 
 
 
 
7bd707d
0664d91
7bd707d
0664d91
7bd707d
 
 
 
 
 
 
 
2861545
 
 
7bd707d
 
 
 
2861545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7bd707d
 
2861545
7bd707d
 
2861545
 
 
7bd707d
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
48
49
50
51
52
53
54
55
import os
import datasets
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/"
_EXTENSION = [".png", ".jpg"]
_URLS_HQ = [f"{_URL_BASE}fbanimehq-{i:02d}.zip" for i in range(12)]
_URLS_SMALL = [
    # _URL_BASE + "fbanimesmall.zip",
]


class FBAnimeHQConfig(datasets.BuilderConfig):

    def __init__(self, urls, **kwargs):
        super(FBAnimeHQConfig, self).__init__(**kwargs)
        self.urls = urls


class FBAnimeHQ(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        FBAnimeHQConfig(name="hq", urls=_URLS_HQ),
        FBAnimeHQConfig(name="small", urls=_URLS_SMALL)
    ]

    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):
        dirs = dl_manager.download_and_extract(self.config.urls)
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"dirs": dirs})]

    def _generate_examples(self, dirs):
        for path in dirs:
            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 _EXTENSION)
            for image_fname in image_fnames:
                yield image_fname, {"image": os.path.join(path, image_fname)}