Remove ExtractImagePatchesToReorgYolo transformation (#2687)

Co-authored-by: Anton Chetverikov <anton.chetverikov@.intel.com>
Co-authored-by: Ilya Churaev <ilya.churaev@intel.com>
This commit is contained in:
Anton Chetverikov 2020-10-23 17:32:54 +03:00 committed by GitHub
parent cab7a77cba
commit c020fd3e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 0 additions and 260 deletions

View File

@ -130,7 +130,6 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In
std::dynamic_pointer_cast<const ::ngraph::opset3::ShuffleChannels>(node) ||
std::dynamic_pointer_cast<const ::ngraph::opset2::BatchToSpace>(node) ||
std::dynamic_pointer_cast<const ::ngraph::opset2::SpaceToBatch>(node) ||
std::dynamic_pointer_cast<const ::ngraph::opset3::ExtractImagePatches>(node) ||
std::dynamic_pointer_cast<const ::ngraph::opset5::HSigmoid>(node) ||
std::dynamic_pointer_cast<const ::ngraph::opset4::HSwish>(node) ||
std::dynamic_pointer_cast<const ::ngraph::opset4::ReduceL1>(node) ||

View File

@ -39,7 +39,6 @@
#include <transformations/op_conversions/reduce_l1_decomposition.hpp>
#include <transformations/op_conversions/reduce_l2_decomposition.hpp>
#include <transformations/op_conversions/convert_pad_to_group_conv.hpp>
#include <transformations/op_conversions/convert_extract_image_patches_to_reorg_yolo.hpp>
#include <transformations/op_conversions/softplus_decomposition.hpp>
#include <transformations/op_conversions/convert_space_to_batch.hpp>
#include <transformations/op_conversions/convert_batch_to_space.hpp>
@ -137,7 +136,6 @@ static void Transformation(ICNNNetwork::Ptr& clonedNetwork, const Config& conf)
// List of enabled/disabled transformations
pass_config->disable<ngraph::pass::ConvertGELU>();
pass_config->disable<ngraph::pass::ConvertExtractImagePatchesToReorgYolo>();
pass_config->disable<ngraph::pass::HSwishDecomposition>();
pass_config->disable<ngraph::pass::ReduceL1Decomposition>();
pass_config->disable<ngraph::pass::ReduceL2Decomposition>();

View File

@ -1,29 +0,0 @@
// Copyright (C) 2018-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <vector>
#include <memory>
#include <transformations_visibility.hpp>
#include <ngraph/pass/graph_rewrite.hpp>
namespace ngraph {
namespace pass {
class TRANSFORMATIONS_API ConvertExtractImagePatchesToReorgYolo;
} // namespace pass
} // namespace ngraph
/**
* @ingroup ie_transformation_common_api
* @brief ConvertExtractImagePatchesToReorgYolo transformation replaces ExtractImagePatches with a ReorgYolo op.
*/
class ngraph::pass::ConvertExtractImagePatchesToReorgYolo : public ngraph::pass::MatcherPass {
public:
NGRAPH_RTTI_DECLARATION;
ConvertExtractImagePatchesToReorgYolo();
};

View File

@ -1,89 +0,0 @@
// 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);
}

View File

@ -9,7 +9,6 @@
#include "transformations/op_conversions/convert_shapeof3.hpp"
#include "transformations/op_conversions/convert_shuffle_channels3.hpp"
#include "transformations/op_conversions/convert_topk3.hpp"
#include "transformations/op_conversions/convert_extract_image_patches_to_reorg_yolo.hpp"
#include "transformations/op_conversions/softplus_decomposition.hpp"
#include "transformations/itt.hpp"
@ -30,7 +29,6 @@ bool ngraph::pass::ConvertOpSet3ToOpSet2::run_on_function(std::shared_ptr<ngraph
manager.register_pass<ngraph::pass::ConvertShapeOf3>();
manager.register_pass<ngraph::pass::ConvertShuffleChannels3>();
manager.register_pass<ngraph::pass::ConvertTopK3>();
manager.register_pass<ngraph::pass::ConvertExtractImagePatchesToReorgYolo>();
manager.register_pass<ngraph::pass::SoftPlusDecomposition>();
manager.set_pass_config(get_pass_config());

View File

@ -1,137 +0,0 @@
// 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;
}