From f479c78890cd82dd6d5343ab8395430c9c86f6d7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Jul 2020 18:11:43 +0300 Subject: [PATCH 01/28] Add mish fusion transformation --- .../include/transformations/mish_fusion.hpp | 30 ++++++++++ .../src/transformations/mish_fusion.cpp | 58 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 inference-engine/src/transformations/include/transformations/mish_fusion.hpp create mode 100644 inference-engine/src/transformations/src/transformations/mish_fusion.cpp diff --git a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp new file mode 100644 index 00000000000000..30172b6a99238a --- /dev/null +++ b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2018-2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include + +#include + +namespace ngraph { +namespace pass { + +class TRANSFORMATIONS_API MishFusion; + +} // namespace pass +} // namespace ngraph + +class ngraph::pass::MishFusion: public ngraph::pass::GraphRewrite { +public: + MishFusion() : GraphRewrite() { + mish_fusion()(); + } + +private: + void mish_fusion(); +}; diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp new file mode 100644 index 00000000000000..88c41958c3b95a --- /dev/null +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -0,0 +1,58 @@ +// Copyright (C) 2018-2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/mish_fusion.hpp" + +#include +#include + +#include +#include + +void ngraph::pass::MishFusion::mish_fusion() { + auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); + auto exp = std::make_shared(input0); + auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}) + auto add = std::make_shared(exp, input_const); + auto log = std::make_shared(add); + auto tanh = std::make_shared(log); + auto mul = std::make_shared(input0, tanh); + + ngraph::graph_rewrite_callback callback = [](pattern::Matcher& m) { + auto mul = std::dynamic_pointer_cast (m.get_match_root()); + if (!mul) { + return false; + } + + auto tanh = std::dynamic_pointer_cast (mul->input(0).get_source_output()); + if (!tanh) { + return false; + } + + auto log = std::dynamic_pointer_cast (tanh->input(0).get_source_output()); + if (!log) { + return false; + } + + auto add = std::dynamic_pointer_cast (log->input(0).get_source_output()); + if (!add) { + return false; + } + + auto exp = std::dynamic_pointer_cast (add->input(0).get_source_output()); + if (!exp) { + return false; + } + + auto mish = std::make_shared(exp->input(0).get_source_output()); + + mish->set_friendly_name(exp->get_friendly_name()); + ngraph::copy_runtime_info({mul, tanh, log, add, exp}, mish); + ngraph::replace_node(exp, mish); + return true; + }; + + auto m = std::make_shared(mul, "MishFusion"); + this->add_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE); +} From c674cefb543ba2f177444762d2cecc0d067f102d Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 21 Jul 2020 12:44:41 +0300 Subject: [PATCH 02/28] Hot fix --- .../src/transformations/include/transformations/mish_fusion.hpp | 2 +- .../src/transformations/src/transformations/mish_fusion.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp index 30172b6a99238a..24c46e57661e2f 100644 --- a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp @@ -22,7 +22,7 @@ class TRANSFORMATIONS_API MishFusion; class ngraph::pass::MishFusion: public ngraph::pass::GraphRewrite { public: MishFusion() : GraphRewrite() { - mish_fusion()(); + mish_fusion(); } private: diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp index 88c41958c3b95a..7d2bec87bc6ed9 100644 --- a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -13,7 +13,7 @@ void ngraph::pass::MishFusion::mish_fusion() { auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); auto exp = std::make_shared(input0); - auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}) + auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}); auto add = std::make_shared(exp, input_const); auto log = std::make_shared(add); auto tanh = std::make_shared(log); From b89c5433050e6607c703cf3788cbd866191a40bf Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 21 Jul 2020 15:18:57 +0300 Subject: [PATCH 03/28] Hot fix --- .../src/transformations/src/transformations/mish_fusion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp index 7d2bec87bc6ed9..8376150cda6c7d 100644 --- a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -25,7 +25,7 @@ void ngraph::pass::MishFusion::mish_fusion() { return false; } - auto tanh = std::dynamic_pointer_cast (mul->input(0).get_source_output()); + auto tanh = std::dynamic_pointer_cast (mul->input(1).get_source_output()); if (!tanh) { return false; } From 7999be50b940563d5f713273c1a994c46a892148 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 21 Jul 2020 19:08:53 +0300 Subject: [PATCH 04/28] fix mish transformation cullback func --- .../transformations/src/transformations/mish_fusion.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp index 8376150cda6c7d..2a79fea76b273d 100644 --- a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -25,22 +25,22 @@ void ngraph::pass::MishFusion::mish_fusion() { return false; } - auto tanh = std::dynamic_pointer_cast (mul->input(1).get_source_output()); + auto tanh = std::dynamic_pointer_cast (mul->input_value(1).get_node_shared_ptr()); if (!tanh) { return false; } - auto log = std::dynamic_pointer_cast (tanh->input(0).get_source_output()); + auto log = std::dynamic_pointer_cast (tanh->input_value(0).get_node_shared_ptr()); if (!log) { return false; } - auto add = std::dynamic_pointer_cast (log->input(0).get_source_output()); + auto add = std::dynamic_pointer_cast (log->input_value(0).get_node_shared_ptr()); if (!add) { return false; } - auto exp = std::dynamic_pointer_cast (add->input(0).get_source_output()); + auto exp = std::dynamic_pointer_cast (add->input_value(0).get_node_shared_ptr()); if (!exp) { return false; } From e6fb57a9896ba8fc1024f13feb3f587dd02f28eb Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Jul 2020 13:54:58 +0300 Subject: [PATCH 05/28] Add mish fusing func test --- .../transformations/mish_fusion_test.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp new file mode 100644 index 00000000000000..c83b0a5769190b --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "common_test_utils/ngraph_test_utils.hpp" + +using namespace testing; + +TEST(TransformationTests, MishFusing) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); + auto exp = std::make_shared(input0); + auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}); + auto add = std::make_shared(exp, input_const); + auto log = std::make_shared(add); + auto tanh = std::make_shared(log); + auto mul = std::make_shared(input0, tanh); + + f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input0}); + + ngraph::pass::InitNodeInfo().run_on_function(f); + ngraph::pass::ConvertDivide().run_on_function(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto mish = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1, 2}); + + f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{data}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} From eacc7ba3a3ba1b139b21389de0e6048472f4aed3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Jul 2020 21:35:05 +0300 Subject: [PATCH 06/28] Revert "Add mish fusing func test" This reverts commit 140acd725ec56ea5ef8521d5a0db2d126177504f. --- .../transformations/mish_fusion_test.cpp | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp deleted file mode 100644 index c83b0a5769190b..00000000000000 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/ngraph_test_utils.hpp" - -using namespace testing; - -TEST(TransformationTests, MishFusing) { - std::shared_ptr f(nullptr), f_ref(nullptr); - { - auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); - auto exp = std::make_shared(input0); - auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}); - auto add = std::make_shared(exp, input_const); - auto log = std::make_shared(add); - auto tanh = std::make_shared(log); - auto mul = std::make_shared(input0, tanh); - - f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input0}); - - ngraph::pass::InitNodeInfo().run_on_function(f); - ngraph::pass::ConvertDivide().run_on_function(f); - ASSERT_NO_THROW(check_rt_info(f)); - } - - { - auto mish = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1, 2}); - - f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{data}); - } - - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; -} From c8d93ba03972d07b71e0ae3f12930622340258cc Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Jul 2020 21:52:17 +0300 Subject: [PATCH 07/28] Add func test --- .../transformations/mish_fusion_test.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp new file mode 100644 index 00000000000000..c83b0a5769190b --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "common_test_utils/ngraph_test_utils.hpp" + +using namespace testing; + +TEST(TransformationTests, MishFusing) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); + auto exp = std::make_shared(input0); + auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}); + auto add = std::make_shared(exp, input_const); + auto log = std::make_shared(add); + auto tanh = std::make_shared(log); + auto mul = std::make_shared(input0, tanh); + + f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input0}); + + ngraph::pass::InitNodeInfo().run_on_function(f); + ngraph::pass::ConvertDivide().run_on_function(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto mish = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1, 2}); + + f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{data}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} From 0402b816191583edf3ff710c3ad9c207ed06fc04 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 17:07:49 +0300 Subject: [PATCH 08/28] Hot fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index c83b0a5769190b..7ba0eafe1cf61a 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -21,7 +21,7 @@ using namespace testing; TEST(TransformationTests, MishFusing) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); + auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); auto exp = std::make_shared(input0); auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}); auto add = std::make_shared(exp, input_const); From 0a8d35f1ea6bb3ece31fe8d8d72443d46b704252 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 17:18:33 +0300 Subject: [PATCH 09/28] fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index 7ba0eafe1cf61a..cf782fd53d1730 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -21,9 +21,9 @@ using namespace testing; TEST(TransformationTests, MishFusing) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); + auto input0 = std::make_shared(element::f64, ngraph::Shape{3, 1, 2}); auto exp = std::make_shared(input0); - auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}); + auto input_const = op::Constant::create(element::f64, ngraph::Shape{1}, {-1}); auto add = std::make_shared(exp, input_const); auto log = std::make_shared(add); auto tanh = std::make_shared(log); From 9c9c9d0b3bbe7e4c16fd249450222bd8e9aeb6b6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 17:21:25 +0300 Subject: [PATCH 10/28] fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index cf782fd53d1730..dd94337d1d0945 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -21,9 +21,9 @@ using namespace testing; TEST(TransformationTests, MishFusing) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input0 = std::make_shared(element::f64, ngraph::Shape{3, 1, 2}); + auto input0 = std::make_shared(ngraph::element::f64, ngraph::Shape{3, 1, 2}); auto exp = std::make_shared(input0); - auto input_const = op::Constant::create(element::f64, ngraph::Shape{1}, {-1}); + auto input_const = ngraph::opset4::Constant::create(ngraph::element::f64, ngraph::Shape{1}, {-1}); auto add = std::make_shared(exp, input_const); auto log = std::make_shared(add); auto tanh = std::make_shared(log); From e1c2ba12e0327dde053195b630d043912005de7d Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 17:24:56 +0300 Subject: [PATCH 11/28] fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index dd94337d1d0945..bed3bd63d44b23 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -37,9 +37,9 @@ TEST(TransformationTests, MishFusing) { } { - auto mish = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1, 2}); + auto mish = std::make_shared(ngraph::Shape{3, 1, 2}); - f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{data}); + f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{input0}); } auto res = compare_functions(f, f_ref); From 77d167b2167eb0423313f20baa2f7ccfccef72d6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 17:26:54 +0300 Subject: [PATCH 12/28] fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index bed3bd63d44b23..01ec9ec3c36bdd 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -37,6 +37,7 @@ TEST(TransformationTests, MishFusing) { } { + auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1, 2}); auto mish = std::make_shared(ngraph::Shape{3, 1, 2}); f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{input0}); From f26fa25d8f4427870792d09bc3027e6885b491d7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 17:27:43 +0300 Subject: [PATCH 13/28] fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index 01ec9ec3c36bdd..dade3cd231d6ff 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -40,7 +40,7 @@ TEST(TransformationTests, MishFusing) { auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1, 2}); auto mish = std::make_shared(ngraph::Shape{3, 1, 2}); - f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{input0}); + f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{data}); } auto res = compare_functions(f, f_ref); From 13f7d79c8442708cdc4440ad21c992a93d22a7d1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 20:32:25 +0300 Subject: [PATCH 14/28] Fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index dade3cd231d6ff..56d042429e467b 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -38,7 +38,7 @@ TEST(TransformationTests, MishFusing) { { auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1, 2}); - auto mish = std::make_shared(ngraph::Shape{3, 1, 2}); + auto mish = std::make_shared(data); f_ref = std::make_shared(ngraph::NodeVector{mish}, ngraph::ParameterVector{data}); } From 1a9e5d8e75d310b2a50a70896a4ad3f271e325bc Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 20:35:39 +0300 Subject: [PATCH 15/28] fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index 56d042429e467b..d95210974c6f51 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -32,7 +32,7 @@ TEST(TransformationTests, MishFusing) { f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input0}); ngraph::pass::InitNodeInfo().run_on_function(f); - ngraph::pass::ConvertDivide().run_on_function(f); + ngraph::pass::MishFusing().run_on_function(f); ASSERT_NO_THROW(check_rt_info(f)); } From e5c5046daed01e2fdcd376e71870cbac01cea574 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jul 2020 20:38:33 +0300 Subject: [PATCH 16/28] fix --- .../inference_engine/transformations/mish_fusion_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index d95210974c6f51..c6ee9edf6ca249 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -32,7 +32,7 @@ TEST(TransformationTests, MishFusing) { f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input0}); ngraph::pass::InitNodeInfo().run_on_function(f); - ngraph::pass::MishFusing().run_on_function(f); + ngraph::pass::MishFusion().run_on_function(f); ASSERT_NO_THROW(check_rt_info(f)); } From 1b93f7802aa27232645e89ce7f6e898bf9bde19b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Jul 2020 13:41:44 +0300 Subject: [PATCH 17/28] Add mish op to python api --- ngraph/python/src/ngraph/__init__.py | 1 + ngraph/python/src/ngraph/opset4/__init__.py | 1 + ngraph/python/src/ngraph/opset4/ops.py | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/ngraph/python/src/ngraph/__init__.py b/ngraph/python/src/ngraph/__init__.py index ebb855417d2265..c85eb4e41882fc 100644 --- a/ngraph/python/src/ngraph/__init__.py +++ b/ngraph/python/src/ngraph/__init__.py @@ -94,6 +94,7 @@ from ngraph.opset4 import max_pool from ngraph.opset4 import maximum from ngraph.opset4 import minimum +from ngraph.opset4 import mish from ngraph.opset4 import mod from ngraph.opset4 import multiply from ngraph.opset4 import mvn diff --git a/ngraph/python/src/ngraph/opset4/__init__.py b/ngraph/python/src/ngraph/opset4/__init__.py index 31c89bafd78997..aac844ff4d00b7 100644 --- a/ngraph/python/src/ngraph/opset4/__init__.py +++ b/ngraph/python/src/ngraph/opset4/__init__.py @@ -83,6 +83,7 @@ from ngraph.opset1.ops import max_pool from ngraph.opset1.ops import maximum from ngraph.opset1.ops import minimum +from ngraph.opset4.ops import mish from ngraph.opset1.ops import mod from ngraph.opset1.ops import multiply from ngraph.opset2.ops import mvn diff --git a/ngraph/python/src/ngraph/opset4/ops.py b/ngraph/python/src/ngraph/opset4/ops.py index 69c3808c6d5dca..a31711be894e13 100644 --- a/ngraph/python/src/ngraph/opset4/ops.py +++ b/ngraph/python/src/ngraph/opset4/ops.py @@ -99,3 +99,13 @@ def non_max_suppression( } return _get_node_factory_opset4().create("NonMaxSuppression", inputs, attributes) + + +@nameable_op +def mish(data: NodeInput, name: Optional[str] = None,) -> Node: + """Return a node which performs Mish. + + :param data: Tensor with input data floating point type. + :return: The new node which performs Mish + """ + return _get_node_factory_opset4().create("Mish", as_nodes(data), {}) From 5978615c8bb0bcc83e4ab735c76c5b647f54f9c8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Jul 2020 17:03:49 +0300 Subject: [PATCH 18/28] Fix mish transformation --- .../src/transformations/mish_fusion.cpp | 5 +++-- .../transformations/mish_fusion_test.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp index 2a79fea76b273d..5fc95fbaa27e1d 100644 --- a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -20,6 +20,7 @@ void ngraph::pass::MishFusion::mish_fusion() { auto mul = std::make_shared(input0, tanh); ngraph::graph_rewrite_callback callback = [](pattern::Matcher& m) { + auto mul = std::dynamic_pointer_cast (m.get_match_root()); if (!mul) { return false; @@ -40,7 +41,7 @@ void ngraph::pass::MishFusion::mish_fusion() { return false; } - auto exp = std::dynamic_pointer_cast (add->input_value(0).get_node_shared_ptr()); + auto exp = std::dynamic_pointer_cast (add->input_value(0).get_node_shared_ptr()); if (!exp) { return false; } @@ -49,7 +50,7 @@ void ngraph::pass::MishFusion::mish_fusion() { mish->set_friendly_name(exp->get_friendly_name()); ngraph::copy_runtime_info({mul, tanh, log, add, exp}, mish); - ngraph::replace_node(exp, mish); + ngraph::replace_node(mul, mish); return true; }; diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index c6ee9edf6ca249..406061b9397ce9 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include #include @@ -31,8 +33,12 @@ TEST(TransformationTests, MishFusing) { f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input0}); - ngraph::pass::InitNodeInfo().run_on_function(f); - ngraph::pass::MishFusion().run_on_function(f); + ngraph::pass::Manager manager; + //manager.register_pass("/home/imironov/projects/dpd_vcp_dl/svg_debug/before.svg"); + manager.register_pass(); + manager.register_pass(); + //manager.register_pass("/home/imironov/projects/dpd_vcp_dl/svg_debug/after.svg"); + manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } From c62b65fc57c7095a709a85839278faa2c4e8c0cb Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 30 Jul 2020 13:42:07 +0300 Subject: [PATCH 19/28] Refactoring mish transformation according to review --- .../include/transformations/mish_fusion.hpp | 13 +--- .../src/transformations/mish_fusion.cpp | 75 +++++++------------ 2 files changed, 32 insertions(+), 56 deletions(-) diff --git a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp index 24c46e57661e2f..8c8f9344dddc4c 100644 --- a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2020 Intel Corporation +// Copyright (C) 2020 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // @@ -9,7 +9,7 @@ #include -#include +#include "ngraph/pattern/matcher.hpp" namespace ngraph { namespace pass { @@ -19,12 +19,7 @@ class TRANSFORMATIONS_API MishFusion; } // namespace pass } // namespace ngraph -class ngraph::pass::MishFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::MishFusion: public ngraph::pass::MatcherPass { public: - MishFusion() : GraphRewrite() { - mish_fusion(); - } - -private: - void mish_fusion(); + MishFusion(); }; diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp index 5fc95fbaa27e1d..4a389c859eb38a 100644 --- a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -9,51 +9,32 @@ #include #include - -void ngraph::pass::MishFusion::mish_fusion() { - auto input0 = std::make_shared(element::f64, Shape{1, 1, 1, 1}); - auto exp = std::make_shared(input0); - auto input_const = op::Constant::create(element::f64, Shape{1}, {-1}); - auto add = std::make_shared(exp, input_const); - auto log = std::make_shared(add); - auto tanh = std::make_shared(log); - auto mul = std::make_shared(input0, tanh); - - ngraph::graph_rewrite_callback callback = [](pattern::Matcher& m) { - - auto mul = std::dynamic_pointer_cast (m.get_match_root()); - if (!mul) { - return false; - } - - auto tanh = std::dynamic_pointer_cast (mul->input_value(1).get_node_shared_ptr()); - if (!tanh) { - return false; - } - - auto log = std::dynamic_pointer_cast (tanh->input_value(0).get_node_shared_ptr()); - if (!log) { - return false; - } - - auto add = std::dynamic_pointer_cast (log->input_value(0).get_node_shared_ptr()); - if (!add) { - return false; - } - - auto exp = std::dynamic_pointer_cast (add->input_value(0).get_node_shared_ptr()); - if (!exp) { - return false; - } - - auto mish = std::make_shared(exp->input(0).get_source_output()); - - mish->set_friendly_name(exp->get_friendly_name()); - ngraph::copy_runtime_info({mul, tanh, log, add, exp}, mish); - ngraph::replace_node(mul, mish); - return true; - }; - - auto m = std::make_shared(mul, "MishFusion"); - this->add_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE); +#include + +ngraph::pass::MishFusion::MishFusion() { + auto input = ngraph::pattern::any_input(); + auto exp = std::make_shared(input); + auto add = std::make_shared(exp, ngraph::pattern::wrap_type()); + auto log = std::make_shared(add); + auto tanh = std::make_shared(log); + auto mul = std::make_shared(input, tanh); + + ngraph::graph_rewrite_callback callback = [=](ngraph::pattern::Matcher& m) { + auto & pattern_to_output = m.get_pattern_value_map(); + auto exp_input = pattern_to_output.at(input); + + auto mish = std::make_shared(exp_input); + + mish->set_friendly_name(m.get_match_root()->get_friendly_name()); + ngraph::copy_runtime_info({pattern_to_output.at(mul).get_node_shared_ptr(), + pattern_to_output.at(tanh).get_node_shared_ptr(), + pattern_to_output.at(log).get_node_shared_ptr(), + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(exp).get_node_shared_ptr()}, mish); + ngraph::replace_node(m.get_match_root(), mish); + return true; + }; + + auto m = std::make_shared(mul, "MishFusion"); + register_matcher(m, callback); } From d468c9f343ee75680c87f431576fc98c5072748b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 30 Jul 2020 18:19:17 +0300 Subject: [PATCH 20/28] Fix mish transformation header --- .../src/transformations/include/transformations/mish_fusion.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp index 8c8f9344dddc4c..fd4ed07764d189 100644 --- a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp @@ -9,6 +9,8 @@ #include +#include +#include #include "ngraph/pattern/matcher.hpp" namespace ngraph { From 57e2c6d644e8c7722cb9251d6a9ab29def8be64f Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 31 Jul 2020 11:50:23 +0300 Subject: [PATCH 21/28] Refactoring code according to review --- .../src/transformations/mish_fusion.cpp | 48 +++++++++---------- .../transformations/mish_fusion_test.cpp | 2 - ngraph/test/op_eval/mish.cpp | 2 +- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp index 4a389c859eb38a..4e974422388aab 100644 --- a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -13,28 +13,28 @@ ngraph::pass::MishFusion::MishFusion() { auto input = ngraph::pattern::any_input(); - auto exp = std::make_shared(input); - auto add = std::make_shared(exp, ngraph::pattern::wrap_type()); - auto log = std::make_shared(add); - auto tanh = std::make_shared(log); - auto mul = std::make_shared(input, tanh); - - ngraph::graph_rewrite_callback callback = [=](ngraph::pattern::Matcher& m) { - auto & pattern_to_output = m.get_pattern_value_map(); - auto exp_input = pattern_to_output.at(input); - - auto mish = std::make_shared(exp_input); - - mish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({pattern_to_output.at(mul).get_node_shared_ptr(), - pattern_to_output.at(tanh).get_node_shared_ptr(), - pattern_to_output.at(log).get_node_shared_ptr(), - pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(exp).get_node_shared_ptr()}, mish); - ngraph::replace_node(m.get_match_root(), mish); - return true; - }; - - auto m = std::make_shared(mul, "MishFusion"); - register_matcher(m, callback); + auto exp = std::make_shared(input); + auto add = std::make_shared(exp, ngraph::pattern::wrap_type()); + auto log = std::make_shared(add); + auto tanh = std::make_shared(log); + auto mul = std::make_shared(input, tanh); + + ngraph::graph_rewrite_callback callback = [=](ngraph::pattern::Matcher& m) { + auto & pattern_to_output = m.get_pattern_value_map(); + auto exp_input = pattern_to_output.at(input); + + auto mish = std::make_shared(exp_input); + + mish->set_friendly_name(m.get_match_root()->get_friendly_name()); + ngraph::copy_runtime_info({pattern_to_output.at(mul).get_node_shared_ptr(), + pattern_to_output.at(tanh).get_node_shared_ptr(), + pattern_to_output.at(log).get_node_shared_ptr(), + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(exp).get_node_shared_ptr()}, mish); + ngraph::replace_node(m.get_match_root(), mish); + return true; + }; + + auto m = std::make_shared(mul, "MishFusion"); + register_matcher(m, callback); } diff --git a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp index 406061b9397ce9..a540cec12d26d3 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mish_fusion_test.cpp @@ -34,10 +34,8 @@ TEST(TransformationTests, MishFusing) { f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input0}); ngraph::pass::Manager manager; - //manager.register_pass("/home/imironov/projects/dpd_vcp_dl/svg_debug/before.svg"); manager.register_pass(); manager.register_pass(); - //manager.register_pass("/home/imironov/projects/dpd_vcp_dl/svg_debug/after.svg"); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } diff --git a/ngraph/test/op_eval/mish.cpp b/ngraph/test/op_eval/mish.cpp index e04d8fac7bbf9a..6cee7dfa96d1a1 100644 --- a/ngraph/test/op_eval/mish.cpp +++ b/ngraph/test/op_eval/mish.cpp @@ -46,6 +46,6 @@ TEST(op_eval, mish_0D) EXPECT_EQ(result->get_element_type(), element::f32); EXPECT_EQ(result->get_shape(), (Shape{})); auto result_data = read_vector(result); - EXPECT_NEAR(result_data[0], expected_result[i][0], 0.3); + EXPECT_NEAR(result_data[0], expected_result[i][0], 0.7); } } From 9d4a04829bc27dd1efe5d0987534f935c56ee9ea Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 31 Jul 2020 12:00:23 +0300 Subject: [PATCH 22/28] Fix unit test for mish op --- ngraph/test/op_eval/mish.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngraph/test/op_eval/mish.cpp b/ngraph/test/op_eval/mish.cpp index 6cee7dfa96d1a1..acc81f0e95f17d 100644 --- a/ngraph/test/op_eval/mish.cpp +++ b/ngraph/test/op_eval/mish.cpp @@ -46,6 +46,6 @@ TEST(op_eval, mish_0D) EXPECT_EQ(result->get_element_type(), element::f32); EXPECT_EQ(result->get_shape(), (Shape{})); auto result_data = read_vector(result); - EXPECT_NEAR(result_data[0], expected_result[i][0], 0.7); + EXPECT_NEAR(result_data[0], expected_result[i][0], 0.000001); } } From 89a40e737636f5a70dc4ef39806ce67e895de874 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 31 Jul 2020 12:51:51 +0300 Subject: [PATCH 23/28] Refactoring name for callback func --- .../src/transformations/src/transformations/mish_fusion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp index 4e974422388aab..62a1e76b8f2c18 100644 --- a/inference-engine/src/transformations/src/transformations/mish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/mish_fusion.cpp @@ -19,7 +19,7 @@ ngraph::pass::MishFusion::MishFusion() { auto tanh = std::make_shared(log); auto mul = std::make_shared(input, tanh); - ngraph::graph_rewrite_callback callback = [=](ngraph::pattern::Matcher& m) { + ngraph::graph_rewrite_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { auto & pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); @@ -36,5 +36,5 @@ ngraph::pass::MishFusion::MishFusion() { }; auto m = std::make_shared(mul, "MishFusion"); - register_matcher(m, callback); + register_matcher(m, matcher_pass_callback); } From 7890aa5092e8c0969ca4a336595256d0729db3d3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 3 Aug 2020 11:56:47 +0300 Subject: [PATCH 24/28] Add mish extractors for mo --- .../extensions/front/tf/activation_ext.py | 12 +++++++++++- model-optimizer/extensions/ops/activation_ops.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/model-optimizer/extensions/front/tf/activation_ext.py b/model-optimizer/extensions/front/tf/activation_ext.py index 4da9556a880a7d..55f8ce97b1cca2 100644 --- a/model-optimizer/extensions/front/tf/activation_ext.py +++ b/model-optimizer/extensions/front/tf/activation_ext.py @@ -14,7 +14,7 @@ limitations under the License. """ from extensions.ops.activation_ops import Abs, Elu, Erf, Exp, ReLU, LeakyReLU, LogicalNot, ReLU6, Sigmoid, \ - Sin, Sinh, Cos, Cosh, Tan, Tanh, Ceiling, Atanh, Acosh, Asinh + Sin, Sinh, Cos, Cosh, Tan, Tanh, Ceiling, Atanh, Acosh, Asinh, Mish from mo.front.extractor import FrontExtractorOp @@ -210,3 +210,13 @@ class CeilExtractor(FrontExtractorOp): def extract(cls, node): Ceiling.update_node_stat(node) return cls.enabled + + +class MishExtractor(FrontExtractorOp): + op = 'Mish' + enabled = True + + @classmethod + def extract(cls, node): + Mish.update_node_stat(node) + return cls.enabled \ No newline at end of file diff --git a/model-optimizer/extensions/ops/activation_ops.py b/model-optimizer/extensions/ops/activation_ops.py index 9127903541d2c8..24aab28bac5adb 100644 --- a/model-optimizer/extensions/ops/activation_ops.py +++ b/model-optimizer/extensions/ops/activation_ops.py @@ -240,3 +240,17 @@ def __init__(self, graph: Graph, attrs: dict): 'infer': None } super().__init__(graph, mandatory_props, attrs) + + +class Mish(Op): + op = 'Mish' + + def __init__(self, graph: Graph, attrs: dict): + mandatory_props = { + 'op': self.op, + 'type': None, + 'in_ports_count': 1, + 'out_ports_count': 1, + 'infer': None + } + super().__init__(graph, mandatory_props, attrs) \ No newline at end of file From 04da9a9cacebed598b069bec7fe2eddaed770a7e Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 3 Aug 2020 13:44:18 +0300 Subject: [PATCH 25/28] Enable mish transformation --- .../common_optimizations/common_optimizations.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index ebba2881f9126d..78cee297537a69 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -11,6 +11,7 @@ #include "transformations/remove_filtering_boxes_by_size.hpp" #include "transformations/init_node_info.hpp" #include "transformations/itt.hpp" +#include "transformations/mish_fusion.hpp" #include #include @@ -32,6 +33,7 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptr(); manager.register_pass(); // partially depends on CF manager.register_pass(); + manager.register_pass(); manager.set_callback(m_transformation_callback); manager.run_passes(f); From cc5a8d77c60746d7709c7c7e4da89253b26dd9b2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 3 Aug 2020 14:17:29 +0300 Subject: [PATCH 26/28] Add empty line --- model-optimizer/extensions/ops/activation_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model-optimizer/extensions/ops/activation_ops.py b/model-optimizer/extensions/ops/activation_ops.py index 24aab28bac5adb..106f3fb2eb45b2 100644 --- a/model-optimizer/extensions/ops/activation_ops.py +++ b/model-optimizer/extensions/ops/activation_ops.py @@ -253,4 +253,4 @@ def __init__(self, graph: Graph, attrs: dict): 'out_ports_count': 1, 'infer': None } - super().__init__(graph, mandatory_props, attrs) \ No newline at end of file + super().__init__(graph, mandatory_props, attrs) From 0aae3b3c406e612a2de0da9062b0564ad76c5b5b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 3 Aug 2020 16:24:42 +0300 Subject: [PATCH 27/28] Add description to mish fuse transformation --- .../transformations/include/transformations/mish_fusion.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp index fd4ed07764d189..0bcfe2e68c86fe 100644 --- a/inference-engine/src/transformations/include/transformations/mish_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/mish_fusion.hpp @@ -21,6 +21,11 @@ class TRANSFORMATIONS_API MishFusion; } // namespace pass } // namespace ngraph +/** + * @ingroup ie_transformation_common_api + * @brief MishFusion transformation replaces group of + * operations: x * tanh(log(exp(x) + 1)) to Mish op. + */ class ngraph::pass::MishFusion: public ngraph::pass::MatcherPass { public: MishFusion(); From a400b27f4c8b4c635316bf5fe7a553ca273a64ab Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 5 Aug 2020 17:47:40 +0300 Subject: [PATCH 28/28] Refactoring Mish op --- .../extensions/front/tf/activation_ext.py | 2 +- model-optimizer/extensions/ops/activation_ops.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/model-optimizer/extensions/front/tf/activation_ext.py b/model-optimizer/extensions/front/tf/activation_ext.py index 55f8ce97b1cca2..83492f8754edad 100644 --- a/model-optimizer/extensions/front/tf/activation_ext.py +++ b/model-optimizer/extensions/front/tf/activation_ext.py @@ -219,4 +219,4 @@ class MishExtractor(FrontExtractorOp): @classmethod def extract(cls, node): Mish.update_node_stat(node) - return cls.enabled \ No newline at end of file + return cls.enabled diff --git a/model-optimizer/extensions/ops/activation_ops.py b/model-optimizer/extensions/ops/activation_ops.py index 106f3fb2eb45b2..145dfdf595a139 100644 --- a/model-optimizer/extensions/ops/activation_ops.py +++ b/model-optimizer/extensions/ops/activation_ops.py @@ -242,15 +242,11 @@ def __init__(self, graph: Graph, attrs: dict): super().__init__(graph, mandatory_props, attrs) -class Mish(Op): +class Mish(Activation): op = 'Mish' + operation = staticmethod(lambda x: x * np.tanh(np.ln(np.exp(x) + 1.0))) def __init__(self, graph: Graph, attrs: dict): - mandatory_props = { - 'op': self.op, - 'type': None, - 'in_ports_count': 1, - 'out_ports_count': 1, - 'infer': None - } - super().__init__(graph, mandatory_props, attrs) + sp_attrs = {'version': 'opset4'} + sp_attrs.update(attrs) + super().__init__(graph, sp_attrs)