手把手解决module ‘tensorflow‘ has no attribute ‘placeholder

这篇具有很好参考价值的文章主要介绍了手把手解决module ‘tensorflow‘ has no attribute ‘placeholder。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、问题背景:构建神经网络在加入卷积层时出现报错

face_recigntion_model.add(Conv2D(32,3,3,input_shape=(IMAGE_SIZE,IMAGE_SIZE,3),activation='relu'))

AttributeError: module 'tensorflow' has no attribute 'placeholder'

2、报错原因:可能是由于tf.placeholder的版本问题,tf.placeholder是tensorflow1.x版本的东西,tensorflow2.0就不能用了

查看自己的TensorFlow版本print(tf.__version__)

我的为2.8.0,需要降版本

3、解决方法:

方法1:

修改import tensorflow as tf

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

方法2:

修改import tensorflow as tf

import tensorflow.compat.v1 as tf

tf.compat.v1.disable_eager_execution()

方法3:我采用上述两种方式都不行,需要手动降TensorFlow的版本,方式为将高版本python改变成低版本python以安装低版本tensorflow.

1、先卸载已有的TensorFlow,在终端中输入:

pip uninstall tensorflow进行卸载

2、将编译环境降为python3.6

由于python3.7以上安装tensorflow只有2.x的版本,所以需要将编译环境也降到python3.6

安装python3.6,在终端中输入:

conda create --name py36 python=3.6 anaconda

重启pycharm,激活python3.6,在终端中输入:

activate py36

验证环境,在终端中输入:

python –version

输出为:

Python 3.6.13 :: Anaconda, Inc.

如果还是原来的版本,需要重新启动下pycharm在检查版本。

3、安装低版本TensorFlow

安装TensorFlow1.4.0,在终端中输入:

pip install tensorflow==1.4.0 -i Simple Index

安装成功

PS:新的编译环境中可能会缺少很多需要用的包,需要采用pip install 下载相关包

4、后续问题补充

缺少cv2、sklearn… 在终端通过pip安装

pip install opencv-python -i Simple Index

pip install scikit-learn -i https://pypi.douban.com/simple

继续报错:cannot import name ‘tf2‘

原因:keras的版本和tensorflow的版本不匹配,终端输入:

pip list找到TensorFlow的版本

tensorflow             1.4.0

在对应表格中找到对应的keras版本,通过pip安装

pip install keras==2.0.8 -i https://pypi.douban.com/simple

module 'tensorflow' has no attribute 'placeholder,opencv,python,卷积神经网络

每解决一个问题就运行下程序,遇到新的问题解决新的问题,直至程序能够运行下去不报错。

5、个人心得

如果网络上提供的方法不能解决问题,不要一直找新的答案,要先清楚问题的原因是什么,再去解决。譬如本次报错的主要问题主要是TensorFlow的版本不对,所以输入什么代码以及有没有用不重要,重要的是需要寻找并完成TensorFlow低版本的替代工作。

如果我解决了你的问题,请点赞给我加油module 'tensorflow' has no attribute 'placeholder,opencv,python,卷积神经网络,也谢谢在解决问题过程中参考的诸位大佬们。。

 主要参考:

将高版本py与tensorflow改变成低版本python以安装低版本tensorflow_树顶上的橙子的博客-CSDN博客_安装低版本tensorflow

 文章来源地址https://www.toymoban.com/news/detail-812900.html

到了这里,关于手把手解决module ‘tensorflow‘ has no attribute ‘placeholder的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【最简单解决办法】:module ‘tensorflow.compat.v1‘ has no attribute ‘contrib‘

    目录 出现错误界面 1.问题原因 2.解决办法 (1)在调用之前首先添加如下代码块并执行 (2)查找响应函数对应的函数调用前缀。 注:若出现错误也是LSTM预测,可直接复制如下代码: 最后问题解决,代码最后成功运行 anaconda下: tensorflow版本:tensorflow2.3.0 python版本:python3

    2023年04月25日
    浏览(42)
  • 解决AttributeError: module tensorflow has no attribute reset_default_graph

    目录 解决AttributeError: module tensorflow has no attribute reset_default_graph 错误原因 解决方法 步骤1: 查看TensorFlow版本 步骤2: 替换过时的方法或属性 步骤3: 更新代码 步骤4: 手动重置默认图(如果适用) 结论 在使用TensorFlow进行深度学习任务时,有时会遇到类似于\\\"AttributeError: module \\\'te

    2024年02月04日
    浏览(36)
  • 解决AttributeError: module ‘keras‘ has no attribute ……

    在成功解决AttributeError: module ‘keras‘ has no attribute ‘utils‘_new1998的博客-CSDN博客这篇博客中博主有提到如何解决这一问题,其中就是要把 更改成为 而博主不知道其中原因,原因其实是在TensorFlow 2.4及以上版本中, import keras 的方式已经被弃用,取而代之的是 import tensorflow.k

    2024年02月11日
    浏览(36)
  • 解决AttributeError: module ‘serial‘ has no attribute ‘Serial‘

    最近在搞上位机时遇到了报错AttributeError: module ‘serial’ has no attribute ‘Serial’,翻译过来就是serial类没有Serial对象。然后卡了一个小时才解决,试了网上很多方法,最后才发现报错原因,这问题python也有责任。 下面说下一般的解决方法。 python3之后串口都改为pyserial,seria

    2024年02月02日
    浏览(41)
  • AttributeError: module ‘numpy‘ has no attribute ‘bool‘解决

    问题原因:在numpy的1.24版本已经弃用了np.bool这个名称,取而代之的是np.bool_ 解决方法: 1.点击出错文件 2.将np.bool更改为np.bool_

    2024年02月12日
    浏览(87)
  • 【已解决】AttributeError: module ‘pandas‘ has no attribute ‘Series‘

    问题描述:pandas是用于数据处理和分析的包,本文是基于笔者在进行模型训练时遇到的一个问题,于是随笔记录下了从发现问题到解决问题的整个过程。 当遇到AttributeError: module \\\'pandas\\\' has no attribute \\\'Series\\\'这样的错误,首先我是在python命令行中进行测试Series属性是否可用。  

    2024年02月11日
    浏览(67)
  • 【已解决】AttributeError: module ‘numpy‘ has no attribute ‘int‘.

    AttributeError: module ‘numpy’ has no attribute ‘int’. np.int was a deprecated alias for the builtin int . To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. 新版本的numpy里面没有np.int了。 第一种,降低numpy版本,安装1.20以下的版本。 第二种,修改源码。 将 修

    2024年02月14日
    浏览(30)
  • AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法

    NumPy是Python中重要的数值计算库,提供了强大的数组操作和数学函数。然而,有时候我们可能会在使用NumPy时遇到\\\"AttributeError: module ‘numpy’ has no attribute ‘array’\\\"的错误提示,这可能会让一些用户感到困惑。在本文中,我们将分享如何解决这个问题的方法,并帮助读者更好地

    2024年02月13日
    浏览(50)
  • 成功解决AttributeError: module ‘numpy‘ has no attribute ‘float‘.

    AttributeError: module ‘numpy’ has no attribute ‘float’. np.float was a deprecated alias for the builtin float . To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for

    2024年02月16日
    浏览(48)
  • Langchain module ‘hnswlib‘ has no attribute ‘Index‘ 错误解决

    使用 Langchain 操作 Chroma 向量数据库时,报一下错误信息, 试着重装了不同 hnswlib 版本没有解决,最后解决方法是,不要使用 hnswlib,使用 chroma-hnswlib, 完结!

    2024年02月13日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包