Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONNX] Frontend refactoring: operations #22121

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@

#include "op/org.openvinotoolkit/deformable_conv_2d.hpp"

#include "default_opset.hpp"
#include "ngraph/node.hpp"
#include "ngraph/op/deformable_convolution.hpp"
#include "openvino/op/deformable_convolution.hpp"
#include "utils/convpool.hpp"

using namespace ov::op;

namespace ngraph {
namespace onnx_import {
OutputVector op::set_1::deformable_conv_2d(const Node& node) {
namespace op {
namespace set_1 {
OutputVector deformable_conv_2d(const Node& node) {
const OutputVector& inputs = node.get_ng_inputs();
const auto strides = convpool::get_strides(node);
const auto dilations = convpool::get_dilations(node);
Expand All @@ -33,16 +35,21 @@ OutputVector op::set_1::deformable_conv_2d(const Node& node) {
const auto deformable_groups = node.get_attribute_value<int64_t>("deformable_groups", 1);
const auto auto_pad_type = convpool::get_auto_pad(node);

return {std::make_shared<default_opset::DeformableConvolution>(inputs.at(0),
inputs.at(1),
inputs.at(2),
strides,
paddings.first,
paddings.second,
dilations,
auto_pad_type,
group,
deformable_groups)};
return {std::make_shared<v8::DeformableConvolution>(inputs.at(0),
inputs.at(1),
inputs.at(2),
strides,
paddings.first,
paddings.second,
dilations,
auto_pad_type,
group,
deformable_groups)};
}
} // namespace set_1

} // namespace op

} // namespace onnx_import

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

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

namespace ngraph {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

#include "ngraph/op/detection_output.hpp"

#include "default_opset.hpp"
#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"
#include "op/org.openvinotoolkit/detection_output.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/detection_output.hpp"

using namespace ov::op;

namespace ngraph {
namespace onnx_import {
Expand All @@ -21,7 +22,7 @@ OutputVector detection_output(const Node& node) {
auto class_preds = inputs[1];
auto proposals = inputs[2];

ov::op::v8::DetectionOutput::Attributes attrs;
v8::DetectionOutput::Attributes attrs;
attrs.background_label_id = static_cast<int>(node.get_attribute_value<int64_t>("background_label_id", 0));
attrs.top_k = static_cast<int>(node.get_attribute_value<int64_t>("top_k", -1));
attrs.variance_encoded_in_target = node.get_attribute_value<int64_t>("variance_encoded_in_target", 0);
Expand Down Expand Up @@ -51,16 +52,16 @@ OutputVector detection_output(const Node& node) {
attrs.objectness_score = node.get_attribute_value<float>("objectness_score", 0);

if (inputs.size() == 3) {
return {std::make_shared<ov::op::v8::DetectionOutput>(box_logits, class_preds, proposals, attrs)};
return {std::make_shared<v8::DetectionOutput>(box_logits, class_preds, proposals, attrs)};
} else if (inputs.size() == 5) {
auto aux_class_preds = inputs[3];
auto aux_box_preds = inputs[4];
return {std::make_shared<ov::op::v8::DetectionOutput>(box_logits,
class_preds,
proposals,
aux_class_preds,
aux_box_preds,
attrs)};
return {std::make_shared<v8::DetectionOutput>(box_logits,
class_preds,
proposals,
aux_class_preds,
aux_box_preds,
attrs)};
} else {
FRONT_END_GENERAL_CHECK(false, "Invalid number of inputs");
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

#include <memory>

#include "default_opset.hpp"
#include "openvino/op/fake_quantize.hpp"

using namespace ov::op;

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector fake_quantize(const onnx_import::Node& node) {
OutputVector fake_quantize(const Node& node) {
const auto inputs = node.get_ng_inputs();
const auto X = inputs.at(0);
const auto input_low = inputs.at(1);
Expand All @@ -22,7 +24,7 @@ OutputVector fake_quantize(const onnx_import::Node& node) {

const auto levels = node.get_attribute_value<std::size_t>("levels");

return {std::make_shared<default_opset::FakeQuantize>(X, input_low, input_high, output_low, output_high, levels)};
return {std::make_shared<v0::FakeQuantize>(X, input_low, input_high, output_low, output_high, levels)};
}

} // namespace set_1
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

#include "generate_proposals.hpp"

#include "default_opset.hpp"
#include "openvino/op/broadcast.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/generate_proposals.hpp"
#include "openvino/op/shape_of.hpp"

using namespace ov::op;

namespace ngraph {
namespace onnx_import {
Expand Down Expand Up @@ -36,24 +43,24 @@ OutputVector generate_proposals(const Node& node) {
const auto& im_info = inputs[2]; // shape [N, 3] or [N, 4]
const auto& anchors = inputs[3]; // shape [A, 4]

ov::op::v9::GenerateProposals::Attributes attrs;
v9::GenerateProposals::Attributes attrs;
attrs.min_size = node.get_attribute_value<float>("min_size", 1.f);
attrs.nms_threshold = node.get_attribute_value<float>("nms_thresh", 0.7f);
attrs.pre_nms_count = node.get_attribute_value<int64_t>("pre_nms_topN", 6000);
attrs.post_nms_count = node.get_attribute_value<int64_t>("post_nms_topN", 300);
attrs.normalized = !node.get_attribute_value<int64_t>("legacy_plus_one", true);

// Broadcast anchors from [A, 4] to [H, W, A, 4] where [H, W] is taken from scores shape.
const auto zero = default_opset::Constant::create(element::i64, Shape{1}, {0});
const auto scores_shape = std::make_shared<default_opset::ShapeOf>(scores);
const auto anchors_shape = std::make_shared<default_opset::ShapeOf>(anchors);
const auto scores_shape_tail = default_opset::Constant::create(element::i64, Shape{2}, {2, 3});
const auto new_anchors_shape_front = std::make_shared<default_opset::Gather>(scores_shape, scores_shape_tail, zero);
const auto zero = v0::Constant::create(element::i64, Shape{1}, {0});
const auto scores_shape = std::make_shared<v3::ShapeOf>(scores);
const auto anchors_shape = std::make_shared<v3::ShapeOf>(anchors);
const auto scores_shape_tail = v0::Constant::create(element::i64, Shape{2}, {2, 3});
const auto new_anchors_shape_front = std::make_shared<v8::Gather>(scores_shape, scores_shape_tail, zero);
const auto new_anchors_shape =
std::make_shared<default_opset::Concat>(OutputVector{new_anchors_shape_front, anchors_shape}, 0);
const auto new_anchors = std::make_shared<default_opset::Broadcast>(anchors, new_anchors_shape);
std::make_shared<v0::Concat>(OutputVector{new_anchors_shape_front, anchors_shape}, 0);
const auto new_anchors = std::make_shared<v3::Broadcast>(anchors, new_anchors_shape);

const auto proposals = std::make_shared<ov::op::v9::GenerateProposals>(im_info, new_anchors, deltas, scores, attrs);
const auto proposals = std::make_shared<v9::GenerateProposals>(im_info, new_anchors, deltas, scores, attrs);

return proposals->outputs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

#include "op/org.openvinotoolkit/group_norm.hpp"

#include "default_opset.hpp"
#include "ngraph/node.hpp"
#include "ngraph/opsets/opset5.hpp"
#include "onnx_import/core/node.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/opsets/opset12.hpp"
#include "utils/common.hpp"
#include "utils/reshape.hpp"
#include "openvino/op/group_normalization.hpp"
#include "openvino/op/squeeze.hpp"

using namespace ov::op;

namespace ngraph {
namespace onnx_import {
Expand All @@ -30,13 +28,13 @@ OutputVector group_norm(const Node& node) {
float eps = node.get_attribute_value<float>("eps", 1e-6f);

if (!scale.get_partial_shape().rank().compatible(1)) {
scale = std::make_shared<default_opset::Squeeze>(scale);
scale = std::make_shared<v0::Squeeze>(scale);
}
if (!bias.get_partial_shape().rank().compatible(1)) {
bias = std::make_shared<default_opset::Squeeze>(bias);
bias = std::make_shared<v0::Squeeze>(bias);
}

return {std::make_shared<ov::opset12::GroupNormalization>(data, scale, bias, num_groups, eps)};
return {std::make_shared<v12::GroupNormalization>(data, scale, bias, num_groups, eps)};
}

} // namespace set_1
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

#include "op/org.openvinotoolkit/normalize.hpp"

#include "default_opset.hpp"
#include "ngraph/op/normalize_l2.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/normalize_l2.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/util/op_types.hpp"
#include "utils/common.hpp"

using namespace ov::op;

namespace ngraph {
namespace onnx_import {
namespace op {
Expand All @@ -23,7 +27,7 @@ OutputVector normalize(const Node& node) {
int64_t across_spatial = node.get_attribute_value<int64_t>("across_spatial", 0);
int64_t channel_shared = node.get_attribute_value<int64_t>("channel_shared", 0);

std::shared_ptr<ngraph::Node> weights;
std::shared_ptr<ov::Node> weights;
if (channel_shared) {
FRONT_END_GENERAL_CHECK(ov::op::util::is_constant(inputs[1].get_node()),
"Weights input must be a constant if channel_shared is set to 1");
Expand All @@ -42,24 +46,23 @@ OutputVector normalize(const Node& node) {
for (int64_t i = 2; i < data_shape.rank().get_length(); ++i) {
weights_shape.push_back(1);
}
auto new_shape =
std::make_shared<default_opset::Constant>(element::i64, Shape{weights_shape.size()}, weights_shape);
weights = std::make_shared<default_opset::Reshape>(inputs[1], new_shape, true);
auto new_shape = std::make_shared<v0::Constant>(element::i64, Shape{weights_shape.size()}, weights_shape);
weights = std::make_shared<v1::Reshape>(inputs[1], new_shape, true);
}

std::shared_ptr<ngraph::Node> axes;
std::shared_ptr<ov::Node> axes;
if (!across_spatial) {
axes = std::make_shared<default_opset::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
axes = std::make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
} else {
axes = common::get_monotonic_range_along_node_rank(data, 1);
}

return {std::make_shared<default_opset::Multiply>(
std::make_shared<default_opset::NormalizeL2>(data, axes, eps, ngraph::op::EpsMode::ADD),
weights)};
return {std::make_shared<v1::Multiply>(std::make_shared<v0::NormalizeL2>(data, axes, eps, ov::op::EpsMode::ADD),
weights)};
}

} // namespace set_1

} // namespace op

} // namespace onnx_import
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
Loading
Loading