技術文章

當前頁面: 首頁 >技術文章 >NXP iMX8基於eIQ框架測試Machine Learning

NXP iMX8基於eIQ框架測試Machine Learning

供稿:韜睿(上海)計算機科技有限公司 2021/3/11 14:14:36

0 人氣:2

  • 關鍵詞: iMX8 Tensorflow eIQ
  • 摘要:隨着嵌入式處理器性能的提升甚至一些嵌入式處理器已經開始集成針對人工智能和機器學習的硬件加速單元NPU,機器學習應用在嵌入式邊緣設備的應用也慢慢展現。為此,NXP也發佈了eIQ for i.MX軟件工具包,用於在NXP的i.MX系列嵌入式處理器上面來支持目前比較常見的各種機器學習推理引擎

1). 簡介

隨着嵌入式處理器性能的提升甚至一些嵌入式處理器已經開始集成針對人工智能和機器學習的硬件加速單元NPU,機器學習應用在嵌入式邊緣設備的應用也慢慢展現。為此,NXP也發佈了eIQ for i.MX軟件工具包,用於在NXPi.MX系列嵌入式處理器上面來支持目前比較常見的各種機器學習推理引擎,比如TensorFlowCaffe等,具體的支持情況可以參考下圖,其中ArmNNTensorFlowLiteONNX可以支持GPU/NPU硬件加速,而OpenCVPyTorch目前只支持在CPU運行。

image001.png

 

NXP eIQ協議棧通過Neural Network Runtime (NNRT)模塊來對不同的前端Runtime進行硬件加速支持,具體的架構可以參考下圖,對於很多機器學習算法場景,通過硬件加速引擎可以很大提升算法推理性能。

image003.png

 

本文的演示的平台來自於Toradex Apalis iMX8 ARM嵌入式平台,這是一個基於NXP iMX8QM ARM處理器,支持Cortex-A72+A53Coretex-M4架構的計算機模塊平台。

 

 

2). 準備

a). Apalis iMX8QM 4GB WB IT ARM核心版配合Ioxra 載板,連接調試串口UART1(載板X22)到開發主機方便調試。載板連接HDMI顯示器。

 

 

3). Apalis iMX8 Ycoto Linux 編譯部署以及配置

a). Apalis iMX8 Ycoto Linux 通過Ycoto/Openembedded 框架編譯,具體的配置方法請參考這裏,參考如下修改後編譯Reference-Multimedia image鏡像

./ iMX8 Ycoto layer 中默認沒有包含NXP Machine LearningOpenCV 4.4.0版本支持,因此首先需要通過下面修改添加相關layer,詳細的NXP Ycoto指南請參考i.MX Yocto Project User's Guide Rev. L5.4.70_2.3.0

-------------------------------

### download related layers from NXP official repository

$ repo init -u //source.codeaurora.org/external/imx/imx-manifest -b imx-linux-zeus -m imx-5.4.70-2.3.0.xml

$ repo sync

$ DISTRO=fsl-imx-wayland MACHINE=imx8qmmek source imx-setup-release.sh -b build

 

### copy mechine learning layer meta-ml to Toradex ycoto environment

$ cp -r …/sources/meta-imx/meta-ml …/oe-core/layers/

 

### modify meta-ml layer …/layers/meta-ml/conf/layer.conf file to support ycoto dunfell

--- a/layers/meta-ml/conf/layer.conf        2021-03-03 15:50:59.718815084 +0800

+++ b/layers/meta-ml/conf/layer.conf     2021-03-03 16:55:46.791158625 +0800

@@ -8,4 +8,4 @@

 BBFILE_COLLECTIONS += "meta-ml"

 BBFILE_PATTERN_meta-ml := "^${LAYERDIR}/"

 BBFILE_PRIORITY_meta-ml = "8"

-LAYERSERIES_COMPAT_meta-ml = "warrior zeus"

+LAYERSERIES_COMPAT_meta-ml = "warrior zeus dunfell"

 

### copy opencv 4.4.0 related to Toradex ycoto environment

$ cp -r …/sources/meta-imx/meta-bsp/recipes-support/opencv/ …/oe-core/layers/meta-toradex-nxp/recipes-support/opencv/

 

