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编码器进行深度学习的先决条件。
使用代码生成代码根
在MATLAB中编写一个入口点功能:
Uses the
coder.loaddeeplearningnetwork
函数来构造和set up a CNN network object. For more information, see加载预告片的网络以生成代码。Calls the
predict
(深度学习工具箱)method of the network on the entry-point function input.Specifies a
MinibatchSize
在thepredict
method 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);
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 the
DeepLearningConfig
属性coder.mkldnnconfig
您创建的对象coder.DeepLearningConfig
。cfg = coder.config('lib');cfg.targetlang ='C ++';cfg.deeplearningconfig = coder.deeplearningconfig('mkldnn');
跑过
代码根
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 * _w
andCNN_GOOGLENET_CONV*_B
correspond to weights and bias parameters for the convolution layers in the network.
使用代码生成theMATLABCoder应用程序
Follow the usual steps for specifying the entry-point function and specifying input types. See使用MATLAB编码器应用程序生成C代码。
在里面Generate Code步:
放语至C ++。
点击更多设置。在里面Deep Learning窗格,设置目标库至
mkl-dnn
。
生成代码。
也可以看看
代码根
|coder.DeepLearningConfig
|coder.loaddeeplearningnetwork
|coder.mkldnnconfig