TensorFlow.NET机器学习入门【8】采用GPU进行学习
随着网络越来约复杂,训练难度越来越大,有条件的可以采用GPU进行学习。本文介绍如何在GPU环境下使用TensorFlow.NET。
TensorFlow.NET使用GPU非常的简单,代码不用做任何修改,更换一个依赖库即可,程序是否能运行成功主要看环境是否安装正确,这篇文章重点介绍的也就是环境的安装了。
CUDA和cuDNN的安装都比较容易,重点是要装对版本。
1、确认安装版本
首先电脑得有一块NVIDIA的显卡!
在桌面右键选择NVIDIA控制面板,在程序左下角点击 :系统信息。

首先要确认显卡CUDA的版本,我的是10.1,实际安装时要根据自己的环境来。
根据显卡CUDA版本,需要安装对应的CUDA Toolkit和cuDNN的包,同时也要引用对应版本的TensorFlow_gpu运行库。
这是TensorFlow官方网站提供的一个对应关系。

2、安装CUDA Toolkit
安装包下载地址:CUDA Toolkit 11.5 Update 1 Downloads | NVIDIA Developer
由于不可描述的原因,网站打开很慢,需要有一定的耐心。
我下载的程序为:cuda_10.1.243_win10_network.exe,要保证前两个版本号和本机显卡的CUDA版本一致,最后一位影响不大。
只要选对版本,安装就没有问题了,基本一路下一步就可以了。
3、安装cuDNN
在NVIDIA网站搜索cuDNN即可找到下载地址,同样要注意版本。
我下载的文件为:cudnn-10.1-windows10-x64-v8.0.5.39.zip
从文件名可以看出,该软件版本为8.0,对应的CUDA版本为10.1,这点和TensonFlow网站上说的不完全一致,但实测可以使用。
注意cuDNN软件不需要安装,只要解压到指定目录即可。
假设CUDA安装目录为:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\V10.1
解压后的文件包括:bin、inclue、lib三个文件夹,和CUDA安装目录下的三个同名文件夹合并即可。
【我怀疑随便解压到什么位置,只要把路径加入到path里即可,但我没有测试过。】
4、更换依赖库
本系列第一篇就介绍过一个TensorFlow,NET项目的依赖库如下:

如果需要采用GPU学习,更改其中的一个库如下即可。

需要注意运行库的版本。我的GPU最高支持2.3
如果此时你的运行环境没有具备,程序运行时会弹出警告,并自动切换到CPU进行计算。
5、调试
如果环境没有安装成功,程序运行会打印下列信息:

2021-08-29 09:46:26.631756: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-08-29 09:46:26.633225: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-08-29 09:46:27.323608: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-08-29 09:46:27.993386: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-08-29 09:46:27.994493: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2021-08-29 09:46:27.997410: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2021-08-29 09:46:27.998498: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2021-08-29 09:46:27.999403: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found
2021-08-29 09:46:28.000402: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2021-08-29 09:46:28.001807: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2021-08-29 09:46:28.001917: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1835] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
关键字:Could not load dynamic library
如果环境安装成功,则显示如下:

