AlienKevin commited on
Commit
a2c6a51
·
1 Parent(s): 9cbdbe2

Create kanjivg_klee.py

Browse files
Files changed (1) hide show
  1. kanjivg_klee.py +55 -0
kanjivg_klee.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+ _CITATION = """\
4
+ @InProceedings{huggingface:dataset,
5
+ title = {KanjiVG & 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 KanjiVG font with stroke order indicated by colors.
13
+ See https://github.com/KanjiVG/kanjivg for more info.
14
+ The right kanji is in the Klee font designed for Japanese
15
+ """
16
+ _HOMEPAGE = "https://huggingface.co/datasets/AlienKevin/kanjivg_klee"
17
+ _LICENSE = "CC0"
18
+ _REPO = "https://huggingface.co/datasets/AlienKevin/kanjivg_klee"
19
+
20
+ class ImageSet(datasets.GeneratorBasedBuilder):
21
+ def _info(self):
22
+ return datasets.DatasetInfo(
23
+ description=_DESCRIPTION,
24
+ features=datasets.Features(
25
+ {
26
+ 'character': datasets.Value("string"),
27
+ 'image': datasets.Image(),
28
+ }
29
+ ),
30
+ supervised_keys=None,
31
+ homepage=_HOMEPAGE,
32
+ citation=_CITATION,
33
+ )
34
+
35
+ def _split_generators(self, dl_manager):
36
+ images_archive = dl_manager.download(f"{_REPO}/resolve/main/images.tgz")
37
+ image_iters = dl_manager.iter_archive(images_archive)
38
+ return [
39
+ datasets.SplitGenerator(
40
+ name=datasets.Split.TRAIN,
41
+ gen_kwargs={
42
+ "images": image_iters
43
+ }
44
+ ),
45
+ ]
46
+
47
+ def _generate_examples(self, images):
48
+ idx = 0
49
+ for filepath, image in images:
50
+ character = filepath.split('/')[-1][:-4]
51
+ yield idx, {
52
+ "image": {"path": filepath, "bytes": image.read()},
53
+ "character": character,
54
+ }
55
+ idx += 1