当前位置: 首页 > news >正文

2021年最新完整统计TensorFlow2.x报错记录与解决方法「希望能帮助到你」

在这里插入图片描述

报错1:module ‘tensorflow’ has no attribute ‘set_random_seed’

原因:在tensorflow 2.x中应该是: tf.random.set_seed

报错2:module ‘tensorflow’ has no attribute ‘GPUOptions’

修改为:tf.compat.v1.

报错3:RuntimeError: set_session is not available when using TensorFlow 2.0.

修改为:tf.compat.v1.keras.backend.set_session()

报错4:AttributeError: module ‘tensorboard.summary._tf.summary’ has no attribute ‘FileWriter’

将tf.summary.FileWriter()换成tf.summary.create_file_writer()

报错5:AttributeError: module ‘tensorflow’ has no attribute ‘get_default_graph’

修改为:使用tf.compat.v1.get_default_graph获取图而不是tf.get_default_graph。

报错6:AttributeError: ‘_thread._local’ object has no attribute ‘value’

解决办法:重新创建一个虚拟环境,版本号对应为:
TensorFlow 1.14.0 + Keras 2.2.5 on Python 3.6.

conda create -n tf1.14 python=3.6
pip3 install --index-url https://pypi.douban.com/simple tensorflow-gpu==1.1.4
pip3 install --index-url https://pypi.douban.com/simple Keras== 2.2.5
pip3 install --index-url https://pypi.douban.com/simple opencv-python==4.1.1.26或pip install opencv-python==4.1.1.26

注意:如果还是报错,那就去pycharm设置的配置环境中安装py-opencv即可

pip install astunparse
pip install opt-einsum
pip install numpy==1.15.4 

报错7:RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

问题产生的原因:无法执行sess.run()的原因是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.
解决办法:
tf.compat.v1.disable_eager_execution()

测试代码:

import os
import cv2
import math
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
print(tf.__version__)

for i in range(3):
    tf.compat.v1.disable_eager_execution()#保证sess.run()能够正常运行
    tf.compat.v1.set_random_seed(1234)
    generate = tf.compat.v1.random_uniform((10,), 0, 10)
    with tf.compat.v1.Session() as sess:
        b = sess.run(generate)
        print(b)

报错8: import cv2 ImportError: numpy.core.multiarray failed to import

原因:由于 Tensorflow 不是最新版本,而 numpy 最新,可能是两者兼容性问题
命令:pip install numpy==1.18.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/

一般情况下是由于numpy版本过高导致的

报错9:ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath’

解决提升:tensorflow-cpu 2.2.0 requires numpy<2.0,>=1.16.0, but you have numpy 1.12.0 which is
incompatible.

报错10:安装numpy部分成功后报错:

tensorflow-cpu 2.2.0 requires scipy==1.4.1; python_version >= “3”, which is not installed.
matplotlib 3.3.0 requires kiwisolver>=1.0.1, which is not installed.
matplotlib 3.3.0 requires pillow>=6.2.0, which is not installed.
matplotlib 3.3.0 requires pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3, which is not installed.
ble.
tensorflow-cpu 2.2.0 requires h5py<2.11.0,>=2.10.0, but you have h5py 3.1.0 which is
incompatible.
tensorflow-cpu 2.2.0 requires numpy<2.0,>=1.16.0, but you have numpy 1.12.0 which is
incompatible.
tensorflow-cpu 2.2.0 requires tensorboard<2.3.0,>=2.2.0, but you have tensorboard 1.14.0 which is incompatible.
tensorflow-cpu 2.2.0 requires tensorflow-estimator<2.3.0,>=2.2.0, but you have tensormatplotlib 3.3.0 requires numpy>=1.15, but you have numpy 1.12.0 which is incompatible.
tensorflow-gpu 1.14.0 requires numpy<2.0,>=1.14.5, but you have numpy 1.12.0 which is incompatible

报错11:tf2_cpu:RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

原因:无法执行sess.run()的原因是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.
解决办法:
tf.compat.v1.disable_eager_execution()

报错12:tf2_cpu:RuntimeError: tf.placeholder() is not compatible with eager execution.

将tf替换为tf.compat.v1.disable_eager_execution()

numpy from versions:

1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.4, 1.11.0b3, 1.11.0rc1, 1.11.0rc2, 1.11.0, 1.11.1rc1, 1.11.1, 1.11.2rc1, 1.11.2, 1.11.3, 1.12.0b1, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.1rc1, 1.12.1, 1.13.0rc1, 1.13.0rc2, 1.13.0, 1.13.1, 
1.13.3, 1.14.0rc1, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0rc1, 1.15.0rc2, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0rc1, 1.16.0rc2, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.17.0rc1, 1.17.0rc2, 1.17.0, 1.17.1, 1.17.2, 1.17.3, 1.17.4, 1.17.5, 1.18.0rc1, 1.18.0, 1.18.1, 1.18.2, 1.18.3, 1.18.4, 1.18

