+++ /dev/null
-// Copyright (C) 2018-2020 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include "transformations/op_conversions/convert_extract_image_patches_to_reorg_yolo.hpp"
-
-#include <memory>
-#include <vector>
-
-#include <ngraph/opsets/opset3.hpp>
-#include <ngraph/rt_info.hpp>
-#include <ngraph/pattern/op/wrap_type.hpp>
-
-NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertExtractImagePatchesToReorgYolo, "ConvertExtractImagePatchesToReorgYolo", 0);
-
-ngraph::pass::ConvertExtractImagePatchesToReorgYolo::ConvertExtractImagePatchesToReorgYolo() {
- auto image = std::make_shared<ngraph::pattern::op::Label>(ngraph::element::f32, ngraph::Shape{1, 1, 1, 1});
- auto eip = std::make_shared<ngraph::opset3::ExtractImagePatches>(image, ngraph::Shape{1, 1}, ngraph::Strides{1, 1}, ngraph::Shape{1, 1},
- ngraph::op::PadType::VALID);
-
- ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) {
- auto &pattern_to_output = m.get_pattern_value_map();
- auto extract_image_patches = std::dynamic_pointer_cast<ngraph::opset3::ExtractImagePatches>(m.get_match_root());
-
- /*
- * In this transformation we raplace ExtractImagePatches operation to ReorgYolo operation
- * if ExtractImagePatches operation attributes obey the following conditions:
- *
- * EIP.sizes = EIP.strides
- * EIP.rates = {1, 1}
- * EIP.PadType = VALID
- * Spatial dimensions of input tensor must be divisible by EIP.strides
- *
- */
-
- if (!extract_image_patches || m_transformation_callback(extract_image_patches)) {
- return false;
- }
-
- if (extract_image_patches->get_auto_pad() != ngraph::op::PadType::VALID) {
- return false;
- }
-
- if (extract_image_patches->get_strides() != extract_image_patches->get_sizes()) {
- return false;
- }
-
- auto p_shape_input = extract_image_patches->get_input_partial_shape(0);
- auto sizes = extract_image_patches->get_sizes();
- auto strides = extract_image_patches->get_strides();
- auto rates = extract_image_patches->get_rates();
-
- // Check that ExtractImagePatches input have static shape and rank == 4
- if (!p_shape_input.rank().is_static() || p_shape_input.rank().get_length() != 4) {
- return false;
- }
-
- // Check that ExtractImagePatches input spatial dimensions are not dynamic
- if (p_shape_input[2].is_dynamic() || p_shape_input[3].is_dynamic()) {
- return false;
- }
-
- // Check that ExtractImagePatches input spatial dimensions are divisible by EIP.strides
- if (p_shape_input[2].get_length() % strides[0] != 0 || p_shape_input[3].get_length() % strides[1] != 0) {
- return false;
- }
-
- // Check that EIP.sizes = EIP.strides
- if (sizes[0] != strides[0] || sizes[1] != strides[1]) {
- return false;
- }
-
- // Check that EIP.rates = {1, 1}
- if (rates[0] != 1 || rates[1] != 1) {
- return false;
- }
-
- auto reorg_yolo = std::make_shared<ngraph::opset3::ReorgYolo>(extract_image_patches->input(0).get_source_output(),
- ngraph::Strides{extract_image_patches->get_strides()});
-
- reorg_yolo->set_friendly_name(extract_image_patches->get_friendly_name());
- ngraph::copy_runtime_info(extract_image_patches, reorg_yolo);
- ngraph::replace_node(extract_image_patches, reorg_yolo);
- return true;
- };
-
- auto m = std::make_shared<ngraph::pattern::Matcher>(eip, "ConvertExtractImagePatchesToReorgYolo");
- register_matcher(m, callback);
-}
+++ /dev/null
-// Copyright (C) 2020 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include <gtest/gtest.h>
-
-#include <string>
-#include <memory>
-
-#include <ngraph/function.hpp>
-#include <ngraph/opsets/opset1.hpp>
-#include <ngraph/opsets/opset3.hpp>
-#include <ngraph/pass/manager.hpp>
-#include <transformations/op_conversions/convert_extract_image_patches_to_reorg_yolo.hpp>
-#include <transformations/init_node_info.hpp>
-#include <transformations/utils/utils.hpp>
-
-#include "common_test_utils/ngraph_test_utils.hpp"
-
-using namespace testing;
-
-// TODO: bug 39971, remove ConvertExtractImagePatchesToReorgYolo transformation
-
-TEST(TransformationTests, ConvertExtractImagePatchesToReorgYoloTestsNegative1) {
- std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
- {
- auto input = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32,
- ngraph::PartialShape{1, 3, ngraph::Dimension::dynamic(), ngraph::Dimension::dynamic()});
-
- auto sizes = ngraph::Shape{5, 5};
- auto strides = ngraph::Strides{5, 5};
- auto rates = ngraph::Shape{1, 1};
- ngraph::op::PadType auto_pad = ngraph::op::PadType::VALID;
-
- auto eip = std::make_shared<ngraph::opset3::ExtractImagePatches>(input, sizes, strides, rates, auto_pad);
-
- f = std::make_shared<ngraph::Function>(ngraph::NodeVector{eip}, ngraph::ParameterVector{input});
- ngraph::pass::Manager manager;
- manager.register_pass<ngraph::pass::InitNodeInfo>();
- manager.register_pass<ngraph::pass::ConvertExtractImagePatchesToReorgYolo>();
- manager.run_passes(f);
- ASSERT_NO_THROW(check_rt_info(f));
- }
-
- {
- auto input = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32,
- ngraph::PartialShape{1, 3, ngraph::Dimension::dynamic(), ngraph::Dimension::dynamic()});
-
- auto sizes = ngraph::Shape{5, 5};
- auto strides = ngraph::Strides{5, 5};
- auto rates = ngraph::Shape{1, 1};
- ngraph::op::PadType auto_pad = ngraph::op::PadType::VALID;
-
- auto eip = std::make_shared<ngraph::opset3::ExtractImagePatches>(input, sizes, strides, rates, auto_pad);
-
- f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{eip}, ngraph::ParameterVector{input});
- }
-
- auto res = compare_functions(f, f_ref);
- ASSERT_TRUE(res.first) << res.second;
-}
-
-TEST(TransformationTests, ConvertExtractImagePatchesToReorgYoloTestsNegative2) {
- std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
- {
- auto input = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, ngraph::Shape{1, 3, 10, 10});
-
- auto sizes = ngraph::Shape{5, 5};
- auto strides = ngraph::Strides{5, 5};
- auto rates = ngraph::Shape{1, 1};
- ngraph::op::PadType auto_pad = ngraph::op::PadType::SAME_LOWER;
-
- auto eip = std::make_shared<ngraph::opset3::ExtractImagePatches>(input, sizes, strides, rates, auto_pad);
-
- f = std::make_shared<ngraph::Function>(ngraph::NodeVector{eip}, ngraph::ParameterVector{input});
-
- ngraph::pass::Manager manager;
- manager.register_pass<ngraph::pass::InitNodeInfo>();
- manager.register_pass<ngraph::pass::ConvertExtractImagePatchesToReorgYolo>();
- manager.run_passes(f);
- ASSERT_NO_THROW(check_rt_info(f));
- }
-
- {
- auto input = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, ngraph::Shape{1, 3, 10, 10});
-
- auto sizes = ngraph::Shape{5, 5};
- auto strides = ngraph::Strides{5, 5};
- auto rates = ngraph::Shape{1, 1};
- ngraph::op::PadType auto_pad = ngraph::op::PadType::SAME_LOWER;
-
- auto eip = std::make_shared<ngraph::opset3::ExtractImagePatches>(input, sizes, strides, rates, auto_pad);
-
- f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{eip}, ngraph::ParameterVector{input});
- }
-
- auto res = compare_functions(f, f_ref);
- ASSERT_TRUE(res.first) << res.second;
-}
-
-TEST(TransformationTests, ConvertExtractImagePatchesToReorgYoloTestsNegative3) {
- std::shared_ptr<ngraph::Function> f(nullptr), f_ref(nullptr);
- {
- auto input = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, ngraph::Shape{1, 3, 10, 10});
-
- auto sizes = ngraph::Shape{3, 3};
- auto strides = ngraph::Strides{5, 5};
- auto rates = ngraph::Shape{1, 1};
- ngraph::op::PadType auto_pad = ngraph::op::PadType::VALID;
-
- auto eip = std::make_shared<ngraph::opset3::ExtractImagePatches>(input, sizes, strides, rates, auto_pad);
-
- f = std::make_shared<ngraph::Function>(ngraph::NodeVector{eip}, ngraph::ParameterVector{input});
-
- ngraph::pass::Manager manager;
- manager.register_pass<ngraph::pass::InitNodeInfo>();
- manager.register_pass<ngraph::pass::ConvertExtractImagePatchesToReorgYolo>();
- manager.run_passes(f);
- ASSERT_NO_THROW(check_rt_info(f));
- }
-
- {
- auto input = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, ngraph::Shape{1, 3, 10, 10});
-
- auto sizes = ngraph::Shape{3, 3};
- auto strides = ngraph::Strides{5, 5};
- auto rates = ngraph::Shape{1, 1};
- ngraph::op::PadType auto_pad = ngraph::op::PadType::VALID;
-
- auto eip = std::make_shared<ngraph::opset3::ExtractImagePatches>(input, sizes, strides, rates, auto_pad);
-
- f_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{eip}, ngraph::ParameterVector{input});
- }
-
- auto res = compare_functions(f, f_ref);
- ASSERT_TRUE(res.first) << res.second;
-}