主要内容

用于ARM目标深度学习的代码生成

本示例展示了如何在不使用硬件支持包的情况下,在基于ARM®的设备上生成和部署预测代码。金宝app

当你使用ARM计算库和硬件支持包生成预测代码时,金宝appcodegen在主机上生成代码,将生成的文件复制到目标硬件,并在目标硬件上构建可执行文件。如果没有硬件支持包,金宝appcodegen在主机上生成代码。您必须运行命令来复制文件并在目标硬件上构建可执行程序。

此示例使用packNGo函数将所有相关文件打包成压缩的zip文件。使用这个例子来学习如何在没有硬件支持包的ARM Neon目标上部署生成的代码金宝apppackNGo

先决条件

  • 支持NEON扩展的ARM处理器金宝app

  • ARM Compute库(目标臂硬件上)

  • 开源计算机视觉图书馆(Open CV)

  • 编译器和库的环境变量

  • MATLAB®编码器™

  • 支持软件金宝app包MATLAB编码器接口的深度学习

  • 深度学习工具箱™

本例使用的ARM Compute库版本可能不是代码生成支持的最新版本。金宝app有关受支金宝app持的库版本和有关设置环境变量的信息,请参见深度学习的先决条件与MATLAB编码器

这个例子不支持MATLAB Online金宝app。

scriezenet_predict函数

这个例子使用DAG网络SqueezeNet来显示使用ARM计算库的图像分类。在深度学习工具箱中可以找到一个用于MATLAB的预先训练的SqueezeNet。的squeezenet_predict函数将SqueezeNet网络加载到持久网络对象中。在对该函数的后续调用中,将重用持久对象。

类型squeezenet_predict
mynet是一个持久化对象,用于加载DAG网络对象。在第一次调用此函数时,将构造并设置持久对象。当函数被调用以后,相同的对象被重用%来调用输入的predict,避免重构和重新加载% network对象。持久mynet;如果isempty(mynet) mynet = code . loaddeeplearningnetwork ('squeezenet','squeezenet');End out = mynet.predict(in);

为静态库设置代码生成配置对象

当您生成针对基于arm的设备的代码且不使用硬件支持包时,请为库创建一个配置对象。金宝app不要为可执行程序创建配置对象。

设置配置对象以生成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;

通过使用生成源C ++代码codegen

codegen配置cfgsqueezenet_predictarg游戏{ones(227, 227, 3, 'single')}-D.arm_compute

代码在主机上当前工作文件夹的arm_compute文件夹中生成。

使用。生成Zip文件packNGo函数

packNGo函数将所有相关文件打包成压缩的zip文件。

zipFileName =“arm_compute.zip”;bInfo =负载(fullfile (' arm_compute ', ' buildInfo.mat '));packNGo (bInfo。buildInfo, {'fileName', zipFileName,'minimalHeaders', false, 'ignoreFileMissing',true});

代码生成为zip文件。

将生成的zip文件复制到目标硬件

复制Zip文件并解压到文件夹中,并删除硬件中的Zip文件

在以下命令中,替换:

  • 密码用你的密码

  • 用户名使用您的用户名

  • targetname与您的设备名称

  • targetloc使用文件的目标文件夹

执行以下步骤从Linux中复制和提取zip文件。

