【1】Matlab深度学习环境配置-入门

本文档详细记录了配置MATLAB2019b进行GPU深度学习的步骤,包括CUDA、cuDNN和TensorRT的安装路径。遇到的错误是GPU代码生成失败,但CUDA和cuDNN环境检查已通过。问题在于'coder'未定义,可能缺少相关组件或配置不完整。寻求帮助以解决MATLAB GPU代码生成错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 编译环境配置

软件需求:

  1. Matlab 2019b
  2. cudnn cudnn-10.1-windows10-x64-v7.6.4.38
  3. TensorRT-6.0.1.5.Windows10.x86_64.cuda-10.1.cudnn7.6
  4. Cuda 10.1 cuda_10.1.105_418.96_win10

下载路径。

Maltab  GPU 环境要求https://ww2.mathworks.cn/help/gpucoder/gs/install-prerequisites.html

CUDNN https://developer.nvidia.com/rdp/cudnn-archive

TenosRThttps://developer.nvidia.com/nvidia-tensorrt-5x-download

CUDA https://developer.nvidia.com/cuda-toolkit-archive

https://blog.youkuaiyun.com/charlotteYue/article/details/106146482

 

Matlab深度学习入门之树莓派与GPU应用。

 

打开cmd nvcc –version 或者 nvcc -V nvidia-smi nvidia-smi -q

NVIDIA-SMI 419.67       Driver Version: 442.19

  1. cudnnlibbininclude复制到cuda包含相同目录下。
  2. tensort 文件夹复制到cuda\v10.1 下面;同时将tensort 下的lib文件夹中的dll拷贝到cuda\v10.1\bin里边。

---------------------------------------------------------------------------------------------------------------

配置环境变量:

CUDA_PATH= C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1

CUDA_PATH_V10_1= C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1

NVIDIA_CUDNN= C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1

NVIDIA_TENSORRT= C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\TensorRT

在Path下添加:

 

打开matlab 进行输入以下命令

mex -setup:' D:\ProgramFiles\MATLAB\R2019b\bin\win64\mexopts\msvc2017.xml' C -v

coder.checkGpuInstall('gpu','codegen','cudnn','quiet');

gpuDeviceCount

 

CUDA_PATH

Path to the CUDA® toolkit installation.

For example:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\

NVIDIA_CUDNN

Path to the root folder of cuDNN installation. The root folder contains the bin, include, and lib subfolders.

For example:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\cuDNN\

NVIDIA_TENSORRT

Path to the root folder of TensorRT installation. The root folder contains the bin, data, include, and lib subfolders.

For example:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\TensorRT\

OPENCV_DIR

Path to the build folder of OpenCV on the host. This variable is required for building and running deep learning examples.

For example:

C:\Program Files\opencv\build

PATH

Path to the CUDA executables. Generally, the CUDA toolkit installer sets this value automatically.

For example:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin

Path to the cudnn.dll dynamic library. The name of this library may be different on your installation.

For example:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\cuDNN\bin

Path to the nvinfer* dynamic libraries of TensorRT. The name of this library may be different on your installation.

For example:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\TensorRT\lib

Path to the Dynamic-link libraries (DLL) of OpenCV. This variable is required for running deep learning examples.

For example:

C:\Program Files\opencv\build\x64\vc15\bin

 

 

Hi there, I was trapped in this error within the whole day. I'm using yolo to dectect objects, while I'm just using it but not trying to compile it. So when I used single or multiple CPUs to run the vehicle_Dataset, I found the training process was unable to be accomplished as matlab was out of memory.

So I turned to try to deploy the taining using my GPU, which is Geforce GTX 1060. I installed the new divers for this Graphic card(ver 430.64), CUDA toolkit 10.1, cuDNN v7.5.1 (April 22, 2019) for CUDA 10.1. Then I created

Variable name: CUDA_PATH

Variable value: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1

in the system variables. Also, I added

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\lib64

in the Path.

All the add-on on this page was also installed:

https://ww2.mathworks.cn/help/vision/ug/code-generation-for-object-detection-using-yolo-v2.html?searchHighlight=yolo&s_tid=doc_srchtitle

