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.

PROCESSOR-SDK-J722S: Issue about convert onnx file to TIDL format

Part Number: PROCESSOR-SDK-J722S

Tool/software:

Hi team,

I am trying to run inference on a custom model following the steps below but encountered an issue:

  1. Flow: ONNX file --> convert to TIDL format --> run inference

    • I can successfully run inference using models from the Model Zoo.
    • However, when I use edgeai-tidl-tools/tidl_tools/tidl_model_import.out to convert my ONNX model to TIDL format and then attempt to run inference, I encounter an error stating that param.yaml does not exist.

My convert model (on the left) differs from the example model in the Model Zoo (on the right).

Questions:

  1. Is it possible to generate config.yaml, dataset.yaml, and param.yaml using tidl_model_import.out? If so, how can I configure them correctly?

  2. Could you please provide an example of converting an ONNX file to TIDL format and running inference?

  3. I also attempted the Custom Model Evaluation method.(github.com/.../custom_model_evaluation.md(github.com/.../custom_model_evaluation.md

    • However, the log shows the error: EP Error Unknown Provider Type: TIDLCompilationProvider when using ['TIDLCompilationProvider', 'CPUExecutionProvider'].
    • Am I missing any settings? My code is below:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import torch
import onnx
import onnxruntime as rt
import subprocess
import os
#
onnx_model_path = "model.onnx"
simplified_onnx_model_path = "model_simplified.onnx"
tidl_artifacts_folder = "./model-artifacts-dir/"
tidl_tools_path = "./app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/tidl_tools/"
# Step 1: ONNX ( PyTorch )
def export_pytorch_model_to_onnx(model, input_shape):
dummy_input = torch.randn(*input_shape)
torch.onnx.export(model, dummy_input, onnx_model_path, opset_version=11)
print(f"ONNX model exported to {onnx_model_path}")
# Step 2:
def check_and_infer_shape(onnx_model_path):
model = onnx.load(onnx_model_path)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Thanks for your kindly help.

  • Hi Ken; we will look into this. First we will do exact what you have done, to find out if we will have the same problem. Could you please provide the software version#; the command for each step, and your Linux environment? So we can replicate them on our side.

    Thanks and regards

    Wen Li

  • My TIDL version is 10.00.04.00, and Ubuntu version is 22.04

    My setup TIDL sop below:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    apt-get update
    apt-get upgrade
    apt install sudo
    sudo apt-get install libyaml-cpp-dev libglib2.0-dev
    apt install git
    apt install wget
    Pip3 install dlr
    pip3 install flatbuffers==2.0
    Sudo apt install cmake
    sudo apt install libopencv-dev
    git clone https://github.com/TexasInstruments/edgeai-tidl-tools.git
    cd edgeai-tidl-tools/
    git checkout 110634e30a121b6efdfba8faf75c347e21caa49e
    export SOC=am67a
    source ./setup.sh
    export SOC=<Your SOC name>
    export TIDL_TOOLS_PATH=$(pwd)/tidl_tools
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TIDL_TOOLS_PATH
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I try two way to convert onnx to TIDL format:

    [1]

    - cd <local path>/tidl_tools

    - ./tidl_model_import.out ../ken_test_model/test.txt

    - test.txt :

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #### lenet
    modelType = 2
    numParamBits = 8
    numFeatureBits = 8
    quantizationStyle = 3
    #quantizationStyle = 2
    inputNetFile = "/app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/ken_test_model/lenet.onnx"
    outputNetFile = "/app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/ken_test_model/lenet_res/lenet.bin"
    outputParamsFile = "/app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/ken_test_model/lenet_res/lenet_"
    inDataNorm = 0
    inDataFormat = 1
    inWidth = 28
    inHeight = 28
    inNumChannels = 1
    numFrames = 1
    inData = "/app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/ken_test_model/0003.jpg"
    # 0 = JPEG/PNG/BMP; 1 = binary; 2 = list
    inFileFormat = 0
    perfSimConfig = /app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/tidl_tools/device_config.cfg
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    - log below: (but can't fnd param.yaml / dataset.yaml, can't run inference)

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    root@914dec19bac9:/app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/tidl_tools# ./tidl_model_import.out ../ken_test_model/test.txt
    ========================= [Model Compilation Started] =========================
    Model compilation will perform the following stages:
    1. Parsing
    2. Graph Optimization
    3. Quantization & Calibration
    4. Memory Planning
    ============================== [Version Summary] ==============================
    -------------------------------------------------------------------------------
    | TIDL Tools Version | 10_00_04_00 |
    -------------------------------------------------------------------------------
    | C7x Firmware Version | 10_00_02_00 |
    -------------------------------------------------------------------------------
    No Meta Arch layer to parse
    ONNX model (Proto) file : /app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/ken_test_model/lenet.onnx
    TIDL network file : /app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/ken_test_model/lenet_res/lenet.bin
    TIDL IO info file : /app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/ken_test_model/lenet_res/lenet_
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    [2]

    - cd <local path>/examples/jupyter_notebooks

    - source ./launch_notebook.sh

    - python3 tidl_model_convert_onnx.py

    - tidl_model_convert_onnx.py below:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    import os
    import tqdm
    import cv2
    import numpy as np
    import onnxruntime as rt
    import shutil
    from scripts.utils import imagenet_class_to_name, download_model
    import matplotlib.pyplot as plt
    from pathlib import Path
    from IPython.display import Markdown as md
    from scripts.utils import loggerWritter
    from scripts.utils import get_svg_path
    import onnx
    def preprocess(image_path):
    # read the image using openCV
    img = cv2.imread(image_path)
    # convert to RGB
    img = img[:,:,::-1]
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    - log below (If this successfully, will convert param.yaml and dataset.yaml?, inference code need these two files):

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    root@914dec19bac9:/app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/examples/jupyter_notebooks# ls
    README.md custom-artifacts custom-model-tvm-dlr.ipynb evm-console-log.ipynb lidar-3dod-onnx.ipynb prebuilt-models tidl_model_convert_onnx.py vcls-hr.ipynb vcls-tfl-arm.ipynb vdet-onnx.ipynb vseg-onnx.ipynb
    colab custom-model-onnx.ipynb debug_tips.ipynb human-pose-estimation-onnx.ipynb logs sample-images tidl_model_convert_tflite.py vcls-onnx-arm.ipynb vcls-tfl.ipynb vdet-tfl.ipynb vseg-tfl.ipynb
    configs custom-model-tfl.ipynb docs launch_notebook.sh models scripts vcls-dlr.ipynb vcls-onnx.ipynb vdet-dlr.ipynb vseg-dlr.ipynb
    root@914dec19bac9:/app/ken/tda4/TIDL10.00.06.00/edgeai-tidl-tools/examples/jupyter_notebooks# python3 tidl_model_convert_onnx.py
    /usr/local/lib/python3.10/dist-packages/onnxruntime/capi/onnxruntime_inference_collection.py:115: UserWarning: Specified provider 'TIDLCompilationProvider' is not in available provider names.Available providers: 'AzureExecutionProvider, CPUExecutionProvider'
    warnings.warn(
    2024-11-08 01:54:33.885035952 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer4.1.bn1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885066086 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer4.0.bn2.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885073018 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer3.0.downsample.1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885080827 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer4.0.downsample.1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885086808 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer3.0.bn1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885092786 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer3.1.bn2.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885099389 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer2.0.downsample.1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885105336 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer3.1.bn1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885110886 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer1.0.bn2.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885117031 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer1.1.bn2.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885123454 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'bn1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885130440 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer1.0.bn1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885137239 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer2.1.bn1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    2024-11-08 01:54:33.885143287 [W:onnxruntime:, graph.cc:4285 CleanUnusedInitializersAndNodeArgs] Removing initializer 'layer1.1.bn1.num_batches_tracked'. It is not used by any node and should be removed from the model.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Please help me to check,

    Thanks for your kindly help.

  • Hello Ken; Thank you for the information. I will try to setup the same configuration/environment as you have; and will up you updated.

    Regards

    Wen Li

  • Hi Wen,

    Thank you very much for your attention, and I look forward to receiving your reply.

    Best regards

  • Hi Ken; I am still working on your one. 

    Meanwhile, have you look at this info yet?

    https://github.com/TexasInstruments/edgeai-tidl-tools/blob/master/docs/custom_model_evaluation.md#custom-model-evaluation

    Thanks and regards

    Wen

  • Hi Wen:

    I have followed the instructions from this link and implemented the process:
    https://github.com/TexasInstruments/edgeai-tidl-tools/blob/master/examples/jupyter_notebooks/custom-model-onnx.ipynb,

    but I encountered the error "EP Error Unknown Provider Type: TIDLCompilationProvider."

    (https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1435070/processor-sdk-j722s-run-onnx-compilation-fail/5503642.)

    Thanks for your kindly help.

    Best regards

  • Hi Ken;

    I will run this 

    https://github.com/TexasInstruments/edgeai-tidl-tools/blob/master/examples/jupyter_notebooks/custom-model-onnx.ipynb

    Jupyter book first to see if I will get the same result. if not we will compare our notes.

    Thanks and regards

    Wen

  • Hi Wen:

    Sorry to bother you, do you get the same result after running the above steps?

    Thanks for your kindly help.