【发布时间】:2021-09-23 10:25:03
【问题描述】:
我希望有人回答以下错误代码,我正在研究有监督的 ML,但遇到了错误。
我的库详细信息(由于我将上述软件包都降级为上面提到的当前软件包详细信息,许多开发人员说要降级它可以工作的版本,但在我的情况下它不起作用):
- Numpy : 1.18.5 当前版本(之前是 1.20.3)
- TensorFlow:2.5.0 当前版本(之前是 2.4.1)
- Python:3.8.8
- Keras:2.4.3
代码如下:
# 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
【问题讨论】:
-
您的代码与您附加的错误不同。代码有
model.add(LSTM(85, input_shape=(1, 53)))行,但错误提示这是`model.add(LSTM(85, input_shape=(train_X.shape[1], train_X.shape[2])))`。 -
你知道怎么解决
-
@Kaveh input_shape=(train_X.shape[1], train_X.shape[2]) ,其中 train_X.shape[1] =1 和 train_X.shape[2]=53
-
请阅读ml标签的描述。
-
@molbdnilo 我的问题与 LSTM 有关
标签: python-3.x numpy tensorflow machine-learning lstm