including "GPU Coder Interface for Deep Learning Libraries support package", Microsoft Visual Studio 2017, "MATLAB Support for MinGW-w64 C/C++ Compiler".

Then, I ran the following code in matlab, which worked very good.

mex -setup:'C:\Program Files\MATLAB\R2018b\bin\win64\mexopts\msvc2017.xml' C -v

mex -setup:'C:\Program Files\MATLAB\R2019a\bin\win64\mexopts\msvc2017.xml' C -v

Then I ran

coder.checkGpuInstall('gpu','codegen','cudnn','quiet');

Matlab inform me as

Error using coder.checkGpuInstall (line 32)

One or more of the system checks did not pass, with the following errors ...

Basic Code Generation: (Test GPU code generation failed with the error 'emlc:compilationError'. View report for further information: View report)

So I click the View report, and it says:

Build error: C++ compiler produced errors. See the Build Log for further details.

While the build logs has 1659 lines... I have attached the ecported reports in tha attachment. So I detected the current setup with coder.checkGpuInstall();

Compatible GPU           : PASSED

CUDA Environment         : PASSED

   Runtime   : PASSED

   cuFFT     : PASSED

   cuSOLVER  : PASSED

   cuBLAS    : PASSED

cuDNN Environment        : PASSED

Basic Code Generation    : FAILED (Test GPU code generation failed with the error 'emlc:compilationError'. View report for further information: View report)

So could anyone help me out of this problem? Thanks a lot in advance!

    1. 错误处理

在命令行里,直接输入 nvidia-smi.exe如果不能识别命令,在确保正确安装相应cuda版本的情况下,在环境变量里加入该执行文件路径即可。
即设置Path变量,我的目录为: C:\Program Files\NVIDIA Corporation\NVSMI

 

So I'm using the provided MATLAB function to check my gpu build but I always end up obtaining this extrange error which says that there is no class or variable "coder". I'm running this under Windows 10 x64, NVIDIA CUDA v10.1 and latest cuDNN libraries on MATLAB R2019a.

coder.checkGpuInstall()

Compatible GPU           : PASSED

CUDA Environment         : PASSED

   Runtime   : PASSED

   cuFFT     : PASSED

   cuSOLVER  : PASSED

   cuBLAS    : PASSED

cuDNN Environment        : PASSED

Error using coder.checkGpuInstall (line 32)

Undefined variable "coder" or class "coder.gpuConfig"

      1. Nvcc  —V错误

https://blog.youkuaiyun.com/jinshelj/article/details/80193021

    1. 配置环境

coder.checkGpuInstall('gpu','codegen','cudnn','quiet')

 

%   Example:

%       gpuEnvObj = coder.gpuEnvConfig;

%       gpuEnvObj.GpuId = 1;

%       gpuEnvObj.BasicCodegen = 1;

%       gpuEnvObj.BasicCodeexec = 1;

%       results = coder.checkGpuInstall(gpuEnvObj);

%

         Hardware: 'host'

            GpuId: 1

     BasicCodegen: 1

    BasicCodeexec: 0

      DeepCodegen: 0

     DeepCodeexec: 0

    DeepLibTarget: ''

         DataType: ''

        GenReport: 0

            Quiet: 0

        Profiling: 0

         CudaPath: 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1'

     TensorrtPath: ''

         NvtxPath: 'C:\Program Files\NVIDIA Corporation\NvToolsExt\'

        CudnnPath: '

  1. 网络资源链接

https://blog.youkuaiyun.com/lanluyug/article/details/89516520

https://www.bilibili.com/video/av78056483/  matlab深度学习

使Jupyter Lab( Jupyter Notebook)支持Matlab的方法 https://blog.youkuaiyun.com/weixin_38538305/article/details/84730078

https://blog.youkuaiyun.com/caokaifa?t=1

https://github.com/weiniuzhu/DeepLearning-Converter-for-Darknet-Matlab-Model-Format  各种模型的导入到matlab

https://ww2.mathworks.cn/videos/automated-lidar-point-cloud-annotation-for-sensor-verification-1527491006097.html

https://www.mathworks.com/academia/courseware/teaching-deep-learning-with-matlab.html

https://www.mathworks.com/academia/courseware/modelling-design-control-robotic-mechanisms.html  机器人机构的建模,设计和控制”课件

 

