File size: 2,058 Bytes
e9cbbe3
a891ed9
e34a884
e9cbbe3
7098a21
 
 
d8e92fd
 
 
7098a21
 
e9cbbe3
 
 
1f52108
7098a21
 
e9cbbe3
 
 
a7e63c0
7098a21
 
a891ed9
35d37c3
7098a21
 
e9cbbe3
e34a884
 
a891ed9
e34a884
e9cbbe3
7098a21
e9cbbe3
 
 
 
 
7098a21
 
e9cbbe3
 
7098a21
e9cbbe3
 
 
7098a21
e9cbbe3
48f0f22
e9cbbe3
a891ed9
e9cbbe3
 
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
import datasets
from datasets.tasks import ImageClassification
_NAMES = ['ა', 'ბ', 'გ', 'დ', 'ე', 'ვ', 'ზ', 'თ', 'ი', 'კ', 'ლ', 'მ', 'ნ', 'ო', 'პ', 'ჟ', 'რ', 'ს', 'ტ', 'უ', 'ფ', 'ქ', 'ღ', 'ყ', 'შ', 'ჩ', 'ც', 'ძ', 'წ', 'ჭ', 'ხ', 'ჯ', 'ჰ']
logger = datasets.logging.get_logger(__name__)

_CITATION = """\
@InProceedings{huggingface:dataset,
title = {Georgian language alphabet dataset},
author={Ana Chikashua},
year={2023}
}
"""
_DESCRIPTION = """
Georgian language handwriting dataset!
"""
_URL = "https://huggingface.co/datasets/AnaChikashua/handwriting/resolve/main/handwriting_dataset.zip"


class HandwritingData(datasets.GeneratorBasedBuilder):
    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            citation=_CITATION,
            features=datasets.Features(
                {
                 "label": datasets.features.ClassLabel(names=_NAMES),
                 "image": datasets.Image()
                 }
            ),
            supervised_keys=("image", "label"),
            homepage="https://huggingface.co/datasets/AnaChikashua/handwriting",
            task_templates=[ImageClassification(image_column="image", label_column="label")],

        )

    def _split_generators(self, dl_manager):
        path = dl_manager.dowload(_URL)
        image_iters = dl_manager.iter_archive(path)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"images": image_iters}
            ),
        ]

    def _generate_examples(self, images):
        """This function returns the examples in the raw (text) form."""
        # Iterate through images
        for idx, filepath, image in enumerate(images):
            # extract the text from the filename
            text = [c for c in filepath if not 0 <= ord(c) <= 127][0]
            yield idx, {
                "label": str(text),
                "image": {"path": filepath, "bytes": image.read()}
            }