File size: 2,656 Bytes
c686aed
 
 
 
 
3f07367
 
c686aed
63db7d3
 
 
 
 
 
c686aed
 
 
63db7d3
c686aed
 
63db7d3
c686aed
 
 
 
 
 
 
 
 
47097fb
 
c686aed
 
 
 
 
3f07367
c686aed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47097fb
c686aed
 
47097fb
c686aed
 
 
47097fb
c686aed
 
47097fb
c686aed
 
 
 
 
47097fb
 
 
 
c686aed
 
 
3f07367
 
 
 
c686aed
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# This script for Hugging Face's datasets library was written by Théo Gigant

import os
import datasets

from PIL import Image

_CITATION = """\
@inproceedings{CycleGAN2017,
  title={Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks},
  author={Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A},
  booktitle={Computer Vision (ICCV), 2017 IEEE International Conference on},
  year={2017}
}
"""

_DESCRIPTION = """\
Two unpaired sets of photos of respectively horses and zebras, designed for unpaired image-to-image translation, as seen in the paper introducing CycleGAN
"""

_HOMEPAGE = "https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/"

_LICENSE = ""

_URL = "http://efrosgans.eecs.berkeley.edu/cyclegan/datasets/horse2zebra.zip"

class Horse2Zebra(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="horse", version=VERSION, description="Images of horses"),
        datasets.BuilderConfig(name="zebra", version=VERSION, description="Images of zebras"),
    ]

    def _info(self):
        features = datasets.Features(
            {
                "image": datasets.Image()
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        urls = _URL
        data_dir = dl_manager.download_and_extract(urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "datapath": os.path.join(data_dir, "horse2zebra"),
                    "split":"train"
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "datapath": os.path.join(data_dir, "horse2zebra"),
                    "split":"test"
                },
            ),
        ]

    def _generate_examples(self, datapath, split):
      if split=="train":
        dir = "trainA" if self.config.name == "horse" else "trainB"
      elif split=="test":
        dir = "testA" if self.config.name == "horse" else "testB"
      image_dir = os.path.join(datapath, dir)
      for idx, image_file in enumerate(os.listdir(image_dir)):
        image_id = image_file.split(".")[0]
        with Image.open(os.path.join(image_dir, image_file)) as img :
            yield idx, {
                "image": img.convert("RGB"),
            }