目录
通过conda安装CUDA、cudnn方法
不通过conda安装CUDA、cudnn方法
安装前言:
安装VS2015
CUDA和Cudnn
安装Anaconda3
测试:
附录:
通过conda安装CUDA、cudnn方法
Anaconda + TensorFlow 2.0 GPU安装
在 Anaconda 中安装 TensorFlow-gpu 2.0(无需下载 CUDA)
不通过conda安装CUDA、cudnn方法
安装前言:
安装之前,你要知道你要用的tensorflow版本的安装环境,如果你不知道就用本文默认的配置,见官网:
https://tensorflow.google/install/source_windows
* TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll')
* TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll')
MSVC+CUDA+cuDNN+python的版本都要正确
CPU版
tensorflow与keras版本的匹配(你可能用到keras),参考Docker的成套配置:
安装VS2015
MSVC是VS附带的软件包:Microsoft Visual C++ 2015 Redistributable和Microsoft 生成工具 2015,tensorflow官网上说可以不用下载VS可以直接单独下载它,但是你最好还是安装一个VisualStudio2015,VS会附带这两个东西。我尝试了很多次只安装Microsoft Visual C++ 2015 Redistributable和Microsoft 生成工具 2015,结果CUDA装不上。
VS2015免费版的下载可以去这个微信公众号找:软件安装管家
tensorflow官网里有单独的MSVC2015的下载地址,我这里也把它给出吧:
安装 Visual C++ 生成工具 2015。此软件包随附在 Visual Studio 2015 中,但可以单独安装:
- 转到 Visual Studio 下载页面,
- 选择“可再发行组件和生成工具”,
- 下载并安装:
- Microsoft Visual C++ 2015 Redistributable 更新 3
- Microsoft 生成工具 2015 更新 3
这里可以看到:
选择x64的,x64是给64位的系统用的,x86是给32位系统用的。
CUDA和Cudnn
视频教程:
https://www.bilibili/video/av70734671/
博客教程
关于CUDA的安装可以参考这个网址里的CUDA安装方法:
https://zhuanlan.zhihu/p/37086409
关于cuDNN的安装你可以参考这个网址的安装方法:
https://blog.csdn/angzhangzhang123/article/details/79637346
windows下同一个显卡配置多个CUDA工具包以及它们之间的切换
https://blog.csdn/qq_27825451/article/details/89135592
ERROR:
Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
solution:当在anaconda prompt可以用tensorflow2.0,但pycharm不可以用,重启pycharm就可以了。注意tensorflow、python、cuda、cudnn的版本都要匹配
安装Anaconda3
至于python我是在看安装CUDA的那篇知乎文章时下载了一个anaconda3,它的默认python版本是3.5
下载tensorflow的时候,也就是anaconda prompt下输入这个命令时:
pip install tensorflow-gpu==1.10.0
它会很慢,或者是卡住了,点击鼠标右键推进它继续或是一个ctrl+c让它结束,重新来。
这个安装tensorflow的步骤是一个难点,它会从官网上下载资源,而且网络不好,时常中断,你只能不断地重复输入这个命令,
或是更换一个更好的镜像源,要坚持下去。
更换国内镜像源:https://topmanopensource.iteye/blog/2004853
测试:
运行此tensorflow_self_check.py文件可以测试你的CUDA、Cudnn与tensorflow是否安装成功:
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""A script for testing that TensorFlow is installed correctly on Windows.
The script will attempt to verify your TensorFlow installation, and print
suggestions for how to fix your installation.
"""
import ctypes
import imp
import sys
def main():
try:
import tensorflow as tf
print("TensorFlow successfully installed.")
if tf.test.is_built_with_cuda():
print("The installed version of TensorFlow includes GPU support.")
else:
print("The installed version of TensorFlow does not include GPU support.")
sys.exit(0)
except ImportError:
print("ERROR: Failed to import the TensorFlow module.")
candidate_explanation = False
python_version = sys.version_info.major, sys.version_info.minor
print("\n- Python version is %d.%d." % python_version)
if not (python_version == (3, 5) or python_version == (3, 6)):
candidate_explanation = True
print("- The official distribution of TensorFlow for Windows requires "
"Python version 3.5 or 3.6.")
try:
_, pathname, _ = imp.find_module("tensorflow")
print("\n- TensorFlow is installed at: %s" % pathname)
except ImportError:
candidate_explanation = False
print("""
- No module named TensorFlow is installed in this Python environment. You may
install it using the command `pip install tensorflow`.""")
try:
msvcp140 = ctypes.WinDLL("msvcp140.dll")
except OSError:
candidate_explanation = True
print("""
- Could not load 'msvcp140.dll'. TensorFlow requires that this DLL be
installed in a directory that is named in your %PATH% environment
variable. You may install this DLL by downloading Microsoft Visual
C++ 2015 Redistributable Update 3 from this URL:
https://www.microsoft/en-us/download/details.aspx?id=53587""")
try:
cudart64_80 = ctypes.WinDLL("cudart64_80.dll")
except OSError:
candidate_explanation = True
print("""
- Could not load 'cudart64_80.dll'. The GPU version of TensorFlow
requires that this DLL be installed in a directory that is named in
your %PATH% environment variable. Download and install CUDA 8.0 from
this URL: https://developer.nvidia/cuda-toolkit""")
try:
nvcuda = ctypes.WinDLL("nvcuda.dll")
except OSError:
candidate_explanation = True
print("""
- Could not load 'nvcuda.dll'. The GPU version of TensorFlow requires that
this DLL be installed in a directory that is named in your %PATH%
environment variable. Typically it is installed in 'C:\Windows\System32'.
If it is not present, ensure that you have a CUDA-capable GPU with the
correct driver installed.""")
cudnn5_found = False
try:
cudnn5 = ctypes.WinDLL("cudnn64_5.dll")
cudnn5_found = True
except OSError:
candidate_explanation = True
print("""
- Could not load 'cudnn64_5.dll'. The GPU version of TensorFlow
requires that this DLL be installed in a directory that is named in
your %PATH% environment variable. Note that installing cuDNN is a
separate step from installing CUDA, and it is often found in a
different directory from the CUDA DLLs. You may install the
necessary DLL by downloading cuDNN 5.1 from this URL:
https://developer.nvidia/cudnn""")
cudnn6_found = False
try:
cudnn = ctypes.WinDLL("cudnn64_6.dll")
cudnn6_found = True
except OSError:
candidate_explanation = True
if not cudnn5_found or not cudnn6_found:
print()
if not cudnn5_found and not cudnn6_found:
print("- Could not find cuDNN.")
elif not cudnn5_found:
print("- Could not find cuDNN 5.1.")
else:
print("- Could not find cuDNN 6.")
print("""
The GPU version of TensorFlow requires that the correct cuDNN DLL be installed
in a directory that is named in your %PATH% environment variable. Note that
installing cuDNN is a separate step from installing CUDA, and it is often
found in a different directory from the CUDA DLLs. The correct version of
cuDNN depends on your version of TensorFlow:
* TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll')
* TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll')
You may install the necessary DLL by downloading cuDNN from this URL:
https://developer.nvidia/cudnn""")
if not candidate_explanation:
print("""
- All required DLLs appear to be present. Please open an issue on the
TensorFlow GitHub page: https://github/tensorflow/tensorflow/issues""")
sys.exit(-1)
if __name__ == "__main__":
main()
然后可以打开Anaconda Prompt:
然后输入:activate tensorflow 激活tensoflow环境。再输入:python 进入python编程环境
测试tensorflow是否是在用GPU,如果是,结果会有GPU:0的输出,把下面这些代码粘贴进Anaconda Prompt
import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
然后打开Anconda Navigatior
进入tensorflow环境:
安装spyder,我这里已经安装了,它显示的是launch。
然后你就可以用spyder这个IDE使用tensorflow框架了。
当你安装了无数次tensorflow后却不尽人愿,那你就卸载了Anaconda重新来吧。
附录:
1.查看已经安装的CUDA版本
cmd下输入:nvcc -V
2.
#查看tensorflow版本
import tensorflow as tf
tf.__version__
#查询tensorflow安装路径为:
tf.__path__
3.怎么卸载tensorflow
卸载命令时‘pip uninstall tensorflow’。但要先确定我们所在的是哪个环境,
如果所在基础python3.6环境,使用这个命令是没有用处的,倒是你输入‘pip u
ninstall python’可以把基础python3.6环境卸载掉。怎样卸载tensorflow呢?
我们需要先激活有tensorflow的环境,命令为‘activate tensorflow’,然后再
输入命令‘pip uninstall tensorflow’就可以了,卸载python2.7环境也是同理,输入‘pip uninstall python27’。? ? ? ? ?
---------------------
作者:aiguiru
来源:CSDN
原文:https://blog.csdn/ifisher999/article/details/81085805
版权声明:本文为博主原创文章,转载请附上博文链接!
4.查看anaconda的所有环境:
命令行下:
conda info --envs
5.
#看tensorflow安装在CPU还是GPU上
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
print(device_lib.list_local_devices())
#看tensorflow安装在CPU还是GPU上
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print (sess.run(c))
sess.close()
6.怎么用pip卸载应用
先命令行下:pip list来查看安装了什么包
https://jingyan.baidu/article/ea24bc39d8497eda62b3313a.html
pip uninstall 要卸载的包名
比如:pip uninstall tensorflow
加上一个参数-y,启动安静模式,即不提示是否卸载。
pip uninstall tensorflow -y
7.win10怎么查看nvidia显卡GPU的利用率在哪查看
https://jingyan.baidu/article/9158e000022d74a254122819.html
命令如下:cd C:\Program Files\NVIDIA Corporation\NVSMI
之后输入命令:nvidia-smi -l
-l这个参数表示每几秒刷新一次,这里的type:C+G表示使用计算及图形过程,C代表计算过程,G代表图形过程
Memory-Usage表示显存使用大小,Volatile Uncorr表示GPU使用率
******完结撒花******
更多推荐
Win10通过Anaconda安装GPU版tensorflow
发布评论