From 85582b1676c6d60462ea611f55da49d97b4ec7f8 Mon Sep 17 00:00:00 2001 From: Alexander Bengtsson Date: Wed, 23 Apr 2025 09:31:28 +0200 Subject: [PATCH] MLBEDSW-10725: Pad shapes before semantic checks - Broadcast semantic-checks are incorrect if tensors have different shapes. Fix by padding shapes to 4D before applying constraints for broadcast. Change-Id: I6c79629b0ee70c77be88984730e2d79e5d774664 Signed-off-by: Alexander Bengtsson --- ethosu/regor/tflite/tflite_model_semantics.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethosu/regor/tflite/tflite_model_semantics.cpp b/ethosu/regor/tflite/tflite_model_semantics.cpp index 08c9a992..3d1b3a6f 100644 --- a/ethosu/regor/tflite/tflite_model_semantics.cpp +++ b/ethosu/regor/tflite/tflite_model_semantics.cpp @@ -755,15 +755,15 @@ void ConstraintMatchingEitherShapes(const Operator &op, const SubGraph &subgraph { auto ifm = TensorFromUsage(regor::TensorUsage::IFM, op, builtinOperator, *subgraph.tensors()); auto ofm = TensorFromUsage(regor::TensorUsage::OFM, op, builtinOperator, *subgraph.tensors()); - auto ifmShape = ShapeFromTens(ifm); - auto ofmShape = ShapeFromTens(ofm); + auto ifmShape = Shape::PadAxes(ShapeFromTens(ifm), 4, 1); + auto ofmShape = Shape::PadAxes(ShapeFromTens(ofm), 4, 1); bool valid = ifmShape == ofmShape; Shape ifm2Shape = Shape(); auto ifm2 = TensorFromUsage(MakeTensorUsage(regor::TensorUsage::IFM, 1), op, builtinOperator, *subgraph.tensors()); if ( ifm2 && !valid ) { - ifm2Shape = ShapeFromTens(ifm2); + ifm2Shape = Shape::PadAxes(ShapeFromTens(ifm2), 4, 1); bool isBroadcastable = true; for ( auto i = 0; i < std::min(ifmShape.Size(), ifm2Shape.Size()); i++ ) { -- GitLab