Commit
·
357fcec
1
Parent(s):
e7d549a
Create klee.py
Browse files
klee.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
|
| 3 |
+
_CITATION = """\
|
| 4 |
+
@InProceedings{huggingface:dataset,
|
| 5 |
+
title = {Klee},
|
| 6 |
+
author={Kevin Li},
|
| 7 |
+
year={2022}
|
| 8 |
+
}
|
| 9 |
+
"""
|
| 10 |
+
_DESCRIPTION = """\
|
| 11 |
+
128x128 PNG images of kanjis from the Klee font
|
| 12 |
+
"""
|
| 13 |
+
_HOMEPAGE = "https://huggingface.co/datasets/AlienKevin/klee"
|
| 14 |
+
_LICENSE = "CC0"
|
| 15 |
+
_REPO = "https://huggingface.co/datasets/AlienKevin/klee"
|
| 16 |
+
|
| 17 |
+
class ImageSet(datasets.GeneratorBasedBuilder):
|
| 18 |
+
def _info(self):
|
| 19 |
+
return datasets.DatasetInfo(
|
| 20 |
+
description=_DESCRIPTION,
|
| 21 |
+
features=datasets.Features(
|
| 22 |
+
{
|
| 23 |
+
'character': datasets.Value("string"),
|
| 24 |
+
'image': datasets.Image(),
|
| 25 |
+
}
|
| 26 |
+
),
|
| 27 |
+
supervised_keys=None,
|
| 28 |
+
homepage=_HOMEPAGE,
|
| 29 |
+
citation=_CITATION,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
def _split_generators(self, dl_manager):
|
| 33 |
+
images_archive = dl_manager.download(f"{_REPO}/resolve/main/images.tgz")
|
| 34 |
+
image_iters = dl_manager.iter_archive(images_archive)
|
| 35 |
+
return [
|
| 36 |
+
datasets.SplitGenerator(
|
| 37 |
+
name=datasets.Split.TRAIN,
|
| 38 |
+
gen_kwargs={
|
| 39 |
+
"images": image_iters
|
| 40 |
+
}
|
| 41 |
+
),
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
def _generate_examples(self, images):
|
| 45 |
+
idx = 0
|
| 46 |
+
for filepath, image in images:
|
| 47 |
+
character = filepath.split('/')[-1][:-4]
|
| 48 |
+
yield idx, {
|
| 49 |
+
"image": {"path": filepath, "bytes": image.read()},
|
| 50 |
+
"character": character,
|
| 51 |
+
}
|
| 52 |
+
idx += 1
|