Skip to content

Commit

Permalink
[tflite2circle] Revise to follow tflite order (Samsung#7946)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
seanshpark authored Nov 10, 2021
1 parent 96ad925 commit 656f494
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions compiler/tflite2circle/src/CircleModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <cassert>
#include <iostream>
#include <map>
#include <memory>

#include "CircleModel.h"
Expand Down Expand Up @@ -206,7 +207,8 @@ template <> void Offset<SubGraphLink>::build(const TFLFlatBufVec *tflite_flatbuf
auto tflite_inputs = it_sg->inputs();
std::vector<int32_t> 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)
{
Expand All @@ -216,10 +218,16 @@ template <> void Offset<SubGraphLink>::build(const TFLFlatBufVec *tflite_flatbuf
{
auto inputs = it_signdef->inputs();
assert(inputs->size() == input_vec.size());
uint32_t input_vec_idx = 0;

std::map<std::string, uint32_t> map_name_index;
for (auto it_tm : *inputs)
{
input_vec[input_vec_idx++] = static_cast<int32_t>(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;
}
}
}
Expand All @@ -240,10 +248,16 @@ template <> void Offset<SubGraphLink>::build(const TFLFlatBufVec *tflite_flatbuf
{
auto outputs = it_signdef->outputs();
assert(outputs->size() == output_vec.size());
uint32_t output_vec_idx = 0;

std::map<std::string, uint32_t> map_name_index;
for (auto it_tm : *outputs)
{
output_vec[output_vec_idx++] = static_cast<int32_t>(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;
}
}
}
Expand Down

0 comments on commit 656f494

Please sign in to comment.