jacinto 机器学习

Jacinto机器学习工具箱通过在所有Jacinto设备上实现机器学习推理,将机器学习推向了前沿。它是作为TI的处理器SDK Linux的一部分提供的,可以免费下载和使用。今天的Jacinto机器学习由Neo-AI-DLR库组成。
• 3.8.1. Neo-AI深度学习运行库
• 3.8.2. TensorFlow Lite
• 3.8.2.1. 介绍
• 3.8.2.2. 支持的版本
• 3.8.2.3. TensorFlow Lite示例应用程序
• 3.8.2.3.1. 运行benchmark_model
• 3.8.2.3.2. 运行label_image示例
3.8.1. Neo-AI深度学习运行库
介绍
Neo-AI-DLR是一个开源的通用运行库,用于深度学习模型和决策树模型,由TVM、AWS SageMaker Neo或Treelite编译。处理器SDK集成了Neo-AI-DLR。DLR代表深度学习运行时。有了这个集成,用户可以使用以下选项来编译Jacinto设备的模型。
•AWS SageMaker neo服务
•离线TVM编译器
例子
Neo-AI-DLR运行推理的例子可以在目标文件系统的/usr/share/dlr中找到:

cd /usr/share/dlr/tests/python/integration/
python3 load_and_run_tvm_model.py

请注意
处理器SDK RTOS还使用TVM运行时和Neo-AI-DLR运行时实现了CNN模型在A72和C7x-MMA上的异构执行。这种异构执行使
•TVM/Neo-AI-DLR作为用户应用程序的顶级推理API
•将子图卸载到C7x/MMA,以加速TIDL执行
•对于TIDL不支持的层,生成代码并在ARM A72核心上运行
请参考《TIDL用户指南(SDK组件)》中的“Open Source Runtime->TVM/Neo-AI-DLR + TIDL Heterogeneous Execution”章节,了解详细的使用说明。
3.8.2 TensorFlow Lite
3.8.2.1 介绍
TensorFlow Lite是一个深度学习模型的开源库。TensorFlow Lite运行在Jacinto Arm内核上.
3.8.2.2 支持版本
•tensorflow Lite 1.15

3.8.2.3 TensorFlow Lite应用示例

示例应用程序安装在/usr/share/tensorflow-lite/examples文件系统上。一个TensorFlow Lite模型(mobilenet_v1_1.0_224_quant.tflite)也安装在相同的位置,用于演示。要使用其他TensorFlow Lite模型,如TensorFlow Lite托管模型,请下载这些模型,然后复制到目标。

root@am57xx-evm:/usr/share/tensorflow-lite/examples# ls -l
total 8356
-rwxr-xr-x 1 root root 2423336 Aug 28 08:27 benchmark_model
-rw-r--r-- 1 root root  940650 Aug 28 07:56 grace_hopper.bmp
-rwxr-xr-x 1 root root 2288600 Aug 28 08:27 label_image
-rw-r--r-- 1 root root   10484 Aug 28 07:56 labels.txt
-rwxr-xr-x 1 root root 2251048 Aug 28 08:27 minimal
-rw-r--r-- 1 root root 4276352 Aug 28 07:56 mobilenet_v1_1.0_224_quant.tflite
-rwxr-xr-x 1 root root    2152 Aug 28 07:56 tflite-benchmark.she

3.8.2.3.1 运行benchmark_model
benchmark_model二进制文件执行Tensorflow Lite模型的计算基准测试。benchmark_model的用法:

usage: ./benchmark_model
Flags:
        --num_runs=50   int32   number of runs
        --run_delay=-1  float   delay between runs in seconds
        --num_threads=1 int32   number of threads
        --benchmark_name=       string  benchmark name
        --output_prefix=        string  benchmark output prefix
        --warmup_runs=1 int32   how many runs to initialize model
        --graph=        string  graph file name
        --input_layer=  string  input layer names
        --input_layer_shape=    string  input layer shape
        --use_nnapi=false       bool    use nnapi api

