利用Anaconda安装TensorFlow2.0的CPU和GPU版本

0 前言

2019年10月Tensorflow正式放出版本2.0,不少网友使用后表示,Tensorflow2.0比Pytorch更好用。

1 准备

我的系统是windows 10,使用Anaconda来管理python环境,通过Anaconda来安装Tensorflow2.0非常简单。
Anaconda安装具体见Anaconda安装教程

2 Tensorflow2.0 CPU版本安装

2.1 新建虚拟环境

使用Anaconda创建一个虚拟环境,具体见Anaconda安装使用教程
选择Anaconda Prompt
在这里插入图片描述
先更新conda

conda update conda

然后新建一个虚拟环境

conda create -n tensorflow2.0-cpu python=3.7

在这里插入图片描述
选择y
在这里插入图片描述
然后激活虚拟环境:

activate tensorflow2.0-cpu

在这里插入图片描述
可以看出环境已经改变,已经进入新建的虚拟环境。

2.2 安装Tensorflow2.0 CPU版本

使用国内清华源来下载,速度快得多

pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

若安装失败,需要多执行上述命令几次。

2.3 验证Tensorflow2.0 CPU版本

新建一个.py文件,用tensorflow2.0-cpu虚拟环境运行

import tensorflow as tf
version = tf.__version__
gpu_ok = tf.test.is_gpu_available()
print("tf version:",version,"\nuse GPU",gpu_ok)

如果没有问题就会出现下列情况:

tf version: 2.0.0
use GPU False

3 tensorflow3.0 GPU 版本安装

3.1 Anaconda创建虚拟环境

同CPU版本一样创建虚拟环境:tensorflow2.0-gpu
先更新conda

conda update conda

然后新建一个虚拟环境

conda create -n tensorflow2.0-gpu python=3.7

在这里插入图片描述
选择y
在这里插入图片描述
然后激活虚拟环境:

activate tensorflow2.0-gpu

3.2 安装tensorflow2.0 GPU版本的NVINDA驱动

安装GPU版本支持,拥有Nvidia的GPU的windows一般都有默认驱动的,只需要安装cudatoolkit 与 cudnn包就可以了,要注意一点需要安装cudatoolkit 10.0 版本,注意一点,如果系统的cudatoolkit小于10.0需要更新一下至10.0。

conda install cudatoolkit=10.0 cudnn

3.3 安装tensorflow2.0 GPU版本

从国内清华源下载

pip install tensorflow-gpu==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

失败时,可以多试几次。

3.4 验证安装

import tensorflow as tf
version = tf.__version__
gpu_ok = tf.test.is_gpu_available()
print("tf version:",version,"\nuse GPU",gpu_ok)

结果:

tf version: 2.0.0
use GPU True
  • 5
    点赞
  • 60
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值