Maltab  GPU 环境要求https://ww2.mathworks.cn/help/gpucoder/gs/install-prerequisites.html

CUDNN https://developer.nvidia.com/rdp/cudnn-archive

TenosRThttps://developer.nvidia.com/nvidia-tensorrt-5x-download

CUDA https://developer.nvidia.com/cuda-toolkit-archive

上述是使用Deep Learning Toolbox建议的环境要求及工具包使用情况。翻译成中文是:

    1. 打开DL Toolbox

在matlab命令框输入:deepNetworkDesigner

如果需要使用alexnet,则需要下载deeplearning for alexnet工具箱

1)需要MATLAB

2)建议使用并行计算工具箱,这是GPU支持所需的图像处理工具箱

3)计算机视觉工具箱推荐

4)GPU编码器推荐

5)MATLAB编码器推荐

6)Simulink推荐

7)建议使用强化学习工具箱

另一方面,matlab还可以利用第三方已经实现好的一些模型处理一般场景。比如用训练好的googLeNet来识别图片,或识别摄像头里的动态场景。

 

    1. GPU coder cnncodegen工具

生产C++代码用于树莓派arm处理器;

cnncodegen(net,xx,xxx)

    1. Squeezenet

轻量级压缩网络

    1.  DeepNetwork Designer
    2. 1.5 ONNX开放式的神经网络交换

ImportONNXnetwork

  1. 调用其它现有网络
  1. 打开get more app输入Transfer Learning,进行下载迁移学习工具箱。

版本 2019.6.2 (1.17 MB) 作者: Kevin Chng

Transfer Learning of Pre-trained Neural Network or Imported ONNX Classification Model in GUI

  1. 例子搜索,Get Started with Transfer Learning
    1. matlab调用keras深度学习模型(环境搭建)
    2. MATLAB对Alexnet模型进行迁移学习  https://blog.youkuaiyun.com/qq_41569159/article/details/89048904
    3. 在matlab上使用自己的数据进行迁移学习  https://blog.youkuaiyun.com/weixin_38538305/article/details/84730078基于Matlab的AlexNet图像迁移学习
    4. 基于Matlab的AlexNet图像迁移学习 
    5. 手把手教你用matlab做深度学习 https://blog.youkuaiyun.com/caokaifa/article/details/81155584
    6. https://www.cnblogs.com/nwpuxuezha/p/7834344.html

    7. https://github.com/JiJingYu

### 如何使用 MATLAB Deep Learning Toolbox 的 ONNX 模型转换器支持包 #### 安装和支持包配置 为了能够利用ONNX模型,在安装了MATLAB及其Deep Learning Toolbox的基础上,还需要额外安装`Deep Learning Toolbox Converter for ONNX Model Format`支持包。可以通过MATLAB Add-Ons管理器来查找并安装该支持包[^1]。 #### 导入ONNX模型到MATLAB 一旦安装完成,可以使用`importNetwork('onnx', modelPath)`函数导入ONNX格式的深度学习模型文件至MATLAB环境中。这里`modelPath`代表存储ONNX模型的具体路径字符串。此命令会返回一个由MATLAB表示的深层网络对象,允许进一步分析或修改这个网络结构。 ```matlab % 假设有一个名为 'myModel.onnx' 的 ONNX 文件位于当前工作目录下 net = importNetwork('onnx', 'myModel.onnx'); disp(net); ``` #### 将MATLAB训练好的DAG Network导出成ONXX格式 对于已经存在于MATLAB中的DAG network类型的深层网络(比如通过迁移学习调整后的网络),如果希望将其保存为ONNX格式以便跨平台共享,则可调用`exportONNXLayers(dlnet, filename)`方法。其中`dlnet`是要导出的层图对象而`filename`则是指定的目标文件名。 ```matlab % dlnet 是一个经过训练得到的 DAGNetwork 对象 exportONNXLayers(dlnet, 'trainedModel.onnx'); ``` #### 验证转换后的模型性能 成功导入或导出了ONNX模型之后,建议运行一些测试样本来验证其行为是否符合预期。这通常涉及到准备一批输入样本以及对应的标签,并计算预测误差或其他评价指标以评估模型的表现[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值