Main Content

Code Generation for Deep Learning Networks with MKL-DNN

MATLAB®CODER™,您可以从已经训练的卷积神经网络(CNN)生成代码,以使用英特尔的嵌入式平台®processor. The code generator takes advantage of the Intel Math Kernel Library for Deep Neural Networks (MKL-DNN). The generated code implements a CNN with the architecture, layers, and parameters specified in the input系列网络(深度学习工具箱)ordagnetwork(深度学习工具箱)network object.

通过使用以下方法之一生成代码:

  • 标准代码根command for C/C++ code generation from MATLAB code.

  • MATLAB编码器应用程序。

Requirements

  • 在窗户上®, code generation for deep learning networks with the代码根function requires微软®视觉工作室®2015 or later.

  • 深度学习库的MATLAB编码器界面。To install this support package, select it from the MATLABAdd-Ons菜单。

  • 深神经网络(MKL-DNN)的英特尔数学内核库

  • 深度学习工具箱™。

  • 编译器和库的环境变量。有关更多信息,请参阅与MATLAB编码器进行深度学习的先决条件

使用代码生成代码根

  1. 在MATLAB中编写一个入口点功能:

    • Uses thecoder.loaddeeplearningnetwork函数来构造和set up a CNN network object. For more information, see加载预告片的网络以生成代码

    • Calls thepredict(深度学习工具箱)method of the network on the entry-point function input.

    • Specifies aMinibatchSize在thepredictmethod to manage memory usage for prediction on multiple input images or observations.

    For example:

    functionout = googlenet_predict(in)%#codegen%持续的对象myNet用于加载串联网络对象。%在对此函数的第一个呼叫中,构造持续的对象,并且% 设置。当函数称为后续时间时,重复使用相同的对象百分比要预测输入,从而避免重建和重新加载%网络对象。执着的mynet;如果isempty(mynet) mynet = coder.loadDeepLearningNetwork('googlenet');结尾%通过输入out =预测(mynet,in,“ MINIBATCHSIZE”,2);

  2. Create a code generation configuration object for MEX or for a static or dynamically linked library. To specify code generation parameters for MKL-DNN, set theDeepLearningConfig属性coder.mkldnnconfig您创建的对象coder.DeepLearningConfig

    cfg = coder.config('lib');cfg.targetlang ='C ++';cfg.deeplearningconfig = coder.deeplearningconfig('mkldnn');
  3. 跑过代码根command. Use the-config选项指定配置对象。使用-args指定输入类型的选项。输入大小对应于GoogleNet网络的输入层大小16不同的图像或观察。

    代码根-configCFGgooglenet_predict-args{一个(224,224,3,16)}-报告

    笔记

    您可以为代码生成指定半精确输入。但是,代码生成器类型将输入投入到单精度。深度学习工具箱使用单精制,浮点算术来用于MATLAB中的所有计算。

生成的代码

该网络作为包含图层类数组的C ++类生成。这设置()类的方法设置手柄并为网络对象的每一层分配内存。这预测()方法调用网络中每个层的预测。代码生成器产生功能googlenet_predict()googlenet_predict.cpp这对应于MATLAB入口点函数。此函数构建网络的静态对象,并调用设置并预测方法。

二进制文件是针对具有参数(例如完全连接和网络中的卷积层)的层导出的。例如,文件cnn_googlenet_conv * _wandCNN_GOOGLENET_CONV*_Bcorrespond to weights and bias parameters for the convolution layers in the network.

使用代码生成theMATLABCoder应用程序

  1. Follow the usual steps for specifying the entry-point function and specifying input types. See使用MATLAB编码器应用程序生成C代码

  2. 在里面Generate Code步:

    • C ++

    • 点击更多设置。在里面Deep Learning窗格,设置目标库mkl-dnn

  3. 生成代码。

也可以看看

|||

Related Topics