TensorFlow-CPU与GPU的安装教程

  • TensorFlow-CPU
  • 1.下载Anaconda
  • 2. 下载Vsual C++
  • 3. 安装TensorFlow-CPU
  • TensorFlow-GPU
  • 1.检测当前GPU驱动版本是否满足大于410版本
  • 2.下载Vsual C++
  • 3.下载Anaconda或Miniconda
  • 4.替代.condarc配置文件
  • 4.安装Tensorflow-GPU



写在前面:CPU和GPU版本可以二选一,建议直接安装GPU版。

TensorFlow-CPU

1.下载Anaconda

  1. 下载Anaconda3-2020.02-Windows-x86_64(如果之前安装过 尽量卸载重新安装)
    下载地址(镜像版本下载很快):点击下载Anaconda3-2020.02-Windows-x86_64
  2. tensorflow gpu 测试 tensorflow gpu cpu_python


2. 下载Vsual C++

(这一步安装运行库很重要,安装完成后务必重启)

下载地址: 点击下载Vsual C++

tensorflow gpu 测试 tensorflow gpu cpu_python_02

3. 安装TensorFlow-CPU

打开anaconda prompt

tensorflow gpu 测试 tensorflow gpu cpu_pip_03

  1. 输入python -m pip install --upgrade pip 回车等候pip升级完成
python -m pip install --upgrade pip

tensorflow gpu 测试 tensorflow gpu cpu_pip_04

  1. 输入pip install tensorflow-cpu==2.3.0 -i https://pypi.doubanio.com/simple 安装tensorflow-cpu版本(豆瓣的资源下载很快)
pip install tensorflow-cpu==2.3.0 -i https://pypi.doubanio.com/simple

tensorflow gpu 测试 tensorflow gpu cpu_tensorflow_05

  1. 安装完成后,输入python回车,再输入import tensorflow as tf 回车,输入tf.__ version __回车,出现tensorflow版本号后表示安装成功
python
import tensorflow as tf 
tf.__version__

tensorflow gpu 测试 tensorflow gpu cpu_anaconda_06

TensorFlow-GPU

1.检测当前GPU驱动版本是否满足大于410版本

在cmd中输入cd C:\Program Files\NVIDIA Corporation\NVSMI回车在输入nvidia-smi回车

cd C:\Program Files\NVIDIA Corporation\NVSMI
nvidia-smi

tensorflow gpu 测试 tensorflow gpu cpu_pip_07


如果你的版本号大于等于410,直接进行下一步。

很明显我的电脑不满足,这时候需要更新显卡驱动,

点击前往Nvidia驱动下载官网 找到你的显卡型号,搜索并下载。

tensorflow gpu 测试 tensorflow gpu cpu_python_08


安装过程,一直点下一步就行,没什么注意点。安装完成重启,再次检测版本号是否满足。就可以进行下一步了。

tensorflow gpu 测试 tensorflow gpu cpu_pip_09

2.下载Vsual C++

(安装完成后务必重启)

下载地址: 点击下载Vsual C++

tensorflow gpu 测试 tensorflow gpu cpu_python_02

3.下载Anaconda或Miniconda

如果还没安装 Anaconda 或 Miniconda,那就安装这两者其中一个。Miniconda 只安装 Conda 和它的环境依赖,而 Anaconda 会预先为你安装好很多包。我倾向于使用 Miniconda 着手,Miniconda只包含conda与python,更简洁,快速。anaconda与Miniconda只能装一个。

点击下载Miniconda

tensorflow gpu 测试 tensorflow gpu cpu_tensorflow_11

4.替代.condarc配置文件

在用户文档下有一个.condarc文件,用记事本打开后替换为以下内容。

tensorflow gpu 测试 tensorflow gpu cpu_anaconda_12


替换为如下:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

替换完成后的配置文件如下

tensorflow gpu 测试 tensorflow gpu cpu_anaconda_13

4.安装Tensorflow-GPU

打开prompt

tensorflow gpu 测试 tensorflow gpu cpu_anaconda_14

输入conda install tensorflow-gpu==2.0.0 回车进入安装

conda install tensorflow-gpu==2.0.0

tensorflow gpu 测试 tensorflow gpu cpu_pip_15


安装完成后输入python回车,import tensorflow as tf 回车,输入tf.test.is_gpu_available()回车

python
import tensorflow as tf 
tf.test.is_gpu_available()

出现true说明大功告成

tensorflow gpu 测试 tensorflow gpu cpu_pip_16

附:miniconda中安装 jupyter
直接输入pip install jupyte -i https://pypi.doubanio.com/simpler回车即可

pip install jupyter -i https://pypi.doubanio.com/simple

tensorflow gpu 测试 tensorflow gpu cpu_tensorflow gpu 测试_17


创建jupyter notebook的快捷方式

新建一个txt文本,编辑内容jupyter notebook,保存为.bat格式即可。

tensorflow gpu 测试 tensorflow gpu cpu_python_18


tensorflow gpu 测试 tensorflow gpu cpu_pip_19