-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
31 lines (23 loc) · 1 KB
/
data.py
File metadata and controls
31 lines (23 loc) · 1 KB
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
import idx2numpy
import numpy as np
def get_training_files():
#Importing training data. 60,000 avaliable training images
TrainingImageFile = "MNIST Database/train-images.idx3-ubyte"
TrainingImages = idx2numpy.convert_from_file(TrainingImageFile)
#Array of 28x28 matrix with values from 0 to 255
TrainingLabelFile = "MNIST Database/train-labels.idx1-ubyte"
TrainingLabels = idx2numpy.convert_from_file(TrainingLabelFile)
#Array of integers 0-9
return TrainingImages, TrainingLabels
def convert_to_one_hot(labels):
out = np.zeros((10, len(labels)))
for i in range(len(labels)):
out[labels[i], i] = 1
return out
def get_test_files():
#Testing set 10,000 images
TestImageFile = "MNIST Database/t10k-images.idx3-ubyte"
TestImages = idx2numpy.convert_from_file(TestImageFile)
TestLabelFile = "MNIST Database/t10k-labels.idx1-ubyte"
TestLabels = idx2numpy.convert_from_file(TestLabelFile)
return TestImages, TestLabels