### modify build/conf/bblayer.conf to add above extra layers

--- a/build/conf/bblayers.conf   

+++ b/build/conf/bblayers.conf   

@@ -24,6 +24,9 @@

   ${TOPDIR}/../layers/meta-openembedded/meta-python \

   ${TOPDIR}/../layers/meta-freescale-distro \

   ${TOPDIR}/../layers/meta-toradex-demos \

+  ${TOPDIR}/../layers/meta-ml \

   ${TOPDIR}/../layers/meta-qt5 \

   \

   \

-------------------------------

 

./ 修改 local.conf,增加mechine learning 相關支持

-------------------------------

### add python and opencv support ###

+IMAGE_INSTALL_append = " python3 python3-pip opencv python3-opencv python3-pillow"

 

### add eIQ support ###

+IMAGE_INSTALL_append = " arm-compute-library nn-imx tensorflow-lite armnn onnxruntime"

+PACKAGECONFIG_append_pn-opencv_mx8 = " dnn jasper qt5 test"

### remove opencl conflict ###

+PACKAGECONFIG_remove_pn-opencv_mx8 = "opencl"

+PACKAGECONFIG_remove_pn-arm-compute-library = "opencl"

 

### option, add onnxruntime and armnn dev support to SDK ###

+TOOLCHAIN_TARGET_TASK_append += " onnxruntime-dev armnn-dev "

 

ACCEPT_FSL_EULA = "1"

-------------------------------

 

./ 編譯imageSDK

-------------------------------

# compile Reference-Multimedia image

$ bitbake bitbake tdx-reference-multimedia-image

 

# compile SDK

bitbake tdx-reference-multimedia-image -c populate_sdk

-------------------------------

 

b). Ycoto Linux image部署

參考這裏通過Toradex Easy installer將上面編譯好的image更新部署到模塊,目前最新穩定版本為Ycoto Linux V5.1,最新測試版本為Ycoto Linux V5.2

 

 

4). TensorFlow Lite 測試

a). NXP iMX8 eIQ TensorFlow Lite 支持特性和協議棧框圖如下

./ TensorFlow Lite v2.3.1

./ Multithreaded computation with acceleration using Arm Neon SIMD instructions on Cortex-A cores

./ Parallel computation using GPU/NPU hardware acceleration (on shader or convolution units)

./ C++ and Python API (supported Python version 3)

./ Per-tensor and Per-channel quantized models support

image005.png

 

b). 示例應用測試

./ Image預裝的TensorFlow Lite測試示例應用位置

/usr/bin/tensorflow-lite-2.3.1/examples

 

./ 基於mobilenet model測試 label_image”示例應用

-------------------------------

$ cd /usr/bin/tensorflow-lite-2.3.1/examples/

 

### Run on CPU

$ ./label_image -m mobilenet_v1_1.0_224_quant.tflite -i grace_hopper.bmp -l labels.txt

Loaded model mobilenet_v1_1.0_224_quant.tflite

resolved reporter

invoked

average time: 44.999 ms

0.780392: 653 military uniform

0.105882: 907 Windsor tie

0.0156863: 458 bow tie

0.0117647: 466 bulletproof vest

0.00784314: 835 suit

 

### Run with GPU acceleration

$ ./label_image -m mobilenet_v1_1.0_224_quant.tflite -i grace_hopper.bmp -l labels.txt -a 1

Loaded model mobilenet_v1_1.0_224_quant.tflite

resolved reporter

INFO: Created TensorFlow Lite delegate for NNAPI.

Applied NNAPI delegate.

invoked

average time: 13.103 ms

0.784314: 653 military uniform

0.105882: 907 Windsor tie

0.0156863: 458 bow tie

0.0117647: 466 bulletproof vest

0.00784314: 668 mortarboard

 

### TensorFlow Lite Python API predefined example script run, no option to choose CPU or GPU, run with GPU acceleration by default if libneuralnetworks.so or

libneuralnetworks.so.1 is found in the /usr/lib directory, otherwise run on CPU

$ python3 label_image.py

