Datasets:
Tasks:
Image Classification
Modalities:
Image
Formats:
imagefolder
Languages:
Georgian
Size:
10K - 100K
Commit
·
e9cbbe3
1
Parent(s):
3ceec13
add dataset builder script
Browse files- handwriting_dataset.py +40 -0
handwriting_dataset.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
|
3 |
+
logger = datasets.logging.get_logger(__name__)
|
4 |
+
_DESCRIPTION = """
|
5 |
+
Georgian language handwriting dataset!
|
6 |
+
"""
|
7 |
+
_URL = 'https://huggingface.co/datasets/AnaChikashua/handwriting/resolve/main/handwriting_dataset.rar'
|
8 |
+
class HandwritingData(datasets.GeneratorBasedBuilder):
|
9 |
+
def _info(self):
|
10 |
+
return datasets.DatasetInfo(
|
11 |
+
description=_DESCRIPTION,
|
12 |
+
features = datasets.Features(
|
13 |
+
{"alphabet": datasets.Value("string"),
|
14 |
+
"image": datasets.Image()
|
15 |
+
}
|
16 |
+
),
|
17 |
+
supervised_keys = None,
|
18 |
+
homepage = "https://huggingface.co/datasets/AnaChikashua/handwriting",
|
19 |
+
)
|
20 |
+
def _split_generators(self, dl_manager):
|
21 |
+
path = dl_manager.dowload(_URL)
|
22 |
+
image_iters = dl_manager.iter_archive(path)
|
23 |
+
return [
|
24 |
+
datasets.SplitGenerator(
|
25 |
+
name = datasets.Split.TRAIN,
|
26 |
+
gen_kwargs = {"images": image_iters}
|
27 |
+
),
|
28 |
+
]
|
29 |
+
def _generate_examples(self, images):
|
30 |
+
"""This function returns the examples in the raw (text) form."""
|
31 |
+
idx = 0
|
32 |
+
# Iterate through images
|
33 |
+
for filepath, image in images:
|
34 |
+
# extract the text from the filename
|
35 |
+
text = filepath.split("/")[-1].split(".")[0]
|
36 |
+
yield idx, {
|
37 |
+
"alphabet": text,
|
38 |
+
"image": {"path": filepath, "bytes": image.read()}
|
39 |
+
}
|
40 |
+
idx += 1
|