我是一个初学者,正在尝试创建一个简单的神经网络,但是,在训练模型时遇到了一个错误,似乎无法确切地知道该怎么做。 好像我的目标样本被多乘了10次?这就是机器无法匹配这两个集合的原因。关于如何更改此设置有任何帮助吗?
y_train = to_categorical(y_train,10)
y_test = to_categorical(y_test,10)
print(y_train.shape)
print(y_test.shape)
print(X_train.shape)
print(y_train.shape)
print(X_test.shape)
print(y_test.shape)
(60000, 784)
(600000, 10)
(10000, 784)
(10000, 10)
model.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test))
ValueError Traceback (most recent call last)
<ipython-input-47-2e160f97f014> in <module>()
----> 1 model.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test))
~/anaconda3_420/lib/python3.5/site-packages/keras/models.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, **kwargs)
865 class_weight=class_weight,
866 sample_weight=sample_weight,
--> 867 initial_epoch=initial_epoch)
868
869 def evaluate(self, x, y, batch_size=32, verbose=1,
~/anaconda3_420/lib/python3.5/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
1520 class_weight=class_weight,
1521 check_batch_axis=False,
-> 1522 batch_size=batch_size)
1523 # Prepare validation data.
1524 do_validation = False
~/anaconda3_420/lib/python3.5/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_axis, batch_size)
1388 for (ref, sw, cw, mode)
1389 in zip(y, sample_weights, class_weights, self._feed_sample_weight_modes)]
-> 1390 _check_array_lengths(x, y, sample_weights)
1391 _check_loss_and_target_compatibility(y,
1392 self._feed_loss_fns,
~/anaconda3_420/lib/python3.5/site-packages/keras/engine/training.py in _check_array_lengths(inputs, targets, weights)
239 'the same number of samples as target arrays. '
240 'Found ' + str(list(set_x)[0]) + ' input samples '
--> 241 'and ' + str(list(set_y)[0]) + ' target samples.')
242 if len(set_w) > 1:
243 raise ValueError('All sample_weight arrays should have '
ValueError: Input arrays should have the same number of samples as target arrays. Found 60000 input samples and 6000000 target samples.