INFO: Created TensorFlow Lite delegate for NNAPI.

Applied NNAPI delegate.

Warm-up time: 5052.5 ms

 

Inference time: 12.7 ms

 

0.674510: military uniform

0.129412: Windsor tie

0.039216: bow tie

0.027451: mortarboard

0.019608: bulletproof vest

-------------------------------

 

c). 更多示例和benchmark測試,C++ API應用開發以及當前eIQ對於TensorFlow Lite不同模型的限制等更多信息可以參考NXP i.MX Machine Learning User's Guide Rev. L5.4.70_2.3.0 Chapter 3 TensorFlow Lite,從上面簡單測試可以看出NPU加速下mobilenet 模型要比CPU運行性能更好。

 

 

5). Arm Compute Library 測試

a). ACL(ARM-Compute Library)是專為ARM CPU & GPU優化設計的計算機視覺和機器學習庫,基於NEON & OpenCL支持的 SIMD 技術,但在iMX8平台目前只支持CPU NEON加速,另外因為其為ARM NN架構的計算引擎,因此一般來説建議直接使用ARM NNNXP iMX8 eIQ ACL支持特性如下

./ Arm Compute Library 20.02.01

./ Multithreaded computation with acceleration using Arm Neon SIMD instructions on Cortex-A cores

./ C++ API only

./ Low-level control over computation

 

b). 示例應用測試

./ Image預裝的ACL測試示例應用位置

/usr/share/arm-compute-library/build/examples

 

./ MobileNet v2 DNN model,隨機輸入量測試

-------------------------------

$ cd /usr/share/arm-compute-library/build/examples

 

$ ./graph_mobilenet_v2

Threads : 1

Target : NEON

Data type : F32

Data layout : NHWC

Tuner enabled? : false

Cache enabled? : false

Tuner mode : Normal

Tuner file :

Fast math enabled? : false

 

Test passed

-------------------------------

 

c). 更多示例測試和參數説明可以參考NXP i.MX Machine Learning User's Guide Rev. L5.4.70_2.3.0 Chapter 4 Arm Compute Library

 

 

6). Arm NN 測試

a). Arm NN是適用於CPUGPUNPU的開源推理引擎,該軟件橋接了現有神經網絡框架(例如 TensorFlow TensorFlow LiteCaffe ONNX)與在嵌入式 Linux 平台上運行的底層處理硬件(例如 CPUGPU NPU)。這樣,開發人員能夠繼續使用他們首選的框架和工具,經 Arm NN 無縫轉換結果後可在底層平台上運行,NXP iMX8 eIQ ARM NN支持特性和協議棧框圖如下

./ Arm NN 20.02.01

./ Multithreaded computation with acceleration using Arm Neon SIMD instructions on Cortex-A cores provided by the ACL

Neon backend

./ Parallel computation using GPU/NPU hardware acceleration (on shader or convolution units) provided by the VSI

NPU backend

./ C++ and Python API (supported Python version 3)

./ Supports multiple input formats (TensorFlow, TensorFlow Lite, Caffe, ONNX)

./ Off-line tools for serialization, deserialization, and quantization (must be built from source)

image007.png

 

b). Apalis iMX8 $Home 目錄下創建如下測試使用目錄以供後續測試使用

-------------------------------

$ mkdir ArmnnTests

$ cd ArmnnTests

$ mkdir data

$ mkdir models

-------------------------------

 

c). Caffe示例應用測試

./ Image包含如下ARM NN Caffe模型測試示例,本文隨機選擇CaffeAlexNet-Armnn進行測試

/usr/bin/CaffeAlexNet-Armnn

/usr/bin/CaffeCifar10AcrossChannels-Armnn

/usr/bin/CaffeInception_BN-Armnn

/usr/bin/CaffeMnist-Armnn

/usr/bin/CaffeResNet-Armnn

/usr/bin/CaffeVGG-Armnn

/usr/bin/CaffeYolo-Armnn

 

./ 部署模型和輸入數據文件到模塊

-------------------------------

