Skip to content

Commit

Permalink
[ONNX] Frontend refactoring: operations (openvinotoolkit#22351)
Browse files Browse the repository at this point in the history
* Refactoring operations M-P

* Fixed code style
  • Loading branch information
gkrivor authored Jan 23, 2024
1 parent 0666d12 commit 76e75aa
Show file tree
Hide file tree
Showing 32 changed files with 135 additions and 171 deletions.
11 changes: 4 additions & 7 deletions src/frontends/onnx/frontend/src/op/matmul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include <memory>

#include "default_opset.hpp"
#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"
#include "openvino/op/matmul.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace detail {
inline OutputVector matmul(const Output<ngraph::Node>& a, const Output<ngraph::Node>& b) {
return {std::make_shared<default_opset::MatMul>(a, b)};
inline OutputVector matmul(const Output<ov::Node>& a, const Output<ov::Node>& b) {
return {std::make_shared<ov::op::v0::MatMul>(a, b)};
}
} // namespace detail
namespace set_1 {
inline OutputVector matmul(const Node& node) {
return {std::make_shared<default_opset::MatMul>(node.get_ng_inputs().at(0), node.get_ng_inputs().at(1))};
return {std::make_shared<ov::op::v0::MatMul>(node.get_ng_inputs().at(0), node.get_ng_inputs().at(1))};
}
} // namespace set_1
} // namespace op
Expand Down
7 changes: 3 additions & 4 deletions src/frontends/onnx/frontend/src/op/max.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "default_opset.hpp"
#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"
#include "openvino/op/maximum.hpp"
#include "utils/variadic.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
inline OutputVector max(const Node& node) {
return variadic::make_ng_variadic_op<default_opset::Maximum>(node, ngraph::op::AutoBroadcastType::NONE);
return variadic::make_ng_variadic_op<ov::op::v1::Maximum>(node, ov::op::AutoBroadcastType::NONE);
}

} // namespace set_1

namespace set_8 {
inline OutputVector max(const Node& node) {
return variadic::make_ng_variadic_op<default_opset::Maximum>(node);
return variadic::make_ng_variadic_op<ov::op::v1::Maximum>(node);
}

} // namespace set_8
Expand Down
4 changes: 2 additions & 2 deletions src/frontends/onnx/frontend/src/op/max_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include "op/max_pool.hpp"

#include <memory>

#include "onnx_import/core/null_node.hpp"
#include "openvino/util/log.hpp"
#include "utils/pooling_factory.hpp"

using namespace ov::op;

