概述
本文以tensorflow2.0.0-alpha0版本为基础,讲解安装
官方安装网址:
https://www.tensorflow.org/install
需要翻墙
1. 安装python环境
1.1. 安装官方python(推荐)
安装python 3.6 版本以上,必须是 64位
1.1.1. 更新pip
python -m pip install --upgrade pip
1.1.2. 安装相关库
- numpy:科学计算库
- matplotlib:绘图
安装命令:
pip install numpy matplotlib -i https://pypi.doubanio.com/simple
说明:-i https://pypi.doubanio.com/simple使用豆瓣源下载
1.2. 安装Anaconda3
Anaconda是一个免费开源的Python和R语言的发行版本,用于计算科学(数据科学、机器学习、大数据处理和预测分析),Anaconda致力于简化包管理和部署。
已经内置python ,也就是说按照Anaconda3后,不需要安装python解释器
Anaconda集成了很多用于计算科学的库,安装后极为庞大,预计5G以上
下载网址:
https://www.anaconda.com/distribution/
3. 安装tensorflow CPU版本(推荐)
作为学习使用,推荐CPU版本,安装简单,对于一般数据量来说,速度也够用了
清华源:
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣源:
pip install tensorflow -i https://pypi.doubanio.com/simple
4. 安装tensorflow GPU版本
4.1 确定GPU是否支持加速
GPU必须是NVIDIA的
在下面的官方网址,列出支持深度神经网络加速的GPU,确定GPU是否支持,如果支持,再安装下面的软件
https://developer.nvidia.com/cuda-gpus
4.2 安装NVIDIA的 CUDA Toolkit
10.0 以上版本
在下面的网址,下载安装相应版本的软件
https://developer.nvidia.com/cuda-downloads
将安装路径添加到系统环境变量
4.3 安装NVIDIA的 cuDNN SDK
7.4.1 以上版本,是NVIDIA为深度神经网络的GPU加速库
在下面网址中下载安装
https://developer.nvidia.com/cudnn
将安装路径添加到系统环境变量
4.4 安装tensorflow
pip install tensorflow-gpu==2.0.0-alpha0 -i https://pypi.doubanio.com/simple
5. 验证tensorflow是否安装成功
执行下面代码
import tensorflow as tf
print(tf.reduce_sum(tf.random.normal([1000, 1000])))
print('版本:',tf.__version__)
能正常运行不报错,并且显示版本: 2.0.0-alpha0 就说明安装成功!
6. 安装开发工具
使用notebook开发
pip install notebook -i https://pypi.doubanio.com/simple
启动:在cmd下执行下面命令
jupyter notebook