| import datasets |
|
|
| _CITATION = """\ |
| @InProceedings{huggingface:dataset, |
| title = {Klee}, |
| author={Kevin Li}, |
| year={2022} |
| } |
| """ |
| _DESCRIPTION = """\ |
| 128x128 PNG images of kanjis from the Klee font |
| """ |
| _HOMEPAGE = "https://huggingface.co/datasets/AlienKevin/klee" |
| _LICENSE = "CC0" |
| _REPO = "https://huggingface.co/datasets/AlienKevin/klee" |
|
|
| class ImageSet(datasets.GeneratorBasedBuilder): |
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features( |
| { |
| 'character': datasets.Value("string"), |
| 'image': datasets.Image(), |
| } |
| ), |
| supervised_keys=None, |
| homepage=_HOMEPAGE, |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| images_archive = dl_manager.download(f"{_REPO}/resolve/main/images.tgz") |
| image_iters = dl_manager.iter_archive(images_archive) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "images": image_iters |
| } |
| ), |
| ] |
|
|
| def _generate_examples(self, images): |
| idx = 0 |
| for filepath, image in images: |
| character = filepath.split('/')[-1][:-4] |
| yield idx, { |
| "image": {"path": filepath, "bytes": image.read()}, |
| "character": character, |
| } |
| idx += 1 |