在tflearn中使用to_categorical时出错

时间:2017-06-30 02:20:17

标签: python tensorflow tflearn

我使用tflearn来训练我的数据集,并使用tflearn.data_utils.build_hdf5_image_dataset来创建hdf5数据集。但是当我尝试使用to_categorical转换类向量时,它会显示

File "/usr/local/lib/python2.7/dist-packages/tflearn/data_utils.py", line 42, in to_categorical

Y[np.arange(len(y)),y] = 1.

IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (50000,) (50000,10)

现在我怀疑它是数据集的问题,我尝试通过cifar-10 iamges制作数据集,并再次显示此错误。这是我的代码,请帮我查一下。感谢。

h5train_file = 'data/cifartrain.h5'
h5test_file = 'data/cifartest.h5'

dataset_file = 'data/cifar/train/'
datatest_file = 'data/cifar/test/'
tflearn.data_utils.build_hdf5_image_dataset(dataset_file, image_shape=(32, 32), mode='folder', output_path=h5train_file, categorical_labels=True, normalize=True)
tflearn.data_utils.build_hdf5_image_dataset(datatest_file, image_shape=(32, 32), mode='folder', output_path=h5test_file, categorical_labels=True, normalize=True)

h5train = h5py.File(h5train_file, 'r')
X = h5train['X']
Y = h5train['Y']

h5test = h5py.File(h5test_file, 'r')
X_test = h5test['X']
Y_test = h5test['Y']
X, Y = shuffle(X, Y)
Y = to_categorical(Y, 10)
Y_test = to_categorical(Y_test, 10)

0 个答案:

没有答案