如果isunix、系统(['sshpass -p password scp -r'fullfile(pwd,zipfilename)“username@targetname: targetloc /”]),结束如果isunix系统('sshpass -p password ssh用户名@ targetname“如果[-d targetloc / arm_compute];然后rm -rf targetloc / arm_compute; fi”'),结束如果isunix、系统(['sshpass -p password SSH username@targetname "unzip 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)“username@targetname: targetloc /”]),结束如果ispc系统('plink.exe -l username -pw password targetname "if [-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“””]),结束

复制示例文件到目标硬件

将这些支持文件从主机复金宝app制到目标硬件:

  • 输入图像,coffeemug.png

  • 生成库文件,squeezenet_predict_rtw.mk

  • makefile构建可执行程序,makefile_squeezenet_arm_generic.mk

  • 同义词集词典,synsetWords.txt

在以下命令中,替换:

  • 密码用你的密码

  • 用户名使用您的用户名

  • targetname与您的设备名称

  • targetloc使用文件的目标文件夹

从Linux运行时,执行以下步骤复制所需的所有文件

如果isunix系统('sshpass -p password SCP squeezenet_predict_rtw。可username@targetname: targetloc / arm_compute /),结束如果isunix系统('sshpass -p password SCP coffemug .png username@targetname:targetloc/arm_compute/'),结束如果isunix系统(’sshpass -p password SCP makefile_squeezenet_arm_generic。可username@targetname: targetloc / arm_compute /),结束如果isunix系统('sshpass -p password scp synsetWords.txt username@targetname:targetloc/arm_compute/'),结束

当从Windows运行时,执行以下步骤复制所有需要的文件

如果ispc系统('pscp.exe -pw password squeezenet_predict_rtw。可username@targetname: targetloc / arm_compute /),结束如果ispc系统('pscp.exe -pw password coffeug .png username@targetname:targetloc/arm_compute/'),结束如果ispc系统('pscp.exe -pw password makefile_squeezenet_arm_generic. exe可username@targetname: targetloc / arm_compute /),结束如果ispc系统('pscp.exe -pw password synsetWords.txt username@targetname:targetloc/arm_compute/'),结束

在目标硬件上构建库

要在目标硬件上构建库,请在ARM硬件上执行生成的makefile。

确保您在目标硬件上设置了环境变量ARM_COMPUTELIB和LD_LIBRARY_PATH。看到深度学习的先决条件与MATLAB编码器.ARM_ARCH变量用于在Makefile中传递基于Arm架构的编译器标志。Makefile中使用ARM_VER变量来编译基于Arm计算版本的代码。按照类似上述步骤替换硬件凭据和路径。

执行以下步骤从Linux构建库。

如果isunix系统('sshpass -p password SCP main_squeezenet_arm_generic.cpp username@targetname:targetloc/arm_compute/'),结束如果isunix、系统([make -C targetloc/arm_compute/ -f squeezenet_predict_rtw. sh -p password ssh username@targetname "可ARM_ARCH = 'dlcfg。ArmArchitecture“ARM_VER = 'dlcfg.armcomputeversion.“””]),结束

执行以下步骤以从Windows构建库。

如果ispc系统('pscp.exe -pw password main_squeezenet_arm_generic.cpp username @ targetname:targetloc / arm_compute /'),结束如果ispc、系统([make -C targetloc/arm_compute/ -f squeezenet_predict_rtw. exe -l username -pw password targetname .exe可ARM_ARCH = 'dlcfg。ArmArchitecture“ARM_VER = 'dlcfg.armcomputeversion.“””]),结束

从目标硬件上的库创建可执行文件

使用源主包装文件构建库以创建可执行文件。main_squeezenet_arm_generic.cpp是c ++主包装文件,它调用squeezenet_predict函数来创建可执行文件。

运行以下命令从Linux创建可执行文件。

如果isunix系统(make -C targetloc/arm_compute/ -f makefile_squeezenet_arm_generic. sh -p password ssh username@targetname "可targetDirName = targetloc / arm_compute”),结束

运行以下命令从Windows创建可执行文件。

如果ispc系统(make -C targetloc/arm_compute/ -f makefile_squeezenet_arm_generic. exe -l user -pw password targetname可targetDirName = targetloc / arm_compute”),结束

在目标硬件上运行可执行文件

使用下面的命令从Linux运行可执行文件。
如果isunix系统('sshpass -p password SSH username@targetname "cd targetloc/arm_compute/;。/ squeezenet coffeemug.png”),结束
使用下面的命令从Windows运行可执行文件。
如果ispc系统('plink.exe -l username -pw password targetname "cd targetloc/arm_compute/;。/ squeezenet coffeemug.png”),结束
5大预言 : ----------------------------- 纸巾蜡烛杯咖啡杯7.309% 1.098% 88.299% 0.634% 0.591%水壶

另请参阅

|||

相关话题