无法将符号张量 (lstm/strided_slice:0) 转换为 numpy 数组

Cannot convert a symbolic Tensor (lstm/strided_slice:0) to a numpy array

我希望有人回答下面的错误代码,我正在研究受监督的 ML,但我遇到了错误。

我的库详细信息(当我将上述两个包降级为上面提到的当前包详细信息时,许多开发人员说降级版本它会工作,但在我的情况下它不工作):

代码如下:

# Defining the LSTM model to be fit
model = Sequential()
model.add(LSTM(85, input_shape=(1, 53)))
model.add(Dense(1))
model.compile(loss='mae', optimizer='adam')
# Fitting the model
history = model.fit(train_X, train_y, epochs=70, batch_size=175, validation_data=(test_X, test_y), verbose=2, shuffle=False)
# Plotting the training progression
pyplot.plot(history.history['loss'], label='train')
pyplot.plot(history.history['val_loss'], label='test')
pyplot.legend()
pyplot.show()

错误:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-10-251aaaf9021e> in <module>
      1 # Defining the LSTM model to be fit
      2 model = Sequential()
----> 3 model.add(LSTM(85, input_shape=(train_X.shape[1], train_X.shape[2])))
      4 model.add(Dense(1))
      5 model.compile(loss='mae', optimizer='adam')

 NotImplementedError: Cannot convert a symbolic Tensor (lstm_2/strided_slice:0) to a numpy array. 
   This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

在添加依赖层 input_shape 的 LSTM 模型时得出解决方案不合适,因此将形状更改为

model = Sequential()
model.add(LSTM(85, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(Dense(1))
model.compile(loss='mae', optimizer='adam')

# Fitting the model
history = model.fit(train_X, train_y, epochs=70, batch_size=175, validation_data=(test_X, test_y), verbose=2, shuffle=False)
# Plotting the training progression
pyplot.plot(history.history['loss'], label='train')
pyplot.plot(history.history['val_loss'], label='test')
pyplot.legend()
pyplot.show()