使用预先安装的mobilenet_v1_1.0_224_quant.tflite模型在目标上运行benchmark_model的示例。

# cd /usr/share/tensorflow-lite/examples
# ./benchmark_model --graph=mobilenet_v1_1.0_224_quant.tflite
STARTING!
Min num runs: [50]
Min runs duration (seconds): [1]
Max runs duration (seconds): [150]
Inter-run delay (seconds): [-1]
Num threads: [1]
Benchmark name: []
Output prefix: []
Min warmup runs: [1]
Min warmup runs duration (seconds): [0.5]
Graph: [mobilenet_v1_1.0_224_quant.tflite]
Input layers: []
Input shapes: []
Use nnapi : [0]
Use legacy nnapi : [0]
Use gpu : [0]
Allow fp16 : [0]
Require full delegation : [0]
Enable op profiling: [0]
Max profiling buffer entries: [1024]
Loaded model mobilenet_v1_1.0_224_quant.tflite
resolved reporter
Initialized session in 126.941ms
Running benchmark for at least 1 iterations and at least 0.5 seconds but termin.
count=7 first=80936 curr=73720 min=73663 max=80936 avg=74766.3 std=2519

3.8.2.3.2 运行label_image例子
label_image提供了一个使用TensorFlow Lite进行图像分类的示例。label_image选项:

--accelerated, -a: [0|1], use Android NNAPI or not
--count, -c: loop interpreter->Invoke() for certain times
--input_mean, -b: input mean
--input_std, -s: input standard deviation
--image, -i: image_name.bmp
--labels, -l: labels for the model
--tflite_model, -m: model_name.tflite
--profiling, -p: [0|1], profiling or not
--num_results, -r: number of results to show
--threads, -t: number of threads
--verbose, -v: [0|1] print more information

使用预先安装的mobilenet_v1_1.0_224_quant.tflite模型,grace_hopper.bmp和labels.txt在目标上运行label_image的示例。

# cd /usr/share/tensorflow-lite/examples
# ./label_image -i grace_hopper.bmp -l labels.txt -m mobilenet_v1_1.0_224_quant.tflite
Loaded model mobilenet_v1_1.0_224_quant.tflite
resolved reporter
invoked
average time: 164.164 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

3.9. ARM可信固件-A
概述
可信固件-A(TF-A)为Armv7-A和Armv8-A提供了安全世界软件的参考实现,包括在异常级别3(EL3)执行的安全监视器。
ATF用作所有K3平台的ARMv8-A核心上的初始启动代码。在设置初始核心状态并应用任何需要的勘误表之后,它将自己设置为EL3监视器处理程序。在这之后,安装secure world软件(OP-TEE),并将执行传递给非安全世界中的Linux内核或U-Boot。
获取ATF源代码

$ git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git

编译 ATF

$ make CROSS_COMPILE=aarch64-linux-gnu- PLAT=k3 DEBUG=1 SPD=opteed all

默认加载位置

ATF image 0x70000000
OP-TEE image 0x9e800000
U-Boot/Linux kernel image 0x80080000
DTB 0x82000000

如果需要,这些选项可以在以下选项中改变默认值:

plat/ti/k3/board/generic/board.mk

3.10. OP-TEE
概述
OP-TEE是一个可信执行环境(Trusted Execution Environment,TEE),设计为运行在Arm上的非安全Linux内核的伴侣;Cortex-a内核使用TrustZone技术。OP-TEE实现TEE Internal Core API v1.1.x,这是公开给受信任应用程序的API,TEE Client API v1.0是描述如何与TEE通信的API。这些API在globalplatformapi规范中定义。
获取OP-TEE源代码

$ git clone https://github.com/OP-TEE/optee_os.git

编译 OP-TEE

$ make CROSS_COMPILE64=aarch64-linux-gnu- PLATFORM=k3 CFG_ARM64_core=y all
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