codegen
这个例子展示了如何使用codegen
生成用于在ARM®处理器上使用深度学习的徽标分类应用程序的代码。徽标分类应用程序使用LogoNet
系列网络从图像执行徽标识别。生成的代码利用了用于计算机视觉和机器学习的ARM计算库。
支持霓虹灯扩展的ARM处理器万博1manbetx
开源计算机视觉库(OpenCV)V3.1
ARM Compute和OpenCV库的环境变量
MATLAB®Coder™用于c++代码生成
支持软件万博1manbetx包MATLAB编码器接口的深度学习
深度学习工具箱™用于使用SeriesNetwork
对象
此示例使用的ARM计算库版本可能不是代码生成支持的最新版本。万博1manbetx有关设置万博1manbetx环境变量的支持版本,请参阅与Matlab编码器深入学习的先决条件(MATLAB编码器)。
Linux®和Windows®平万博1manbetx台支持此示例,不支持Matlab Online。
下载净化物LogoNet
网络并将其保存为logonet.mat.
,如果它不存在。该网络是在MATLAB®中开发的,其架构类似于AlexNet的架构。该网络可以在各种照明条件和摄像机角下识别32个标识。
网= getLogonet ();
该网络包含22层,包括卷积层、全连通层和分类输出层。
net.layers.
ANS = 22×1层阵列,层数:1'ImageInput'图像输入227×227×3图像,具有“Zerocenter”归一化和'Randfliplr'增强2'Conv_1'卷积96 5×5×3卷绕卷发[1 1]和填充[0 0 0 0] 3'Relu_1'Relu Relu 4'MaxPool_1'最大池3×3最大汇集步进[2 2]和填充[0 0 0 0] 5'CONC_2'卷积128 3×3×96围绕的卷曲[1 1]和填充[0 0 0 0] 6'Relu_2'Relu Relu 7'MaxPool_2'最大池3×3最大池与步幅[2 2]和填充[0 0 0 0] 8'conv_3'卷积384 3×3×128卷曲的卷发[11]和填充[0 0 0 0] 9'Creu_3'Relu 10'MaxPool_3'最大池3×3最大汇集步进[2 2]和填充[0 00 0] 11'CONC_4'卷积128 3×3×384卷曲的卷程[2 2]和填充[0 0 0 0] 12'CREU_4'CREU RELU 13'MAXPOOL_4'最大池3×3最大池与步幅汇集[22]和填充[0 0 0 0] 14'FC_1'完全连接的2048完全连接的层15'Relu_5'Relu Relu 16'Dropout_1'DroPOUT 50%丢弃器17'FC_2'完全连接2048完全连接的层18'Relu_6'Relu Relu 19'Dropout_2'丢弃50%丢弃20'FC_3'完全连接的32完全连接的层21'SoftMax'Softmax SoftMax SoftMax 22'ClassOutput'分类输出Frossentropyex与“adidas”和31个其他班级
在ARM目标硬件上,确保设置ARM_Computelib,LD_Library_Path包含ARM Compute库文件夹的路径。
看到与Matlab编码器深入学习的先决条件(MATLAB编码器)。
的logonet_predict.m
入口点函数对图像进行输入,利用保存在LogoNet
MAT-file。从中加载网络对象logonet.mat.
进入持久网络变量logonet。在对函数的后续调用中,持久对象已重用。
类型logonet_predict.
函数= logonet_predict(in)%#codegen%copyry 2017-2020 mathworks,Inc.持久登录;如果是isempty(ogonet)logonet = coder.loaddeeplearningnetwork('logonet.mat','logonet');结束= logonet.predict(in);结束
当您生成针对基于arm的设备的代码且不使用硬件支持包时,请为库创建一个配置对象。万博1manbetx不要为可执行程序创建配置对象。
设置配置对象以生成C ++代码和代码的生成。
cfg = coder.config (“自由”);cfg。TargetLang =“c++”;cfg。GenCodeOnly = true;
创建一个编码器。ARMNEONConfig
目的。指定图书馆版本和目标ARM处理器的体系结构。例如,假设目标板是带有ARMv8架构和ARM计算库版本19.05的遥控/ ROCK960板。
dlcfg =编码器。DeepLearningConfig ('arm-compute');dlcfg.armcomputeversion =.“19.05”;dlcfg.armarchitecture ='ARMv8';
设置DeeplearningConfig
代码生成配置对象到深度学习配置对象的属性。
cfg。DeepLearningConfig = dlcfg;
codegen
codegen配置cfglogonet_predict.arg游戏{ones(227, 227, 3, 'single')}-D.arm_compute
中生成的代码arm_compute
文件夹的当前工作文件夹。
packNGo
功能packNGo函数将所有相关文件打包成压缩的zip文件。
zipfilename ='arm_compute.zip';binfo = load(fullfile('arm_compute','buildinfo.mat'));packngo(binfo.buildinfo,{'filename',zipfilename,'minimalheaders',false,'Ignorefilemissing',true});
复制Zip文件并解压到一个文件夹中。从目标硬件中删除Zip文件。
在以下命令中,替换:
密码
用你的密码
用户名
使用您的用户名
targetname
与您的设备名称
targetloc.
使用文件的目标文件夹
运行这些命令以从Linux复制和提取ZIP文件。
如果iSunix,系统(['sshpass -p password scp -r'fullfile(pwd,zipfilename)'用户名@ targetname:targetloc /']),结束如果isunix系统('sshpass -p password ssh用户名@ targetname“如果[-d targetloc / arm_compute];然后rm -rf targetloc / arm_compute; fi”'),结束如果iSunix,系统(['sshpass -p password ssh用户名@ targetname“解压缩targetloc /'Zipfilename.'-d targetloc / arm_compute“'']),结束如果iSunix,系统(['sshpass -p password SSH username@targetname "rm -rf targetloc'Zipfilename.“””]),结束
运行这些命令从Windows复制并解压zip文件。
如果ispc、系统(['pscp.exe -pw password -r 'fullfile(pwd,zipfilename)'用户名@ targetname:targetloc /']),结束如果ispc系统('plink.exe -l username -pw pandent targetname“如果[-d targetloc / arm_compute];然后rm -rf targetloc / arm_compute; fi”'),结束如果ispc、系统([plink.exe -l username -pw password targetname "unzip targetloc/ "Zipfilename.'-d targetloc / arm_compute“'']),结束如果ispc、系统(['plink.exe -l username -pw pandelation targetname“rm -rf targetloc”Zipfilename.“””]),结束
将这些支持文件从主机复万博1manbetx制到目标硬件:
输入图像,coderdemo_google.png
生成库文件,logonet_predict_rtw.mk.
makefile构建可执行程序,makefile_arm_logo.mk.
同义词集词典,synsetwordslogodet.txt.
在以下命令中,替换:
密码
用你的密码
用户名
使用您的用户名
targetname
与您的设备名称
targetloc.
使用文件的目标文件夹
从Linux运行时,执行以下步骤复制所需的所有文件
如果isunix系统('sshpass -p password SCP logonet_predict_rtw。可username@targetname: targetloc / arm_compute /),结束如果isunix系统('sshpass -p password SCP coderdemo_google.png username@targetname:targetloc/arm_compute/'),结束如果isunix系统('sshpass -p password SCP makefile_arm_logo。可username@targetname: targetloc / arm_compute /),结束如果isunix系统('sshpass -p password scp synswordslogodet.txt用户名@ targetname:targetloc / arm_compute /'),结束
从Windows运行时执行以下步骤以复制所有必需的文件
如果ispc系统('pscp.exe -pw password logonet_predict_rtw.mk用户名@ targetname:targetloc / arm_compute /'),结束如果ispc系统('pscp.exe -pw panderderderdemo_google.png用户名@ targetname:targetloc / arm_compute /'),结束如果ispc系统('pscp.exe -pw password makefile_arm_logo.mk用户名@ targetname:targetloc / arm_compute /'),结束如果ispc系统('pscp.exe -pw password synsetwordslogott .txt username@targetname:targetloc/arm_compute/'),结束
要在目标硬件上构建库,请在ARM硬件上执行生成的Makefile。
确保您在目标硬件上设置了环境变量ARM_COMPUTELIB和LD_LIBRARY_PATH。看到与Matlab编码器深入学习的先决条件(MATLAB编码器)。ARM_ARCH变量用于Makefile以通过ARM架构通过编译器标志。ARM_VER变量用于Makefile以编译基于ARM Compute版本的代码。在类似于上一节中的这些命令中替换硬件凭据和路径。
执行以下步骤以从Linux构建库。
如果isunix系统('sshpass -p password SCP main_arm_logo.cpp username@targetname:targetloc/arm_compute/'),结束如果iSunix,系统(['sshpass -p password ssh用户名@ targetname“make -c targetloc / arm_compute / -f logonet_predict_rtw.mk arm_arch ='dlcfg。ArmArchitecture“ARM_VER = 'dlcfg.armcomputeversion.“””]),结束
执行以下步骤以从Windows构建库。
如果ispc系统('pscp.exe -pw password main_arm_logo.cpp username@targetname:targetloc/arm_compute/'),结束如果ispc、系统(['plink.exe -l username -pw pandent targetname“make -c targetloc / arm_compute / -f logonet_predict_rtw.mk arm_arch ='dlcfg。ArmArchitecture“ARM_VER = 'dlcfg.armcomputeversion.“””]),结束
使用源主包装文件构建库以创建可执行文件。main_arm_logo.cpp.
是调用的C ++主包装文件logonet_predict.
函数。
运行以下命令以从Linux创建可执行文件。
如果isunix系统('sshpass -p password ssh用户名@ targetname“make -c targetloc / arm_compute / -f makefile_arm_logo.mk targetdirname = targetloc / arm_compute”'),结束
运行以下命令从Windows创建可执行文件。
如果ispc系统('plink.exe -l username -pw wastual targetname“make -c targetloc / arm_compute / -f makefile_arm_logo.mk targetdirname = targetloc / arm_compute”''),结束
使用以下命令从Linux运行可执行文件。
如果isunix系统('sshpass -p password SSH username@targetname "cd targetloc/arm_compute/;。/ logonet coderdemo_google.png”),结束
使用下面的命令从Windows运行可执行文件。
如果ispc系统('plink.exe -l username -pw pandent targetname“cd targetloc / arm_compute /; ./logonet coderdemo_google.png”'),结束
5大预言 : ----------------------------- 谷歌99.992% 0.003%电晕0.003%啤酒0.001%埃索0.000%的联邦快递