Skip to content

[luci-interpreter] ReshapeOp with 0 and -1 in shape #15679

@seanshpark

Description

@seanshpark

ReshapeOp from ONNX has 0 and from this value, luci-interpreter halts without message.
maybe by divide by zero error.

static void resolveUnknownDimension(const Shape &input_shape, Shape *output_shape)
{
  const int32_t num_input_elements = input_shape.num_elements();
  int32_t num_output_elements = 1;
  int unknown_dim_index = -1;
  for (int i = 0; i < output_shape->num_dims(); ++i)
  {
    const int32_t value = output_shape->dim(i);
    if (value == -1)
    {
      assert(unknown_dim_index == -1);
      unknown_dim_index = i;
    }
    else
    {
      num_output_elements *= value;
    }
  }
  if (unknown_dim_index != -1)
  {
    output_shape->dim(unknown_dim_index) = num_input_elements / num_output_elements; <-----------
    num_output_elements *= output_shape->dim(unknown_dim_index);
  }

Image

what to do

  • throw with there's a 0 in shape message
  • treat 0 like the ONNX does

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions