[TF FE] Speed up compilation - part 3 (#21211)

Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>
This commit is contained in:
Roman Kazantsev authored and GitHub committed 2023-11-21 14:44:21 +00:00
1 parent 54a68c8a13
commit d1f71ee233
14 files changed
+205 -153

No files matched your search

@@ -3,12 +3,16 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/divide.hpp"
#include "openvino/op/power.hpp"
#include "openvino/op/range.hpp"
#include "openvino/op/reduce_sum.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov;
using namespace ov::opset10;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -21,15 +25,15 @@ OutputVector translate_l2_loss_op(const NodeContext& node) {
auto input = node.get_input(0);
auto const_two = create_same_type_const_scalar<float>(input, 2);
auto squared_input = make_shared<Power>(input, const_two);
auto squared_input = make_shared<v1::Power>(input, const_two);
auto input_rank = compute_subgraph_scalar_rank(input, element::i32, true);
auto const_zero = make_shared<Constant>(element::i32, Shape{}, 0);
auto const_one = make_shared<Constant>(element::i32, Shape{}, 1);
auto reduction_axes = make_shared<Range>(const_zero, input_rank, const_one, element::i32);
auto squared_input_sum = make_shared<ReduceSum>(squared_input, reduction_axes);
auto const_zero = make_shared<v0::Constant>(element::i32, Shape{}, 0);
auto const_one = make_shared<v0::Constant>(element::i32, Shape{}, 1);
auto reduction_axes = make_shared<v4::Range>(const_zero, input_rank, const_one, element::i32);
auto squared_input_sum = make_shared<v1::ReduceSum>(squared_input, reduction_axes);
auto l2_loss = make_shared<Divide>(squared_input_sum, const_two);
auto l2_loss = make_shared<v1::Divide>(squared_input_sum, const_two);
set_node_name(node.get_name(), l2_loss);
return {l2_loss};
}
@@ -3,10 +3,11 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/prelu.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -16,8 +17,8 @@ ov::OutputVector translate_leaky_relu_op(const NodeContext& node) {
default_op_checks(node, 1, {"LeakyRelu", "LEAKY_RELU"});
auto features = node.get_input(0);
auto alpha = node.get_attribute<float>("alpha", 0.2f);
auto alpha_const = make_shared<Constant>(element::f32, Shape{1}, alpha);
auto leaky_relu = make_shared<PRelu>(features, alpha_const);
auto alpha_const = make_shared<v0::Constant>(element::f32, Shape{1}, alpha);
auto leaky_relu = make_shared<v0::PRelu>(features, alpha_const);
set_node_name(node.get_name(), leaky_relu);
return {leaky_relu};
}
@@ -3,11 +3,16 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/convert_like.hpp"
#include "openvino/op/divide.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/range.hpp"
#include "openvino/op/subtract.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -23,20 +28,20 @@ OutputVector translate_linspace_op(const NodeContext& node) {
// compute delta value, i.e. distance between neighbor values of the result
auto const_one = create_same_type_const_scalar<int32_t>(num, 1);
Output<Node> num_minus_one = make_shared<Subtract>(num, const_one);
num_minus_one = make_shared<ConvertLike>(num_minus_one, start);
Output<Node> delta = make_shared<Subtract>(stop, start);
delta = make_shared<Divide>(delta, num_minus_one);
Output<Node> num_minus_one = make_shared<v1::Subtract>(num, const_one);
num_minus_one = make_shared<v1::ConvertLike>(num_minus_one, start);
Output<Node> delta = make_shared<v1::Subtract>(stop, start);
delta = make_shared<v1::Divide>(delta, num_minus_one);
// generate a range of numbers [0, 1, ..., num)
// to have exact numbers of elements equal to num
auto const_zero = create_same_type_const_scalar<int32_t>(num, 0);
Output<Node> range0_n = make_shared<Range>(const_zero, num, const_one, ov::element::f32);
range0_n = make_shared<ConvertLike>(range0_n, start);
Output<Node> range0_n = make_shared<v4::Range>(const_zero, num, const_one, ov::element::f32);
range0_n = make_shared<v1::ConvertLike>(range0_n, start);
// compute the result
Output<Node> linspace = make_shared<Multiply>(range0_n, delta);
linspace = make_shared<Add>(linspace, start);
Output<Node> linspace = make_shared<v1::Multiply>(range0_n, delta);
linspace = make_shared<v1::Add>(linspace, start);
set_node_name(node.get_name(), linspace.get_node_shared_ptr());
return {linspace};
}
@@ -3,11 +3,18 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/equal.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/non_zero.hpp"
#include "openvino/op/reduce_logical_or.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/select.hpp"
#include "openvino/op/unsqueeze.hpp"
using namespace std;
using namespace ov;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -23,27 +30,27 @@ OutputVector translate_list_diff_op(const NodeContext& node) {
auto out_idx = node.get_attribute<element::Type>("out_idx", element::i32);
// unsqueeze both operand to make comparison elements between each other
auto const_zero = make_shared<Constant>(element::i32, Shape{1}, 0);
auto const_one = make_shared<Constant>(element::i32, Shape{1}, 1);
auto unsqueeze_x = make_shared<Unsqueeze>(x, const_one);
auto unsqueeze_y = make_shared<Unsqueeze>(y, const_zero);
auto const_zero = make_shared<v0::Constant>(element::i32, Shape{1}, 0);
auto const_one = make_shared<v0::Constant>(element::i32, Shape{1}, 1);
auto unsqueeze_x = make_shared<v0::Unsqueeze>(x, const_one);
auto unsqueeze_y = make_shared<v0::Unsqueeze>(y, const_zero);
// generate a mask where elements x and y are different
// compute 0-1 mask of elements in x that are absent in y
// 1 means element is absent in y, 0 - otherwise
auto equal = make_shared<Equal>(unsqueeze_x, unsqueeze_y);
auto reduce_axis = make_shared<Constant>(element::i32, ov::Shape{}, 1);
Output<Node> mask_01 = make_shared<ReduceLogicalOr>(equal, reduce_axis, false);
mask_01 = make_shared<Select>(mask_01, const_zero, const_one);
auto equal = make_shared<v1::Equal>(unsqueeze_x, unsqueeze_y);
auto reduce_axis = make_shared<v0::Constant>(element::i32, ov::Shape{}, 1);
Output<Node> mask_01 = make_shared<v1::ReduceLogicalOr>(equal, reduce_axis, false);
mask_01 = make_shared<v1::Select>(mask_01, const_zero, const_one);
// compute indices of x elements different from elements of y
// compute indices of elements in x that are absent in y
Output<Node> idx = make_shared<NonZero>(mask_01, out_idx);
auto new_shape = make_shared<Constant>(element::i32, Shape{1}, -1);
idx = make_shared<Reshape>(idx, new_shape, false);
Output<Node> idx = make_shared<v3::NonZero>(mask_01, out_idx);
auto new_shape = make_shared<v0::Constant>(element::i32, Shape{1}, -1);
idx = make_shared<v1::Reshape>(idx, new_shape, false);
// gather elements from x that are absent in y
auto out = make_shared<Gather>(x, idx, const_zero);
auto out = make_shared<v8::Gather>(x, idx, const_zero);
// set tensor names
set_out_name({node.get_name() + ":0"}, out);
@@ -3,11 +3,12 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/log.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -20,8 +21,8 @@ OutputVector translate_log_1p_op(const NodeContext& node) {
default_op_checks(node, 1, {"Log1p"});
auto x = node.get_input(0);
auto const_one = create_same_type_const_scalar<float>(x, 1);
auto x_plus_one = make_shared<Add>(x, const_one);
auto log1p = make_shared<Log>(x_plus_one);
auto x_plus_one = make_shared<v1::Add>(x, const_one);
auto log1p = make_shared<v0::Log>(x_plus_one);
set_node_name(node.get_name(), log1p);
return {log1p};
}
@@ -2,11 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/log_softmax.hpp"
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -16,7 +17,7 @@ namespace op {
OutputVector translate_log_softmax_op(const NodeContext& node) {
default_op_checks(node, 1, {"LogSoftmax", "LOG_SOFTMAX"});
auto logits = node.get_input(0);
auto log_softmax = make_shared<LogSoftmax>(logits, -1);
auto log_softmax = make_shared<v5::LogSoftmax>(logits, -1);
set_node_name(node.get_name(), log_softmax);
return {log_softmax};
}
@@ -2,12 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/lrn.hpp"
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/constant.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -38,9 +40,9 @@ OutputVector translate_lrn_op(const NodeContext& node) {
// the current implementation supports only the normalization across channel (axes={1})
// and spatial dimensions (axes={2,3})
// so we have to transpose inputs and outputs due to this limitation
auto axis = make_shared<Constant>(element::i32, Shape{1}, 1);
auto axis = make_shared<v0::Constant>(element::i32, Shape{1}, 1);
ov::frontend::tensorflow::convert_nhwc_to_nchw(true, input);
Output<Node> lrn = make_shared<LRN>(input, axis, alpha, beta, bias, attr_size);
Output<Node> lrn = make_shared<v0::LRN>(input, axis, alpha, beta, bias, attr_size);
ov::frontend::tensorflow::convert_nchw_to_nhwc(true, lrn);
set_node_name(node.get_name(), lrn.get_node_shared_ptr());
return {lrn};
@@ -3,12 +3,19 @@
//
#include "common_op_table.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/broadcast.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/strided_slice.hpp"
#include "openvino/op/unsqueeze.hpp"
#include "openvino/op/util/attr_types.hpp"
#include "openvino/opsets/opset8.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -34,56 +41,59 @@ OutputVector translate_matrix_diag_op(const NodeContext& node) {
// 1. unsqueeze to have at least three rank input of a shape [1, I, J, ..., M, N, 1]
// because dimensions [I, J, ..., M] can be absent
auto unsqueeze_axis = make_shared<Constant>(element::i64, Shape{2}, std::vector<int64_t>{0, -1});
auto unsqueeze_diag = make_shared<Unsqueeze>(diagonal, unsqueeze_axis);
auto unsqueeze_axis = make_shared<v0::Constant>(element::i64, Shape{2}, std::vector<int64_t>{0, -1});
auto unsqueeze_diag = make_shared<v0::Unsqueeze>(diagonal, unsqueeze_axis);
// 2. compute a size of the last dimension of the diagonal input of a shape [I, J, ..., M, N],
// i.e. N that will be diagonalized
auto unsqueeze_diag_shape = make_shared<ShapeOf>(unsqueeze_diag);
auto last_dim = make_shared<StridedSlice>(unsqueeze_diag_shape,
make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{-2}),
make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{-1}),
make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{1}),
std::vector<int64_t>({0}),
std::vector<int64_t>({0}));
auto unsqueeze_diag_shape = make_shared<v3::ShapeOf>(unsqueeze_diag);
auto last_dim =
make_shared<v1::StridedSlice>(unsqueeze_diag_shape,
make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{-2}),
make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{-1}),
make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1}),
std::vector<int64_t>({0}),
std::vector<int64_t>({0}));
// 3. generate a tensor of zeros of a shape [1, I, J, ..., M, N, N]
auto diag_shape = make_shared<ShapeOf>(diagonal);
auto one_dim = make_shared<Constant>(last_dim->get_element_type(), Shape{1}, std::vector<int64_t>{1});
auto padding_shape = make_shared<Concat>(OutputVector({one_dim, diag_shape, last_dim}), 0);
auto diag_shape = make_shared<v3::ShapeOf>(diagonal);
auto one_dim = make_shared<v0::Constant>(last_dim->get_element_type(), Shape{1}, std::vector<int64_t>{1});
auto padding_shape = make_shared<v0::Concat>(OutputVector({one_dim, diag_shape, last_dim}), 0);
auto padding =
make_shared<Broadcast>(make_shared<Constant>(diagonal_type, Shape{1}, std::vector<int64_t>{0}), padding_shape);
make_shared<v3::Broadcast>(make_shared<v0::Constant>(diagonal_type, Shape{1}, std::vector<int64_t>{0}),
padding_shape);
// 4. concatenate to get input tensor with zero padding of a shape [1, I, J, ..., M, N, N + 1]
auto zero_padded_diag = make_shared<Concat>(OutputVector({unsqueeze_diag, padding}), -1);
auto zero_padded_diag = make_shared<v0::Concat>(OutputVector({unsqueeze_diag, padding}), -1);
// reshape padded tensor to get a shape [I, J, ..., M, N * N + N]
// 4.1 retrieve a part of the shape value [1, I, J, ..., M]
auto new_shape_padded_diag1 =
make_shared<StridedSlice>(unsqueeze_diag_shape,
make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{0}),
make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{-2}),
make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{1}),
std::vector<int64_t>({0}),
std::vector<int64_t>({0}));
make_shared<v1::StridedSlice>(unsqueeze_diag_shape,
make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{0}),
make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{-2}),
make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1}),
std::vector<int64_t>({0}),
std::vector<int64_t>({0}));
// 4.2 compute the last part of a shape that is [N * N + N]
auto last_dim_squared = make_shared<Multiply>(last_dim, last_dim);
auto new_shape_padded_diag2 = make_shared<Add>(last_dim_squared, last_dim);
auto last_dim_squared = make_shared<v1::Multiply>(last_dim, last_dim);
auto new_shape_padded_diag2 = make_shared<v1::Add>(last_dim_squared, last_dim);
// 4.3 compute a new shape and reshape padded diagonal
auto new_shape_padded_diag = make_shared<Concat>(OutputVector({new_shape_padded_diag1, new_shape_padded_diag2}), 0);
auto reshaped_padded_diag = make_shared<Reshape>(zero_padded_diag, new_shape_padded_diag, false);
auto new_shape_padded_diag =
make_shared<v0::Concat>(OutputVector({new_shape_padded_diag1, new_shape_padded_diag2}), 0);
auto reshaped_padded_diag = make_shared<v1::Reshape>(zero_padded_diag, new_shape_padded_diag, false);
// 5. cut off padding in the reshaped padded tensor to get a shape [1, I, J, ..., M, N * N]
auto cut_padded_diag = make_shared<Slice>(
auto cut_padded_diag = make_shared<v8::Slice>(
reshaped_padded_diag,
make_shared<Constant>(last_dim_squared->get_element_type(), Shape{1}, std::vector<int64_t>{0}),
make_shared<v0::Constant>(last_dim_squared->get_element_type(), Shape{1}, std::vector<int64_t>{0}),
last_dim_squared,
make_shared<Constant>(last_dim_squared->get_element_type(), Shape{1}, std::vector<int64_t>{1}),
make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{-1}));
make_shared<v0::Constant>(last_dim_squared->get_element_type(), Shape{1}, std::vector<int64_t>{1}),
make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{-1}));
// 6. return the expected shape for the result [I, J, ..., M, N, N]
auto resulted_shape = make_shared<Concat>(OutputVector({diag_shape, last_dim}), 0);
auto resulted_diag = make_shared<Reshape>(cut_padded_diag, resulted_shape, false);
auto resulted_shape = make_shared<v0::Concat>(OutputVector({diag_shape, last_dim}), 0);
auto resulted_diag = make_shared<v1::Reshape>(cut_padded_diag, resulted_shape, false);
set_node_name(node.get_name(), resulted_diag);
return {resulted_diag};
@@ -3,10 +3,8 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
using namespace std;
using namespace ov::opset8;
namespace ov {
namespace frontend {
@@ -2,13 +2,21 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/non_max_suppression.hpp"
#include "common_op_table.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert_like.hpp"
#include "openvino/op/pad.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/slice.hpp"
#include "openvino/op/squeeze.hpp"
#include "openvino/op/unsqueeze.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov;
using namespace ov::opset10;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -19,22 +27,22 @@ Output<Node> normalize_selected_indices(const Output<Node>& ov_selected_indices,
bool pad_to_max_output_size) {
// OpenVINO NonMaxSuppression outputs selected_indices in a form [batch_index, class_index, box_index]
// but we need only box_index
auto start = make_shared<Constant>(element::i32, Shape{1}, 2);
auto stop = make_shared<Constant>(element::i32, Shape{1}, 3);
auto step = make_shared<Constant>(element::i32, Shape{1}, 1);
auto axis = make_shared<Constant>(element::i32, Shape{1}, 1);
Output<Node> selected_indices = make_shared<Slice>(ov_selected_indices, start, stop, step, axis)->output(0);
selected_indices = make_shared<Squeeze>(selected_indices, axis)->output(0);
auto start = make_shared<v0::Constant>(element::i32, Shape{1}, 2);
auto stop = make_shared<v0::Constant>(element::i32, Shape{1}, 3);
auto step = make_shared<v0::Constant>(element::i32, Shape{1}, 1);
auto axis = make_shared<v0::Constant>(element::i32, Shape{1}, 1);
Output<Node> selected_indices = make_shared<v8::Slice>(ov_selected_indices, start, stop, step, axis)->output(0);
selected_indices = make_shared<v0::Squeeze>(selected_indices, axis)->output(0);
if (pad_to_max_output_size) {
Output<Node> num_selected_indices = make_shared<ShapeOf>(selected_indices);
num_selected_indices = make_shared<ConvertLike>(num_selected_indices, max_output_size);
auto num_padded_elements = make_shared<Subtract>(max_output_size, num_selected_indices);
Output<Node> num_selected_indices = make_shared<v3::ShapeOf>(selected_indices);
num_selected_indices = make_shared<v1::ConvertLike>(num_selected_indices, max_output_size);
auto num_padded_elements = make_shared<v1::Subtract>(max_output_size, num_selected_indices);
auto pad_element = create_same_type_const_scalar<int64_t>(selected_indices, 0);
auto pads_begin = create_same_type_const<int64_t>(max_output_size, vector<int64_t>{0}, Shape{1});
auto pad_mode = ov::op::PadMode::CONSTANT;
selected_indices =
make_shared<Pad>(selected_indices, pads_begin, num_padded_elements, pad_element, pad_mode)->output(0);
make_shared<v1::Pad>(selected_indices, pads_begin, num_padded_elements, pad_element, pad_mode)->output(0);
}
return selected_indices;
@@ -55,21 +63,21 @@ NamedOutputVector translate_non_max_suppression_op(const NodeContext& node) {
// prepare boxes: in TensorFlow NonMaxSuppression operation there is no batch dimension
// so we need to introduce it to be aligned with OpenVINO NonMaxSuppression
// boxes of shape [num_batches, num_boxes, 4]
auto boxes_axis = make_shared<Constant>(element::i32, Shape{1}, 0);
auto ov_boxes = make_shared<Unsqueeze>(boxes, boxes_axis);
auto boxes_axis = make_shared<v0::Constant>(element::i32, Shape{1}, 0);
auto ov_boxes = make_shared<v0::Unsqueeze>(boxes, boxes_axis);
// prepare scores: in TensorFlow NonMaxSuppression operation there is no batch and class dimensions
// so we need to introduce them to be aligned with OpenVINO NonMaxSuppression scores
// of shape [num_batches, num_classes, num_boxes]
auto scores_axes = make_shared<Constant>(element::i32, Shape{2}, vector<int32_t>{0, 1});
auto ov_scores = make_shared<Unsqueeze>(scores, scores_axes);
auto scores_axes = make_shared<v0::Constant>(element::i32, Shape{2}, vector<int32_t>{0, 1});
auto ov_scores = make_shared<v0::Unsqueeze>(scores, scores_axes);
const auto& op_type = node.get_op_type();
// set all thresholds to zero, default values
Output<Node> iou_threshold = make_shared<Constant>(element::f32, Shape{}, 0.0);
Output<Node> score_threshold = make_shared<Constant>(element::f32, Shape{}, 0.0);
Output<Node> soft_nms_sigma = make_shared<Constant>(element::f32, Shape{}, 0.0);
Output<Node> iou_threshold = make_shared<v0::Constant>(element::f32, Shape{}, 0.0);
Output<Node> score_threshold = make_shared<v0::Constant>(element::f32, Shape{}, 0.0);
Output<Node> soft_nms_sigma = make_shared<v0::Constant>(element::f32, Shape{}, 0.0);
bool pad_to_max_output_size = false;
bool valid_outputs = false;
bool selected_scores = false;
@@ -77,7 +85,7 @@ NamedOutputVector translate_non_max_suppression_op(const NodeContext& node) {
// NonMaxSuppression has three inputs and one output, selected indices
// iou_threshold comes as attribute
auto iou_threshold_value = node.get_attribute<float>("iou_threshold", 0.5);
iou_threshold = make_shared<Constant>(element::f32, Shape{}, iou_threshold_value);
iou_threshold = make_shared<v0::Constant>(element::f32, Shape{}, iou_threshold_value);
} else if (op_type == "NonMaxSuppressionV2") {
// NonMaxSuppressionV2 has four inputs and one output, selected indices
// iou_threshold comes as input
@@ -112,15 +120,15 @@ NamedOutputVector translate_non_max_suppression_op(const NodeContext& node) {
TENSORFLOW_OP_VALIDATION(node, false, "Internal error TensorFlow Frontend: no translator for " + op_type);
}
auto non_max_suppression = make_shared<NonMaxSuppression>(ov_boxes,
ov_scores,
max_output_size,
iou_threshold,
score_threshold,
soft_nms_sigma,
NonMaxSuppression::BoxEncodingType::CORNER,
false,
element::i32);
auto non_max_suppression = make_shared<v9::NonMaxSuppression>(ov_boxes,
ov_scores,
max_output_size,
iou_threshold,
score_threshold,
soft_nms_sigma,
v9::NonMaxSuppression::BoxEncodingType::CORNER,
false,
element::i32);
auto tf_selected_indices =
normalize_selected_indices(non_max_suppression->output(0), max_output_size, pad_to_max_output_size);
@@ -131,14 +139,14 @@ NamedOutputVector translate_non_max_suppression_op(const NodeContext& node) {
if (selected_scores) {
tf_selected_scores =
normalize_selected_indices(non_max_suppression->output(1), max_output_size, pad_to_max_output_size);
tf_selected_scores = make_shared<ConvertLike>(tf_selected_scores, boxes)->output(0);
tf_selected_scores = make_shared<v1::ConvertLike>(tf_selected_scores, boxes)->output(0);
named_results.push_back({"selected_scores", tf_selected_scores});
}
Output<Node> tf_valid_outputs;
if (valid_outputs) {
// In TensorFlow valid_outputs output is a scalar
tf_valid_outputs = make_shared<Squeeze>(non_max_suppression->output(2))->output(0);
tf_valid_outputs = make_shared<v0::Squeeze>(non_max_suppression->output(2))->output(0);
named_results.push_back({"valid_outputs", tf_valid_outputs});
}
@@ -2,11 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/one_hot.hpp"
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -21,7 +22,7 @@ OutputVector translate_one_hot_op(const NodeContext& node) {
auto off_value = node.get_input(3);
auto axis = node.get_attribute<int64_t>("axis", -1);
auto one_hot = make_shared<OneHot>(indices, depth, on_value, off_value, axis);
auto one_hot = make_shared<v1::OneHot>(indices, depth, on_value, off_value, axis);
set_node_name(node.get_name(), one_hot);
return {one_hot};
}
@@ -3,10 +3,12 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/unsqueeze.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -18,15 +20,15 @@ OutputVector translate_pack_op(const NodeContext& node) {
auto num_size = static_cast<int>(node.get_input_size());
auto axis = node.get_attribute<int64_t>("axis", 0);
auto axis_const = make_shared<Constant>(element::i64, Shape{}, axis);
auto axis_const = make_shared<v0::Constant>(element::i64, Shape{}, axis);
OutputVector concat_inputs;
for (int ind = 0; ind < num_size; ++ind) {
auto in = node.get_input(ind);
concat_inputs.push_back(make_shared<Unsqueeze>(in, axis_const));
concat_inputs.push_back(make_shared<v0::Unsqueeze>(in, axis_const));
}
auto pack = make_shared<Concat>(concat_inputs, axis);
auto pack = make_shared<v0::Concat>(concat_inputs, axis);
set_node_name(node.get_name(), pack);
return {pack};
}
+14 -10
View File
@@ -2,13 +2,17 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/pad.hpp"
#include "common_op_table.hpp"
#include "openvino/opsets/opset9.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/gather.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov;
using namespace ov::opset9;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -18,12 +22,12 @@ static void slice_pads_begin_end(const Output<Node>& paddings,
shared_ptr<Node>& pads_begin,
shared_ptr<Node>& pads_end) {
// TODO: fix IR reader to accept padding of i32 type
auto paddings_i64 = make_shared<Convert>(paddings, element::i64);
auto axis = make_shared<Constant>(element::i32, Shape{}, 1);
auto index_zero = make_shared<Constant>(element::i32, Shape{}, 0);
auto index_one = make_shared<Constant>(element::i32, Shape{}, 1);
pads_begin = make_shared<Gather>(paddings_i64, index_zero, axis);
pads_end = make_shared<Gather>(paddings_i64, index_one, axis);
auto paddings_i64 = make_shared<v0::Convert>(paddings, element::i64);
auto axis = make_shared<v0::Constant>(element::i32, Shape{}, 1);
auto index_zero = make_shared<v0::Constant>(element::i32, Shape{}, 0);
auto index_one = make_shared<v0::Constant>(element::i32, Shape{}, 1);
pads_begin = make_shared<v8::Gather>(paddings_i64, index_zero, axis);
pads_end = make_shared<v8::Gather>(paddings_i64, index_one, axis);
}
static OutputVector translate_pad_base_op(const NodeContext& node,
@@ -36,7 +40,7 @@ static OutputVector translate_pad_base_op(const NodeContext& node,
shared_ptr<Node> pads_begin, pads_end;
slice_pads_begin_end(paddings, pads_begin, pads_end);
auto pad = make_shared<Pad>(input, pads_begin, pads_end, constant_value, pad_mode);
auto pad = make_shared<v1::Pad>(input, pads_begin, pads_end, constant_value, pad_mode);
set_node_name(node.get_name(), pad);
return {pad};
}
@@ -72,7 +76,7 @@ OutputVector translate_mirror_pad_op(const NodeContext& node) {
shared_ptr<Node> pads_begin, pads_end;
slice_pads_begin_end(paddings, pads_begin, pads_end);
auto pad = make_shared<Pad>(input, pads_begin, pads_end, pad_mode);
auto pad = make_shared<v1::Pad>(input, pads_begin, pads_end, pad_mode);
set_node_name(node.get_name(), pad);
return {pad};
}
@@ -3,11 +3,19 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset9.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/broadcast.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/reduce_max.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/scatter_update.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/slice.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov::opset9;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -27,9 +35,9 @@ OutputVector translate_parallel_dynamic_stitch_op(const NodeContext& node) {
int N = static_cast<int>(in_size / 2);
OutputVector indices_to_concat;
OutputVector data_to_concat;
auto const_minus_one = make_shared<Constant>(ov::element::i32, Shape{1}, -1);
auto const_zero = make_shared<Constant>(ov::element::i32, Shape{1}, 0);
auto const_one = make_shared<Constant>(ov::element::i32, Shape{1}, 1);
auto const_minus_one = make_shared<v0::Constant>(ov::element::i32, Shape{1}, -1);
auto const_zero = make_shared<v0::Constant>(ov::element::i32, Shape{1}, 0);
auto const_one = make_shared<v0::Constant>(ov::element::i32, Shape{1}, 1);
for (int i = 0; i < N; ++i) {
auto indices = node.get_input(i);
auto data = node.get_input(N + i);
@@ -40,33 +48,33 @@ OutputVector translate_parallel_dynamic_stitch_op(const NodeContext& node) {
indices_pshape.rank().is_static(),
"Only static rank for `indices` input is supported.");
auto rank_val = rank.get_length();
auto norm_indices = make_shared<Reshape>(indices, const_minus_one, false);
auto norm_indices = make_shared<v1::Reshape>(indices, const_minus_one, false);
if (rank_val < 1) {
data = make_shared<Unsqueeze>(data, const_zero);
data = make_shared<v0::Unsqueeze>(data, const_zero);
} else if (rank_val > 1) {
auto data_shape = make_shared<ShapeOf>(data, ov::element::i32);
auto start = make_shared<Constant>(ov::element::i32, Shape{1}, rank_val);
auto stop = make_shared<Constant>(ov::element::i32, Shape{1}, numeric_limits<int>::max());
auto shape_of_single_element = make_shared<Slice>(data_shape, start, stop, const_one);
auto new_shape = make_shared<Concat>(OutputVector{const_minus_one, shape_of_single_element}, 0);
data = make_shared<Reshape>(data, new_shape, false);
auto data_shape = make_shared<v3::ShapeOf>(data, ov::element::i32);
auto start = make_shared<v0::Constant>(ov::element::i32, Shape{1}, rank_val);
auto stop = make_shared<v0::Constant>(ov::element::i32, Shape{1}, numeric_limits<int>::max());
auto shape_of_single_element = make_shared<v8::Slice>(data_shape, start, stop, const_one);
auto new_shape = make_shared<v0::Concat>(OutputVector{const_minus_one, shape_of_single_element}, 0);
data = make_shared<v1::Reshape>(data, new_shape, false);
}
data_to_concat.push_back(data);
indices_to_concat.push_back(norm_indices);
}
auto update = make_shared<Concat>(data_to_concat, 0);
auto indices = make_shared<Concat>(indices_to_concat, 0);
auto data_shape = make_shared<ShapeOf>(update, ov::element::i32);
auto update = make_shared<v0::Concat>(data_to_concat, 0);
auto indices = make_shared<v0::Concat>(indices_to_concat, 0);
auto data_shape = make_shared<v3::ShapeOf>(update, ov::element::i32);
auto zero = create_same_type_const_scalar<int32_t>(node.get_input(N), 0);
auto zeros = make_shared<Broadcast>(zero, data_shape);
auto max_idx = make_shared<ReduceMax>(indices, Constant::create(element::i32, {1}, {0}), true);
auto stop = make_shared<Add>(max_idx->output(0), const_one);
auto start = make_shared<Constant>(ov::element::i32, Shape{1}, 0);
auto axis = make_shared<Constant>(ov::element::i32, Shape{1}, 0);
auto sliced_zeros = make_shared<Slice>(zeros, start, stop, const_one, axis);
auto zeros = make_shared<v3::Broadcast>(zero, data_shape);
auto max_idx = make_shared<v1::ReduceMax>(indices, v0::Constant::create(element::i32, {1}, {0}), true);
auto stop = make_shared<v1::Add>(max_idx->output(0), const_one);
auto start = make_shared<v0::Constant>(ov::element::i32, Shape{1}, 0);
auto axis = make_shared<v0::Constant>(ov::element::i32, Shape{1}, 0);
auto sliced_zeros = make_shared<v8::Slice>(zeros, start, stop, const_one, axis);
auto result = make_shared<ScatterUpdate>(sliced_zeros, indices, update, const_zero);
auto result = make_shared<v3::ScatterUpdate>(sliced_zeros, indices, update, const_zero);
set_node_name(node.get_name(), result);
return result->outputs();
}