0
檢查對象時
我的代碼如下:MNIST ValueError異常在Keras
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense, Activation
(x_train, y_train), (x_test, y_test) = mnist.load_data()
y_train = np_utils.to_categorical(y_train, 10)
y_test = np_utils.to_categorical(y_test, 10)
model = Sequential()
model.add(Dense(output_dim=500, input_shape=(28, 28)))
model.add(Activation("tanh"))
model.add(Dense(10))
model.add(Activation("softmax"))
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
model.fit(x_train, y_train, nb_epoch=50, batch_size=20)
這得到了以下錯誤:
ValueError: Error when checking target: expected activation_2 to have 3 dimensions, but got array with shape (60000, 10)
我覺得形狀(60000,10)是y_train
形狀這有2個維度,而預計3個維度的地方。
我應該在哪裏編輯?