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,下载下来,下载,安装之 ...
随机推荐
- acknowledge
accord+knowledge. accord好几个意思,knowledge不遑多让,We gotta acknowledge the word acknowledge has many meani ...
- Elasticsearch【基础入门】
目录 一.操作index 1.查看index 2.增加index 3.删除index 二.操作index 1.新增document 2.查询type 全部数据 3.查找指定 id 的 document ...
- Linux学习 - 流程控制
一.if语句 1 单分支if条件语句 (1) if [ 条件判断式 ];then 程序 fi (2) if [ 条件判断式 ] then 程序 fi 例:检测根分区的使用量 2 双分支if条件语 ...
- Android 清除本地缓存
主要功能:清除内.外缓存,清除数据库,清除Sharepreference,清除files和清除自定义目录 public class DataCleanManager { //清除本应用内部缓存(/da ...
- Spring Cloud声明式调用Feign负载均衡FeignClient详解
为了深入理解Feign,下面将从源码的角度来讲解Feign.首先来看看FeignClient注解@FeignClient的源码,代码如下: FeignClient注解被@Target(ElementT ...
- Linux基础命令---nfsstat显示nfs信息
nfsstat nfsstat指令用来显示nfs客户端和服务器的活动信息. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora. 1.语法 nfsstat ...
- OpenStack之七: compute服务(端口8774)
注意此处的bug,参考o版 官网地址 https://docs.openstack.org/nova/stein/install/controller-install-rdo.html 控制端配置 # ...
- 2.8 GO 参数传递
简单将GO中参数传递分为三类 数字.字符.字符串等类型 结构体 方法 GO的方法本身就是地址的入口,打印一个方法输出的是这个方法的地址 func test_func(){ //0x488a30 fmt ...
- 【Spring Framework】12种spring中定义bean的方法
前言 在庞大的java体系中,spring有着举足轻重的地位,它给每位开发者带来了极大的便利和惊喜.我们都知道spring是创建和管理bean的工厂,它提供了多种定义bean的方式,能够满足我们日常工 ...
- Maven配置大全
maven项目打jar包(带依赖) <build> <plugins> <plugin> <artifactId>maven-assembly-plug ...