我正在尝试制作一个简单的 Keras 模型。但无论我指定什么输出形状,输出层始终是该形状(1,),因此由于输出层和目标数据形状不匹配,我无法训练我的模型。
import keras
from keras.models import Sequential
from keras.layers import InputLayer, LSTM, Dense
# 63 is the number of unique characters
# 128 is the length of a sequence of characters
X = ... # X is an one-hot ndarray; X.shape == (96092, 128, 63)
Y = ... # Y is an one-hot ndarray; Y.shape == (96092, 63)
model = Sequential()
model.add(InputLayer([128, 63]))
model.add(LSTM(96))
model.add(Dense(63))
model.compile(
optimizer=keras.optimizers.RMSprop(1e-3, decay=1e-5),
loss=keras.losses.sparse_categorical_crossentropy,
)
model.fit(X, Y) # ValueError: Error when checking target: expected dense_4 to have shape (1,) but got array with shape (63,)
如您所见,输出密集层的形状是,(1,)但它必须是形状(63,)。我究竟做错了什么?
我正在使用带有预装 Keras 的 Google Colab。
明月笑刀无情
相关分类