Forums - Onnx2Dlc: Incorrect output shape inference of Expand

4 posts / 0 new
Last post
Onnx2Dlc: Incorrect output shape inference of Expand
anhtu.nguyen
Join Date: 22 Jun 22
Posts: 11
Posted: Wed, 2022-08-10 07:04

Hello,

I'm converting Onnx to Dlc using snpe1.64 and I found a strange behavior of output shape inference of Expand operation.

In the file snpe-1.64.0.3605/lib/python/qti/aisw/converters/onnx/data_translations.py at the class OnnxExpandTranslation, your logic to find output shape is not always correct. 

# ------------------------------------------------------------------------------
# Expand
# ------------------------------------------------------------------------------
class OnnxExpandTranslation(OnnxTranslationBase):
def __init__(self):
OnnxTranslationBase.__init__(self)
self.register_op_schema('Expand', [8, 13])

def extract_parameters(self, src_op, converter_context):
graph = converter_context.ir_graph
src_input_names = list(map(str, src_op.input))

shape_constant_op = self.fetch_constant_op(src_input_names[1], converter_context, dtype=np.int32, fail_if_not_found=True)
log_debug1(code_to_message.get_debugging_message("DEBUG_STATIC_OP")(src_input_names[1]))

output_shape = [int(dim_size) for dim_size in shape_constant_op.tensor]

return op_adapter.ExpandOp(src_op.name,
output_shape)

def extract_input_names(self, src_op, converter_context):
return [str(src_op.input[0])]

In this code, you use the value of constant tensor in Expand Operation as the output shape, but according to documentation of Onnx (https://github.com/onnx/onnx/blob/main/docs/Operators.md#Expand), the output shape should also follow broadcast rule.

For exemple:

If you  have an input with shape (3, 1), and your constant tensor is (2, 1, 6), you should have output shape equal to (2, 3, 6) instead of (2, 1, 6) in your implementation. You can read the example in Onnx documentation for more information.

 

  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Sun, 2022-09-04 06:22

Dear customer,

I assume your issue is the incorrect dimension between ONNX and SNPE.

SNPE supported to NHWC but ONNX default is NCHW so that you need to convert SNPE result(NHWC) to ONNX format(NCHW). Then start to your outputs comparsion.

BR.

Wei

  • Up0
  • Down0
rajan.sharma
Join Date: 9 May 22
Posts: 2
Posted: Wed, 2022-09-14 21:47

Hi weihuan

So, that means expand ops is supported rite? but i am also trying onnx to dlc converter and i am getting error like (converter does not support op type expand). 

and for scatter_nd ops i am also getting error that converter does not support op type scatter_nd.

I saw in SNPE sdk documentation inside revision history (https://developer.qualcomm.com/sites/default/files/docs/snpe/revision_hi...) that from snpe-1.59.0 both expand and scatter_nd are supported. But not sure why i am getting these error. can you please help me to fix that. 

Thanks

Rajan

 

  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Sat, 2022-09-17 23:25

Dear customer,

The ops of Scatter sill don't support on SNPE yet. You can try to wirte SNPE UDL or SNPE UDO if you want to support you feature ops.

BR.

Wei

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.