From 3ec04ac9e38d26193e0081a8e0fa3b8b667bb688 Mon Sep 17 00:00:00 2001 From: Dwight Lidman Date: Thu, 30 Apr 2020 11:54:48 +0200 Subject: MLBEDSW-1498: Add Resize_Bilinear operator support This patch adds support for the ResizeBilinear operator. It is implemented using a 2x2 Nearest Neighbor upscale followed by a 2x2 Average Pool. Depending on the argument align_corners the output is either of shape: - (2 * M, 2 * N) when align_corners == True, or - (2 * M - 1, 2 * N - 1) when align_corners == False where (M, N) is the input shape. The padding mode is SAME when align_corners == True and VALID when align_corners == False. The argument half_pixel_centers is out of scope and is as of now ignored. Note that only upscaling by a factor of 2 is supported. Change-Id: Ia6d6d010c4f1bb13f5f839bc8d16872a626d9a3b Signed-off-by: Dwight Lidman --- ethosu/vela/register_command_stream_generator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ethosu/vela/register_command_stream_generator.py') diff --git a/ethosu/vela/register_command_stream_generator.py b/ethosu/vela/register_command_stream_generator.py index 460cf016..7a4faa80 100644 --- a/ethosu/vela/register_command_stream_generator.py +++ b/ethosu/vela/register_command_stream_generator.py @@ -401,6 +401,8 @@ def generate_register_command_stream(nng, sg, arch, verbose=False): use_global_scale = False # Specifies type of rounding to be used. rounding_mode = rounding.TFL + if primary_op.type == 'ResizeBilinear': + rounding_mode = rounding.TRUNCATE fmf = primary_op.attrs.get("fused_memory_function", None) faf = primary_op.attrs.get("fused_activation_function", None) @@ -537,7 +539,11 @@ def generate_register_command_stream(nng, sg, arch, verbose=False): emit.cmd0_with_param(cmd0.NPU_SET_ACC_FORMAT, acc_format_map[shared_buffer.use_accumulator_element]) - emit.cmd0_with_param(cmd0.NPU_SET_IFM_UPSCALE, 0) + if primary_op.type == 'ResizeBilinear': + # perform nearest neighbor upscale + emit.cmd0_with_param(cmd0.NPU_SET_IFM_UPSCALE, 1) + else: + emit.cmd0_with_param(cmd0.NPU_SET_IFM_UPSCALE, 0) if npu_block_type in set( (NpuBlockType.ConvolutionMxN, NpuBlockType.ConvolutionDepthWise, NpuBlockType.Pooling) @@ -579,7 +585,7 @@ def generate_register_command_stream(nng, sg, arch, verbose=False): valid_padding = sum(explicit_padding) == 0 - if primary_op.type in set(("AvgPool", "AvgPoolAct")) and valid_padding: + if primary_op.type in set(("AvgPool", "AvgPoolAct", "ResizeBilinear")) and valid_padding: # For valid padding vela has to output scaling values if faf == "Sigmoid" or faf == "Tanh": rescale = 0x3000 * cmd.ifm_tensor.quantization.scale_f32 -- cgit v1.2.1