May 2020
Intermediate to advanced
404 pages
10h 52m
English
There are two label files available to us in the MNIST dataset: train-labels-idx1-ubyte and t10k-labels-idx1-ubyte. To view these files, we can use the following function, which takes input of the filename as an argument and produces an array of one-hot-encoded labels:
def loadLabelFile(filelabel): f = open(filelabel, "rb") f.read(8) labels_arr = [] while True: row = [0 for x in range(10)] try: label = ord(f.read(1)) row[label] = 1 labels_arr.append(row) except: break f.close() label_sets = np.array(labels_arr) return label_sets
This function returns a numpy array of labels in one-hot encoding, with the dimensions of the number of samples in the dataset times by 10. Let's observe a single entry in order ...
Read now
Unlock full access