【发布时间】:2021-09-25 16:05:16
【问题描述】:
我目前正在关注本教程的多变量时间序列 LSTM https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/?unapproved=616760&moderation-hash=4e3c737e7c47cf8d889faaf84c3f73db#comment-616760
我们在构建模型时遇到了一个问题:
from math import sqrt
from numpy import concatenate
from matplotlib import pyplot
from pandas import read_csv
from pandas import DataFrame
from pandas import concat
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import mean_squared_error
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
...
# design network
model = Sequential()
model.add(LSTM(50, input_shape=(train_X.shape[1], train_X.shape[2]))) #error here
我得到的错误是NotImplementedError: Cannot convert a symbolic Tensor (lstm_4/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
其他一切似乎都在运行。我得到了一个收益/损失图和一切。这个特定的代码部分只是给了我这个错误。我查了一下,有些人在没有正确安装 Tensorflow 后得到了这个错误。据我所知,它安装得很好,并且在我导入它时似乎没有给我任何问题。
我正在使用 Python 3.7.9 上的 Spyder 5.0.5;但是,我在 Spyder 中的特定环境是 Miniconda 3,即 Python 3.9.5。卸载并重新安装我的软件包似乎不起作用。升级我的包会产生一条消息,基本上说明没有要安装的升级。
编辑:
TensorFlow 2.5.0 版
keras 2.5.0 版
numpy 版本 1.20.3
【问题讨论】:
-
我找到了一个假设的解决方案
pip install --force-reinstall numpy==1.19.3。显然问题出现在 numpy 版本 1.20 和 1.21 中。但是,现在我得到了pandas的错误。ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject这就是我首先升级 numpy 的原因。 -
是的@AcidCatfish,这个问题之前已经解决了
by downgrading by either downgrading python 3.8 to 3.6 or 1.20 to 1.18/1.19,由于兼容性而发生,下面是一些可能对你有帮助的文章。 stackoverflow.com/questions/66207609/…exerror.com/… -
谢谢!我实际上找到了我遇到降级问题的主要原因。您建议的修复方法有效。
标签: python tensorflow keras