[TF FE][TF Hub] Fix conversion of SavedModel with only numerical names operations (#19166)
* [TF FE] Fix conversion of SavedModel with only numerical names operations Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com> * Compare tensor names in the unit-test Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com> --------- Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>
This commit is contained in:
parent
1ffab2fe30
commit
600c2d8283
@ -37,14 +37,17 @@ void extract_operation_name_and_port(const std::string& port_name,
|
||||
auto left_part = port_name.substr(0, pos);
|
||||
auto right_part = port_name.substr(pos + 1, port_name.length() - pos);
|
||||
|
||||
if (left_part.find_first_not_of("0123456789") == std::string::npos) {
|
||||
port_type = "in";
|
||||
operation_name = right_part;
|
||||
port_index = std::atoi(left_part.c_str());
|
||||
} else if (right_part.find_first_not_of("0123456789") == std::string::npos) {
|
||||
// it gives priority to parsing output ports
|
||||
// because pruning is less important than out-of-the-box conversion
|
||||
// for OOB conversion, the model refers only output ports
|
||||
if (right_part.find_first_not_of("0123456789") == std::string::npos) {
|
||||
port_type = "out";
|
||||
operation_name = left_part;
|
||||
port_index = std::atoi(right_part.c_str());
|
||||
} else if (left_part.find_first_not_of("0123456789") == std::string::npos) {
|
||||
port_type = "in";
|
||||
operation_name = right_part;
|
||||
port_index = std::atoi(left_part.c_str());
|
||||
} else {
|
||||
FRONT_END_GENERAL_CHECK(false, "Incorrect port name specified: " + port_name);
|
||||
}
|
||||
|
@ -157,3 +157,27 @@ TEST_F(FrontEndConversionWithReferenceTestsF, SavedModelWithIntermediateOutput)
|
||||
model_ref = make_shared<Model>(OutputVector{result1, result2}, ParameterVector{input1, input2});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FrontEndConversionWithReferenceTestsF, SavedModelWithNumericalNames) {
|
||||
comparator.enable(FunctionsComparator::CmpValues::TENSOR_NAMES);
|
||||
// The test aims to check that model with only numerical names for operation
|
||||
// is successfully converted
|
||||
// it is a tricky case because colision between naming input and output ports may occur
|
||||
{ model = convert_model("saved_model_with_numerical_names"); }
|
||||
{
|
||||
// create a reference graph
|
||||
auto x = make_shared<Parameter>(element::f32, Shape{1});
|
||||
x->output(0).set_names({"0"});
|
||||
auto y = make_shared<Parameter>(element::f32, Shape{1});
|
||||
y->output(0).set_names({"1"});
|
||||
auto z = make_shared<Parameter>(element::f32, Shape{1});
|
||||
z->output(0).set_names({"2"});
|
||||
auto add = make_shared<Add>(x, y);
|
||||
add->output(0).set_names({"3", "3:0"});
|
||||
auto sub = make_shared<Subtract>(add, z);
|
||||
sub->output(0).set_names({"4"});
|
||||
auto result = make_shared<Result>(sub);
|
||||
result->output(0).set_names({"4"});
|
||||
model_ref = make_shared<Model>(ResultVector{result}, ParameterVector{x, y, z});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2023 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
# Create the graph and model
|
||||
tf.compat.v1.reset_default_graph()
|
||||
with tf.compat.v1.Session() as sess:
|
||||
tf_x = tf.compat.v1.placeholder(dtype=tf.float32, shape=[1], name='0')
|
||||
tf_y = tf.compat.v1.placeholder(dtype=tf.float32, shape=[1], name='1')
|
||||
tf_z = tf.compat.v1.placeholder(dtype=tf.float32, shape=[1], name='2')
|
||||
add = tf.add(tf_x, tf_y, name="3")
|
||||
sub = tf.subtract(add, tf_z, name="4")
|
||||
tf.compat.v1.saved_model.simple_save(sess, os.path.join(sys.argv[1], "saved_model_with_numerical_names"),
|
||||
inputs={'0': tf_x, '1': tf_y, '2': tf_z}, outputs={'4': sub})
|
Loading…
Reference in New Issue
Block a user