### 這裏下載,bvlc_alexnet_1.caffemodel 模型文件,部署到 Apalis iMX8 ~/ArmnnTests/modelsshark.jpg 輸入文件,部署到Apalis iMX8 ~/ArmnnTests/data

$ cd ArmnnTests

 

### Run with C++ backend, CPU without NEON

$ CaffeAlexNet-Armnn --data-dir=data --model-dir=models --compute=CpuRef

Info: ArmNN v20200200

 

Info: = Prediction values for test #0

Info: Top(1) prediction is 2 with value: 0.706227

Info: Top(2) prediction is 0 with value: 1.26575e-05

Info: Total time for 1 test cases: 15.842 seconds

Info: Average time per test case: 15841.653 ms

Info: Overall accuracy: 1.000

 

### Run with ACL NEON backend, CPU with NEON

$ CaffeAlexNet-Armnn --data-dir=data --model-dir=models --compute=CpuAcc

Info: ArmNN v20200200

 

Info: = Prediction values for test #0

Info: Top(1) prediction is 2 with value: 0.706226

Info: Top(2) prediction is 0 with value: 1.26573e-05

Info: Total time for 1 test cases: 0.237 seconds

Info: Average time per test case: 236.571 ms

Info: Overall accuracy: 1.000

 

### Run with GPU/NPU backend

$ CaffeAlexNet-Armnn --data-dir=data --model-dir=models --compute=VsiNpu

Info: ArmNN v20200200

 

, size = 618348Warn-Start NN executionInfo: = Prediction values for test #0

Info: Top(1) prediction is 2 with value: 0.706227

Info: Top(2) prediction is 0 with value: 1.26573e-05

Info: Total time for 1 test cases: 0.304 seconds

Info: Average time per test case: 304.270 ms

Info: Overall accuracy: 1.000

-------------------------------

 

d). TensorFlow示例應用測試

./ Image包含如下ARM NN TensorFlow模型測試示例,本文隨機選擇TfInceptionV3-Armnn進行測試

/usr/bin/TfCifar10-Armnn

/usr/bin/TfInceptionV3-Armnn

/usr/bin/TfMnist-Armnn

/usr/bin/TfMobileNet-Armnn

/usr/bin/TfResNext-Armnn

 

./ 部署模型和輸入數據文件到模塊

-------------------------------

### 這裏下載,inception_v3_2016_08_28_frozen.pb 模型文件,部署到 Apalis iMX8 ~/ArmnnTests/modelsshark.jpg, Dog.jpg, Cat.jpg 輸入文件,部署到Apalis iMX8 ~/ArmnnTests/data

$ cd ArmnnTests

 

### Run with C++ backend, CPU without NEON

$ TfInceptionV3-Armnn --data-dir=data --model-dir=models --compute=CpuRef

Info: ArmNN v20200200

 

Info: = Prediction values for test #0

Info: Top(1) prediction is 208 with value: 0.454895

Info: Top(2) prediction is 160 with value: 0.00278846

Info: Top(3) prediction is 131 with value: 0.000483914

Info: Top(4) prediction is 56 with value: 0.000304587

Info: Top(5) prediction is 27 with value: 0.000220489

Info: = Prediction values for test #1

Info: Top(1) prediction is 283 with value: 0.481285

Info: Top(2) prediction is 282 with value: 0.268979

Info: Top(3) prediction is 151 with value: 0.000375892

Info: Top(4) prediction is 24 with value: 0.00036751

Info: Top(5) prediction is 13 with value: 0.000330214

Info: = Prediction values for test #2

Info: Top(1) prediction is 3 with value: 0.986568

Info: Top(2) prediction is 0 with value: 1.51615e-05

Info: Total time for 3 test cases: 1477.627 seconds

Info: Average time per test case: 492542.205 ms

Info: Overall accuracy: 1.000

 

### Run with ACL NEON backend, CPU with NEON

$ TfInceptionV3-Armnn --data-dir=data --model-dir=models --compute=CpuAcc

Info: ArmNN v20200200

 

Info: = Prediction values for test #0

Info: Top(1) prediction is 208 with value: 0.454888

Info: Top(2) prediction is 160 with value: 0.00278851

