AI-For-Beginners
AI-For-Beginners copied to clipboard
pickle.load(mnist_pickle) returns UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)
lessons\3-NeuralNetworks\03-Perceptron
running MNIST = pickle.load(mnist_pickle)
results in
5 with gzip.open('../03-Perceptron/mnist.pkl.gz', 'rb') as mnist_pickle: 6 ----> 7 MNIST = pickle.load(mnist_pickle) 8
UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)
Workaround, which creates future problems:
MNIST = pickle.load(mnist_pickle, encoding="latin1") works well, however, the next step to plot the dataset would result in
**TypeError Traceback (most recent call last) C:\Users\IGOR~1.KOR\AppData\Local\Temp/ipykernel_32352/2720090614.py in ----> 1 print(MNIST['Train']['Features'][0][130:180]) 2 print(MNIST['Train']['Labels'][0]) 3 features = MNIST['Train']['Features'].astype(np.float32) / 256.0 4 labels = MNIST['Train']['Labels'] 5 fig = pylab.figure(figsize=(10,5))
TypeError: tuple indices must be integers or slices, not str**
additional info:
mnist.pkl.gz is not available in the original location, so I downloaded it from https://github.com/mnielsen/neural-networks-and-deep-learning/blob/master/data/mnist.pkl.gz
I assume the data is structured differently in this file.
I see couple of ways of fixing issue:
- bring back mnist.pkl.gz to the repository (since it's missing currently) and make sure accessing fields by strings works there
- change to code to access data using integers, not strings (this seem to work):
print(MNIST[0][0][0][130:180]) print(MNIST[0][1][0]) features = MNIST[0][0].astype(np.float32) / 256.0 labels = MNIST[0][1] fig = pylab.figure(figsize=(10,5)) for i in range(10): ax = fig.add_subplot(1,10,i+1) pylab.imshow(features[i].reshape(28,28)) pylab.show()
i fixed the 'ascii' code error by specifying the encoding parameter: MNIST = pickle.load(mnist_pickle, encoding='latin1')
link to the commit: https://github.com/cutePanda123/AI-For-Beginners/commit/a73db3c0e3ac5c67c1b4b6aecda5f07c8a53d48d