还是参见官网.
1.创建conda 环境
以下命令在cmd窗口按顺序执行.
conda create --name tensorflow python=3.5
创建一个名为tensorflow的环境, 语言版本为3.5activate tensorflow
激活指定环境- 安装cpu版本的TF
- 旧
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl
- 新
pip install --ignore-installed --upgrade tensorflow
- 测试
#tensorflowTest.py
import tensorflow as tf
hello = tf.constant('Hello,TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))
2. IDE指定conda环境
图2-1 在IDEA中指定对应的conda环境
3. cuda + cuDNN
相比于cpu, gpu可以获得高至10倍的加速比!
名词约定:
- MSVS
Microsoft VIsual Studio
图3-1 CUDA
3.1 查看GPU是否支持cuda
我的是1050 Ti.
支持型号查看地址: 这里
3.2 cuda 9.0
该段记录日期 2018/03/07
windows-10 64 bit
+python 3.5
+ visual studio 2017 community
+ cuda toolkit 9.0
+cuDNN v7.1.1 (Feb 28, 2018), for CUDA 9.0
+tensorflow 1.6-gpu
windows-10 64 bit
+python 3.5
+ visual studio 2017 community
+ cuda toolkit 9.0
+cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0
+tensorflow 1.6-gpu
-
visual studio中只安装 visual c++相关组件即可.
-
cuda toolkit 9.0 安装包大小约1.5G.
安装后会自动在PATH
中添加它的路径.
figure 安装成功后的目录内容 -
cuDNN v7.1.1 (Feb 28, 2018), for CUDA 9.0
加删除线是因为 会报错
2018-03-13 20:44:03.100572: E C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\stream_executor\cuda\cuda_dnn.cc:378] Loaded runtime CuDNN library: 7101 (compatibility version 7100) but source was compiled with 7003 (compatibility version 7000). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.
figure cuDNN v7.1.1压缩包内容
约200MB, 在三个文件夹中分别包含 .h .dll .lib
三个文件. 复制到cuda的文件夹下即可.
- cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0
下载后为cudnn-9.0-windows10-x64-v7.zip
. 使用方法同上.
3.3 cuda 8.0
windows-10 64 bit
+python 3.5
+visual studio 2015 community
+ cuda toolkit 8.0
+cudnn-8.0-windows10-x64-v6.0
+tensorflow 1.3-gpu
- tf_1.3 版本只支持 cuda 8.0.
- cuda 8.0 只支持 MSVS 2015, 不支持 MSVS 2017.
- 因为MSVS 2015太落后, 所以在微软官网注册后才能下载. 推荐
Visual Studio Community 2015 with Update 3
.
3.4 cuDNN
The NVIDIA CUDA Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. cuDNN provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, normalization, and activation layers. cuDNN is part of the NVIDIA Deep Learning SDK.
喵的, nvidia下载页面总是显示 NVIDIA Developer Site is under going maintenance., 最后还是百度网盘找到了资源[4].
忍不住给nvidia发邮件, 是他们网络加速代理商zenlogic出了问题, 我给他们提供截图, ip, 报文信息等线索帮助他们排查.
figure nvidia的人很重视, 要求网络代理商小时级汇报进展
最后解决了.
figure 感人的下载页面
3.5 加速验证
figure: cpu无波动, gpu load升高
figure: 控制台显示运算在GPU上进行
4. tf版本与python版本的常见搭配
python 3.6 搭配 tf 1.12
实践成功于 2022.12.05
conda create --name tf1.12 python=3.6
conda activate tf1.12
# 没有这一行, 会报错 protobuf requires Python '>=3.7' but the running Python is 3.6.13
python -m pip install --upgrade pip
pip install tensorflow==1.12
python 3.7 搭配 tf 1.13
conda create --name tf1.13 python=3.7
conda activate tf1.13
pip install tensorflow==1.13
参考
- cudnn 简介
- 一个常见报错, No module named “_pywrap_tensorflow” error
- nvidia官方教程,cudnn-install-windows
- 百度网盘资源 cudnn-8.0-windows10-x64-v6.0.zip