From 656f494f6488f95038affbf01064e2d18299ef65 Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Wed, 10 Nov 2021 18:10:25 +0900 Subject: [PATCH] [tflite2circle] Revise to follow tflite order (#7946) This will revise to store circle input/output sequence with SignatureDef to follow tflite ordering to make possible for evaluation. ONE-DCO-1.0-Signed-off-by: SaeHie Park --- compiler/tflite2circle/src/CircleModel.cpp | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/compiler/tflite2circle/src/CircleModel.cpp b/compiler/tflite2circle/src/CircleModel.cpp index 90cc415ffbe..458a5b31f83 100644 --- a/compiler/tflite2circle/src/CircleModel.cpp +++ b/compiler/tflite2circle/src/CircleModel.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include "CircleModel.h" @@ -206,7 +207,8 @@ template <> void Offset::build(const TFLFlatBufVec *tflite_flatbuf auto tflite_inputs = it_sg->inputs(); std::vector input_vec{tflite_inputs->begin(), tflite_inputs->end()}; - // apply signature_def to input tensor index so that input orders are correct + // apply signature_def to input tensor index so that input orders follow like tensorflow lite + // interpreter._get_full_signature_list() method, which is ordered(sorted) in name // NOTE we do not need this when circle format supports signature_def if (_tfl_signature_def_offsets != nullptr) { @@ -216,10 +218,16 @@ template <> void Offset::build(const TFLFlatBufVec *tflite_flatbuf { auto inputs = it_signdef->inputs(); assert(inputs->size() == input_vec.size()); - uint32_t input_vec_idx = 0; + + std::map map_name_index; for (auto it_tm : *inputs) { - input_vec[input_vec_idx++] = static_cast(it_tm->tensor_index()); + map_name_index[it_tm->name()->str()] = it_tm->tensor_index(); + } + uint32_t input_vec_idx = 0; + for (auto &item : map_name_index) + { + input_vec[input_vec_idx++] = item.second; } } } @@ -240,10 +248,16 @@ template <> void Offset::build(const TFLFlatBufVec *tflite_flatbuf { auto outputs = it_signdef->outputs(); assert(outputs->size() == output_vec.size()); - uint32_t output_vec_idx = 0; + + std::map map_name_index; for (auto it_tm : *outputs) { - output_vec[output_vec_idx++] = static_cast(it_tm->tensor_index()); + map_name_index[it_tm->name()->str()] = it_tm->tensor_index(); + } + uint32_t output_vec_idx = 0; + for (auto &item : map_name_index) + { + output_vec[output_vec_idx++] = item.second; } } }