http://tflearn.org/installation/

报错13:from keras.application.xception import Xception

ModuleNotFoundError: No module named ‘keras.application’

解决方法:改为keras_applications
import tensorflow.keras.applications.ResNet50
from keras_applications.resnet import ResNet50

import tensorflow.keras.applications.ResNet50
from keras.applications.resnet50 import ResNet50

报错14:set_session is not available when using TensorFlow 2.0.

若是遇到如题错误:keras.backend.tensorflow_backend.set_session(tf.compat.v1.Session(config=config))

改为tf.compat.v1.keras.backend.set_session(tf.compat.v1.Session(config=config))

报错15:module ‘tensorflow’ has no attribute ‘enable_eager_execution’

解决办法:tf.compat.v1.enable_eager_execution()

报错16:module ‘tensorboard.summary._tf.summary’ has no attribute ‘FileWriter’

解决办法:将原来使用的tf.summary.FileWriter()换成tf.train.SummaryWriter()

或者将tf.summary.FileWriter()换成tf.summary.create_file_writer(),解决问题!

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 2004年7月16日
  • Release of the Data Access Application Block 3.1
  • 【长篇博文】Docker学习笔记与深度学习环境的搭建和部署(一)
  • 两个小时学会DirectDraw编程 (转载)
  • 【长篇博文】Docker学习笔记与深度学习环境的搭建和部署(二)
  • 从系统中取得指定资源图像(转载)
  • 【长篇博文】Docker学习笔记(四):镜像的分层、打包、双向绑定、导入导出、Dockerfile的构建、部署与发布
  • PyTorch1.8-gpu和TensorFlow-gpu-2.5已发布【附下载地址和安装教程】
  • 2004年7月19日
  • 使用TensorRT提高GPU上的YOLOv4对象检测速度
  • 论文《Focal Loss for Dense Object Detection》Detectron2的安装与测试(测试案例:全景分割、姿态估计、实例分割、目标检测 - Faster R-CNN)
  • 反叛之冰:Internet Communications Engine
  • 【经典视觉算法推荐】Focal Loss 论文公式推导及主要贡献
  • 2004年7月20日
  • YOLO自带的图像数据增强方法
  • 【108天】Java——《Head First Java》笔记(第1-4章)
  • 【vuex入门系列02】mutation接收单个参数和多个参数
  • JS字符串转数字方法总结
  • leetcode-27. Remove Element
  • Linux学习笔记6-使用fdisk进行磁盘管理
  • mysql中InnoDB引擎中页的概念
  • puppeteer stop redirect 的正确姿势及 net::ERR_FAILED 的解决
  • SQLServer之创建数据库快照
  • vue脚手架vue-cli
  • Yii源码解读-服务定位器(Service Locator)
  • 基于axios的vue插件,让http请求更简单
  • 嵌入式文件系统
  • 如何设计一个微型分布式架构?
  • 实现菜单下拉伸展折叠效果demo
  • 阿里云API、SDK和CLI应用实践方案
  • ​数据结构之初始二叉树(3)
  • (13)Latex:基于ΤΕΧ的自动排版系统——写论文必备
  • (152)时序收敛--->(02)时序收敛二
  • (LeetCode 49)Anagrams
  • (ZT)出版业改革:该死的死,该生的生
  • (二十九)STL map容器(映射)与STL pair容器(值对)
  • (每日持续更新)jdk api之StringBufferInputStream基础、应用、实战
  • (七)MySQL是如何将LRU链表的使用性能优化到极致的?
  • (转)Sublime Text3配置Lua运行环境
  • (最完美)小米手机6X的Usb调试模式在哪里打开的流程
  • .aanva
  • .Net Core webapi RestFul 统一接口数据返回格式
  • .net core webapi 部署iis_一键部署VS插件:让.NET开发者更幸福
  • .NET Core日志内容详解,详解不同日志级别的区别和有关日志记录的实用工具和第三方库详解与示例
  • .NET Core中的时区转换问题
  • .net wcf memory gates checking failed
  • .net6 当连接用户的shell断掉后,dotnet会自动关闭,达不到长期运行的效果。.NET 进程守护
  • .net8.0与halcon编程环境构建
  • .net经典笔试题
  • .Net实现SCrypt Hash加密
  • .net图片验证码生成、点击刷新及验证输入是否正确
  • ::before和::after 常见的用法
  • :class的用法及应用
  • @EnableConfigurationProperties注解使用
  • @manytomany 保存后数据被删除_[Windows] 数据恢复软件RStudio v8.14.179675 便携特别版...