tensorflow 2.0 安装------------CPU版

由于我的电脑只有cpu没有gpu,也没有nvidia显卡,所以我也没安装cuda
只需要安装tensorflow即可
pip install tensorflow==2.0.0-alpha0

安装过程中可能会报错
如果报grpcio相关的错误请输入:
pip install protobuf
pip install grpcio-tools
还报错再输入:
pip install grpcio-tools -i https://pypi.doubanio.com/simple
如果报超时timeout错误,请多次输入:
pip install tensorflow==2.0.0-alpha0 这是网络的问题
安装完成后输入样例代码:
import tensorflow as tf
import timeit

with tf.device(’/cpu:0’):

cpu_a=tf.random.normal([2,2])
cpu_b=tf.random.normal([2,2])
print(cpu_a.device,cpu_b.device)

def cpu_run():

with tf.device('cpu:0'):
    c=tf.matmul(cpu_a,cpu_b)
return c

cpu_time=timeit.timeit(cpu_run, number=100)
cpu_time=timeit.timeit(cpu_run,number=100)
print(‘run time:’,cpu_time)

安装成功即可显示结果
2019-06-14 17:29:43.429094: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
/job:localhost/replica:0/task:0/device:CPU:0 /job:localhost/replica:0/task:0/device:CPU:0
run time: 0.014292467803760811

Process finished with exit code 0

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值