Skip to content

Commit

Permalink
Maxpool revise (openvinotoolkit#3397)
Browse files Browse the repository at this point in the history
* create MaxPoolLayer test

* Create single layer tests for MaxPool for cpu plugin

* create max_pool_2d_ceil unit test

* Update MaxPool spec

* add comments describing AUTO and NOTSET types

* create unit test for MaxPool

* add type_prop test for default values

* add MaxPool unit tests to CMakeList

* Remove second constructor and change the first one so it has default values for rounding_type and auto_pad

* style-apply

* Update the spec

* add max pool single layer test instances for different pad type

* add 5D input max pool single layer test instance for cpu plugin

* Remove max pool single layer tests files

* add more test instances for max pool single layer tests for cpu plugin

* add newline characters
  • Loading branch information
pszmel authored and mryzhov committed Dec 11, 2020
1 parent 0c9e6b9 commit c5587ea
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 37 deletions.
11 changes: 6 additions & 5 deletions docs/ops/pooling/MaxPool_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@
* *floor*
* **Type**: string
* **Default value**: *floor*
* **Required**: *no*

* *auto_pad*

* **Description**: *auto_pad* how the padding is calculated. Possible values:
* None (not specified): use explicit padding values.
* *explicit*: use explicit padding values.
* *same_upper (same_lower)* the input is padded to match the output size. In case of odd padding value an extra padding is added at the end (at the beginning).
* *valid* - do not use padding.
* **Type**: string
* **Default value**: None
* **Default value**: *explicit*
* **Required**: *no*
* **Note**: *pads_begin* and *pads_end* attributes are ignored when *auto_pad* is specified.

Expand All @@ -70,9 +71,9 @@

**Mathematical Formulation**

\f[
output_{j} = MAX\{ x_{0}, ... x_{i}\}
\f]
\f[
output_{j} = max(x_{0}, ..., x_{i})
\f]

**Example**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ const std::vector<InferenceEngine::Precision> netPrecisions = {

const std::vector<std::vector<size_t >> kernels = {{3, 3},
{3, 5}};
const std::vector<std::vector<size_t >> kernel3D = {{2, 2, 2}};

const std::vector<std::vector<size_t >> strides = {{1, 1},
{1, 2}};
const std::vector<std::vector<size_t >> strides3D = {{1, 1, 1},
{2, 2, 2}};
const std::vector<std::vector<size_t >> padBegins = {{0, 0},
{0, 2}};
const std::vector<std::vector<size_t >> padBegins3D = {{0, 0, 0}};
const std::vector<std::vector<size_t >> padEnds = {{0, 0},
{0, 2}};
const std::vector<std::vector<size_t >> padEnds3D = {{0, 0, 0}};
const std::vector<ngraph::op::RoundingType> roundingTypes = {ngraph::op::RoundingType::CEIL,
ngraph::op::RoundingType::FLOOR};
////* ========== Max Polling ========== */
Expand All @@ -46,7 +52,7 @@ const auto maxPool_ExplicitPad_FloorRounding_Params = ::testing::Combine(
::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling
);

INSTANTIATE_TEST_CASE_P(smoke_MaxPool_ExplicitPad_FloorRpunding, PoolingLayerTest,
INSTANTIATE_TEST_CASE_P(smoke_MaxPool_ExplicitPad_FloorRounding, PoolingLayerTest,
::testing::Combine(
maxPool_ExplicitPad_FloorRounding_Params,
::testing::ValuesIn(netPrecisions),
Expand All @@ -58,6 +64,126 @@ INSTANTIATE_TEST_CASE_P(smoke_MaxPool_ExplicitPad_FloorRpunding, PoolingLayerTes
::testing::Values(CommonTestUtils::DEVICE_CPU)),
PoolingLayerTest::getTestCaseName);

/* +========== Same Upper Pad Floor Rounding ========== */
const auto maxPool_SameUpperPad_FloorRounding_Params = ::testing::Combine(
::testing::Values(ngraph::helpers::PoolingTypes::MAX),
::testing::ValuesIn(kernels),
::testing::ValuesIn(strides),
::testing::ValuesIn(padBegins),
::testing::ValuesIn(padEnds),
::testing::Values(ngraph::op::RoundingType::FLOOR),
::testing::Values(ngraph::op::PadType::SAME_UPPER),
::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling
);

INSTANTIATE_TEST_CASE_P(smoke_MaxPool_SameUpperPad_FloorRounding, PoolingLayerTest,
::testing::Combine(
maxPool_SameUpperPad_FloorRounding_Params,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t >({1, 3, 30, 30})),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
PoolingLayerTest::getTestCaseName);

/* +========== Same Lower Pad Floor Rounding ========== */
const auto maxPool_SameLowerPad_FloorRounding_Params = ::testing::Combine(
::testing::Values(ngraph::helpers::PoolingTypes::MAX),
::testing::ValuesIn(kernels),
::testing::ValuesIn(strides),
::testing::ValuesIn(padBegins),
::testing::ValuesIn(padEnds),
::testing::Values(ngraph::op::RoundingType::FLOOR),
::testing::Values(ngraph::op::PadType::SAME_LOWER),
::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling
);

INSTANTIATE_TEST_CASE_P(smoke_MaxPool_SameLowerPad_FloorRounding, PoolingLayerTest,
::testing::Combine(
maxPool_SameUpperPad_FloorRounding_Params,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t >({1, 3, 30, 30})),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
PoolingLayerTest::getTestCaseName);

/* ========== Explicit Pad Floor Rounding 5D input========== */
const auto maxPool_ExplicitPad_FloorRounding_5Dinput_Params = ::testing::Combine(
::testing::Values(ngraph::helpers::PoolingTypes::MAX),
::testing::ValuesIn(kernel3D),
::testing::ValuesIn(strides3D),
::testing::ValuesIn(padBegins3D),
::testing::ValuesIn(padEnds3D),
::testing::Values(ngraph::op::RoundingType::FLOOR),
::testing::Values(ngraph::op::PadType::EXPLICIT),
::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling
);

INSTANTIATE_TEST_CASE_P(smoke_MaxPool_ExplicitPad_FloorRounding_5Dinput, PoolingLayerTest,
::testing::Combine(
maxPool_ExplicitPad_FloorRounding_5Dinput_Params,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t >({32, 32, 2, 2, 2})),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
PoolingLayerTest::getTestCaseName);

/* ========== Same Upper Pad Floor Rounding 5D input========== */
const auto maxPool_SameUpperPad_FloorRounding_5Dinput_Params = ::testing::Combine(
::testing::Values(ngraph::helpers::PoolingTypes::MAX),
::testing::ValuesIn(kernel3D),
::testing::ValuesIn(strides3D),
::testing::ValuesIn(padBegins3D),
::testing::ValuesIn(padEnds3D),
::testing::Values(ngraph::op::RoundingType::FLOOR),
::testing::Values(ngraph::op::PadType::SAME_UPPER),
::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling
);

INSTANTIATE_TEST_CASE_P(smoke_MaxPool_SameUpperPad_FloorRounding_5Dinput, PoolingLayerTest,
::testing::Combine(
maxPool_SameUpperPad_FloorRounding_5Dinput_Params,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t >({32, 32, 2, 2, 2})),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
PoolingLayerTest::getTestCaseName);

/* ========== Same Lower Pad Ceil Rounding 5D input========== */
const auto maxPool_SameLowerPad_CeilRounding_5Dinput_Params = ::testing::Combine(
::testing::Values(ngraph::helpers::PoolingTypes::MAX),
::testing::ValuesIn(kernel3D),
::testing::ValuesIn(strides3D),
::testing::ValuesIn(padBegins3D),
::testing::ValuesIn(padEnds3D),
::testing::Values(ngraph::op::RoundingType::CEIL),
::testing::Values(ngraph::op::PadType::SAME_LOWER),
::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling
);

INSTANTIATE_TEST_CASE_P(smoke_MaxPool_SameLowerPad_CeilRounding_5Dinput, PoolingLayerTest,
::testing::Combine(
maxPool_SameUpperPad_FloorRounding_5Dinput_Params,
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t >({32, 32, 2, 2, 2})),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
PoolingLayerTest::getTestCaseName);

/* ========== Explicit Pad Ceil Rounding ========== */
const auto maxPool_ExplicitPad_CeilRounding_Params = ::testing::Combine(
::testing::Values(ngraph::helpers::PoolingTypes::MAX),
Expand All @@ -70,7 +196,7 @@ const auto maxPool_ExplicitPad_CeilRounding_Params = ::testing::Combine(
::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling
);

INSTANTIATE_TEST_CASE_P(smoke_MaxPool_ExplicitPad_CeilRpunding, PoolingLayerTest,
INSTANTIATE_TEST_CASE_P(smoke_MaxPool_ExplicitPad_CeilRounding, PoolingLayerTest,
::testing::Combine(
maxPool_ExplicitPad_CeilRounding_Params,
::testing::ValuesIn(netPrecisions),
Expand Down
22 changes: 3 additions & 19 deletions ngraph/core/include/ngraph/op/max_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,8 @@ namespace ngraph
const Shape& pads_begin,
const Shape& pads_end,
const Shape& kernel,
op::RoundingType rounding_mode,
const PadType& auto_pad);

/// \brief Constructs a batched max pooling operation.
///
/// \param arg The node producing the input data batch tensor.
/// \param strides The strides.
/// \param pads_begin The beginning of padding shape.
/// \param pads_end The end of padding shape.
/// \param kernel The kernel shape.
/// \param rounding_mode Whether to use ceiling or floor rounding type while
/// computing output shape.
MaxPool(const Output<Node>& arg,
const Strides& strides,
const Shape& pads_begin,
const Shape& pads_end,
const Shape& kernel,
op::RoundingType rounding_mode);
op::RoundingType rounding_mode = op::RoundingType::FLOOR,
const PadType& auto_pad = op::PadType::EXPLICIT);

bool visit_attributes(AttributeVisitor& visitor) override;
size_t get_version() const override { return 1; }
Expand Down Expand Up @@ -108,7 +92,7 @@ namespace ngraph
Shape m_pads_begin;
Shape m_pads_end;
PadType m_auto_pad;
op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
op::RoundingType m_rounding_type;

private:
bool update_auto_padding(const PartialShape& in_shape,
Expand Down
4 changes: 3 additions & 1 deletion ngraph/core/include/ngraph/op/util/attr_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ namespace ngraph
/// Floor(num_dims/2) at the beginning and
/// Ceil(num_dims/2) at the end
/// VALID - No padding
///
/// AUTO - Deprecated. User should not use it in the future
/// NOTSET - Deprecated. User should not use it in the future

enum class PadType
{
EXPLICIT = 0,
Expand Down
10 changes: 0 additions & 10 deletions ngraph/core/src/op/max_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ op::v1::MaxPool::MaxPool(const Output<Node>& arg,
constructor_validate_and_infer_types();
}

op::v1::MaxPool::MaxPool(const Output<Node>& arg,
const Strides& strides,
const Shape& pads_begin,
const Shape& pads_end,
const Shape& kernel,
op::RoundingType rounding_type)
: v1::MaxPool(arg, strides, pads_begin, pads_end, kernel, rounding_type, op::PadType::EXPLICIT)
{
}

bool ngraph::op::v1::MaxPool::visit_attributes(AttributeVisitor& visitor)
{
visitor.on_attribute("strides", m_strides);
Expand Down
1 change: 1 addition & 0 deletions ngraph/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ set(MULTI_TEST_SRC
backend/lrn.in.cpp
backend/matmul.in.cpp
backend/maximum.in.cpp
backend/max_pool.in.cpp
backend/minimum.in.cpp
backend/multiple_backends.in.cpp
backend/multiple_result.in.cpp
Expand Down
Loading

0 comments on commit c5587ea

Please sign in to comment.