tanganke commited on
Commit
0527717
1 Parent(s): 58be35a

Delete loading script

Browse files
Files changed (1) hide show
  1. emnist_letters.py +0 -89
emnist_letters.py DELETED
@@ -1,89 +0,0 @@
1
- import struct
2
-
3
- import numpy as np
4
-
5
- import datasets
6
- from datasets.tasks import ImageClassification
7
-
8
-
9
- _URL = "./raw/"
10
- _URLS = {
11
- "train_images": "emnist-letters-train-images-idx3-ubyte.gz",
12
- "train_labels": "emnist-letters-train-labels-idx1-ubyte.gz",
13
- "test_images": "emnist-letters-test-images-idx3-ubyte.gz",
14
- "test_labels": "emnist-letters-test-labels-idx1-ubyte.gz",
15
- }
16
-
17
-
18
- class EMNIST(datasets.GeneratorBasedBuilder):
19
-
20
- BUILDER_CONFIGS = [
21
- datasets.BuilderConfig(
22
- name="emnist-letters",
23
- version=datasets.Version("1.0.0"),
24
- )
25
- ]
26
-
27
- def _info(self):
28
- return datasets.DatasetInfo(
29
- features=datasets.Features(
30
- {
31
- "image": datasets.Image(),
32
- "label": datasets.features.ClassLabel(
33
- names=list(chr(i) for i in range(65, 91))
34
- ),
35
- }
36
- ),
37
- supervised_keys=("image", "label"),
38
- task_templates=[
39
- ImageClassification(
40
- image_column="image",
41
- label_column="label",
42
- )
43
- ],
44
- )
45
-
46
- def _split_generators(self, dl_manager):
47
- urls_to_download = {key: _URL + fname for key, fname in _URLS.items()}
48
- downloaded_files = dl_manager.download_and_extract(urls_to_download)
49
- return [
50
- datasets.SplitGenerator(
51
- name=datasets.Split.TRAIN,
52
- gen_kwargs={
53
- "filepath": (
54
- downloaded_files["train_images"],
55
- downloaded_files["train_labels"],
56
- ),
57
- "split": "train",
58
- },
59
- ),
60
- datasets.SplitGenerator(
61
- name=datasets.Split.TEST,
62
- gen_kwargs={
63
- "filepath": (
64
- downloaded_files["test_images"],
65
- downloaded_files["test_labels"],
66
- ),
67
- "split": "test",
68
- },
69
- ),
70
- ]
71
-
72
- def _generate_examples(self, filepath, split):
73
- """This function returns the examples in the raw form."""
74
- # Images
75
- with open(filepath[0], "rb") as f:
76
- # First 16 bytes contain some metadata
77
- _ = f.read(4)
78
- size = struct.unpack(">I", f.read(4))[0]
79
- _ = f.read(8)
80
- images = np.frombuffer(f.read(), dtype=np.uint8).reshape(size, 28, 28)
81
-
82
- # Labels
83
- with open(filepath[1], "rb") as f:
84
- # First 8 bytes contain some metadata
85
- _ = f.read(8)
86
- labels = np.frombuffer(f.read(), dtype=np.uint8) - 1
87
-
88
- for idx in range(size):
89
- yield idx, {"image": images[idx], "label": str(labels[idx])}