|
|
|
|
|
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"), |
|
} |
|
|
|
|