Windows11 显卡GTX1650 搭建CUDA+cuDNN环境,并安装对应版本的Anaconda和TensorFlow-GPU


前言

为了调用计算机的GTX1650显卡进行深度学习的模型和训练,需要先搭建好CUDA和cuDNN环境。此外,TensorFlow-gpu版本对python、CUDA和cuDNN的版本也有要求,安装前需要先确定好各个软件需要安装的版本。


提示:以下是本篇文章正文内容,下面案例可供参考

一、安装部署环境

安装环境软件版本
PC系统版本Windows 11 21H2
显卡驱动版本496.76
显卡CUDA算力7.5
CUDA版本cuda_10.0.130_411.31_win10
cuDNN版本cudnn-10.0-windows10-x64-v7.6.5.32
Python版本python-3.7.9-amd64
Anaconda版本Anaconda3-2020.02-Windows-x86_64
TensorFlow-GPU版本1.13.1

显卡信息:
在这里插入图片描述

显卡CUDA算力
在这里插入图片描述

二、安装各个软件

首先安装最新的显卡驱动,从NVIDIA驱动程序官网下载符合本机显卡的最新驱动,默认安装即可。
在这里插入图片描述

1.CUDA和cuDNN的版本选择及安装

查看本机显卡支持的CUDA版本,打开NVIDIA Control Panel(NVIDIA控制面板),点左下角系统信息→组件,查看NVCUDA.DLL的系统版本,此为显卡支持的最高CUDA版本。
在这里插入图片描述

1.1 CUDA的版本选择及安装

目前网上的教程大多要装CUDA9.0版本配合VS2015使用,但由于GTX1650显卡上市较晚,安装CUDA9.0时提示以下错误:
在这里插入图片描述

为了后续配合Visual Studio 2015和TensorFlow-GPU版本使用,选择CUDA10.0版本安装,进CUDA下载官网,下载离线包
在这里插入图片描述
将Base Installer下载下来,双击解压默认下一步安装即可。

若解压时提示Could not create file “C:\TEMP\CUDA1\GFExperience\chrome_elf.dll” 拒绝访问 错误,将电脑上的杀毒软件(360安全卫士)全部退出,再重新解压即可出现CUDA安装程序界面。
在这里插入图片描述
安装完成后应该会自动将CUDA安装位置添加到系统的环境变量中,可以打开设置→系统→高级系统设置→环境变量→系统环境变量,检查是否有下图红框处的环境变量,若没有,手动添加即可。
在这里插入图片描述

1.2 cuDNN的版本选择及安装

cuDNN版本 cuDNN v7.6.5 (November 5th, 2019), for CUDA 10.0
在这里插入图片描述
登录上NVIDIA账号,下载zip包解压后,将对应文件夹的文件放到CUDA安装路径下的对应文件夹里即可。
将其中’bin‘中的’cudnn64_7.dll‘拷贝到cuda10.0安装路径下的bin文件夹中,cuda对应的文件夹的路径为C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin,如下图所示:
在这里插入图片描述
同样的,将cudnn中include下的’cudnn.h‘拷贝到cuda文件夹中的include的文件夹中(C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include)
,cudnn文件中的’lib/x64’中的‘cudnn.lib’拷贝到cude文件中的’lib/x64’中(C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64)。
至此完成了CUDA10.0和cuDNN的安装。

1.3 测试CUDA是否安装成功

  • cmd里查看版本信息nvcc -V
    在这里插入图片描述

  • cmd里输入nvidia-smi查看GPU运行时的监测界面
    在这里插入图片描述
    注:若安装的是CUDA9.0 ,在cmd中需进到以下路径(C:\Program Files\NVIDIA Corporation\NVSMI)执行nvidia-smi才能看到GPU的监测界面。

  • 进入下面图片的路径(C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\demo_suite),然后按住‘shift’+鼠标右击,点击’在此处打开powershell窗口‘,输入: .\bandwidthTest.exe 返回Result=PASS
    在这里插入图片描述
    同理输入:.\deviceQuery.exe 返回:Result=PASS,说明CUDA安装成功了。
    在这里插入图片描述
    同时从上图的 CUDA Capability Major/Minor version number 行可以看到CUDA算力为7.5。

2. TensorFlow-GPU、Python和Anaconda版本的选择与安装

TensorFlow与python、CUDA、cuDNN、编译器环境的对应关系可参考官网的说明

Windows端地址:https://tensorflow.google.cn/install/source_windows
在这里插入图片描述
在这里插入图片描述
需要安装的是Windows TensorFlow-GPU版本,前面已部署好CUDA10.0环境,所以依据上表,选择安装TensorFlow-GPU 1.13.1版本,该版本支持python3.5-3.7,我们选择python 3.7版本。我们在安装anaconda的时候你并不知道会包含哪个版本的python,可以参考《anaconda python 版本对应关系》此篇博文的表来决定安装哪个版本的Anaconda。在Anaconda下载镜像站


