I am trying to use the mnist_data for hand written digit recognition.Now i tried this code to load the data.
import cPickle
import numpy as np
def load_data():
f = open('G:/thesis paper/data sets/mnist.pkl.gz', 'rb')
training_data, validation_data, test_data = cPickle.load(f)
f.close()
return (training_data, validation_data, test_data)
def load_data_nn():
training_data, validation_data, test_data = load_data()
inputs = [np.reshape(x, (784, 1)) for x in training_data[0]]
results = [vectorized_result(y) for y in training_data[1]]
training_data = zip(inputs, results)
test_inputs = [np.reshape(x, (784, 1)) for x in test_data[0]]
return (training_data, test_inputs, test_data[1])
def vectorized_result(j):
e = np.zeros((10, 1))
e[j] = 1.0
return e
if __name__ == '__main__':
tr_data,test_inp,test_data=load_data_nn()
But i am getting this error.
File "D:/NeuralNet/mnist_loader.py", line 42, in load_data
training_data, validation_data, test_data = cPickle.load(f) cPickle.UnpicklingError: invalid load key, ''.
I couldn't understand what the error is trying to say and how to remove this error..Thanks in advance..
The argument you've passed to cPickle.load() has to be a .pkl file. mnist.pkl is provided inside of mnist.pkl.gz
So, you have to open that .gz first. Try this:
import gzip
f = gzip.open('mnist.pkl.gz', 'rb')
train_set, valid_set, test_set = cPickle.load(f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With