【发布时间】:2020-08-03 09:37:56
【问题描述】:
我正在使用堆叠 LSTM 进行多类分类,其中有 5 个“字符串”标签。 这是代码的sn-p:
# define parameters
#epochs, batch_size = 20, 46
epochs, batch_size = 5, 40
# define model
model = Sequential()
model.add(LSTM(128,input_shape=(X_train.shape[1],X_train.shape[2]),return_sequences=True))
model.add(LSTM(100, activation='relu',return_sequences=True))
model.add(LSTM(64, activation='relu'))
model.add(Dense(5, activation='softmax'))
model.compile(loss='sparse_categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
#-------------------------------------------------------------------
history = model.fit(X_train, Y_train,
epochs=epochs,
batch_size=batch_size,
verbose=1)
我收到了这个错误:
UnimplementedError: Cast string to float is not supported
[[node metrics/accuracy/Cast (defined at C:\Users\"emitted"LSTM.py:152) ]] [Op:__inference_distributed_function_4954348]
Function call stack:
distributed_function
我知道如何解决这个错误! 有谁知道可能是什么原因?以及如何调试这个错误?
【问题讨论】:
标签: python tensorflow keras lstm softmax