このペ,ジの翻訳は最新ではありません。ここをクリックして,英語の最新版を参照してください。
codegen
を使用したARM计算による深層学習の予測この例では,codegen
を使用して、手臂®プロセッサでの深層学習を使用するロゴ分類用途のコードを生成する方法を説明します。ロゴ分類アプリケ,ションは,LogoNet
系列ネットワクを使用してメジからロゴを認識します。生成コードはコンピュータービジョンおよび機械学習用の臂计算库を利用します。
霓虹拡張をサポ,トする,手臂プロセッサ
开源计算机视觉库(OpenCV) v3.1
ARM ComputeおよびOpenCVラescブラリの環境変数
MATLAB®Coder™(c++コド生成用)
MATLAB编码器深度学习接口サポ,トパッケ,ジ
深度学习工具箱™(SeriesNetwork
オブジェクトを使用するため)
この例で使用されている臂计算库のバージョンは,コード生成でサポートされている最新バージョンではない可能性があります。サポトされるラブラリのバジョン,および環境変数の設定の詳細にいては,MATLAB编码器を使用した深層学習の前提条件(MATLAB编码器)を参照してください。
この例は,Linux®プラットフォームとWindows®プラットフォームでサポートされていますが,MATLAB在线ではサポートされていません。
事前学習済みのLogoNet
ネットワ,クをダウンロ,ドして,これが存在しない場合はlogonet.mat
という名前で保存します。このネットワークはMATLAB®で開発されたもので,アーキテクチャはAlexNetと似ています。このネットワクはさまざまなラティング条件とカメラの角度の下で32個のロゴを認識できます。
net = getLogonet();
ネットワ,クには,畳み込み層,全結合層,分類出力層など,22個の層が含まれています。
网层
ans = 22×1带有图层的图层数组:1“imageinput”图像输入227×227×3图片zerocenter正常化和randfliplr的扩增2 conv_1卷积96 5×5×3旋转步[1]和填充[0 0 0 0]3‘relu_1 ReLU ReLU 4“maxpool_1”马克斯池3×3马克斯池步(2 - 2)和填充[0 0 0 0]5 conv_2卷积128 3×3×96旋转步[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旋转步[1]和填充[0 0 0 0]9 ' relu_3 ReLU ReLU 10“maxpool_3”马克斯池3×3马克斯池步(2 - 2)和填充[0 0 0 0]11 conv_4卷积128 3×3×384旋转步(2 - 2)和填充[0 0 0 0]12的relu_4 ReLU ReLU 13“maxpool_4”马克斯池3×3马克斯池步(2 - 2)和填充[0 0 0 0]14 fc_1完全连接2048完全连接层15 ' relu_5 ReLU ReLU 16“dropout_1”辍学50%辍学17 fc_2完全Connected 2048 fully connected layer 18 'relu_6' ReLU ReLU 19 'dropout_2' Dropout 50% dropout 20 'fc_3' Fully Connected 32 fully connected layer 21 'softmax' Softmax softmax 22 'classoutput' Classification Output crossentropyex with 'adidas' and 31 other classes
手臂ターゲットハードウェアで,ARM_COMPUTELIBが設定されていてLD_LIBRARY_PATHに臂计算库フォルダーへのパスが含まれていることを確認します。
MATLAB编码器を使用した深層学習の前提条件(MATLAB编码器)を参照してください。
エントリポ@ @ント関数logonet_predict.m
は,化学键メ,化学键ジ入力を受け取り,LogoNet
.matファイルに保存されている深層学習ネットワークを使用して,イメージについて予測を実行します。この関数は,LogoNet.mat
からネットワ,クオブジェクトを永続ネットワ,ク変数logonetに読み込みます。それ以降,この関数を呼び出すと,永続オブジェクトが再利用されます。
类型logonet_predict
function out = logonet_predict(in) %#codegen % Copyright 2017-2020 The MathWorks, Inc. persistent logonet;if isempty(logonet) logonet = code . loaddeeplearningnetwork (' logonet .mat','logonet');End out = logonet.predict(in);结束
ハードウェアサポートパッケージを使用せずに手臂ベースのデバイス向けのコードを生成する場合,ライブラリ用の構成オブジェクトを作成します。実行可能プログラム用の構成オブジェクトは作成しません。
c++コドの生成のみを行うための構成オブジェクトを設定します。
CFG = code .config(“自由”);cfg。TargetLang =“c++”;cfg。GenCodeOnly = true;
编码器。ARMNEONConfig
オブジェクトを作成します。タゲットarmプロセッサのラブラリバジョンとアキテクチャを指定します。たとえば,ターゲットボードがARMv8アーキテクチャと臂计算库バージョン19.05を備えたHiKey / Rock960ボードであるとします。
DLCFG =编码器。DeepLearningConfig (“arm-compute”);dlcfg。ArmComputeVersion =“19.05”;dlcfg。ArmArchitecture =“armv8”;
コ,ド生成構成オブジェクトのDeepLearningConfig
プロパティに,深層学習構成オブジェクトを設定します。
cfg。DeepLearningConfig = dlcfg;
codegen
を使用したc++ソスコドの生成codegen配置cfglogonet_predictarg游戏{ones(227,227,3, 'single')}- darm_compute
コ,ドは,ホストコンピュ,タ,の現在の作業フォルダ,にあるarm_compute
フォルダ,に生成されます。
packNGo
を使用したzipファ目录ルの生成関数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ファx x x x x x x x x x x x x x x x x x x x x x x x x x x x
如果isunix、系统([密码:SCP -rzipFileName fullfile (pwd)“username@targetname: targetloc /”]),结束如果isunix系统('sshpass -p password SSH username@targetname "if [-d targetloc/arm_compute];rm -rf targetloc/arm_compute;fi”),结束如果isunix、系统([' SSH username@targetname "unzip targetloc/'zipFileName-d targetloc/arm_compute"']),结束如果isunix、系统([' SSH username@targetname "rm -rf targetloc'zipFileName“””]),结束
Windowsからzipファaapl / aapl / aapl / aapl / aapl / aapl / aapl / aapl / aapl / aapl / aapl / aapl
如果ispc、系统(['pscp.exe -pw密码-r 'zipFileName fullfile (pwd)“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 password targetname "rm -rf targetloc'zipFileName“””]),结束
以下のサポトファルをホストコンピュタからタゲットハドウェアにコピします。
入力▪メ▪ジ(coderdemo_google.png
)
ラesc esc esc esc esc esclogonet_predict_rtw.mk
)
実行可能プログラムをビルドするためのmakefile (makefile_arm_logo.mk
)
Synsetディクショナリ(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 synsetwordslogodt .txt username@targetname:targetloc/arm_compute/'),结束
Windowsから実行する場合,以下の手順を実行して必要なファ。
如果ispc系统('pscp.exe -pw密码logonet_predict_rtw。可username@targetname: targetloc / arm_compute /),结束如果ispc系统('pscp.exe -pw密码coderdemo_google.png username@targetname:targetloc/arm_compute/'),结束如果ispc系统('pscp.exe -pw密码makefile_arm_logo。可username@targetname: targetloc / arm_compute /),结束如果ispc系统('pscp.exe -pw密码synsetwordslogodt .txt username@targetname:targetloc/arm_compute/'),结束
ターゲットハードウェアでライブラリをビルドするには,生成されたmakefileを手臂ハードウェアで実行します。
ターゲットハードウェアで環境変数ARM_COMPUTELIBとLD_LIBRARY_PATHが設定されていることを確認します。MATLAB编码器を使用した深層学習の前提条件(MATLAB编码器)を参照してください。変数ARM_ARCHは、手臂アーキテクチャに基づいてコンパイラフラグを渡すためにmakefileで使用されます。変数ARM_VERは,手臂计算のバージョンに基づいてコードをコンパイルするためにmakefileで使用されます。以下のコマンドのハ,ドウェア資格情報とパスを,前の節と同様に置き換えます。
Linuxからラaapl . exeブラリをビルドするには,以下の手順を実行します。
如果isunix系统(SCP main_arm_logo.cpp username@targetname:targetloc/arm_compute/'),结束如果isunix、系统(['sshpass -p password ssh username@targetname "make -C targetloc/arm_compute/ -f logonet_predict_rtw。可ARM_ARCH = 'dlcfg。ArmArchitecture“ARM_VER = 'dlcfg。ArmComputeVersion“””]),结束
Windowsからラaapl . exeブラリをビルドするには、以下の手順を実行します。
如果ispc系统('pscp.exe -pw密码main_arm_logo.cpp username@targetname:targetloc/arm_compute/'),结束如果ispc、系统(['plink.exe -l username -pw password targetname "make -C targetloc/arm_compute/ -f logonet_predict_rtw. exe -l username -pw password targetname "可ARM_ARCH = 'dlcfg。ArmArchitecture“ARM_VER = 'dlcfg。ArmComputeVersion“””]),结束
ソスのメンラッパファルを使用してラブラリをビルドし実行可能ファルを作成します。main_arm_logo.cpp
は,関数logonet_predict
を呼び出すc++メンラッパファルです。
Linuxから実行可能ファaapl . exeルを作成するには,以下のコマンドを実行します。
如果isunix系统('sshpass -p password ssh username@targetname "make -C targetloc/arm_compute/ -f makefile_arm_logo。可targetDirName = targetloc / arm_compute”),结束
Windowsから実行可能ファaapl . exeルを作成するには、以下のコマンドを実行します。
如果ispc系统('plink.exe -l username -pw password targetname "make -C targetloc/arm_compute/ -f makefile_arm_logo. exe -l username -pw password可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 password targetname "cd targetloc/arm_compute/;。/ logonet coderdemo_google.png”),结束
5大预言 : ----------------------------- 谷歌99.992% 0.003%电晕0.003%啤酒0.001%埃索0.000%的联邦快递