文章目录
*
– 检测当前python版本
– 去tensorflow官网查看支持此python版本的tensorflow版本并下载
– 安装
– 测试
检测当前python版本
anaconda安装最方便,安装好后看版本
因为tensorflow需要和python版本对应
在cmd中输入python,查看版本号
; 去tensorflow官网查看支持此python版本的tensorflow版本并下载
https://pypi.org/project/tensorflow/#files
官网为每一个python版本都提供了三个操作系统,mac,win,linux的版本,选择自己的版本,我的是win
下载对应的whl文件
安装
pip install xxxxx.whl --user
然后,您可以下载相关文件并自动进行配置。
[En]
Then you can download the relevant files and configure them automatically.
测试
测试一个加法运算
结果是4.0
tensorflow版本号是2.6.0
tf.disable_eager_execution()
此函数只能在创建任何图、运算或张量之前调用。它可以用于从TensorFlow 1.x到2.x的复杂迁移项目的程序开头。
这里的tensorflow版本已经很高了,很多属性和之前1.x有了区别
比如session属性已经被转移到其他属性中去了
所以import tensorflow.compat.v1 as tf代替了import tensorflow as tf
import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_eager_execution()
constant1 = tf.constant(2.0)
constant2 = tf.constant(2.0)
sum=tf.add(constant1,constant2)
with tf.Session() as sess:
print(sess.run(sum))
print(tf.__version__)
Original: https://blog.csdn.net/lidashent/article/details/121027152
Author: lidashent
Title: 常识——tensorflow安装cpu版本
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/514888/
转载文章受原作者版权保护。转载请注明原作者出处!