Info: Top(3) prediction is 131 with value: 0.00048392

Info: Top(4) prediction is 56 with value: 0.000304589

Info: Top(5) prediction is 27 with value: 0.000220489

Info: = Prediction values for test #1

Info: Top(1) prediction is 283 with value: 0.481286

Info: Top(2) prediction is 282 with value: 0.268977

Info: Top(3) prediction is 151 with value: 0.000375891

Info: Top(4) prediction is 24 with value: 0.000367506

Info: Top(5) prediction is 13 with value: 0.000330212

Info: = Prediction values for test #2

Info: Top(1) prediction is 3 with value: 0.98657

Info: Top(2) prediction is 0 with value: 1.51611e-05

Info: Total time for 3 test cases: 4.541 seconds

Info: Average time per test case: 1513.509 ms

Info: Overall accuracy: 1.000

 

### Run with GPU/NPU backend

$ TfInceptionV3-Armnn --data-dir=data --model-dir=models --compute=VsiNpu

Info: ArmNN v20200200

 

, size = 1072812Warn-Start NN executionInfo: = Prediction values for test #0

Info: Top(1) prediction is 208 with value: 0.454892

Info: Top(2) prediction is 160 with value: 0.00278848

Info: Top(3) prediction is 131 with value: 0.000483917

Info: Top(4) prediction is 56 with value: 0.000304589

Info: Top(5) prediction is 27 with value: 0.00022049

Warn-Start NN executionInfo: = Prediction values for test #1

Info: Top(1) prediction is 283 with value: 0.481285

Info: Top(2) prediction is 282 with value: 0.268977

Info: Top(3) prediction is 151 with value: 0.000375891

Info: Top(4) prediction is 24 with value: 0.000367508

Info: Top(5) prediction is 13 with value: 0.000330214

Warn-Start NN executionInfo: = Prediction values for test #2

Info: Top(1) prediction is 3 with value: 0.986568

Info: Top(2) prediction is 0 with value: 1.51615e-05

Info: Total time for 3 test cases: 5.617 seconds

Info: Average time per test case: 1872.355 ms

Info: Overall accuracy: 1.000

-------------------------------

 

e). ONNX示例應用測試

./ Image包含如下ARM NN ONNX模型測試示例,本文隨機選擇OnnxMobileNet-Armnn進行測試

/usr/bin/OnnxMnist-Armnn

/usr/bin/OnnxMobileNet-Armnn

 

./ 部署模型和輸入數據文件到模塊

-------------------------------

### 這裏下載,mobilenetv2-1.0.onnx 模型文件,部署到 Apalis iMX8 ~/ArmnnTests/modelsshark.jpg, Dog.jpg, Cat.jpg 輸入文件,部署到Apalis iMX8 ~/ArmnnTests/data

$ cd ArmnnTests

 

### Run with C++ backend, CPU without NEON

$ OnnxMobileNet-Armnn --data-dir=data --model-dir=models --compute=CpuRef

Info: ArmNN v20200200

 

Info: = Prediction values for test #0

Info: Top(1) prediction is 208 with value: 17.1507

Info: Top(2) prediction is 207 with value: 15.3666

Info: Top(3) prediction is 159 with value: 11.0918

Info: Top(4) prediction is 151 with value: 5.26187

Info: Top(5) prediction is 112 with value: 4.09802

Info: = Prediction values for test #1

Info: Top(1) prediction is 281 with value: 13.6938

Info: Top(2) prediction is 43 with value: 6.8851

Info: Top(3) prediction is 39 with value: 6.33825

Info: Top(4) prediction is 24 with value: 5.8566

Info: Top(5) prediction is 8 with value: 3.78032

Info: = Prediction values for test #2

Info: Top(1) prediction is 2 with value: 22.6968

Info: Top(2) prediction is 0 with value: 5.99574

Info: Total time for 3 test cases: 163.569 seconds

Info: Average time per test case: 54523.023 ms

Info: Overall accuracy: 1.000

 

### Run with ACL NEON backend, CPU with NEON

$ OnnxMobileNet-Armnn --data-dir=data --model-dir=models --compute=CpuAcc

Info: ArmNN v20200200

 

Info: = Prediction values for test #0

Info: Top(1) prediction is 208 with value: 17.1507

Info: Top(2) prediction is 207 with value: 15.3666

Info: Top(3) prediction is 159 with value: 11.0918

Info: Top(4) prediction is 151 with value: 5.26187

Info: Top(5) prediction is 112 with value: 4.09802

Info: = Prediction values for test #1

Info: Top(1) prediction is 281 with value: 13.6938

Info: Top(2) prediction is 43 with value: 6.88511

Info: Top(3) prediction is 39 with value: 6.33825

Info: Top(4) prediction is 24 with value: 5.8566

Info: Top(5) prediction is 8 with value: 3.78032

Info: = Prediction values for test #2

Info: Top(1) prediction is 2 with value: 22.6968

Info: Top(2) prediction is 0 with value: 5.99574

Info: Total time for 3 test cases: 1.222 seconds

Info: Average time per test case: 407.494 ms

Info: Overall accuracy: 1.000

 

### Run with GPU/NPU backend

$ OnnxMobileNet-Armnn --data-dir=data --model-dir=models --compute=VsiNpu

Info: ArmNN v20200200

 

, size = 602112Warn-Start NN executionInfo: = Prediction values for test #0

Info: Top(1) prediction is 208 with value: 8.0422

Info: Top(2) prediction is 207 with value: 7.98566

Info: Top(3) prediction is 159 with value: 6.76481

Info: Top(4) prediction is 151 with value: 4.16534

Info: Top(5) prediction is 60 with value: 2.40269

Warn-Start NN executionInfo: = Prediction values for test #1

Info: Top(1) prediction is 287 with value: 5.98563

Info: Top(2) prediction is 24 with value: 5.49244

Info: Top(3) prediction is 8 with value: 2.24259

Info: Top(4) prediction is 7 with value: 1.36127

Info: Top(5) prediction is 5 with value: -1.69145

Error: Prediction for test case 1 (287) is incorrect (should be 281)

Warn-Start NN executionInfo: = Prediction values for test #2

Info: Top(1) prediction is 2 with value: 11.099

Info: Top(2) prediction is 0 with value: 3.42508

Info: Total time for 3 test cases: 0.258 seconds

Info: Average time per test case: 86.134 ms

Error: One or more test cases failed

-------------------------------

 

f). 除了上述推理引擎前端,TensorFlow Lite也是支持的,更多示例測試和參數説明以及ARMNN C++ API/Python API開發流程可以參考NXP i.MX Machine Learning User's Guide Rev. L5.4.70_2.3.0 Chapter 5 Arm NN

 

 

7). ONNX 測試

a). ONNX也是一款開源的機器學習推理引擎,NXP iMX8 eIQ ONNX支持特性和協議棧框圖如下

./ ONNX Runtime 1.1.2

./ Multithreaded computation with acceleration using Arm Neon SIMD instructions on Cortex-A cores provided by the ACL and Arm NN execution providers

./ Parallel computation using GPU/NPU hardware acceleration (on shader or convolution units) provided by the VSI NPU execution provider

./ C++ and Python API (supported Python version 3)

image009.png

 

b). 示例應用測試

./ ONNX Runtime 提供了一個onnx_test_runner BSP以及預裝於/usr/bin)用於運行ONNX model zoo提供的測試模型,下面幾個模型是在iMX8 eIQ測試過的模型

MobileNet v2, ResNet50 v2, ResNet50 v1, SSD Mobilenet v1, Yolo v3

 

./ MobileNet v2 模型測試

-------------------------------

### 從這裏下載模型文件壓縮包,然後在Apalis iMX8設備上$Home 目錄解壓出文件夾 mobilenetv2-7

$ cd /home/root/

### Run with ARMNN backend with CPU NEON

$ onnx_test_runner -j 1 -c 1 -r 1 -e armnn ./mobilenetv2-7/

…[E:onnxruntime:Default, runner.cc:217 operator()] Test mobilenetv2-7 finished in 0.907 seconds, t

