0

I am getting crazy trying to solve this problem

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

I started with a fresh installation of Anaconda on my Windows 10 PC:

    C:\WINDOWS\system32>conda info

     active environment : base
    active env location : C:\Anaconda3
            shell level : 1
       user config file : C:\Users\Administrator\.condarc
 populated config files :
          conda version : 4.12.0
    conda-build version : 3.21.4
         python version : 3.8.8.final.0
       virtual packages : __win=0=0
                          __archspec=1=x86_64
       base environment : C:\Anaconda3  (writable)
      conda av data dir : C:\Anaconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Anaconda3\pkgs
                          C:\Users\Administrator\.conda\pkgs
                          C:\Users\Administrator\AppData\Local\conda\conda\pkgs
       envs directories : C:\Anaconda3\envs
                          C:\Users\Administrator\.conda\envs
                          C:\Users\Administrator\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.12.0 requests/2.25.1 CPython/3.8.8 Windows/10 Windows/10.0.19041
          administrator : True
             netrc file : None
           offline mode : False

Then I installed the tensorflow package with

conda install tensorflow

Then I tried to create a model following this example, in particular lines

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

Which generates the error (the actual line generating the error is the addition of the LSTM layer).

I then tried to upgrade to TF 2.6.0, however, giving the following update command

conda install -c conda-forge tensorflow=2.6.0

leads to a nightmare of conflicts that cannot be resolved (several hours later the conflict output is past 8 klines and overflows my shell buffer).

I have two questions:

  1. How can I resolve the problem, meaning I need python 3.8 and tensorflow supporting LSTM networks? Does my plan to try upgrading to 2.6.0 make sense?
  2. How it is possible that a stable release from Anaconda does ship with a broken tensorflow package? Could be the example being outdated? In this case can somebody suggest the right syntax?

Sincerely,

  • 1
    Well, this problem apperas to be the same as the one posted here. https://stackoverflow.com/questions/66207609/notimplementederror-cannot-convert-a-symbolic-tensor-lstm-2-strided-slice0-t. Now my question could read: "How can I install FT 2.6.0? Why the buggy 2.3.0 gets selected if I give the command conda install tensorflow?" – Alkhwarizmi May 03 '22 at 09:48

1 Answers1

0

Tensorflow supports LSTM from TensorFlow v2.2.0. Also make sure that keras 2.3 is installed to avoid the error. Check the keras version with the following command.

conda list | grep keras

If you wish to upgrade tensorflow,

Uninstall tensorflow with the following command.

conda uninstall tensorflow

please create a conda environment and then install tensorflow with the pip command. It is recommended to use pip over conda since TensorFlow is only officially  released to PyPI.

#create environment
conda create --name tf python=3.
#Activate it 
conda activate tf

TensorFlow requires a recent version of pip, so upgrade your pip installation to be sure you're running the latest version.

pip install --upgrade pip

Then, install TensorFlow with pip.

pip install tensorflow==2.6

Please refer to this document for more information. Thank you!