From 7720d823662b665043ae85849be3af1484f9e00e Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Tue, 23 Nov 2021 14:40:57 +0100 Subject: [PATCH] [MO] Fix fetching output Place in moc_frontend (#8431) --- model-optimizer/mo/moc_frontend/extractor.py | 5 -- .../moc_frontend/moc_extractor_test_actual.py | 65 ++++--------------- .../mock_mo_ov_frontend/mock_mo_frontend.hpp | 8 ++- 3 files changed, 18 insertions(+), 60 deletions(-) diff --git a/model-optimizer/mo/moc_frontend/extractor.py b/model-optimizer/mo/moc_frontend/extractor.py index b5ddd83b1fd..4f40a898726 100644 --- a/model-optimizer/mo/moc_frontend/extractor.py +++ b/model-optimizer/mo/moc_frontend/extractor.py @@ -27,11 +27,6 @@ def decode_name_with_port(input_model: InputModel, node_name: str): found_node_names.append('Tensor:' + node_name) found_nodes.append(node) - node = input_model.get_place_by_operation_name(node_name) - if node: - found_node_names.append('Operation:' + node_name) - found_nodes.append(node) - regexp_post = r'(.+):(\d+)' match_post = re.search(regexp_post, node_name) if match_post: diff --git a/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py b/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py index 861754ca981..1b3226dd0a4 100644 --- a/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py +++ b/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py @@ -52,17 +52,6 @@ class TestMainFrontend(unittest.TestCase): model_stat = get_model_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 1 - assert node - - # Mock model has 'operation' operation place - @mock_needed - def test_decode_name_with_port_op(self): - node = decode_name_with_port(self.model, "operation") - model_stat = get_model_statistic() - - assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 1 assert node # pylint: disable=wrong-spelling-in-comment @@ -73,14 +62,13 @@ class TestMainFrontend(unittest.TestCase): decode_name_with_port(self.model, 'mocknoname') model_stat = get_model_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 1 - # Mock model has both tensor and operation with same name and non-equal data + # Mock model has both tensor and tensor:0 places with non equal data # Collision is expected @mock_needed - def test_decode_name_with_port_collision_op_tensor(self): + def test_decode_name_with_port_collision(self): with self.assertRaisesRegex(Error, 'Name\\ collision.*tensorAndOp*'): - decode_name_with_port(self.model, 'tensorAndOp') + decode_name_with_port(self.model, 'tensorAndOp:0') model_stat = get_model_statistic() place_stat = get_place_statistic() @@ -88,6 +76,7 @@ class TestMainFrontend(unittest.TestCase): assert model_stat.get_place_by_operation_name == 1 assert place_stat.is_equal_data > 0 + # Mock model has 'operation' and output port up to 10 @mock_needed def test_decode_name_with_port_delim_op_out(self): @@ -96,7 +85,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_output_port == 1 assert place_stat.lastArgInt == 7 assert node @@ -109,39 +98,11 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_input_port == 1 assert place_stat.lastArgInt == 7 assert node - # Mock model has 'operation' and 'operation:0' op places, collision is expected - @mock_needed - def test_decode_name_with_port_delim_op_collision_out(self): - with self.assertRaisesRegex(Error, 'Name\\ collision(?!.*Tensor.*).*operation\\:0*'): - decode_name_with_port(self.model, 'operation:0') - model_stat = get_model_statistic() - place_stat = get_place_statistic() - - assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 - assert place_stat.is_equal_data > 0 - assert place_stat.get_output_port == 1 - assert place_stat.lastArgInt == 0 - - # Mock model has 'operation' and '0:operation' op places, collision is expected - @mock_needed - def test_decode_name_with_port_delim_op_collision_in(self): - with self.assertRaisesRegex(Error, 'Name\\ collision(?!.*Tensor.*).*0\\:operation*'): - decode_name_with_port(self.model, '0:operation') - model_stat = get_model_statistic() - place_stat = get_place_statistic() - - assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 - assert place_stat.is_equal_data > 0 - assert place_stat.get_input_port == 1 - assert place_stat.lastArgInt == 0 - # Mock model has 'tensor' and 'tensor:0' tensor places, no collision is expected @mock_needed def test_decode_name_with_port_delim_tensor_no_collision_out(self): @@ -150,7 +111,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_output_port == 0 assert node @@ -162,7 +123,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_input_port == 0 assert node @@ -175,7 +136,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_output_port == 1 assert place_stat.lastArgInt == 1234 @@ -188,7 +149,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_input_port == 1 assert place_stat.lastArgInt == 1234 @@ -203,7 +164,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_output_port == 1 assert place_stat.is_equal_data > 0 assert node @@ -219,7 +180,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 2 + assert model_stat.get_place_by_operation_name == 1 assert place_stat.get_input_port == 1 assert place_stat.is_equal_data > 0 assert node @@ -238,7 +199,7 @@ class TestMainFrontend(unittest.TestCase): place_stat = get_place_statistic() assert model_stat.get_place_by_tensor_name == 1 - assert model_stat.get_place_by_operation_name == 3 + assert model_stat.get_place_by_operation_name == 2 assert place_stat.get_input_port == 1 assert place_stat.get_output_port == 1 # At least 3 comparisons of places are expected diff --git a/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp b/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp index 5c0577921e1..e946d03e51b 100644 --- a/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp +++ b/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp @@ -165,7 +165,7 @@ public: m_stat.m_get_output_port++; m_stat.m_lastArgInt = -1; m_stat.m_lastArgString = outputName; - return std::make_shared(); + return std::make_shared(outputName); } Place::Ptr get_output_port(const std::string& outputName, int outputPortIndex) const override @@ -199,6 +199,8 @@ public: bool is_equal_data(Ptr another) const override { + if (m_is_op) + throw "Not implemented"; m_stat.m_is_equal_data++; m_stat.m_lastArgPlace = another; std::shared_ptr mock = std::dynamic_pointer_cast(another); @@ -212,7 +214,7 @@ public: return true; } } - return mock->m_is_op == m_is_op; + return !mock->m_is_op && m_name == mock->m_name; } //---------------Stat-------------------- @@ -284,7 +286,7 @@ class MOCK_API InputModelMockPy : public InputModel "tensor", "tensor:0", "0:tensor", - "tensorAndOp", + "tensorAndOp:0", "conv2d:0", "0:conv2d", "mock_input1",