emnist

I am working on writing a ANN in python that parses the emnist dataset. Information about the dataset can be found here
NIST
The EMNIST Dataset
What is it?The EMNIST dataset is a set of handwritten character digits derived from the
3 Replies
KeithBrown7526
from gzip import decompress
import os
from idx2numpy import convert_from_file

from matplotlib import pyplot as plt

mapping = {}
with open("data/emnist-mapping.txt", "r") as mapping_file:
for line in mapping_file:
mapping[line.split(" ")[0]] = chr(int(line.split(" ")[1]))

def main(decompress_files=True):
if decompress_files:
for filename in os.listdir(os.path.join(os.path.dirname(__file__), "data")):
with open(f"data/{filename}", "rb") as compressed:
with open(f"data/{filename.replace(".gz", "")}", "wb+") as new:
new.write(decompress(compressed.read()))

print("Files decompressed")

index = 26

with open("data/emnist-test-images-idx3-ubyte", "rb") as images:
image_data = convert_from_file(images)
image = image_data[index]

with open("data/emnist-test-labels-idx1-ubyte", "rb") as labels:
label_data = convert_from_file(labels)
label = label_data[index]

plt.imshow(image.T, cmap="gray")
plt.title(f"Label: {mapping[str(label)]}")
plt.show()

if __name__ == "__main__":
main(decompress_files=False)
from gzip import decompress
import os
from idx2numpy import convert_from_file

from matplotlib import pyplot as plt

mapping = {}
with open("data/emnist-mapping.txt", "r") as mapping_file:
for line in mapping_file:
mapping[line.split(" ")[0]] = chr(int(line.split(" ")[1]))

def main(decompress_files=True):
if decompress_files:
for filename in os.listdir(os.path.join(os.path.dirname(__file__), "data")):
with open(f"data/{filename}", "rb") as compressed:
with open(f"data/{filename.replace(".gz", "")}", "wb+") as new:
new.write(decompress(compressed.read()))

print("Files decompressed")

index = 26

with open("data/emnist-test-images-idx3-ubyte", "rb") as images:
image_data = convert_from_file(images)
image = image_data[index]

with open("data/emnist-test-labels-idx1-ubyte", "rb") as labels:
label_data = convert_from_file(labels)
label = label_data[index]

plt.imshow(image.T, cmap="gray")
plt.title(f"Label: {mapping[str(label)]}")
plt.show()

if __name__ == "__main__":
main(decompress_files=False)
Step one is parsing the data
KeithBrown7526
It provides me with a nice example image the next step (which ill be working on later) is the actualy network itself.