里选择自己需要的版本即可,本文选择的是 Anaconda3-2020.02-Windows-x86_64.exe安装包,该版本支持创建python2.7、3.5、3.6、3.7、3.8的虚拟环境。

2.1 安装Anaconda并创建虚拟环境

将Anaconda3-2020.02-Windows-x86_64.exe默认安装即可,安装完成后打开Anaconda Navigator,创建tensorflow-gpu虚拟环境,python版本选择3.7。
创建虚拟环境
创建完成后选中tensorflow-gpu,Open with Terminal
在这里插入图片描述

2.2 安装TensorFlow-GPU

(tensorflow-gpu) C:\Users\admin>pip install tensorflow-gpu==1.13.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

在这里插入图片描述

2.3 测试TensorFlow-GPU是否可用

测试TensorFlow-GPU的第一种方法:
输入以下命令测试,若打印true,表示调用GPU成功。

(tensorflow-gpu) C:\Users\admin>python
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:35:01) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>import tensorflow as tf
>>>tf.test.is_gpu_available()
2021-11-25 16:54:47.265632: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-11-25 16:54:47.390464: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: NVIDIA GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.515
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.25GiB
2021-11-25 16:54:47.390874: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2021-11-25 16:54:47.858586: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-11-25 16:54:47.858887: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0
2021-11-25 16:54:47.860156: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N
2021-11-25 16:54:47.861235: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 2933 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5)
True

在这里插入图片描述
测试TensorFlow-GPU的第二种方法:
将以下代码保存成tfgpu-get.py文件

import tensorflow as tf
if tf.test.gpu_device_name():
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
    print("Please install GPU version of TF")

在命令行中执行,若输出以下内容,表示调用GPU成功,TensorFlow-GPU可用。

(tensorflow-gpu) C:\Users\admin>python tfgpu-test.py
2021-11-25 16:59:45.388468: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-11-25 16:59:45.495860: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: NVIDIA GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.515
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.25GiB
2021-11-25 16:59:45.496494: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2021-11-25 16:59:45.834991: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-11-25 16:59:45.835298: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0
2021-11-25 16:59:45.836502: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N
2021-11-25 16:59:45.837311: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 2933 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5)
2021-11-25 16:59:45.839926: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2021-11-25 16:59:45.840107: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-11-25 16:59:45.840986: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0
2021-11-25 16:59:45.842483: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N
2021-11-25 16:59:45.843361: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 2933 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5)
Default GPU Device: /device:GPU:0

至此完成了Anaconda和TensorFlow-GPU的安装与测试。

三. 参考文章

《windows10 显卡GTX1050安装tensorflow-gpu教程以及Tensorflow不同版本要求与CUDA及CUDNN版本对应关系(GPU版本)》
《windows tensorflow-gpu的安装》
《在 Windows 环境中从源代码构建》
《Tensorflow不同版本要求与CUDA及CUDNN版本对应关系》
《anaconda python 版本对应关系》
等。

总结

以上内容仅供参考,按照步骤操作时应对应修改相关文件路径。

  • 20
    点赞
  • 134
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
对于安装 TensorFlow-GPU 1.14.0,您需要确保您的 Anaconda 环境已正确设置,并且已安装了正确版本CUDAcuDNN。 下面是安装步骤: 1. 首先,确保您已经成功安装Anaconda。如果还没有安装,请按照官方文档的指导进行安装。 2. 接下来,您需要安装 CUDA 10.0。您可以从 NVIDIA 官方网站下载适用于您的操作系统的 CUDA 安装程序,并按照指示进行安装。 3. 安装 CUDA 后,您需要安装 cuDNN 7.4。您需要先注册一个 NVIDIA 开发者账号,然后从 NVIDIA 开发者网站下载 cuDNN 安装包。根据您的操作系统和 CUDA 版本选择正确的版本,并根据 cuDNN 安装指南进行安装。 4. 安装CUDAcuDNN 后,打开 Anaconda Prompt(Windows)或终端(macOS/Linux)。 5. 创建一个新的环境并激活它: ``` conda create -n tf_gpu_env python=3.7 conda activate tf_gpu_env ``` 6. 在新环境安装 TensorFlow-GPU 1.14.0: ``` pip install tensorflow-gpu==1.14.0 ``` 7. 安装完成后,您可以通过运行以下代码来验证 TensorFlow 是否正确安装并使用 GPU: ```python import tensorflow as tf print(tf.test.is_gpu_available()) ``` 如果输出为 True,则表示 TensorFlow 正确安装并且可以使用 GPU。 请注意,安装 TensorFlow-GPU 需要确保您的系统满足 CUDAcuDNN 的要求,并且您的 GPU 支持 CUDA。如果您遇到任何问题,请参考 TensorFlow 官方文档或在相关论坛上寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值