TexasInstruments/edgeai-tidl-tools

Model parsing error: false depthwise convolution layer

Closed this issue · 1 comments

I have created a simple model with single convolution layer, one input and one output channel:

import onnx
import onnx.helper as helper
import onnx.numpy_helper as numpy_helper
import numpy as np
 
# Create a tensor for the weights of the convolutional layer
weights = np.random.randn(1, 1, 9, 1).astype(np.float32)
weights_tensor = numpy_helper.from_array(weights, name='conv1_weight')

# Create the input tensor value info
input_tensor = helper.make_tensor_value_info('input', onnx.TensorProto.FLOAT, [1, 1, 5, 5])

# Create the output tensor value info
output_tensor = helper.make_tensor_value_info('output', onnx.TensorProto.FLOAT, [1, 1, 5, 5])

# Create the node (layer)
conv_node = helper.make_node(
    'Conv',
    inputs=['input', 'conv1_weight'],
    outputs=['output'],
    kernel_shape=[9, 1],
    pads=[4, 0, 4, 0],
    strides=[1, 1]
)

# Create the graph
graph = helper.make_graph(
    [conv_node],
    'conv_graph',
    [input_tensor],
    [output_tensor],
    [weights_tensor]
)
 
# Create the model
model = helper.make_model(graph, producer_name='onnx-example')
 
# Save the model to a file
onnx.save(model, 'single_conv_layer.onnx')
 
print("ONNX model for a single convolutional layer has been created and saved as 'single_conv_layer.onnx'")

During the model compilation I have received the following message from the parser while there is no depthwise convolution layer in the model:

[TIDL Import]  UNSUPPORTED: Allowlisting : Layer name - output : Depthwise convolution layer with Kernel 9x1 and Stride 1x1 is not supported -- [tidlAllowlistingConstraints/tidl_constraint.cpp, 85]
[TIDL Import] [PARSER] UNSUPPORTED: Layer is not supported by TIDL --- layer type - Conv, Node name -  -- [tidl_onnxRtImport_core.cpp, 519]

Thus, the parser reports a false depthwise convolution layer since the number of groups equals to 1 and all inputs are convolved to all outputs. Here is the Python code used for model compilation:

import numpy as np
import onnxruntime as rt

##########################################
###          Script parameters         ###
##########################################

model_path = 'single_conv_layer.onnx'
EP_list = ['TIDLCompilationProvider','CPUExecutionProvider']
options = {}
options['artifacts_folder'] = './model-artifacts-dir/'
options['tidl_tools_path'] = '/home/root/tidl_tools'
options['debug_level'] = 1

##########################################


so = rt.SessionOptions()

# Load the ONNX model
session = rt.InferenceSession(model_path, providers=EP_list, provider_options=[options, {}], sess_options=so)

# Create a random input tensor with the same shape as the input tensor defined in the model
input_data = np.random.rand(1, 1, 5, 5).astype(np.float32)

# Run the model
outputs = session.run(None, {'input': input_data})

# Print the output
print("Model output:", outputs[0])

You can find single_conv_layer.onnx file in the archive single_conv_layer.zip. Below is complete console log for model compilation with debug_level=3:

tidl_tools_path                                 = /home/root/tidl_tools
artifacts_folder                                = ./model-artifacts-dir/
tidl_tensor_bits                                = 8
debug_level                                     = 3
num_tidl_subgraphs                              = 16
tidl_denylist                                   =
tidl_denylist_layer_name                        =
tidl_denylist_layer_type                        =
tidl_allowlist_layer_name                       =
model_type                                      =
tidl_calibration_accuracy_level                 = 7
tidl_calibration_options:num_frames_calibration = 20
tidl_calibration_options:bias_calibration_iterations = 50
mixed_precision_factor = -1.000000
model_group_id = 0
power_of_2_quantization                         = 2
ONNX QDQ Enabled                                = 0
enable_high_resolution_optimization             = 0
pre_batchnorm_fold                              = 1
add_data_convert_ops                            = 0
output_feature_16bit_names_list                 =
m_params_16bit_names_list                       =
m_single_core_layers_names_list                 =
Inference mode                                  = 0
Number of cores                                 = 1
reserved_compile_constraints_flag               = 1601
partial_init_during_compile                     = 0
ti_internal_reserved_1                          =

========================= [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             |
-------------------------------------------------------------------------------
|            Runtime Version           |            1.14.0+10000005           |
-------------------------------------------------------------------------------
|          Model Opset Version         |                  18                  |
-------------------------------------------------------------------------------

NOTE: The runtime version here specifies ONNXRT_VERSION+TIDL_VERSION
Ex: 1.14.0+1000XXXX -> ONNXRT 1.14.0 and a TIDL_VERSION 10.00.XX.XX

============================== [Parsing Started] ==============================

[TIDL Import] [PARSER] WARNING: Network not identified as Object Detection network : (1) Ignore if network is not Object Detection network (2) If network is Object Detection network, please specify "model_type":"OD" as part of OSRT compilation options
[TIDL Import]  UNSUPPORTED: Allowlisting : Layer name - output : Depthwise convolution layer with Kernel 9x1 and Stride 1x1 is not supported -- [tidlAllowlistingConstraints/tidl_constraint.cpp, 85]
[TIDL Import] [PARSER] UNSUPPORTED: Layer is not supported by TIDL --- layer type - Conv, Node name -  -- [tidl_onnxRtImport_core.cpp, 519]

------------------------- Subgraph Information Summary -------------------------
-------------------------------------------------------------------------------
|          Core           |      No. of Nodes       |   Number of Subgraphs   |
-------------------------------------------------------------------------------
| C7x                     |                       0 |                       0 |
| CPU                     |                       1 |                       x |
-------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| Node | Node Name |                                   Reason                                    |
--------------------------------------------------------------------------------------------------
| Conv | output    | Depthwise convolution layer with Kernel 9x1 and Stride 1x1 is not supported |
--------------------------------------------------------------------------------------------------
Running Runtimes GraphViz - /home/root/tidl_tools/tidl_graphVisualiser_runtimes.out ./model-artifacts-dir//allowedNode.txt ./model-artifacts-dir//tempDir/graphvizInfo.txt ./model-artifacts-dir//tempDir/runtimes_visualization.svg
============================= [Parsing Completed] =============================

Model output: [[[[ 0.24346259  0.7302017  -0.3997852  -0.09163873  0.1756232 ]
   [ 0.5447106   0.14750001  0.44192222  0.50972265  0.668015  ]
   [ 0.25353688  1.1781881   0.46983877  0.47023544  0.4859341 ]
   [-0.5246689  -0.97710145 -0.54835     0.01153768 -0.42153066]
   [-0.13848214 -0.18936723 -0.2901531  -0.37395775  0.07250781]]]]

The issue was reported to TI's E2E Processors forum: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1413779/am69a-parsing-error-false-depthwise-convolution-layer
I will close it here to avoid duplication.