2021-08-29 09:46:26.631756: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-08-29 09:46:26.633225: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-08-29 09:46:27.323608: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-08-29 09:46:27.993386: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-08-29 09:46:27.994493: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2021-08-29 09:46:27.997410: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2021-08-29 09:46:27.998498: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2021-08-29 09:46:27.999403: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found
2021-08-29 09:46:28.000402: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2021-08-29 09:46:28.001807: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2021-08-29 09:46:28.001917: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1835] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
关键字:Successfully opened dynamic library
【相关资源】
源码:Git: https://gitee.com/seabluescn/tf_not.git
TensorFlow.NET机器学习入门【8】采用GPU进行学习的更多相关文章
- TensorFlow.NET机器学习入门【3】采用神经网络实现非线性回归
上一篇文章我们介绍的线性模型的求解,但有很多模型是非线性的,比如: 这里表示有两个输入,一个输出. 现在我们已经不能采用y=ax+b的形式去定义一个函数了,我们只能知道输入变量的数量,但不知道某个变量 ...
- TensorFlow.NET机器学习入门【4】采用神经网络处理分类问题
上一篇文章我们介绍了通过神经网络来处理一个非线性回归的问题,这次我们将采用神经网络来处理一个多元分类的问题. 这次我们解决这样一个问题:输入一个人的身高和体重的数据,程序判断出这个人的身材状况,一共三 ...
- TensorFlow.NET机器学习入门【5】采用神经网络实现手写数字识别(MNIST)
从这篇文章开始,终于要干点正儿八经的工作了,前面都是准备工作.这次我们要解决机器学习的经典问题,MNIST手写数字识别. 首先介绍一下数据集.请首先解压:TF_Net\Asset\mnist_png. ...
- TensorFlow.NET机器学习入门【6】采用神经网络处理Fashion-MNIST
"如果一个算法在MNIST上不work,那么它就根本没法用:而如果它在MNIST上work,它在其他数据上也可能不work". -- 马克吐温 上一篇文章我们实现了一个MNIST手 ...
- TensorFlow.NET机器学习入门【7】采用卷积神经网络(CNN)处理Fashion-MNIST
本文将介绍如何采用卷积神经网络(CNN)来处理Fashion-MNIST数据集. 程序流程如下: 1.准备样本数据 2.构建卷积神经网络模型 3.网络学习(训练) 4.消费.测试 除了网络模型的构建, ...
- TensorFlow.NET机器学习入门【0】前言与目录
曾经学习过一段时间ML.NET的知识,ML.NET是微软提供的一套机器学习框架,相对于其他的一些机器学习框架,ML.NET侧重于消费现有的网络模型,不太好自定义自己的网络模型,底层实现也做了高度封装. ...
- TensorFlow.NET机器学习入门【1】开发环境与类型简介
项目开发环境为Visual Studio 2019 + .Net 5 创建新项目后首先通过Nuget引入相关包: SciSharp.TensorFlow.Redist是Google提供的TensorF ...
- TensorFlow.NET机器学习入门【2】线性回归
回归分析用于分析输入变量和输出变量之间的一种关系,其中线性回归是最简单的一种. 设: Y=wX+b,现已知一组X(输入)和Y(输出)的值,要求出w和b的值. 举个例子:快年底了,销售部门要发年终奖了, ...
- 45、Docker 加 tensorflow的机器学习入门初步
[1]最近领导天天在群里发一些机器学习的链接,搞得好像我们真的要搞机器学习似的,吃瓜群众感觉好神奇呀. 第一步 其实也是最后一步,就是网上百度一下,Docker Toolbox,下载下来,下载,安装之 ...
随机推荐
- 一文搞懂指标采集利器 Telegraf
作者| 姜闻名 来源|尔达 Erda 公众号 导读:为了让大家更好的了解 MSP 中 APM 系统的设计实现,我们决定编写一个<详聊微服务观测>系列文章,深入 APM 系统的产品.架构 ...
- day15 数组
day15 数组 数组 1.什么是数组? 什么是数组? 具备某种相同属性的数据集合 [root@localhost ~]# array_name=(ddd) [root@localhost ~]# d ...
- 【leetcode】834. Sum of Distances in Tree(图算法)
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are ...
- 【Android】安装插件 + 改变文字大小、颜色 + 隐藏代码区块的直线
安装插件 可以在搜寻框里面填入关键字搜寻,具体的插件,网上有很多介绍了 改变文字大小.颜色 隐藏代码区块的直线
- EBS 抓trace 文件
如果要对FORM的操作做TRACE操作,可以使用 帮助->诊断->跟踪 中启用跟踪功能来实现. 但是如果要实现对并发请求的trace,需要在 系统管理员->并发->方案-> ...
- shell神器curl命令的用法 curl用法实例笔记
shell神器curl命令的用法举例,如下: ##基本用法(配合sed/awk/grep) $curl http://www.jquerycn.cn ##下载保存 $curl http://www.j ...
- js将数字转为千分位/清除千分位
/** * 千分位格式化数字 * * @param s * 传入需要转换的数字 * @returns {String} */ function formatNumber(s) { if (!isNaN ...
- shell脚本实现openss自建CA和证书申请
#!/bin/bash # #******************************************************************** #Author: Ma Xue ...
- C++ friend详解
私有成员只能在类的成员函数内部访问,如果想在别处访问对象的私有成员,只能通过类提供的接口(成员函数)间接地进行.这固然能够带来数据隐藏的好处,利于将来程序的扩充,但也会增加程序书写的麻烦. C++ 是 ...
- 3、Spring的DI依赖注入
一.DI介绍 1.DI介绍 依赖注入,应用程序运行依赖的资源由Spring为其提供,资源进入应用程序的方式称为注入. Spring容器管理容器中Bean之间的依赖关系,Spring使用一种被称为&qu ...