Skip to content

Support dynamic shape output for CompiledModel #5774

@leeroyka

Description

@leeroyka

LiteRT v2.1.1 CompiledModel C++ Android

The model has a dynamic shape of the input and output tensors.
When I change the size of the input tensor, the output shape does not change.

Example:

my model has:

Input:
  0: name=data, shape=[ 1 -1 -1 3], dtype=float32

Output:
  0: name=out_0, shape=[ 1 -1 -1 18], dtype=float32
  1: name=out_1, shape=[ 1 -1 -1 18], dtype=float32
  2: name=out_2, shape=[ 1 -1 -1 18], dtype=float32
  3: name=out_3, shape=[ 1 -1 -1 18], dtype=float32

c++ code:

    LITERT_ABORT_IF_ERROR(compiled_model.ResizeInputTensor("data", {1, 1088, 1920, 3}));
    LITERT_ASSIGN_OR_ABORT(auto input_buffers,
                         compiled_model.CreateInputBuffers());
    LITERT_ASSIGN_OR_ABORT(auto output_buffers,
                         compiled_model.CreateOutputBuffers());

    auto input_buffer_size = input_buffers[0].Size();
    LOGI("INPUT_BUFFER_SIZE: %zu", *input_buffer_size);
    LOGI("OUTPUT_BUFFER_SIZE: %zu", output_buffers.size());
    for (size_t i = 0; i < output_buffers.size(); ++i) {
        auto output_buffers_size = output_buffers[i].Size();
        LOGI("Output buffer %zu size: %zu", i, *output_buffers_size);
    }

logs:

INPUT_BUFFER_SIZE: 25067520
OUTPUT_BUFFER_SIZE: 4
Output buffer 0 size: 72
Output buffer 1 size: 72
Output buffer 2 size: 72
Output buffer 3 size: 72

but for my models output shapes should be:

  out_0 shape=(1, 68, 120, 18)
  out_1 shape=(1, 136, 240, 18)
  out_2 shape=(1, 17, 30, 18)
  out_3 shape=(1, 34, 60, 18) 

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions