OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[FE] Migrate tensorflow frontend to use std::fs::path (#35356)
Alicja Miloszewska4fb36f87de13
diff --git a/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp b/src/frontends/tensorflow/src/checkpoint_v1_reader.cppindex d8ac5892f65..fe1e8704d76 100644--- a/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp+++ b/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp@@ -17,13 +17,13 @@using namespace ov::frontend::tensorflow;namespace {-std::vector<std::string> list_files_in_dir(const std::string& directory_path) {- std::vector<std::string> res;+std::vector<std::filesystem::path> list_files_in_dir(const std::filesystem::path& directory_path) {+ std::vector<std::filesystem::path> res;try {ov::util::iterate_files(- ov::util::make_path(directory_path),+ directory_path,[&res](const std::filesystem::path& file_path) {- res.push_back(ov::util::path_to_string(file_path));+ res.push_back(file_path);},true);} catch (...) {@@ -33,11 +33,11 @@ std::vector<std::string> list_files_in_dir(const std::string& directory_path) {}} // namespace-CheckpointV1Reader::CheckpointV1Reader(const std::string& checkpoints) : m_checkpoints(checkpoints) {}+CheckpointV1Reader::CheckpointV1Reader(const std::filesystem::path& checkpoints) : m_checkpoints(checkpoints) {}void CheckpointV1Reader::initialize() {// figure out if the input is a file or a directory of checkpoints- std::vector<std::string> checkpoints_paths;+ std::vector<std::filesystem::path> checkpoints_paths;if (ov::util::directory_exists(m_checkpoints)) {checkpoints_paths = list_files_in_dir(m_checkpoints);} else if (ov::util::file_exists(m_checkpoints)) {@@ -48,18 +48,20 @@ void CheckpointV1Reader::initialize() {m_variables_info_map.clear();- for (auto checkpoint_path : checkpoints_paths) {+ for (const auto& checkpoint_path : checkpoints_paths) {// create ifstream for each shardstd::shared_ptr<std::ifstream> shard_stream =std::make_shared<std::ifstream>(checkpoint_path, std::ifstream::in | std::ifstream::binary);- FRONT_END_GENERAL_CHECK(- shard_stream && shard_stream->is_open(),- "[TensorFlow Frontend] incorrect model: checkpoint file " + checkpoint_path + "does not exist");+ FRONT_END_GENERAL_CHECK(shard_stream && shard_stream->is_open(),+ "[TensorFlow Frontend] incorrect model: checkpoint file ",+ checkpoint_path,+ " does not exist");const int32_t shard_ind = static_cast<int32_t>(m_shards.size());m_shards.push_back(shard_stream);- m_shard_names.push_back(checkpoint_path);+ const std::string shard_name = ov::util::path_to_string(checkpoint_path);+ m_shard_names.push_back(shard_name);std::string value;- find_entry(shard_stream, checkpoint_path, SAVED_TENSOR_SLICES_KEY, value);+ find_entry(shard_stream, shard_name, SAVED_TENSOR_SLICES_KEY, value);// parse empty index block// This is only present at the first item of each checkpoint file and servesdiff --git a/src/frontends/tensorflow/src/checkpoint_v1_reader.hpp b/src/frontends/tensorflow/src/checkpoint_v1_reader.hppindex 168185ab299..70d2606135f 100644--- a/src/frontends/tensorflow/src/checkpoint_v1_reader.hpp+++ b/src/frontends/tensorflow/src/checkpoint_v1_reader.hpp@@ -6,6 +6,7 @@#include <sys/stat.h>+#include <filesystem>#include <unordered_map>#include <vector>@@ -31,7 +32,7 @@ struct VariableInfo {// reads checkpoints of v1 version// it parses value, shape and type for Variable nodesclass CheckpointV1Reader {- const std::string m_checkpoints;+ const std::filesystem::path m_checkpoints;// a map from Variable name to its informationstd::unordered_map<std::string, VariableInfo> m_variables_info_map;// a vector of streams for shards, where shard is one checkpoint file@@ -41,8 +42,7 @@ class CheckpointV1Reader {public:/// \brief constructs CheckpointV1Reader for a given directory of checkpoint files- // CheckpointV1Reader(const std::string& checkpoints_dir);- CheckpointV1Reader(const std::string& checkpoints);+ CheckpointV1Reader(const std::filesystem::path& checkpoints);/// \brief initialize Checkpoint V1 readervoid initialize();diff --git a/src/frontends/tensorflow/src/frontend.cpp b/src/frontends/tensorflow/src/frontend.cppindex 20762bd9857..65ebc0c0c46 100644--- a/src/frontends/tensorflow/src/frontend.cpp+++ b/src/frontends/tensorflow/src/frontend.cpp@@ -142,21 +142,20 @@ bool FrontEnd::supported_impl(const std::vector<ov::Any>& variants) const {if (variants.size() != 1 + extra_variants_num)return false;- std::filesystem::path model_fs_path, checkpoints_dir;- if (const auto path = ov::frontend::get_path_from_any(variants[0])) {- model_fs_path = path.value();- } else if (const auto paths = ov::frontend::get_path_vec_from_any(variants[0])) {+ std::filesystem::path model_path, checkpoints_or_tags;+ if (auto path = ov::frontend::get_path_from_any(variants[0])) {+ model_path = std::move(*path);+ } else if (auto paths = ov::frontend::get_path_vec_from_any(variants[0])) {if (paths->size() == 2) {- model_fs_path = paths.value()[0];- checkpoints_dir = paths.value()[1];+ model_path = std::move((*paths)[0]);+ checkpoints_or_tags = std::move((*paths)[1]);}}// to figure out if the model with v1 checkpoints is supported,// it is sufficient to check only the input model format// avoid parsing of checkpoints here- if (!model_fs_path.empty() && checkpoints_dir.empty()) {- auto model_path = model_fs_path.native();+ if (!model_path.empty() && checkpoints_or_tags.empty()) {if (GraphIteratorProto::is_supported(model_path)) {// handle binary protobuf format// for automatic deduction of the frontend to convert the model@@ -170,8 +169,7 @@ bool FrontEnd::supported_impl(const std::vector<ov::Any>& variants) const {// handle text protobuf formatreturn true;}- } else if (!model_fs_path.empty() && !checkpoints_dir.empty()) {- auto model_path = model_fs_path.native();+ } else if (!model_path.empty() && !checkpoints_or_tags.empty()) {// here, we assume to get the input model path and checkpoints directoryif (GraphIteratorProto::is_supported(model_path)) {// binary protobuf format with checkpoints@@ -202,17 +200,16 @@ ov::frontend::InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& va"frozen formats (.pb and .pbtxt), SavedModel and MetaGraph (.meta) formats, and v1 checkpoints.";FRONT_END_GENERAL_CHECK(variants.size() == 1 + extra_variants_num, err_msg);- std::filesystem::path model_fs_path, checkpoints_fs_dir;- if (const auto path = ov::frontend::get_path_from_any(variants[0])) {- model_fs_path = path.value();- } else if (const auto paths = ov::frontend::get_path_vec_from_any(variants[0])) {+ std::filesystem::path model_path, checkpoints_or_tags;+ if (auto path = ov::frontend::get_path_from_any(variants[0])) {+ model_path = std::move(*path);+ } else if (auto paths = ov::frontend::get_path_vec_from_any(variants[0])) {FRONT_END_GENERAL_CHECK(paths->size() == 2, err_msg);- model_fs_path = paths.value()[0];- checkpoints_fs_dir = paths.value()[1];+ model_path = std::move((*paths)[0]);+ checkpoints_or_tags = std::move((*paths)[1]);}- if (!model_fs_path.empty() && checkpoints_fs_dir.empty()) {- const auto model_path = model_fs_path.native();+ if (!model_path.empty() && checkpoints_or_tags.empty()) {if (GraphIteratorProto::is_supported(model_path)) {// handle binary protobuf formatreturn std::make_shared<InputModel>(std::make_shared<GraphIteratorProto>(model_path), m_telemetry);@@ -243,10 +240,9 @@ ov::frontend::InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& va// handle text protobuf formatreturn std::make_shared<InputModel>(std::make_shared<GraphIteratorProtoTxt>(model_path), m_telemetry);}- } else if (!model_fs_path.empty() && !checkpoints_fs_dir.empty()) {+ } else if (!model_path.empty() && !checkpoints_or_tags.empty()) {// here, we assume to get the input model path and checkpoints directory- const auto model_path = ov::util::path_to_string(model_fs_path);- const auto checkpoints_dir = ov::util::path_to_string(checkpoints_fs_dir);+ const auto checkpoints_dir = checkpoints_or_tags;if (GraphIteratorProto::is_supported(model_path)) {auto graph_iterator = std::make_shared<GraphIteratorProto>(model_path, checkpoints_dir);// handle binary protobuf format with checkpoints@@ -272,7 +268,7 @@ ov::frontend::InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& vagraph_iterator->get_checkpoint_v1_reader(),false);} else if (GraphIteratorSavedModel::is_supported(model_path)) {- auto saved_model_tags = checkpoints_dir;+ const auto saved_model_tags = ov::util::path_to_string(checkpoints_or_tags);std::shared_ptr<GraphIteratorSavedModel> graph_iterator;graph_iterator = std::make_shared<GraphIteratorSavedModel>(model_path, saved_model_tags, mmap_enabled);return std::make_shared<InputModel>(graph_iterator,diff --git a/src/frontends/tensorflow/src/graph_iterator_meta.cpp b/src/frontends/tensorflow/src/graph_iterator_meta.cppindex 8f069c56376..d71b2771af8 100644--- a/src/frontends/tensorflow/src/graph_iterator_meta.cpp+++ b/src/frontends/tensorflow/src/graph_iterator_meta.cpp@@ -29,18 +29,10 @@ bool GraphIteratorMeta::is_valid_signature(const ::tensorflow::SignatureDef& sigreturn true;}-template <>-std::basic_string<char> get_variables_index_name<char>(const std::string name) {- return name + ".index";+std::filesystem::path get_variables_index_name(const std::filesystem::path& name) {+ return std::filesystem::path(name) += ".index";}-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)-template <>-std::basic_string<wchar_t> get_variables_index_name<wchar_t>(const std::wstring name) {- return name + L".index";-}-#endif-} // namespace tensorflow} // namespace frontend} // namespace ovdiff --git a/src/frontends/tensorflow/src/graph_iterator_meta.hpp b/src/frontends/tensorflow/src/graph_iterator_meta.hppindex 3c4e3174f08..f409b009e84 100644--- a/src/frontends/tensorflow/src/graph_iterator_meta.hpp+++ b/src/frontends/tensorflow/src/graph_iterator_meta.hpp@@ -4,6 +4,7 @@#pragma once+#include <filesystem>#include <map>#include "graph_iterator_proto.hpp"@@ -14,16 +15,7 @@ namespace ov {namespace frontend {namespace tensorflow {-template <typename T>-std::basic_string<T> get_variables_index_name(const std::basic_string<T> name) {}--template <>-std::basic_string<char> get_variables_index_name<char>(const std::string name);--#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)-template <>-std::basic_string<wchar_t> get_variables_index_name<wchar_t>(const std::wstring name);-#endif+std::filesystem::path get_variables_index_name(const std::filesystem::path& name);// Loads graph from Tensorflow MetaGraph file (*.meta)class GraphIteratorMeta : public GraphIteratorProto {@@ -36,21 +28,18 @@ class GraphIteratorMeta : public GraphIteratorProto {bool m_mmap_enabled;public:- template <typename T>- GraphIteratorMeta(const std::basic_string<T>& path, const bool mmap_enabled)+ GraphIteratorMeta(const std::filesystem::path& path, const bool mmap_enabled): m_metagraph_def(std::make_shared<::tensorflow::MetaGraphDef>()),m_mmap_enabled(mmap_enabled) {this->read_meta(path);}- template <typename T>- static bool is_supported(const std::basic_string<T>& path) {+ static bool is_supported(const std::filesystem::path& path) {FRONT_END_GENERAL_CHECK(util::directory_exists(path) || util::file_exists(path),- "Could not open the file: \"",- util::path_to_string(path),- '"');+ "Could not open the file: ",+ path);try {- std::ifstream mg_stream(path.c_str(), std::ios::in | std::ifstream::binary);+ std::ifstream mg_stream(path, std::ios::in | std::ifstream::binary);auto metagraph_def = std::make_shared<::tensorflow::MetaGraphDef>();return mg_stream && mg_stream.is_open() && metagraph_def->ParsePartialFromIstream(&mg_stream) &&metagraph_def->has_graph_def() && metagraph_def->graph_def().node_size() > 0;@@ -82,17 +71,17 @@ public:private:bool is_valid_signature(const ::tensorflow::SignatureDef& signature) const;- template <typename T>- bool read_meta(const std::basic_string<T>& path) {- std::basic_string<T> model_path = path.substr(0, path.find_last_of('.'));+ bool read_meta(const std::filesystem::path& path) {+ auto model_path = path;+ model_path.replace_extension();- std::ifstream mg_stream{path.c_str(), std::ifstream::in | std::ifstream::binary};+ std::ifstream mg_stream{path, std::ifstream::in | std::ifstream::binary};FRONT_END_GENERAL_CHECK(mg_stream && mg_stream.is_open(), "Model file does not exist");- std::basic_string<T> varIndexPath = get_variables_index_name<T>(model_path);+ auto varIndexPath = get_variables_index_name(model_path);if (ov::util::file_exists(varIndexPath)) {m_variables_index = std::make_shared<VariablesIndex>(m_mmap_enabled);- std::ifstream vi_stream{varIndexPath.c_str(), std::ifstream::in | std::ifstream::binary};+ std::ifstream vi_stream{varIndexPath, std::ifstream::in | std::ifstream::binary};FRONT_END_GENERAL_CHECK(vi_stream && vi_stream.is_open(), "MetaGraph's variable index file does not exist");FRONT_END_GENERAL_CHECK(m_variables_index->read_variables(vi_stream, model_path, false),"MetaGraph's variable index file cannot be parsed");diff --git a/src/frontends/tensorflow/src/graph_iterator_proto.hpp b/src/frontends/tensorflow/src/graph_iterator_proto.hppindex 966fe8e631a..37ce202f095 100644--- a/src/frontends/tensorflow/src/graph_iterator_proto.hpp+++ b/src/frontends/tensorflow/src/graph_iterator_proto.hpp@@ -4,10 +4,8 @@#pragma once+#include <filesystem>#include <fstream>-#if defined(__MINGW32__) || defined(__MINGW64__)-# include <filesystem>-#endif#include <vector>#include "checkpoint_v1_reader.hpp"@@ -59,8 +57,7 @@ protected:}}- template <typename T>- void initialize_v1_checkpoints(const std::basic_string<T>& checkpoint_directory) {+ void initialize_v1_checkpoints(const std::filesystem::path& checkpoint_directory) {m_checkpoint_v1_reader = std::make_shared<CheckpointV1Reader>(checkpoint_directory);m_checkpoint_v1_reader->initialize();}@@ -107,16 +104,11 @@ public:}/// \brief Construct GraphIterator for the frozen model without v1 checkpoints- template <typename T>- GraphIteratorProto(const std::basic_string<T>& model_path)+ GraphIteratorProto(const std::filesystem::path& model_path): m_graph_def(std::make_shared<::tensorflow::GraphDef>()),m_func_def(nullptr),m_checkpoint_v1_reader(nullptr) {-#if defined(__MINGW32__) || defined(__MINGW64__)- std::ifstream pb_stream(std::filesystem::path(model_path), std::ios::in | std::ifstream::binary);-#elsestd::ifstream pb_stream(model_path, std::ios::in | std::ifstream::binary);-#endifFRONT_END_GENERAL_CHECK(pb_stream && pb_stream.is_open(), "Model file does not exist");FRONT_END_GENERAL_CHECK(m_graph_def->ParseFromIstream(&pb_stream), "Model cannot be parsed");@@ -125,8 +117,7 @@ public:}/// \brief Construct GraphIterator for the frozen model with v1 checkpoints- template <typename T>- GraphIteratorProto(const std::basic_string<T>& model_path, const std::basic_string<T>& checkpoint_directory)+ GraphIteratorProto(const std::filesystem::path& model_path, const std::filesystem::path& checkpoint_directory): m_graph_def(std::make_shared<::tensorflow::GraphDef>()),m_func_def(nullptr),m_checkpoint_v1_reader(nullptr) {@@ -140,18 +131,12 @@ public:}/// \brief Check if the input file is supported- template <typename T>- static bool is_supported(const std::basic_string<T>& path) {+ static bool is_supported(const std::filesystem::path& path) {FRONT_END_GENERAL_CHECK(util::directory_exists(path) || util::file_exists(path),- "Could not open the file: \"",- util::path_to_string(path),- '"');+ "Could not open the file: ",+ path);try {-#if defined(__MINGW32__) || defined(__MINGW64__)- std::ifstream pb_stream(std::filesystem::path(path), std::ios::in | std::ifstream::binary);-#elsestd::ifstream pb_stream(path, std::ios::in | std::ifstream::binary);-#endifauto graph_def = std::make_shared<::tensorflow::GraphDef>();return pb_stream && pb_stream.is_open() && graph_def->ParsePartialFromIstream(&pb_stream) &&graph_def->node_size() > 0;diff --git a/src/frontends/tensorflow/src/graph_iterator_proto_txt.hpp b/src/frontends/tensorflow/src/graph_iterator_proto_txt.hppindex 7922939116f..7c65970d21b 100644--- a/src/frontends/tensorflow/src/graph_iterator_proto_txt.hpp+++ b/src/frontends/tensorflow/src/graph_iterator_proto_txt.hpp@@ -4,10 +4,8 @@#pragma once+#include <filesystem>#include <fstream>-#if defined(__MINGW32__) || defined(__MINGW64__)-# include <filesystem>-#endif#include "google/protobuf/io/zero_copy_stream_impl.h"#include "google/protobuf/text_format.h"@@ -22,13 +20,8 @@ namespace tensorflow {class GraphIteratorProtoTxt : public GraphIteratorProto {public:/// \brief Construct GraphIterator for the frozen model in text format without v1 checkpoints- template <typename T>- GraphIteratorProtoTxt(const std::basic_string<T>& path) : GraphIteratorProto() {-#if defined(__MINGW32__) || defined(__MINGW64__)- std::ifstream pbtxt_stream(std::filesystem::path(path), std::ios::in);-#else+ GraphIteratorProtoTxt(const std::filesystem::path& path) : GraphIteratorProto() {std::ifstream pbtxt_stream(path, std::ios::in);-#endifFRONT_END_GENERAL_CHECK(pbtxt_stream && pbtxt_stream.is_open(), "Model file does not exist");auto input_stream = std::make_shared<::google::protobuf::io::IstreamInputStream>(&pbtxt_stream);FRONT_END_GENERAL_CHECK(input_stream, "Model cannot be read");@@ -41,8 +34,7 @@ public:}/// \brief Construct GraphIterator for the frozen model in text format with v1 checkpoints- template <typename T>- GraphIteratorProtoTxt(const std::basic_string<T>& path, const std::basic_string<T>& checkpoint_directory)+ GraphIteratorProtoTxt(const std::filesystem::path& path, const std::filesystem::path& checkpoint_directory): GraphIteratorProto() {std::ifstream pbtxt_stream(path, std::ios::in);FRONT_END_GENERAL_CHECK(pbtxt_stream && pbtxt_stream.is_open(), "Model file does not exist");@@ -58,14 +50,12 @@ public:}/// \brief Check if the input file is supported- template <typename T>- static bool is_supported(const std::basic_string<T>& path) {+ static bool is_supported(const std::filesystem::path& path) {FRONT_END_GENERAL_CHECK(util::directory_exists(path) || util::file_exists(path),- "Could not open the file: \"",- util::path_to_string(path),- '"');+ "Could not open the file: ",+ path);try {- std::ifstream pbtxt_stream(path.c_str(), std::ios::in);+ std::ifstream pbtxt_stream(path, std::ios::in);bool model_exists = (pbtxt_stream && pbtxt_stream.is_open());if (!model_exists) {return false;diff --git a/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp b/src/frontends/tensorflow/src/graph_iterator_saved_model.cppindex 717ae5c5a02..37715b98a58 100644--- a/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp+++ b/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp@@ -29,43 +29,24 @@ bool GraphIteratorSavedModel::is_valid_signature(const ::tensorflow::SignatureDereturn true;}-bool GraphIteratorSavedModel::is_supported(const std::string& path) {+bool GraphIteratorSavedModel::is_supported(const std::filesystem::path& path) {if (ov::util::directory_exists(path)) {- FRONT_END_GENERAL_CHECK(util::file_exists(ov::util::path_join({path, "saved_model.pb"})),- "Could not open the file: \"",- ov::util::path_join({path, "saved_model.pb"}),- '"');+ FRONT_END_GENERAL_CHECK(util::file_exists(path / "saved_model.pb"),+ "Could not open the file: ",+ path / "saved_model.pb");return true;} else {return false;}}-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)-bool GraphIteratorSavedModel::is_supported(const std::wstring& path) {- return ov::util::directory_exists(path) && ov::util::file_exists(ov::util::path_join_w({path, L"saved_model.pb"}));+std::filesystem::path get_saved_model_name() {+ return "saved_model.pb";}-#endif-template <>-std::basic_string<char> get_saved_model_name<char>() {- return "/saved_model.pb";+std::filesystem::path get_variables_index_name() {+ return std::filesystem::path("variables") / "variables.index";}-template <>-std::basic_string<char> get_variables_index_name<char>() {- return "/variables/variables.index";-}--#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)-template <>-std::basic_string<wchar_t> get_saved_model_name<wchar_t>() {- return L"/saved_model.pb";-}-template <>-std::basic_string<wchar_t> get_variables_index_name<wchar_t>() {- return L"/variables/variables.index";-}-#endifstd::vector<std::string> GraphIteratorSavedModel::split_tags(const std::string tags) const {std::vector<std::string> tag_list = {};diff --git a/src/frontends/tensorflow/src/graph_iterator_saved_model.hpp b/src/frontends/tensorflow/src/graph_iterator_saved_model.hppindex 0a2ee5ac1a1..16a264a06f1 100644--- a/src/frontends/tensorflow/src/graph_iterator_saved_model.hpp+++ b/src/frontends/tensorflow/src/graph_iterator_saved_model.hpp@@ -4,6 +4,7 @@#pragma once+#include <filesystem>#include <map>#include "graph_iterator_proto.hpp"@@ -15,22 +16,8 @@ namespace ov {namespace frontend {namespace tensorflow {-template <typename T>-std::basic_string<T> get_saved_model_name() {}-template <typename T>-std::basic_string<T> get_variables_index_name() {}--template <>-std::basic_string<char> get_saved_model_name<char>();-template <>-std::basic_string<char> get_variables_index_name<char>();--#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)-template <>-std::basic_string<wchar_t> get_saved_model_name<wchar_t>();-template <>-std::basic_string<wchar_t> get_variables_index_name<wchar_t>();-#endif+std::filesystem::path get_saved_model_name();+std::filesystem::path get_variables_index_name();// Loads graph from Tensorflow Saved Model file (saved_model.pb)class GraphIteratorSavedModel : public GraphIteratorProto {@@ -43,17 +30,13 @@ class GraphIteratorSavedModel : public GraphIteratorProto {bool m_mmap_enabled;public:- template <typename T>- GraphIteratorSavedModel(const std::basic_string<T>& path, const std::string& tags, const bool mmap_enabled)+ GraphIteratorSavedModel(const std::filesystem::path& path, const std::string& tags, const bool mmap_enabled): m_saved_model(std::make_shared<::tensorflow::SavedModel>()),m_mmap_enabled(mmap_enabled) {this->read_saved_model(path, tags);}- static bool is_supported(const std::string& path);-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)- static bool is_supported(const std::wstring& path);-#endif+ static bool is_supported(const std::filesystem::path& path);std::shared_ptr<VariablesIndex> get_variables_index() {return m_variables_index;@@ -78,16 +61,15 @@ public:private:bool is_valid_signature(const ::tensorflow::SignatureDef& signature) const;- template <typename T>- bool read_saved_model(const std::basic_string<T>& path, const std::string& tags) {- std::basic_string<T> save_model_path = path + get_saved_model_name<T>();- std::ifstream sm_stream{save_model_path.c_str(), std::ifstream::in | std::ifstream::binary};+ bool read_saved_model(const std::filesystem::path& path, const std::string& tags) {+ const auto save_model_path = path / get_saved_model_name();+ std::ifstream sm_stream{save_model_path, std::ifstream::in | std::ifstream::binary};FRONT_END_GENERAL_CHECK(sm_stream && sm_stream.is_open(), "[TensorFlow Frontend] Model file does not exist");- std::basic_string<T> varIndexPath = path + get_variables_index_name<T>();+ const auto varIndexPath = path / get_variables_index_name();if (ov::util::file_exists(varIndexPath)) {m_variables_index = std::make_shared<VariablesIndex>(m_mmap_enabled);- std::ifstream vi_stream{varIndexPath.c_str(), std::ifstream::in | std::ifstream::binary};+ std::ifstream vi_stream{varIndexPath, std::ifstream::in | std::ifstream::binary};FRONT_END_GENERAL_CHECK(vi_stream && vi_stream.is_open(),"[TensorFlow Frontend] Saved Model's variable index file does not exist");FRONT_END_GENERAL_CHECK(m_variables_index->read_variables(vi_stream, path),diff --git a/src/frontends/tensorflow/src/variables_index.cpp b/src/frontends/tensorflow/src/variables_index.cppindex d269b91ef90..87d5bf87b3d 100644--- a/src/frontends/tensorflow/src/variables_index.cpp+++ b/src/frontends/tensorflow/src/variables_index.cpp@@ -206,7 +206,9 @@ void VariablesIndex::read_checkpointable_object_graph() {}}-bool VariablesIndex::read_variables(std::ifstream& vi_stream, const std::string& path, const bool is_saved_model) {+bool VariablesIndex::read_variables(std::ifstream& vi_stream,+ const std::filesystem::path& path,+ const bool is_saved_model) {m_variables_index.clear();read_variables_index(vi_stream, m_variables_index);read_bundle_header();@@ -216,9 +218,11 @@ bool VariablesIndex::read_variables(std::ifstream& vi_stream, const std::string&std::snprintf(suffix.data(), suffix.size(), "data-%05d-of-%05d", shard, m_total_shards);std::filesystem::path fullPath;if (is_saved_model) {- fullPath = ov::util::path_join({path, "variables", std::string("variables.") + suffix.data()});+ fullPath = path / "variables" / (std::string("variables.") + suffix.data());} else {- fullPath = ov::util::make_path(path + "." + suffix.data());+ fullPath = path;+ fullPath += ".";+ fullPath += suffix.data();}if (m_mmap_enabled) {m_data_files[shard].mmap = load_mmap_object(fullPath);@@ -234,36 +238,6 @@ bool VariablesIndex::read_variables(std::ifstream& vi_stream, const std::string&return true;}-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)-bool VariablesIndex::read_variables(std::ifstream& vi_stream, const std::wstring& path, const bool is_saved_model) {- m_variables_index.clear();- read_variables_index(vi_stream, m_variables_index);- read_bundle_header();-- std::vector<wchar_t> suffix(20);- for (int32_t shard = 0; shard < m_total_shards; ++shard) {- swprintf_s(suffix.data(), suffix.size(), L"data-%05d-of-%05d", shard, m_total_shards);- std::filesystem::path fullPath;- if (is_saved_model) {- fullPath = ov::util::path_join_w({path, L"variables", std::wstring(L"variables.") + suffix.data()});- } else {- fullPath = path + L"." + suffix.data();- }- if (m_mmap_enabled) {- m_data_files[shard].mmap = load_mmap_object(fullPath);- FRONT_END_GENERAL_CHECK(m_data_files[shard].mmap->data(), "Variable index data cannot be mapped");- } else {- m_data_files[shard].stream =- std::shared_ptr<std::ifstream>(new std::ifstream(fullPath, std::ifstream::in | std::ifstream::binary));- FRONT_END_GENERAL_CHECK(m_data_files[shard].stream->is_open(), "Variable index data file does not exist");- }- }-- read_checkpointable_object_graph();- return true;-}-#endif-struct PtrNode {using SharedPtrNode = std::shared_ptr<PtrNode>;diff --git a/src/frontends/tensorflow/src/variables_index.hpp b/src/frontends/tensorflow/src/variables_index.hppindex b120beba255..a61c8b0a467 100644--- a/src/frontends/tensorflow/src/variables_index.hpp+++ b/src/frontends/tensorflow/src/variables_index.hpp@@ -4,6 +4,7 @@#pragma once+#include <filesystem>#include <map>#include "graph_iterator_proto.hpp"@@ -52,15 +53,7 @@ public:/// \param path A path to file with variables data/// \param is_saved_model Flag shows variables index is a part of Saved Model format/// \returns Returns true in case of everything loads successfully, false otherwise- bool read_variables(std::ifstream& vi_stream, const std::string& path, const bool is_saved_model = true);-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)- /// \brief Reads variables from opened variable index file. Can cause an asserts in case of issues.- /// \param vi_stream Opened stream file, file pointer doesn't matter, it will be rewind internally.- /// \param path A path to file with variables data- /// \param is_saved_model Flag shows variables index is a part of Saved Model format- /// \returns Returns true in case of everything loads successfully, false otherwise- bool read_variables(std::ifstream& vi_stream, const std::wstring& path, const bool is_saved_model = true);-#endif+ bool read_variables(std::ifstream& vi_stream, const std::filesystem::path& path, const bool is_saved_model = true);/// \brief Returns data and size of data of stored variable/// \param name Name of variable