我有这个错误:AttributeError:' dict'对象没有属性' train'在我的代码中:
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)
执行时,我收到错误:
train_data = svhn.train.images # Returns np.array
AttributeError: 'dict' object has no attribute 'train'
我该如何解决这个问题?
答案 0 :(得分:1)
我没有看到任何错误... scipy.io.loadmat
returns a dictionary,并且基本词典没有“train”属性。如果matlab文件中有“train”变量,那么它将被存储为字典键,因此您可以将其作为svhn['train']
(而不是svhn.train
)进行访问。