window10 如何安装GPU版本的tensorflow, 正确安装cuda, cudnn

本教程详细讲解在Windows 10系统下安装GPU版本的TensorFlow流程,包括检查硬件驱动、选择TensorFlow版本、安装CUDA和cuDNN等关键步骤,确保GPU加速的深度学习框架正常运行。
部署运行你感兴趣的模型镜像

window10 系统如何安装GPU版本的tensorflow, 并安装正确的cuda, cudnn

第一步: 安装前,硬件和驱动检查。(直接跳过第一步)
查看显卡是否支持cuda
https://developer.nvidia.com/cuda-gpus
是否支持某个版本的cuda,还得参考显卡驱动的要求。
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
根据显卡下载驱动
https://www.nvidia.cn/Download/index.aspx?

第二步:选择tensorflow 版本,比如想要安装tensorflow-2.1.0 版本。(先不着急安装,在第四步安装)

第三步:安装cuda(CUDA是NVIDIA推出的用于自家GPU的并行计算框架)。按照tensorflow官网的cuda对照表,根据你要想要安装的tensorflow版本,选择安装一个对应版本的cuda。(比如你想要装tensorflow-2.1.0 版本,tensorflow官网说要按照cuda 10, 但是没说是10.0,10.1,还是10.2。 我一般会选中间的10.1版本,最新的可能不兼容。) 如果安装出错,请检查第一步。检验安装是否成功,在terminal输入:nvcc -V
tensorflow官网cuda对照表 https://tensorflow.google.cn/install/source_windows

第四步:安装tensorflow(pip install tensorflow-gpu==2.1.0)
安装完成后,在python导入tensorflow模块。如有提示报错,再根据报错下载对的cuda版本(如你在第三步安装了cuda-10.2版本,python导入tensorflow,报错可能无法找到cudart64_101.dll,101对应cuda是10.1版本,那么去下载10.1版本cuda安装吧。再次安装新的cuda版本时,选择自定义安装,只需要安装cuda组件(没必要重复安装其他组件))。如果你刚好安装的是正确版本cuda, 在python导入tensorflow模块时会提示类似下面:Successfully opened dynamic library cudart64_101.dll)这里101表示我目前安装的tensorflow成功的匹配了我已经安装了的cuda 10.1版本。

第五步:安装cudnn(cudnn是一个神经网络层加速库文件。没有账户就注册一个)。 cudnn版本对应cuda的版本(下载页面都是对应cuda版本下载的,容易)
下载完成后,如何设置cudnn,官网给了很好的说明。
https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

第六步:再次运行tensorflow。如果还是报错,建议重新安装tensorflow。这里的目的是为了让tensorflow自己找到对应版本的cuda(根据第三步,我重新安装tensorflow-2.1.0)
pip uninstall tensorflow
pip install tensorflow-gpu==2.1.0

如果你需要安装多个版本的tensorflow, 可能会需要多个对应版本的cuda和cudnn
创建不同的虚拟环境,每个虚拟环境里安装不同的tensorflow(步骤如上), tensorflow会根据自身版本的需求找到对应的cuda版本。实际使用时,直接切换虚拟环境就可以。

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.无mkl支持; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 TI 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]://home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: bazel build --config=opt --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值