我希望有人回答下面的错误代码,我正在处理监督ML,但我遇到了一个错误。
我的库详细信息(当我将上面的包降级为上面提到的当前包详细信息时,许多开发人员都说要降级版本,它会起作用,但在我的情况下,它不起作用(:
- Numpy:1.18.5当前版本(早期版本为1.20.3(
- TensorFlow:2.5.0当前版本(早期版本为2.4.1(
- Python:3.8.8
- 角蛋白: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
在添加依赖于层输入的LSTM模型时得到了解决方案_shape不合适,所以将形状更改为
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()