进入CMD 环境中,python -m pip install tensorflow(多次尝试)(pip3 install tensorflow)
安装成功!
此次安装没有安装CUDA,tensorflow的计算在单机CPU下进行。
或者用conda install tensorflow-gpu
安装
文章图片
文章图片
使用conda install tensorflow-gpu安装tensorflow时未指定版本,导致安装了tensorflow2.1版本。而tf.Session是1.X版本tensorflow中的代码。
解决方法
- 使用tensorflow 2.x版本的接口进行调用
tf.Session() --> tf.compat.v1.Session()- 使用以前的版本。(sudo pip install tensorflow==1.14)
import tensorflow as tf
>>>hello = tf.constant('Hello, TensorFlow!')
>>>sess = tf.Session()
>>>print(sess.run(hello))
但是出现module ‘tensorflow’ has no attribute ‘Session’. Did you mean: ‘version’?报错

文章图片
报错AttributeError: module ‘tensorflow’ has no attribute ‘Session’。这其实不是安装错误,是因为在新的Tensorflow 2.0版本中已经移除了Session这一模块,改换运行代码
tf.compat.v1.Session()
就可以获得与原先相同的输出信息。如果觉得不方便,也可以改换低版本的Tensorflow,直接用pip即可安装
sudo pip install tensorflow==1.14
查看tensorflow版本 由于tensorflow版本不同,可能一些函数的调用也有变换,这时候可能需要查看tensorflow版本,可以在终端输入查询命令如下:
import tensorflow as tf
tf.__version__

文章图片
报错: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()【笔记|tensorflow框架搭建问题解决】

文章图片

文章图片
推荐阅读
- 人工智能|Mask R-CNN详解和安装
- 工具|微信困扰我很久的难题,终于有解了
- Python列表的循环遍历 - while 和 for
- 【Python】列表嵌套和列表嵌套的数据查询
- 笔记|使用STM32cubemx进行定时器单多路pwm输入捕获
- 笔记|Mybatis---ResultMap自定义映射规则
- python|计算机网络-基于python的TCP套接字编程
- 计算机视觉二 局部图像描述子 SIFT算法
- python|【计算机视觉】局部图像描述子(Harris角点检测及匹配)