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