Moved apply auto padding to dev API (#20257)

This commit is contained in:
Ilya Churaev 2023-10-06 12:20:26 +04:00 committed by GitHub
parent d6c2a10b38
commit fb40081475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 16 deletions

View File

@ -4,10 +4,17 @@
#pragma once
#include "openvino/core/node.hpp"
#include "openvino/core/coordinate_diff.hpp"
#include "openvino/core/core_visibility.hpp"
#include "openvino/core/partial_shape.hpp"
#include "openvino/core/shape.hpp"
#include "openvino/core/strides.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/util/attr_types.hpp"
namespace ov {
namespace util {
/// \brief Normalize value to the max if value is negative.
///
/// \param value Input value to normalize.
@ -47,5 +54,29 @@ OPENVINO_API std::shared_ptr<op::v0::Constant> constantfold_subgraph(const Outpu
* @return Shared pointer to constant data or nullptr.
*/
OPENVINO_API std::shared_ptr<op::v0::Constant> get_constant_from_source(const Output<Node>& source);
/// \brief Apply auto padding to padding_above and padding_below inputs
/// if all needed informations are known.
///
/// \param image_shape The shape of input image.
/// \param filter_shape The shape of filter input.
/// \param filter_strides The strides of applied padding.
/// \param filter_dilations The dilations of applied padding.
/// \param pad_type The type of padding. Auto padding is applied only
/// for SAME_UPPER and SAME_LOWER mode.
/// \param padding_above The beginning of padding shape.
/// \param end The beginning of padding shape.
///
/// \return true if auto padding was applied successfully (all needed informations such as
/// spatial dims are known), false otherwise.
OPENVINO_API
bool try_apply_auto_padding(const PartialShape& image_shape,
const Shape& filter_shape,
const Strides& filter_strides,
const Strides& filter_dilations,
const op::PadType pad_type,
CoordinateDiff& padding_above,
CoordinateDiff& padding_below);
} // namespace util
} // namespace ov

View File

@ -658,23 +658,23 @@ void ov::infer_auto_padding(const Shape& image_shape,
CoordinateDiff& padding_below) {
const auto image_dims = std::vector<Dimension>(std::begin(image_shape), std::end(image_shape));
// because image_shape is fully known result of try_apply_infer_auto_padding is ignored
ngraph::try_apply_auto_padding(image_dims,
filter_shape,
filter_strides,
filter_dilations,
pad_type,
padding_above,
padding_below);
ov::util::try_apply_auto_padding(image_dims,
filter_shape,
filter_strides,
filter_dilations,
pad_type,
padding_above,
padding_below);
}
bool ngraph::try_apply_auto_padding(const PartialShape& image_shape,
const Shape& filter_shape,
const Strides& filter_strides,
const Strides& filter_dilations,
const op::PadType pad_type,
CoordinateDiff& padding_above,
CoordinateDiff& padding_below) {
NGRAPH_CHECK(pad_type == op::PadType::SAME_UPPER || pad_type == op::PadType::SAME_LOWER);
bool ov::util::try_apply_auto_padding(const PartialShape& image_shape,
const Shape& filter_shape,
const Strides& filter_strides,
const Strides& filter_dilations,
const op::PadType pad_type,
CoordinateDiff& padding_above,
CoordinateDiff& padding_below) {
OPENVINO_ASSERT(pad_type == op::PadType::SAME_UPPER || pad_type == op::PadType::SAME_LOWER);
if (image_shape.rank().is_dynamic()) {
return false;
@ -700,6 +700,22 @@ bool ngraph::try_apply_auto_padding(const PartialShape& image_shape,
return true;
}
bool ngraph::try_apply_auto_padding(const PartialShape& image_shape,
const Shape& filter_shape,
const Strides& filter_strides,
const Strides& filter_dilations,
const op::PadType pad_type,
CoordinateDiff& padding_above,
CoordinateDiff& padding_below) {
return ov::util::try_apply_auto_padding(image_shape,
filter_shape,
filter_strides,
filter_dilations,
pad_type,
padding_above,
padding_below);
}
ngraph::PartialShape ngraph::infer_slice_shape(const Node* node,
const PartialShape& input_shape,
const std::vector<int64_t>& begin,