result:

        Models: 1

        Total test cases: 3

                Succeeded: 3

                Not implemented: 0

                Failed: 0

        Stats by Operator type:

                Not implemented(0):

                Failed:

Failed Test Cases:

 

### Run with ACL backend with CPU NEON

$ onnx_test_runner -j 1 -c 1 -r 1 -e acl ./mobilenetv2-7/

…[E:onnxruntime:Default, runner.cc:217 operator()] Test mobilenetv2-7 finished in 0.606 seconds, t

result:

        Models: 1

        Total test cases: 3

                Succeeded: 3

                Not implemented: 0

                Failed: 0

        Stats by Operator type:

                Not implemented(0):

                Failed:

Failed Test Cases:

 

### Run with GPU/NPU backend

$ onnx_test_runner -j 1 -c 1 -r 1 -e vsi_npu ./mobilenetv2-7/

…[E:onnxruntime:Default, runner.cc:217 operator()] Test mobilenetv2-7 finished in 0.446 seconds, t

result:

        Models: 1

        Total test cases: 3

                Succeeded: 3

                Not implemented: 0

                Failed: 0

        Stats by Operator type:

                Not implemented(0):

                Failed:

Failed Test Cases:

-------------------------------

 

c). 更多示例測試和參數説明以及C++ API可以參考NXP i.MX Machine Learning User's Guide Rev. L5.4.70_2.3.0 Chapter 6 ONNX Runtime

 

 

8). OpenCV 測試

a). OpenCV是大家熟知的一款開源的傳統機器視覺庫,它包含一個ML模塊可以提供傳統的機器學習算法,可以支持神經網絡推理(DNN模型)和傳統機器學習算法(ML模型),NXP iMX8 eIQ OpenCV支持特性如下

./ OpenCV 4.4.0

./ C++ and Python API (supported Python version 3)

./ Only CPU computation is supported

./ Input image or live camera (webcam) is supported

 

b). 示例應用測試

./ BSP 預裝 OpenCV測試模型數據如下

DNN示例應用 - /usr/share/OpenCV/samples/bin

輸入數據、模型配置文件 - /usr/share/opencv4/testdata/dnn

 

./ Image classification DNN示例應用測試

-------------------------------

### 這裏下載,模型文件squeezenet_v1.1.caffemodel和配置文件model.yml複製到 /usr/share/OpenCV/samples/bin

### 複製數據文件到執行目錄

$ cp /usr/share/opencv4/testdata/dnn/dog416.png /usr/share/OpenCV/samples/bin/

$ cp /usr/share/opencv4/testdata/dnn/squeezenet_v1.1.prototxt /usr/share/OpenCV/samples/bin/

$ cp /usr/share/OpenCV/samples/data/dnn/classification_classes_ILSVRC2012.txt /usr/share/OpenCV/samples/bin/

 

$ cd /usr/share/OpenCV/samples/bin/

### Run with default image

$ ./example_dnn_classification --input=dog416.png --zoo=models.yml squeezenet

image011.png

 

### Run with actual camera(/dev/video2) input

./example_dnn_classification --device=2 --zoo=models.yml squeezenet

image013.png

-------------------------------

 

c). 更多示例測試和説明可以參考NXP i.MX Machine Learning User's Guide Rev. L5.4.70_2.3.0 Chapter 8 OpenCV machine learning demos

 

 

9). 總結

本文基於NXP eIQ 機器學習工具庫在iMX8嵌入式平台簡單演示了多種機器學習推理引擎示例應用,並簡單對比了CPU NEONGPU進行模型推理的性能表現,實際進行相關應用開發的時候還會遇到很多學習模型到實際推理模型轉換的問題,本文就不做涉及。

 

參考文獻

i.MX Machine Learning User's Guide Rev. L5.4.70_2.3.0

i.MX Yocto Project User's Guide Rev. L5.4.70_2.3.0

//developer.toradex.cn/knowledge-base/board-support-package/openembedded-core


審核編輯(王靜)
更多內容請訪問 韜睿(上海)計算機科技有限公司(//c.gongkong.com/?cid=16879)

手機掃描二維碼分享本頁

工控網APP下載安裝

 

我來評價

評價:
一般