[Shape inference] Pooling: Dimension div fix (#17197)

* Dimension div fix

* codestyle fixes

* Convolution labels propagation test instances corrected
This commit is contained in:
Vladislav Golubev 2023-04-27 18:18:12 +02:00 committed by GitHub
parent 893b29eab4
commit bf59a67d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 4 deletions

View File

@ -161,7 +161,7 @@ auto ceil_div(const TDim& dim, const typename TDim::value_type divisor) -> TDim
if (dim.is_static()) {
return {util::ceil_div<T>(dim.get_length(), divisor)};
} else if (dim.get_max_length() == static_cast<T>(dim::inf_bound)) {
return {dim};
return {util::ceil_div<T>(dim.get_min_length(), divisor), dim.get_max_length()};
} else {
return {util::ceil_div<T>(dim.get_min_length(), divisor), util::ceil_div<T>(dim.get_max_length(), divisor)};
}
@ -183,7 +183,7 @@ auto floor_div(const TDim& dim, const typename TDim::value_type divisor) -> TDim
if (dim.is_static()) {
return {dim.get_length() / divisor};
} else if (dim.get_max_length() == static_cast<T>(dim::inf_bound)) {
return {dim};
return {dim.get_min_length() / divisor, dim.get_max_length()};
} else {
return {dim.get_min_length() / divisor, dim.get_max_length() / divisor};
}

View File

@ -130,7 +130,7 @@ TEST(type_prop, bin_convolution_auto_padding_same_data_batch_spatial_dims_dynami
pad_value,
auto_pad);
EXPECT_THAT(get_shape_labels(conv->get_output_partial_shape(0)), ElementsAre(10, 20, 12, ov::no_label));
EXPECT_THAT(get_shape_labels(conv->get_output_partial_shape(0)), ElementsAre(10, 20, ov::no_label, ov::no_label));
EXPECT_EQ(conv->get_output_partial_shape(0), (PartialShape{1, Dimension::dynamic(), Dimension::dynamic(), 5}));
EXPECT_EQ(conv->get_pads_begin(), (CoordinateDiff{0, 1}));
EXPECT_EQ(conv->get_pads_end(), (CoordinateDiff{0, 1}));

View File

@ -117,7 +117,7 @@ TEST(type_prop, convolution_v1_partial_auto_padding_same_spatial_dims_dynamic) {
make_shared<op::v1::Convolution>(data_batch, filters, strides, pads_begin, pads_end, dilations, auto_pad);
EXPECT_EQ(conv->get_output_partial_shape(0), PartialShape({1, 1, Dimension::dynamic(), {2, 3}}));
EXPECT_THAT(get_shape_labels(conv->get_output_partial_shape(0)), ElementsAre(10, 20, 12, ov::no_label));
EXPECT_THAT(get_shape_labels(conv->get_output_partial_shape(0)), ElementsAre(10, 20, ov::no_label, ov::no_label));
EXPECT_EQ(conv->get_pads_begin(), (CoordinateDiff{0, 0}));
EXPECT_EQ(conv->get_pads_end(), (CoordinateDiff{0, 0}));
}

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "dimension_util.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/type_prop.hpp"
@ -271,6 +272,44 @@ TEST(type_prop, max_pool_v8_4D_with_dilations) {
EXPECT_EQ(mp->get_output_partial_shape(1), expected_output_shape);
}
TEST(type_prop, max_pool_v8_4D_dynamic_dims_with_non_zero_low_range_floor_mode) {
PartialShape arg_shape{Dimension::dynamic(), 64, {198, ov::util::dim::inf_bound}, {198, ov::util::dim::inf_bound}};
const Strides strides{2, 2};
const Strides dilations{1, 1};
const Shape pads_begin{0, 0};
const Shape pads_end{0, 0};
const Shape kernel_shape{2, 2};
const auto rounding_mode = op::RoundingType::FLOOR;
const auto arg = make_shared<op::Parameter>(element::f32, arg_shape);
const auto mp =
make_shared<op::v8::MaxPool>(arg, strides, dilations, pads_begin, pads_end, kernel_shape, rounding_mode);
const auto expected_output_shape =
PartialShape{Dimension::dynamic(), 64, {99, ov::util::dim::inf_bound}, {99, ov::util::dim::inf_bound}};
EXPECT_EQ(mp->get_output_partial_shape(0), expected_output_shape);
EXPECT_EQ(mp->get_output_partial_shape(1), expected_output_shape);
}
TEST(type_prop, max_pool_v8_4D_dynamic_dims_with_non_zero_low_range_ceil_mode) {
PartialShape arg_shape{Dimension::dynamic(), 64, {198, ov::util::dim::inf_bound}, {198, ov::util::dim::inf_bound}};
const Strides strides{2, 2};
const Strides dilations{1, 1};
const Shape pads_begin{0, 0};
const Shape pads_end{0, 0};
const Shape kernel_shape{2, 2};
const auto rounding_mode = op::RoundingType::CEIL;
const auto arg = make_shared<op::Parameter>(element::f32, arg_shape);
const auto mp =
make_shared<op::v8::MaxPool>(arg, strides, dilations, pads_begin, pads_end, kernel_shape, rounding_mode);
const auto expected_output_shape =
PartialShape{Dimension::dynamic(), 64, {99, ov::util::dim::inf_bound}, {99, ov::util::dim::inf_bound}};
EXPECT_EQ(mp->get_output_partial_shape(0), expected_output_shape);
EXPECT_EQ(mp->get_output_partial_shape(1), expected_output_shape);
}
TEST(type_prop, max_pool_v8_4D_interval_dims_with_dilations) {
PartialShape arg_shape{{2, 3}, {1, 3}, {2, 13}, {6, 13}};
set_shape_labels(arg_shape, 10);