This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] EDGE-AI-STUDIO:edgeai-tidl-tools

Guru**** 2405515 points
Other Parts Discussed in Thread: AM69A

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1489068/edge-ai-studio-edgeai-tidl-tools

器件型号:EDGE-AI-STUDIO
主题中讨论的其他器件:AM69A

工具与软件:

为什么模型分析器 ONR-CL-6110-resNet50示例比我自己使用 edgeai-tidl-tools 版本10_01_04_00编译的 RESNET50 ONNX 模型快三倍?

模型分析器 - AM69A - Example model ~23MB -输入张量: uint8[1,3224]: 2ms
edgeai-tidl-tools - AM69A - myresnet50模型~92MB -输入张量: float32[1,3224]: 6ms

它将帮助我理解为什么不在我自己的 ONNX 模型上进行量化、如果丢失量化是我的 RESNET50推理结果比模型分析器 ONR-CL-6110-RESNet50示例慢三倍的主要原因、那么这将会帮助我理解为什么没有在我自己的 ONNX 模型上进行量化。

运行我自己的 ONNX 模型的步骤:

  • 准备 edgeai-tidl-tools Docker 容器。
  • 运行 Docker 容器并构建示例:
   source ./scripts/run_python_examples.sh

准备自己的 ONNX 模型(float32):

  • 将自己的 ONNX 模型添加到:
   models/public/resnet50_f32.onnx
  • 将自己的 ONNX 模型配置添加到:
    examples/osrt_python/model_configs.py
       models_configs = {
           "cl-ort-resnet50-224x224": create_model_config(
               task_type="classification",
               source=dict(
                   model_url="",
                   infer_shape=True,
               ),
               preprocess=dict(
                   resize=256,
                   crop=224,
                   data_layout="NCHW",
                   resize_with_pad=False,
                   reverse_channels=False,
               ),
               session=dict(
                   session_name="onnxrt",
                   model_path=os.path.join(models_base_path, "resnet50_f32.onnx"),
                   input_mean=[123.675, 116.28, 103.53],
                   input_scale=[0.017125, 0.017507, 0.017429],
                   input_optimization=True,
                   # Explicit quantization keeps the ONNX on float 32 data type.
                   # quantization=dict(
                   #     quantize=True,
                   #     quantization_style="uint8",
                   # ),  
               ),
               extra_info=dict(num_images=numImages, num_classes=1000),
           ),

  • 编译自己的 float32 ONNX:
   cd ./examples/osrt_python/ort
   python3 onnxrt_ep.py -c -m cl-ort-resnet50-224x224

我找到了-o明确优化自己的 ONNX 模型的选项、但仍然没有为我提供量化模型输出。

  • 可选:在 Docker 容器中推断自己的 ONNX 模型(x86 CPU 仿真):
   python3 onnxrt_ep.py -m cl-ort-resnet50-224x224
  • 将依赖关系自有的 ONNX 复制到 AM69A 开发底板并运行推理:
   cd /home/root/
   python3 ./scripts/gen_test_report.py
  • AM69A 开发底板的基准测试:
    • 确保目标上的 git 版本标签10_01_04_00。
    • 将编译后的模型工件复制到 AM69A 器件。
   python3 onnxrt_ep.py -m cl-ort-resnet50-224x224
   python3 gen_test_report.py
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Holger、

    DSP 针对 8位或16位 int 进行了优化、因此您可以在示例模型中看到更短的推理时间。 edgeai-tidl-tools 文档对此进行了进一步说明、最近在另一个 E2E 主题中对此进行了讨论。

    edgeai-tidl-tools: https://github.com/TexasInstruments/edgeai-tidl-tools/blob/master/docs/tidl_fsg_quantization.md

    E2E 讨论: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1478914/processor-sdk-j722s-the-question-about-running-inference-with-the-default-model-mobilenetv1

    如果您对此有任何其他问题、敬请告知。

    谢谢!

    Fabiana

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Fabiana:

    感谢您的反馈、尤其是与量化设置相关的链接。


    我了解在编译步骤后、我的 float32 ONNX 模型仍然是 float32模型:

    python3 onnxrt_ep.py -c -m cl-ort-resnet50-224x224
    

    这意味着我使用默认编译设置时没有 uint8量化。

    在 AM69A 器件上推理此 float32 ONNX 模型需要执行一次性的训练后量化步骤(uint8、uint32、混合)。 由于缺少 AM69A 器件的训练数据、我想 PTQ 是"无训练量化–最简单易用"(来源: 德州仪器(TI))。

    我的推理基准比较:

    • 模型分析器- AM69A - ONR-CL-6110-RESNet50 -输入张量: uint8[1,3224]: 2 ms
    • edgeai-tidl-tools - AM69A -我的 resnet50_F32.onnx -输入张量: float32[1,3224]: 6 ms

    这导致性能降低3倍、这代表了非优化编译的默认设置。 为了实现完全推理潜力、需要优化量化和校准设置(来源: 德州仪器(TI))。


    对于预量化的 ONNX uint8模型、必须设置advanced_options:prequantized_model为1 (来源: 德州仪器(TI))。


    如果我的总结正确、我会将我的问题标记为已解决。

    此致、

    Holger

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Holger、

    是的、您的理解是正确的。 尽管 float32模型使本例中的 uint8示例模型的性能降低了因子3、但  推理基准测试比较的差异不应该完全相同。

    谢谢!

    Fabiana