OPENVINO_SUPPRESS_DEPRECATED_START
namespace ngraph {
namespace onnx_import {
Expand Down
9 changes: 4 additions & 5 deletions src/frontends/onnx/frontend/src/op/max_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
///
/// \brief Convert ONNX MaxPool operation to an nGraph node.
/// \brief Convert ONNX MaxPool operation to an OV node.
///
/// \param node The ONNX node object representing this operation.
///
/// \return The vector containing Ngraph nodes producing output of ONNX MaxPool
/// \return The vector containing OV nodes producing output of ONNX MaxPool
/// operation.
///
OutputVector max_pool(const Node& node);
Expand All @@ -28,11 +27,11 @@ OutputVector max_pool(const Node& node);

namespace set_8 {
///
/// \brief Convert ONNX MaxPool operation to an nGraph node.
/// \brief Convert ONNX MaxPool operation to an OV node.
///
/// \param node The ONNX node object representing this operation.
///
/// \return The vector containing Ngraph nodes producing output of ONNX MaxPool
/// \return The vector containing OV nodes producing output of ONNX MaxPool
/// operation.
///
OutputVector max_pool(const Node& node);
Expand Down
20 changes: 8 additions & 12 deletions src/frontends/onnx/frontend/src/op/max_roi_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

#include "op/max_roi_pool.hpp"

#include <cstddef>
#include <memory>
#include <vector>
#include "openvino/frontend/exception.hpp"
#include "openvino/op/roi_pooling.hpp"

#include "ngraph/check.hpp"
#include "ngraph/type/element_type.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "default_opset.hpp"
using namespace ov::op;

OPENVINO_SUPPRESS_DEPRECATED_START
namespace ngraph {
namespace onnx_import {
namespace op {
Expand All @@ -23,14 +19,14 @@ OutputVector max_roi_pool(const Node& node) {
const auto X = inputs.at(0);
const auto rois = inputs.at(1);

OPENVINO_ASSERT(X.get_element_type() == element::f16 || X.get_element_type() == element::f32 ||
X.get_element_type() == element::f64,
"MaxRoiPool operator only supports float16, float32 and float64 datatypes.");
FRONT_END_GENERAL_CHECK(X.get_element_type() == element::f16 || X.get_element_type() == element::f32 ||
X.get_element_type() == element::f64,
"MaxRoiPool operator only supports float16, float32 and float64 datatypes.");

const auto pooled_shape = node.get_attribute_value<std::vector<size_t>>("pooled_shape");
const auto spatial_scale = node.get_attribute_value<float>("spatial_scale", 1.0);

return {std::make_shared<default_opset::ROIPooling>(X, rois, Shape(pooled_shape), spatial_scale, "max")};
return {std::make_shared<v0::ROIPooling>(X, rois, Shape(pooled_shape), spatial_scale, "max")};
}
} // namespace set_1
} // namespace op
Expand Down
1 change: 0 additions & 1 deletion src/frontends/onnx/frontend/src/op/max_roi_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
Expand Down
12 changes: 8 additions & 4 deletions src/frontends/onnx/frontend/src/op/mean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@

#include "op/mean.hpp"

#include "default_opset.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/divide.hpp"
#include "utils/variadic.hpp"

using namespace ov::op;

OPENVINO_SUPPRESS_DEPRECATED_START
namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector mean(const Node& node) {
auto sum = variadic::make_ng_variadic_op<default_opset::Add>(node).front();
auto count = default_opset::Constant::create(sum.get_element_type(), Shape{}, {node.get_ng_inputs().size()});
auto sum = variadic::make_ng_variadic_op<v1::Add>(node).front();
auto count = v0::Constant::create(sum.get_element_type(), Shape{}, {node.get_ng_inputs().size()});

return {std::make_shared<default_opset::Divide>(sum, count)};
return {std::make_shared<v1::Divide>(sum, count)};
}

} // namespace set_1
Expand Down
1 change: 0 additions & 1 deletion src/frontends/onnx/frontend/src/op/mean.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
Expand Down
19 changes: 8 additions & 11 deletions src/frontends/onnx/frontend/src/op/mean_variance_normalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

#include "op/mean_variance_normalization.hpp"

#include <cstdint>
#include <memory>

#include "default_opset.hpp"
#include "ngraph/axis_set.hpp"
#include "ngraph/validation_util.hpp"
#include "openvino/core/validation_util.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/mvn.hpp"
#include "openvino/opsets/opset5.hpp"

using namespace ov::op;

OPENVINO_SUPPRESS_DEPRECATED_START
namespace ngraph {
Expand All @@ -23,7 +20,7 @@ OutputVector mean_variance_normalization(const Node& node) {
bool across_channels = node.get_attribute_value<std::int64_t>("across_channels", 0);
bool normalize_variance = node.get_attribute_value<std::int64_t>("normalize_variance", 1);

return {std::make_shared<ov::op::v0::MVN>(data, across_channels, normalize_variance)};
return {std::make_shared<v0::MVN>(data, across_channels, normalize_variance)};
}

} // namespace set_1
Expand All @@ -34,10 +31,10 @@ OutputVector mean_variance_normalization(const Node& node) {
auto axes = node.get_attribute_value<std::vector<std::int64_t>>("axes", {0, 2, 3});
OPENVINO_SUPPRESS_DEPRECATED_START
const std::vector<std::size_t> normalized_axes =
ngraph::normalize_axes(node.get_description(), axes, data.get_partial_shape().rank());
ov::normalize_axes(node.get_description(), axes, data.get_partial_shape().rank());
OPENVINO_SUPPRESS_DEPRECATED_END
auto const_axes = default_opset::Constant::create(element::i64, Shape{normalized_axes.size()}, normalized_axes);
return {std::make_shared<ov::op::v6::MVN>(data, const_axes, true, 1e-09f, ov::op::MVNEpsMode::OUTSIDE_SQRT)};
auto const_axes = v0::Constant::create(element::i64, Shape{normalized_axes.size()}, normalized_axes);
return {std::make_shared<v6::MVN>(data, const_axes, true, 1e-09f, ov::op::MVNEpsMode::OUTSIDE_SQRT)};
}

} // namespace set_9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
Expand Down
8 changes: 3 additions & 5 deletions src/frontends/onnx/frontend/src/op/min.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "default_opset.hpp"
#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"
#include "utils/variadic.hpp"
#include "openvino/op/minimum.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
inline OutputVector min(const Node& node) {
return variadic::make_ng_variadic_op<default_opset::Minimum>(node, ngraph::op::AutoBroadcastType::NONE);
return variadic::make_ng_variadic_op<ov::op::v1::Minimum>(node, ov::op::AutoBroadcastType::NONE);
}

} // namespace set_1

namespace set_8 {
inline OutputVector min(const Node& node) {
return variadic::make_ng_variadic_op<default_opset::Minimum>(node);
return variadic::make_ng_variadic_op<ov::op::v1::Minimum>(node);
}

} // namespace set_8
Expand Down
17 changes: 8 additions & 9 deletions src/frontends/onnx/frontend/src/op/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@

#include "op/mod.hpp"

#include <memory>

#include "default_opset.hpp"
#include "exceptions.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/abs.hpp"
#include "openvino/op/floor_mod.hpp"
#include "openvino/op/mod.hpp"

using namespace ov::op;

OPENVINO_SUPPRESS_DEPRECATED_START
namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector mod(const Node& node) {
Output<ngraph::Node> dividend{node.get_ng_inputs().at(0)};
Output<ngraph::Node> divisor{node.get_ng_inputs().at(1)};
Output<ov::Node> dividend{node.get_ng_inputs().at(0)};
Output<ov::Node> divisor{node.get_ng_inputs().at(1)};

std::int64_t fmod = node.get_attribute_value<std::int64_t>("fmod", 0);
OutputVector output;
if (fmod == 1) {
output = {std::make_shared<default_opset::Mod>(dividend, divisor)};
output = {std::make_shared<v1::Mod>(dividend, divisor)};
} else if (fmod == 0) {
FRONT_END_GENERAL_CHECK(dividend.get_element_type().is_integral() && divisor.get_element_type().is_integral(),
"If the input type is floating point, then `fmod` attribute "
"must be set to 1.");
output = {std::make_shared<default_opset::FloorMod>(dividend, divisor)};
output = {std::make_shared<v1::FloorMod>(dividend, divisor)};
} else {
OPENVINO_THROW("Unsupported value of 'fmod' attribute (should be: 0 or 1)");
}
Expand Down
1 change: 0 additions & 1 deletion src/frontends/onnx/frontend/src/op/mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
Expand Down
9 changes: 3 additions & 6 deletions src/frontends/onnx/frontend/src/op/mul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include <memory>

#include "default_opset.hpp"
#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"
#include "openvino/op/multiply.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
inline OutputVector mul(const Node& node) {
return common::handle_opset6_binary_op<default_opset::Multiply>(node);
return common::handle_opset6_binary_op<ov::op::v1::Multiply>(node);
}

} // namespace set_1

namespace set_7 {
inline OutputVector mul(const Node& node) {
return {std::make_shared<default_opset::Multiply>(node.get_ng_inputs().at(0), node.get_ng_inputs().at(1))};
return {std::make_shared<ov::op::v1::Multiply>(node.get_ng_inputs().at(0), node.get_ng_inputs().at(1))};
}

} // namespace set_7
Expand Down
1 change: 0 additions & 1 deletion src/frontends/onnx/frontend/src/op/neg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"
#include "openvino/op/negative.hpp"

Expand Down
13 changes: 6 additions & 7 deletions src/frontends/onnx/frontend/src/op/nms_rotated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#include "openvino/core/deprecated.hpp"
OPENVINO_SUPPRESS_DEPRECATED_START

#include "default_opset.hpp"
#include "onnx_import/core/node.hpp"
#include "openvino/core/node_vector.hpp"
#include "openvino/opsets/opset13.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/nms_rotated.hpp"

namespace ngraph {
namespace onnx_import {
Expand All @@ -22,11 +21,11 @@ inline OutputVector nms_rotated(const Node& node) {
auto iou_threshold = node.get_attribute_value<float>("iou_threshold");
auto score_threshold = node.get_attribute_value<float>("score_threshold");
auto max_output_boxes_per_class =
default_opset::Constant::create(element::i64, Shape{1}, {std::numeric_limits<int64_t>::max()});
auto iou_threshold_const = default_opset::Constant::create(element::f32, Shape{}, {iou_threshold});
auto score_threshold_const = default_opset::Constant::create(element::f32, Shape{}, {score_threshold});
ov::op::v0::Constant::create(element::i64, Shape{1}, {std::numeric_limits<int64_t>::max()});
auto iou_threshold_const = ov::op::v0::Constant::create(element::f32, Shape{}, {iou_threshold});
auto score_threshold_const = ov::op::v0::Constant::create(element::f32, Shape{}, {score_threshold});

auto nms = std::make_shared<ov::opset13::NMSRotated>(node.get_ng_inputs().at(0),
auto nms = std::make_shared<ov::op::v13::NMSRotated>(node.get_ng_inputs().at(0),
node.get_ng_inputs().at(1),
max_output_boxes_per_class,
iou_threshold_const,
Expand Down
Loading

0 comments on commit 76e75aa

Please sign in to comment.