keras lstm/anaconda问题,无法使用python 3.8的conda升级到2.6.0

发布于 2025-01-25 17:12:29 字数 2721 浏览 2 评论 0原文

我很疯狂地尝试解决这个问题< /a>

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

我从Windows 10 PC上的Anaconda进行全新安装开始:

    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

然后我安装了TensorFlow软件包,

conda install tensorflow

然后尝试按照

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')

生成错误的行(生成错误的实际行是LSTM层的添加)。

然后,我尝试升级到TF 2.6.0,但是,给出以下更新命令

conda install -c conda-forge tensorflow=2.6.0

导致无法解决的冲突噩梦(几个小时后,冲突输出超过8 klines,并溢出了我的壳缓冲区)。

我有两个问题:

  1. 如何解决问题,这意味着我需要Python 3.8和支持LSTM网络的TensorFlow?我尝试升级到2.6.0的计划是否有意义?
  2. Anaconda稳定释放的可能性如何才能用破损的张量包装发货?可能是过时的榜样?在这种情况下,有人可以建议正确的语法吗?

真挚地,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2025-02-01 17:12:29

TensorFlow支持TensorFlow v2.2.0的LSTM。另外,请确保安装KERAS 2.3以避免错误。
使用以下命令检查KERAS版本。

conda list | grep keras

如果您想升级TensorFlow,

请使用以下命令卸载TensorFlow。

conda uninstall tensorflow

请创建一个conda环境,然后使用PIP命令安装TensorFlow。建议在conda上使用PIP,因为TensorFlow仅是正式的NBSP;发布给PYPI。

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

TensorFlow需要最近版本的PIP,因此请升级PIP安装,以确保您正在运行最新版本。

pip install --upgrade pip

然后,使用PIP安装TensorFlow。

pip install tensorflow==2.6

请参阅此文档以获取更多信息。谢谢你!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文