File size: 7,684 Bytes
8f5e012 e6a3ac4 8f5e012 30797c9 e6a3ac4 8f5e012 5679ebe 8f5e012 5679ebe 8f5e012 10344b3 9467ecf 10344b3 8f5e012 10344b3 8f5e012 10344b3 8f5e012 e6a3ac4 10344b3 e6a3ac4 10344b3 8f5e012 10344b3 8f5e012 e6a3ac4 8f5e012 e6a3ac4 8f5e012 e6a3ac4 ad96d5b 8f5e012 10344b3 30797c9 e6a3ac4 9467ecf 8f5e012 e6a3ac4 8f5e012 30797c9 e6a3ac4 8f5e012 e6a3ac4 8f5e012 30797c9 8f5e012 e6a3ac4 |
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
"""Cartoonset-10k Data Set"""
from io import BytesIO
from typing import Optional
import tarfile
import pandas as pd
import datasets
_CITATION = r"""
@article{DBLP:journals/corr/abs-1711-05139,
author = {Amelie Royer and
Konstantinos Bousmalis and
Stephan Gouws and
Fred Bertsch and
Inbar Mosseri and
Forrester Cole and
Kevin Murphy},
title = {{XGAN:} Unsupervised Image-to-Image Translation for many-to-many Mappings},
journal = {CoRR},
volume = {abs/1711.05139},
year = {2017},
url = {http://arxiv.org/abs/1711.05139},
eprinttype = {arXiv},
eprint = {1711.05139},
timestamp = {Mon, 13 Aug 2018 16:47:38 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-1711-05139.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
"""
_DESCRIPTION = """\
Cartoon Set is a collection of random, 2D cartoon avatar images. The cartoons vary in 10 artwork
categories, 4 color categories, and 4 proportion categories, with a total of ~1013 possible
combinations. We provide sets of 10k and 100k randomly chosen cartoons and labeled attributes.
"""
_DATA_URLS = {
"10k": "https://huggingface.co/datasets/cgarciae/cartoonset/resolve/1.0.0/data/cartoonset10k.tgz",
"100k": "https://huggingface.co/datasets/cgarciae/cartoonset/resolve/1.0.0/data/cartoonset100k.tgz",
}
class Cartoonset(datasets.GeneratorBasedBuilder):
"""Cartoonset-10k Data Set"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="10k",
version=datasets.Version("1.0.0", ""),
description="Loads the Cartoonset-10k Data Set (images only).",
),
datasets.BuilderConfig(
name="10k+features",
version=datasets.Version("1.0.0", ""),
description="Loads the Cartoonset-10k Data Set (images and attributes).",
),
datasets.BuilderConfig(
name="100k",
version=datasets.Version("1.0.0", ""),
description="Loads the Cartoonset-100k Data Set (images only).",
),
datasets.BuilderConfig(
name="100k+features",
version=datasets.Version("1.0.0", ""),
description="Loads the Cartoonset-100k Data Set (images and attributes).",
),
]
DEFAULT_CONFIG_NAME = "10k"
def _info(self):
features = {"img_bytes": datasets.Value("binary")}
if self.config.name.endswith("+features"):
features.update(
{
"eye_angle": datasets.Value("int32"),
"eye_angle_num_categories": datasets.Value("int32"),
"eye_lashes": datasets.Value("int32"),
"eye_lashes_num_categories": datasets.Value("int32"),
"eye_lid": datasets.Value("int32"),
"eye_lid_num_categories": datasets.Value("int32"),
"chin_length": datasets.Value("int32"),
"chin_length_num_categories": datasets.Value("int32"),
"eyebrow_weight": datasets.Value("int32"),
"eyebrow_weight_num_categories": datasets.Value("int32"),
"eyebrow_shape": datasets.Value("int32"),
"eyebrow_shape_num_categories": datasets.Value("int32"),
"eyebrow_thickness": datasets.Value("int32"),
"eyebrow_thickness_num_categories": datasets.Value("int32"),
"face_shape": datasets.Value("int32"),
"face_shape_num_categories": datasets.Value("int32"),
"facial_hair": datasets.Value("int32"),
"facial_hair_num_categories": datasets.Value("int32"),
"hair": datasets.Value("int32"),
"hair_num_categories": datasets.Value("int32"),
"eye_color": datasets.Value("int32"),
"eye_color_num_categories": datasets.Value("int32"),
"face_color": datasets.Value("int32"),
"face_color_num_categories": datasets.Value("int32"),
"hair_color": datasets.Value("int32"),
"hair_color_num_categories": datasets.Value("int32"),
"glasses": datasets.Value("int32"),
"glasses_num_categories": datasets.Value("int32"),
"glasses_color": datasets.Value("int32"),
"glasses_color_num_categories": datasets.Value("int32"),
"eye_slant": datasets.Value("int32"),
"eye_slant_num_categories": datasets.Value("int32"),
"eyebrow_width": datasets.Value("int32"),
"eyebrow_width_num_categories": datasets.Value("int32"),
"eye_eyebrow_distance": datasets.Value("int32"),
"eye_eyebrow_distance_num_categories": datasets.Value("int32"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(features),
supervised_keys=("img_bytes",),
homepage="https://www.cs.toronto.edu/~kriz/cifar.html",
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager):
url = _DATA_URLS[self.config.name.replace("+features", "")]
archive = dl_manager.download(url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"files": dl_manager.iter_archive(archive),
"split": "train",
},
),
]
def _generate_examples(self, files, split):
"""This function returns the examples in the raw (text) form."""
if self.config.name.endswith("+features"):
return self._generate_examples_with_features(files, split)
else:
return self._generate_examples_without_features(files, split)
def _generate_examples_without_features(self, files, split):
path: str
file_obj: tarfile.ExFileObject
root: str
for path, file_obj in files:
root = path[:-4]
if path.endswith(".png"):
image = file_obj.read()
yield root, {"img_bytes": image}
def _generate_examples_with_features(self, files, split):
path: str
file_obj: tarfile.ExFileObject
outputs = {}
root: Optional[str] = None
for path, file_obj in files:
root = path[:-4]
if root not in outputs:
outputs[root] = {}
current_output = outputs[root]
if path.endswith(".png"):
image = file_obj.read()
current_output["img_bytes"] = image
else:
df = pd.read_csv(
BytesIO(file_obj.read()),
header=None,
names=["feature", "value", "num_categories"],
)
for index, row in df.iterrows():
current_output[row.feature] = row.value
current_output[f"{row.feature}_num_categories"] = row.num_categories
if "img_bytes" in current_output and len(current_output) > 1:
yield root, current_output
del outputs[root]
root = None
if len(outputs) > 0:
raise ValueError(
f"Unable to extract the following samples: {list(outputs)}"
)
|