I got this error while converting an onnx model to DLC model using snpe-onnx-to-dlc, Error: ValueError: getBroadcastedTensorShape: Unable to broadcast shapes: IrTensorShape(dims = [1,64,18,0] , dy_axes=[]) and IrTensorShape(dims = [1,64,0,2147483647] , dy_axes=[])
2025-05-30 18:33:53,388 - 240 - ERROR - Node /bg_predictor/bg_encoder/layer1/layer1.0/Add: getBroadcastedTensorShape: Unable to broadcast shapes: IrTensorShape(dims = [1,64,18,0] , dy_axes=[]) and IrTensorShape(dims = [1,64,0,2147483647] , dy_axes=[])
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
The error you're encountering during the ONNX to DLC conversion is due to incompatible tensor shapes that cannot be broadcasted. The specific issue arises from the Add operation involving two tensors with shapes [1, 64, 18, 0] and [1, 64, 0, 2147483647]. Here's how to resolve it:
Root Cause
The error occurs because the broadcasting rules for tensor shapes are violated. In ONNX/SNPE, tensor dimensions must be compatible for operations like Add, where:
Dimensions must be equal, or
One of the dimensions is 1 (for broadcasting).
In your case:
The third dimension is 18 vs. 0 (invalid).
The fourth dimension is 0 vs. 2147483647 (a large number, likely a placeholder for dynamic input).
The presence of 0 and 2147483647 suggests dynamic or undefined shapes in the original ONNX model, which the SNPE converter cannot resolve during the DLC conversion.
Solutions
1. Specify Input Shapes Explicitly
If the model uses dynamic dimensions, provide concrete input shapes during conversion using the --input_shapes flag. For example:
Replace input_name with the actual input tensor name and adjust the dimensions to match your intended input (e.g., 1, 64, 18, 2147483647).
2. Validate the ONNX Model
Use tools like Netron or ONNX Runtime to inspect the model and identify:
Layers with invalid or dynamic shapes.
Mismatches in tensor dimensions.
3. Fix Dynamic Shapes in the Model
If the model uses dynamic shapes (e.g., 0 or -1), ensure they are replaced with fixed values. For example:
Replace 0 with a concrete value (e.g., 224 for image height).
Use onnx.shape or onnx.reshape to enforce fixed dimensions if needed.
4. Check for Unsupported Operators
Ensure all operators in the model are supported by SNPE. Use the SNPE operator list to verify compatibility. If unsupported operators are present, modify the model or use a workaround.
5. Debug the Add Operation
Inspect the Add node (/bg_predictor/bg_encoder/layer1/layer1.0/Add) in the model:
Confirm the shapes of the two input tensors.
Ensure they are compatible (e.g., same dimensions or broadcastable).
If not, adjust the model (e.g., add Reshape or Squeeze layers).
6. Update SNPE Tools
Ensure you're using the latest version of SNPE and the ONNX converter. Older versions may have bugs or limited support for certain ONNX features.
Example Fix
If the model expects a fixed input size (e.g., 1x64x18x2147483647), modify the conversion command: