# Python Examples
- [Python Examples](#python-examples)
- [Introduction](#introduction)
- [OSRT based user work flow](#osrt-based-user-work-flow)
- [Model Compilation on PC](#model-compilation-on-pc)
- [Model Inference on EVM](#model-inference-on-evm)
- [User options for TFLite and ONNX Runtime](#user-options-for-tflite-and-onnx-runtime)
- [Required](#required)
- [Optional](#optional)
- [User options for TVM](#user-options-for-tvm)
- [Trouble Shooting](#trouble-shooting)
## Introduction
TIDL provides multiple deployment options with industry defined inference engines as listed below. These inference engines are being referred as Open Source Run Times in this document.
* **TFLite Runtime**: [TensorFlow Lite](https://www.tensorflow.org/lite/guide/inference) based inference with heterogeneous execution on cortex-A** + C7x-MMA, using TFlite Delegates [TFLite Delgate](https://www.tensorflow.org/lite/performance/delegates) API
* **ONNX RunTime**: [ONNX Runtime]( https://www.onnxruntime.ai/) based inference with heterogeneous execution on cortex-A** + C7x-MMA.
* **TVM/Neo-AI RunTime**: [TVM]( https://tvm.apache.org)/[Neo-AI-DLR]( https://github.com/neo-ai/neo-ai-dlr) based inference with heterogeneous execution on cortex-A** + C7x-MMA
>** *TDA4VM has cortex-A72 as its MPU, refer to the device TRM to know which cortex-A MPU* it contains.
These heterogeneous execution enables:
1. OSRT as the top level inference API for user applications
2. Offloading subgraphs to C7x/MMA for accelerated execution with TIDL
3. Runs optimized code on ARM core for layers that are not supported by TIDL
## OSRT based user work flow
The diagram below illustrates the TFLite based work flow as an example. ONNX RunTime and TVM/Neo-AI RunTime also follows similar work flow. The User needs to run the model compilation (sub-graph(s) creation and quantization) on PC and the generated artifacts can be used for inference on the device.
![TFLite runtime based user work flow](../../docs/tflrt_work_flow.png)
## Model Compilation on PC
![OSRT Compile Steps](../../docs/osrt_compile_steps.png)
1. Prepare the Environment for the Model compilation by follwoing the setup section [here](../../README.md#setup)
2. Run for model compilation in the corresponding example folder – This step generates artifacts needed for inference in the \<repo base>\/model-artifacts folder. Each subgraph is identified in the artifacts using the tensor index of its output in the model
```
cd examples/osrt_python/tfl
python3 tflrt_delegate.py -c
```
3. Run Inference on PC - Optionally user can test the inference in host emulation mode and check the output; the output images will be saved in the corresponding specified artifacts folder
```
python3 tflrt_delegate.py
```
4. Run Inference on PC without offload - Optionally user can test the inference in host emulation mode without using any delegation to TI Delegate
```
python3 tflrt_delegate.py -d
```
## Model Inference on EVM
The artifacts generated by python scripts in the above section can be inferred using either python or C/C++ APIs. The following steps are for running inference using python API.
![OSRT Run Steps](../../docs/osrt_run_steps.png)
1. Copy the below folders from PC to the EVM where this repo is cloned
```
./model-artifacts
./models
```
2. Run the inference script in the corresponding example folder on the EVM and check the results, performance etc.
```
cd examples/osrt_python/tfl
python3 tflrt_delegate.py
```
Note : These scripts are only for basic functionally testing and performance check. Accuracy of the models can be benchmarked using the python module released here [edgeai-benchmark](https://github.com/TexasInstruments/edgeai-benchmark)
## User options for TFLite and ONNX Runtime
An example call to TFLite interpreter from the python interface using delegate mechanism:
interpreter = tflite.Interpreter(model_path='path_to_model', \
experimental_delegates=[tflite.load_delegate('libtidl_tfl_delegate.so.1.0', delegate_options)])
An example call to ONNX runtime session from the python interface :
EP_list = ['TIDLExecutionProvider','CPUExecutionProvider']
sess = rt.InferenceSession('path_to_model' ,providers=EP_list, provider_options=[delegate_options, {}], sess_options=so)
'delegate_options' in the inference session call comprise of the following options (required and optional). All these options are common for TFLite and ONNX runtime.
### Required
The following options need to be specified by user while creating TFLite interpreter:
| Name | Value |
|:-------------------|:--------------------------------------------------------|
| tidl_tools_path | to be set to ${TIDL_TOOLS_PATH} - Path from where to pick TIDL related tools |
| artifacts_folder | folder where user intends to store all the compilation artifacts |
### Optional
The following options are set to default values, to be specified if modification needed by user. Below optional arguments are specific to model compilation and not applicable to inference except the 'debug_level'
| Name | Description | Default values |
|:-------------------|:--------------------------------------------------------|:--------------------------:|
| platform | "J7" | "J7" |
| version | TIDL version - open source runtimes supported from version 7.2 onwards | (7,3) |
| tensor_bits | Number of bits for TIDL tensor and weights - 8/16 | 8 |
| debug_level | 0 - no debug, 1 - rt debug prints, >=2 - increasing levels of debug and trace dump | 0 |
| max_num_subgraphs | offload up to \<num\> tidl subgraphs | 16 |
| deny_list | force disable offload of a particular operator to TIDL [^2] | "" - Empty list |
| accuracy_level | 0 - basic calibration, 1 - higher accuracy(advanced bias calibration), 9 - user defined [^3] | 1 |
| advanced_options:calibration_frames | Number of frames to be used for calibration - min 10 frames recommended | 20 |
| advanced_options:calibration_iterations | Number of bias calibration iterations | 50 |
| advanced_options:output_feature_16bit_names_list | List of names of the layers (comma separated string) as in the original model whose feature/activation output user wants to be in 16 bit [^4] | "" |
| advanced_options:params_16bit_names_list | List of names of the output layers (separated by comma or space or tab) as in the original model whose parameters user wants to be in 16 bit [^1] | "" |
| advanced_options:quantization_scale_type | 0 for non-power-of-2, 1 for power-of-2 | 0 |
| advanced_options:high_resolution_optimization | 0 for disable, 1 for enable | 0 |
| advanced_options:pre_batchnorm_fold | Fold batchnorm layer into following convolution layer, 0 for disable, 1 for enable | 1 |
| advanced_options:add_data_convert_ops | Adds the Input and Output format conversions to Model and performs the same in DSP instead of ARM. This is currently a experimental feature. | 0 |
| object_detection:confidence_threshold | Override "nms_score_threshold" parameter threshold in tflite detection post processing layer | Read from model |
| object_detection:nms_threshold | Override "nms_iou_threshold" parameter threshold in tflite detection post processing layer |
没有合适的资源?快使用搜索试试~ 我知道了~
Edgeai TIDL工具和示例 - 此存储库包含为深度学习运行时开发的工具和示例_python_代码_下载
共309个文件
py:146个
jpg:49个
ipynb:20个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 169 浏览量
2022-07-03
01:35:56
上传
评论
收藏 7.39MB ZIP 举报
温馨提示
此存储库包含为 TI 的 EdgeAI 解决方案提供的深度学习运行时 (DLRT) 产品开发的示例。此存储库还包含有助于在 TI 的 EdgeAI 解决方案上快速部署 AI 应用程序以实现最佳性能的工具。 以下部分描述了在您的设备上安装此存储库、相关组件并在其上运行示例的步骤。本页中解释的大多数步骤对于 PC 仿真和目标执行都是通用的。如果 PC 和目标之间的任何步骤不同,则在本文档中标注相同。 设置 此存储库在 Ubuntu 18.04 上以 PC 仿真模式、AM62 EVM 和 TDA4VM EVM 使用 PSDK-RTOS 版本进行验证 此存储库仅适用于 PC 上的 python 3.6(在 Ubuntu 18.04 中是默认设置) 我们也在 PC 的 docker 容器下进行了验证。请参阅Dockerfile以获取安装在 ubuntu 18.04 基线之上的依赖项列表 运行以下脚本在您的机器上安装依赖组件并设置所有必需的环境 setup.sh 使用环境变量 DEVICE。在采购 setup.sh 之前设置相同 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
Edgeai TIDL工具和示例 - 此存储库包含为深度学习运行时开发的工具和示例_python_代码_下载 (309个子文件)
laptop.bmp 881KB
elephant.bmp 839KB
zebra.bmp 801KB
bus.bmp 706KB
bicycle.bmp 613KB
common.cmake 22KB
pbPlots.cpp 194KB
edgeai_classnames.cpp 51KB
ort_priority_scheduling.cpp 49KB
tfl_priority_scheduling.cpp 41KB
onnx_main.cpp 28KB
dlr_main.cpp 26KB
post_process.cpp 23KB
tfl_main.cpp 22KB
model_info.cpp 20KB
classification.cpp 13KB
arg_parsing.cpp 10KB
arg_parsing.cpp 9KB
pre_process.cpp 6KB
ti_logger.cpp 6KB
print_utils.cpp 4KB
utility_functs.cpp 4KB
supportLib.cpp 764B
golden_ref_full.csv 8KB
golden_ref_j7es.csv 1023B
golden_ref_pc.csv 980B
Dockerfile 1KB
.gitignore 80B
model_info.h 16KB
post_process.h 11KB
ti_logger.h 6KB
arg_parsing.h 5KB
arg_parsing.h 5KB
tfl_priority_scheduling.h 5KB
tfl_main.h 4KB
ort_priority_scheduling.h 4KB
dlr_main.h 4KB
pre_process.h 4KB
utility_functs.h 4KB
print_utils.h 4KB
onnx_main.h 4KB
classification.h 4KB
edgeai_classnames.h 3KB
pbPlots.hpp 32KB
supportLib.hpp 287B
custom-model-tvm-dlr.ipynb 17KB
custom-model-onnx.ipynb 15KB
lidar-3dod-onnx.ipynb 14KB
custom-model-tfl.ipynb 14KB
human-pose-estimation-onnx.ipynb 13KB
vcls-hr.ipynb 12KB
vcls-onnx.ipynb 12KB
vcls-tfl.ipynb 12KB
vcls-dlr.ipynb 11KB
vdet-onnx.ipynb 11KB
vdet-tfl.ipynb 11KB
vseg-tfl.ipynb 10KB
vseg-onnx.ipynb 10KB
vdet-dlr.ipynb 10KB
vcls-onnx-arm.ipynb 10KB
vseg-dlr.ipynb 10KB
vcls-tfl-arm.ipynb 10KB
debug_tips.ipynb 5KB
benchmark_accuracy.ipynb 5KB
evm-console-log.ipynb 1KB
ADE_val_00001801.jpg 494KB
ADE_val_00001801.jpg 494KB
ski_jump.jpg 143KB
street_walk_3.jpg 140KB
street_walk_2.jpg 139KB
horseman.jpg 134KB
ski.jpg 131KB
cpp_out_od-ort-ssd-lite_mobilenetv2_fpn.jpg 116KB
cpp_out_od-ort-ssd-lite_mobilenetv2_fpn.jpg 116KB
ti_lindau_I00000.jpg 92KB
soccer.jpg 91KB
schoolkids.jpg 88KB
cpp_out_ss-tfl-deeplabv3_mnv2_ade20k_float.jpg 87KB
cpp_out_ss-tfl-deeplabv3_mnv2_ade20k_float.jpg 87KB
cpp_out_ss-ort-deeplabv3lite_mobilenetv2.jpg 87KB
cpp_out_ss-ort-deeplabv3lite_mobilenetv2.jpg 87KB
cpp_out_cl-ort-resnet18-v1.jpg 66KB
cpp_out_cl-ort-resnet18-v1.jpg 66KB
cpp_out_cl-dlr-onnx_mobilenetv2.jpg 65KB
cpp_out_cl-dlr-onnx_mobilenetv2_device.jpg 64KB
cpp_out_cl-dlr-tflite_inceptionnetv3_device.jpg 64KB
cpp_out_cl-dlr-tflite_inceptionnetv3.jpg 64KB
cpp_out_cl-tfl-mobilenet_v1_1.0_224.jpg 64KB
cpp_out_cl-tfl-mobilenet_v1_1.0_224.jpg 64KB
apples.jpg 51KB
py_out_od-ort-ssd-lite_mobilenetv2_fpn_ADE_val_00001801.jpg 50KB
py_out_od-ort-ssd-lite_mobilenetv2_fpn_ADE_val_00001801.jpg 50KB
py_out_ss-ort-deeplabv3lite_mobilenetv2_ADE_val_00001801.jpg 49KB
py_out_ss-ort-deeplabv3lite_mobilenetv2_ADE_val_00001801.jpg 49KB
py_out_ss-tfl-deeplabv3_mnv2_ade20k_float_ADE_val_00001801.jpg 48KB
py_out_ss-tfl-deeplabv3_mnv2_ade20k_float_ADE_val_00001801.jpg 48KB
cpp_out_od-tfl-ssd_mobilenet_v2_300_float.jpg 41KB
cpp_out_od-tfl-ssd_mobilenet_v2_300_float.jpg 41KB
ADE_val_00000590.jpg 32KB
airshow.jpg 19KB
共 309 条
- 1
- 2
- 3
- 4
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- delphi实现DBGrid全选和反选功能
- 25C11F41-2B2A-4D1A-AAA8-7C654526B129.pdf
- Android Studio Jellyfish(android-studio-2023.3.1.18-cros.deb)
- MVC+EF框架+EasyUI实现权限管理源码程序
- python第66-75天,Day66-75.rar
- python后端服务project-of-tornado.rar
- python测验,hello-tornado.rar
- 基于SpringBoot+Vue3快速开发平台、自研工作流引擎源码设计.zip
- docker安装部署全流程
- 基于树莓派的人脸识别系统python源码+项目部署说明+超详细代码注释.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功