0

I'm currently following this tutorial for multi-variate time series LSTM https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/?unapproved=616760&moderation-hash=4e3c737e7c47cf8d889faaf84c3f73db#comment-616760

I am running into an issue when we build the model:

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

The error I'm getting is 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 Everything else seems to run though. I get a gain/loss plot and everything. This particular section of code just gives me this error. I had looked it up and some people got this error after not installing Tensorflow properly. As far as I can tell, it is installed fine and doesn't seem to give me any issues when I had imported it.

I am using Spyder 5.0.5 which would be on Python 3.7.9; however, my specific environment in Spyder is Miniconda 3 which is Python 3.9.5. Uninstalling and reinstalling my packages doesn't seem to work. Upgrading my packages yields a message basically stating that there are no upgrades to install.

EDIT:

TensorFlow version 2.5.0

keras version 2.5.0

numpy version 1.20.3

AcidCatfish
  • 192
  • 8
  • I had found one supposed solution ```pip install --force-reinstall numpy==1.19.3```. Apparently the issue arises in numpy versions 1.20 and 1.21. However, now I get and error with ```pandas``` . ```ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject``` which is why I had upgraded numpy in the first place. – AcidCatfish Jul 16 '21 at 22:58
  • 1
    Yes @AcidCatfish,This issue has been solved earlier `by downgrading by either downgrading python 3.8 to 3.6 or 1.20 to 1.18/1.19` , occurs due to compatibility , Below are some articles which might help in your case. https://stackoverflow.com/questions/66207609/notimplementederror-cannot-convert-a-symbolic-tensor-lstm-2-strided-slice0-t/66207610 https://exerror.com/notimplementederror-cannot-convert-a-symbolic-tensor-lstm_2-strided_slice0-to-a-numpy-array/ –  Jul 29 '21 at 06:43
  • Thank you! I actually found the main reason I was running into problems with downgrading. The fixed you suggest works. – AcidCatfish Aug 01 '21 at 22:43

1 Answers1

0

Make sure, if using Spyder IDE you are only using Pip or Conda to install packages and that you are not mixing the two.

If this is the case, create a new environment from scratch and set that as your interpreter.

Make sure you freeze all other packages when you downgrade or install a specific version of a package. This way, you can ensure that nothing auto-updates.

Furthermore, if you are using Miniconda or Anaconda, any issues with installing packages can usually be solved by using conda install -c -conda-forge <some package>.

If using Spyder, while you can usually install packages from the console in the IDE, it is still advised to install packages from your terminal outside of the IDE. Make sure you are installing into the same environment that is set as the interpreter in your Spyder. You can use the cd command to change the working directory to your environment folder and then conda activate <environment name> and you can install into the environment directly.

AcidCatfish
  • 192
  • 8