Reputation: 31
I have this error: AttributeError: 'dict' object has no attribute 'train' in my code below :
def main(unused_argv):
# Load training and eval data
image_ind = 10
svhn = sio.loadmat('train_32x32.mat')
# access to the dict
x_train = svhn['X']
y_train = svhn['y']
# show sample
plt.imshow(x_train[:,:,:,image_ind])
print(y_train[image_ind])
train_data = svhn.train.images # Returns np.array
train_labels = np.asarray(svhn.train.labels, dtype=np.int32)
eval_data = sio.loadmat('test_32x32.mat')
# access to the dict
x_test = eval_data['X']
y_test = eval_data['y']
eval_dataSVHN = eval_data.test.images # Returns np.array
eval_labels = np.asarray(eval_data.test.labels, dtype=np.int32)
when executing, I am getting the error:
train_data = svhn.train.images # Returns np.array
AttributeError: 'dict' object has no attribute 'train'
How can I fix this?
Upvotes: 1
Views: 6767
Reputation: 2786
I don't see anything wrong... scipy.io.loadmat
returns a dictionary, and base dictionaries don't have a "train" attribute. If there is a "train" variable in the matlab file, then it will be stored as dictionary key, so you can access it as svhn['train']
(as opposed to svhn.train
).
Upvotes: 2