From 497a19edf68d03eab086c9a77e8d726040560855 Mon Sep 17 00:00:00 2001 From: Evgenya Stepyreva Date: Wed, 19 Apr 2023 17:27:41 +0400 Subject: [PATCH] CVS-102308 Read tflite model to vector (#17048) --- .../tensorflow_lite/src/graph_iterator_flatbuffer.cpp | 11 +++-------- .../tensorflow_lite/src/graph_iterator_flatbuffer.hpp | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.cpp b/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.cpp index cc093066956e88..5bdba29f355c6d 100644 --- a/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.cpp +++ b/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.cpp @@ -18,18 +18,13 @@ GraphIteratorFlatBuffer::GraphIteratorFlatBuffer(const std::wstring& path) #endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT GraphIteratorFlatBuffer::GraphIteratorFlatBuffer(const std::string& path) { - std::ifstream model_file; - model_file.open(path, std::ios::binary | std::ios::in); + std::ifstream model_file(path, std::ios::binary | std::ios::in); FRONT_END_GENERAL_CHECK(model_file && model_file.is_open(), "Model file does not exist: ", path); - model_file.seekg(0, std::ios::end); - auto length = model_file.tellg(); - model_file.seekg(0, std::ios::beg); - char* data = new char[length]; - model_file.read(data, length); + m_data = {(std::istreambuf_iterator(model_file)), std::istreambuf_iterator()}; model_file.close(); - m_model = std::shared_ptr(tflite::GetMutableModel(data), [](tflite::Model* p) {}); + m_model = tflite::GetModel(m_data.data()); const auto subgraphs = m_model->subgraphs(); FRONT_END_GENERAL_CHECK(subgraphs->size() == 1, "Number of sub-graphs in the model is ", diff --git a/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.hpp b/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.hpp index 497d2b4fae87fa..9430bc158d7ef7 100644 --- a/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.hpp +++ b/src/frontends/tensorflow_lite/src/graph_iterator_flatbuffer.hpp @@ -23,8 +23,9 @@ struct TensorInfo { class GraphIteratorFlatBuffer { size_t node_index = 0; + std::vector m_data; std::vector m_nodes; - std::shared_ptr m_model; + const tflite::Model* m_model; public: explicit GraphIteratorFlatBuffer(const std::string& path);