From cf2519f6c324600f89cd35967885a7910bc38a9e Mon Sep 17 00:00:00 2001 From: Johan Gunnarsson Date: Mon, 3 Mar 2025 14:24:42 +0100 Subject: [PATCH] MLBEDSW-10504: Fix RESIZE bilinear of a 1x1 tensor We can't use the replicate mode for resize with the bilinear mode. Using the replicate mode breaks the scaling that is expected after a bilinear resize. Signed-off-by: Johan Gunnarsson Change-Id: I51be807a2e8c1633cc1ff42bd33e87323921585e --- .../compiler/high_level_command_stream_generator.cpp | 8 ++------ ethosu/regor/compiler/tflite_graph_optimiser.cpp | 6 +++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ethosu/regor/compiler/high_level_command_stream_generator.cpp b/ethosu/regor/compiler/high_level_command_stream_generator.cpp index 21d81c0a..6974e4b7 100644 --- a/ethosu/regor/compiler/high_level_command_stream_generator.cpp +++ b/ethosu/regor/compiler/high_level_command_stream_generator.cpp @@ -419,17 +419,13 @@ static std::shared_ptr MakeOperation(SchedulerOperation *schedOp, op->parameters.resize.scaleX = resize->scaleX; op->parameters.resize.offsetY = resize->offset.y; op->parameters.resize.offsetX = resize->offset.x; - if ( ifmShape.Width() == 1 && ifmShape.Height() == 1 ) - { - // 1x1 IFMs can be handled with replicate - op->parameters.resize.mode = ArchResizeMode::Replicate; - } - else if ( resize->mode == tosa::ResizeMode::NEAREST ) + if ( resize->mode == tosa::ResizeMode::NEAREST ) { op->parameters.resize.mode = ArchResizeMode::Nearest; } else { + assert(resize->mode == tosa::ResizeMode::BILINEAR); op->parameters.resize.mode = ArchResizeMode::Bilinear; } } diff --git a/ethosu/regor/compiler/tflite_graph_optimiser.cpp b/ethosu/regor/compiler/tflite_graph_optimiser.cpp index d47651bf..ec8c6a54 100644 --- a/ethosu/regor/compiler/tflite_graph_optimiser.cpp +++ b/ethosu/regor/compiler/tflite_graph_optimiser.cpp @@ -1241,16 +1241,20 @@ Operation *TFLiteGraphOptimiser::ConvertResize(Graph *const graph, Operation *co attr->scaleY = {height_n, height_d}; attr->offset = {widthOffset, heightOffset}; attr->border = {0, 0}; - attr->mode = (opType == OpType::ResizeBilinear) ? tosa::ResizeMode::BILINEAR : tosa::ResizeMode::NEAREST; int shift = 0; if ( opType == OpType::ResizeBilinear && (ifmConn->shape.Width() > 1 || ifmConn->shape.Height() > 1) ) { + attr->mode = tosa::ResizeMode::BILINEAR; // ResizeBilinear is post-scaled with // 1 / (height_n * width_n) // as the scale-factor is a power of two, we can use shift shift = IntLog2(width_n * height_n); } + else + { + attr->mode = tosa::ResizeMode::NEAREST; + } // Set explicit scaling Quantization ofmQuant = ofmConn->quantization; -- GitLab