Upload folder using huggingface_hub
Browse files
README.md
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
dataset_info:
|
3 |
+
config_name: emnist-mnist
|
4 |
+
features:
|
5 |
+
- name: image
|
6 |
+
dtype: image
|
7 |
+
- name: label
|
8 |
+
dtype:
|
9 |
+
class_label:
|
10 |
+
names:
|
11 |
+
'0': '0'
|
12 |
+
'1': '1'
|
13 |
+
'2': '2'
|
14 |
+
'3': '3'
|
15 |
+
'4': '4'
|
16 |
+
'5': '5'
|
17 |
+
'6': '6'
|
18 |
+
'7': '7'
|
19 |
+
'8': '8'
|
20 |
+
'9': '9'
|
21 |
+
splits:
|
22 |
+
- name: train
|
23 |
+
num_bytes: 25579752
|
24 |
+
num_examples: 60000
|
25 |
+
- name: test
|
26 |
+
num_bytes: 4271749
|
27 |
+
num_examples: 10000
|
28 |
+
download_size: 17594390
|
29 |
+
dataset_size: 29851501
|
30 |
+
---
|
31 |
+
|
32 |
+
|
33 |
+
# Dataset Card for "emnist-mnist"
|
34 |
+
|
35 |
+
## Dataset Information
|
36 |
+
|
37 |
+
The `emnist-mnist` dataset is a set of images of handwritten digits. The dataset is split into a training set and a test set.
|
38 |
+
|
39 |
+
## Data Fields
|
40 |
+
|
41 |
+
- `image`: The image of the handwritten digit. The data type of this field is `image`.
|
42 |
+
- `label`: The label of the handwritten digit. The data type of this field is `class_label`, and it can take on the values '0' to '9'.
|
43 |
+
|
44 |
+
## Data Splits
|
45 |
+
|
46 |
+
- `train`: The training set consists of 60000 examples, with a total size of 25579752 bytes.
|
47 |
+
- `test`: The test set consists of 10000 examples, with a total size of 4271749 bytes.
|
emnist_mnist.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-mnist-train-images-idx3-ubyte.gz",
|
12 |
+
"train_labels": "emnist-mnist-train-labels-idx1-ubyte.gz",
|
13 |
+
"test_images": "emnist-mnist-test-images-idx3-ubyte.gz",
|
14 |
+
"test_labels": "emnist-mnist-test-labels-idx1-ubyte.gz",
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
class EMNIST(datasets.GeneratorBasedBuilder):
|
19 |
+
|
20 |
+
BUILDER_CONFIGS = [
|
21 |
+
datasets.BuilderConfig(
|
22 |
+
name="emnist-mnist",
|
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=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
|
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)
|
87 |
+
|
88 |
+
for idx in range(size):
|
89 |
+
yield idx, {"image": images[idx], "label": str(labels[idx])}
|
raw/emnist-mnist-test-images-idx3-ubyte.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:906c3165bfab536456427d8f7d007b7cfa88457cfa88e8ff6fb7bf94c8ccc018
|
3 |
+
size 2513615
|
raw/emnist-mnist-test-labels-idx1-ubyte.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:61b660932af457e9be95b50e11438347f1a4468428ae4efdb21ee65cbffa0031
|
3 |
+
size 5144
|
raw/emnist-mnist-train-images-idx3-ubyte.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ccd6166b6b8702fa8d4929daeaae1722cb5a20f2e5b13ee0c799a3d1294adf85
|
3 |
+
size 15046151
|
raw/emnist-mnist-train-labels-idx1-ubyte.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a04b8595692322748140be589a7329918171eb1c7bf91287621e7cf557d20865
|
3 |
+
size 29480
|