Add SLT to Template Plugin: NonMaxSuppression-4,3,1 (#9511)
* Add SLT to Template Plugin: NonMaxSuppression-4 * Add SLT to Template Plugin: NonMaxSuppression-4,3,1
This commit is contained in:
parent
35bcb77182
commit
a23a398dc0
@ -828,7 +828,6 @@ InfoForNMS5 get_info_for_nms5_eval(const std::shared_ptr<op::v5::NonMaxSuppressi
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace nms_v5
|
} // namespace nms_v5
|
||||||
|
|
||||||
template <element::Type_t ET>
|
template <element::Type_t ET>
|
||||||
@ -867,6 +866,519 @@ bool evaluate(const shared_ptr<op::v5::NonMaxSuppression>& op,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace nms_v4 {
|
||||||
|
using V4BoxEncoding = op::v4::NonMaxSuppression::BoxEncodingType;
|
||||||
|
|
||||||
|
struct InfoForNMS4 {
|
||||||
|
int64_t max_output_boxes_per_class;
|
||||||
|
float iou_threshold;
|
||||||
|
float score_threshold;
|
||||||
|
float soft_nms_sigma;
|
||||||
|
Shape out_shape;
|
||||||
|
Shape boxes_shape;
|
||||||
|
Shape scores_shape;
|
||||||
|
std::vector<float> boxes_data;
|
||||||
|
std::vector<float> scores_data;
|
||||||
|
size_t out_shape_size;
|
||||||
|
bool sort_result_descending;
|
||||||
|
ngraph::element::Type output_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t boxes_port = 0;
|
||||||
|
constexpr size_t scores_port = 1;
|
||||||
|
|
||||||
|
PartialShape infer_selected_indices_shape(const std::vector<std::shared_ptr<HostTensor>>& inputs,
|
||||||
|
int64_t max_output_boxes_per_class) {
|
||||||
|
const auto boxes_ps = inputs[boxes_port]->get_partial_shape();
|
||||||
|
const auto scores_ps = inputs[scores_port]->get_partial_shape();
|
||||||
|
|
||||||
|
// NonMaxSuppression produces triplets
|
||||||
|
// that have the following format: [batch_index, class_index, box_index]
|
||||||
|
PartialShape result = {Dimension::dynamic(), 3};
|
||||||
|
|
||||||
|
if (boxes_ps.rank().is_static() && scores_ps.rank().is_static()) {
|
||||||
|
const auto num_boxes_boxes = boxes_ps[1];
|
||||||
|
if (num_boxes_boxes.is_static() && scores_ps[0].is_static() && scores_ps[1].is_static()) {
|
||||||
|
const auto num_boxes = num_boxes_boxes.get_length();
|
||||||
|
const auto num_classes = scores_ps[1].get_length();
|
||||||
|
|
||||||
|
result[0] = std::min(num_boxes, max_output_boxes_per_class) * num_classes * scores_ps[0].get_length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_corner(float* boxes, const Shape& boxes_shape) {
|
||||||
|
size_t total_num_of_boxes = shape_size(boxes_shape) / 4;
|
||||||
|
for (size_t i = 0; i < total_num_of_boxes; ++i) {
|
||||||
|
float* current_box = boxes + 4 * i;
|
||||||
|
|
||||||
|
float y1 = current_box[0];
|
||||||
|
float x1 = current_box[1];
|
||||||
|
float y2 = current_box[2];
|
||||||
|
float x2 = current_box[3];
|
||||||
|
|
||||||
|
float ymin = std::min(y1, y2);
|
||||||
|
float ymax = std::max(y1, y2);
|
||||||
|
float xmin = std::min(x1, x2);
|
||||||
|
float xmax = std::max(x1, x2);
|
||||||
|
|
||||||
|
current_box[0] = ymin;
|
||||||
|
current_box[1] = xmin;
|
||||||
|
current_box[2] = ymax;
|
||||||
|
current_box[3] = xmax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_center(float* boxes, const Shape& boxes_shape) {
|
||||||
|
size_t total_num_of_boxes = shape_size(boxes_shape) / 4;
|
||||||
|
for (size_t i = 0; i < total_num_of_boxes; ++i) {
|
||||||
|
float* current_box = boxes + 4 * i;
|
||||||
|
|
||||||
|
float x_center = current_box[0];
|
||||||
|
float y_center = current_box[1];
|
||||||
|
float width = current_box[2];
|
||||||
|
float height = current_box[3];
|
||||||
|
|
||||||
|
float y1 = y_center - height / 2.0;
|
||||||
|
float x1 = x_center - width / 2.0;
|
||||||
|
float y2 = y_center + height / 2.0;
|
||||||
|
float x2 = x_center + width / 2.0;
|
||||||
|
|
||||||
|
current_box[0] = y1;
|
||||||
|
current_box[1] = x1;
|
||||||
|
current_box[2] = y2;
|
||||||
|
current_box[3] = x2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_box_encoding(float* boxes, const Shape& boxes_shape, const V4BoxEncoding box_encoding) {
|
||||||
|
if (box_encoding == V4BoxEncoding::CORNER) {
|
||||||
|
normalize_corner(boxes, boxes_shape);
|
||||||
|
} else {
|
||||||
|
normalize_center(boxes, boxes_shape);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> prepare_boxes_data(const std::shared_ptr<HostTensor>& boxes,
|
||||||
|
const Shape& boxes_shape,
|
||||||
|
const V4BoxEncoding box_encoding) {
|
||||||
|
auto result = get_floats(boxes, boxes_shape);
|
||||||
|
normalize_box_encoding(result.data(), boxes_shape, box_encoding);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> prepare_scores_data(const std::shared_ptr<HostTensor>& scores, const Shape& scores_shape) {
|
||||||
|
auto result = get_floats(scores, scores_shape);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoForNMS4 get_info_for_nms4_eval(const std::shared_ptr<op::v4::NonMaxSuppression>& nms4,
|
||||||
|
const std::vector<std::shared_ptr<HostTensor>>& inputs) {
|
||||||
|
InfoForNMS4 result;
|
||||||
|
|
||||||
|
result.max_output_boxes_per_class = inputs.size() > 2 ? get_integers(inputs[2], Shape({}))[0] : 0;
|
||||||
|
result.iou_threshold = inputs.size() > 3 ? get_floats(inputs[3], Shape({}))[0] : 0.0f;
|
||||||
|
result.score_threshold = inputs.size() > 4 ? get_floats(inputs[4], Shape({}))[0] : 0.0f;
|
||||||
|
result.soft_nms_sigma = inputs.size() > 5 ? get_floats(inputs[5], Shape({}))[0] : 0.0f;
|
||||||
|
|
||||||
|
auto selected_indices_shape = infer_selected_indices_shape(inputs, result.max_output_boxes_per_class);
|
||||||
|
result.out_shape = selected_indices_shape.to_shape();
|
||||||
|
|
||||||
|
result.boxes_shape = inputs[boxes_port]->get_shape();
|
||||||
|
result.scores_shape = inputs[scores_port]->get_shape();
|
||||||
|
|
||||||
|
result.boxes_data = prepare_boxes_data(inputs[boxes_port], result.boxes_shape, nms4->get_box_encoding());
|
||||||
|
result.scores_data = prepare_scores_data(inputs[scores_port], result.scores_shape);
|
||||||
|
|
||||||
|
result.out_shape_size = shape_size(result.out_shape);
|
||||||
|
|
||||||
|
result.sort_result_descending = nms4->get_sort_result_descending();
|
||||||
|
|
||||||
|
result.output_type = nms4->get_output_type();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace nms_v4
|
||||||
|
|
||||||
|
template <element::Type_t ET>
|
||||||
|
bool evaluate(const shared_ptr<op::v4::NonMaxSuppression>& op,
|
||||||
|
const HostTensorVector& outputs,
|
||||||
|
const HostTensorVector& inputs) {
|
||||||
|
auto info = nms_v4::get_info_for_nms4_eval(op, inputs);
|
||||||
|
|
||||||
|
std::vector<int64_t> selected_indices(info.out_shape_size);
|
||||||
|
std::vector<float> selected_scores(info.out_shape_size);
|
||||||
|
int64_t valid_outputs = 0;
|
||||||
|
|
||||||
|
runtime::reference::non_max_suppression(info.boxes_data.data(),
|
||||||
|
info.boxes_shape,
|
||||||
|
info.scores_data.data(),
|
||||||
|
info.scores_shape,
|
||||||
|
info.max_output_boxes_per_class,
|
||||||
|
info.iou_threshold,
|
||||||
|
info.score_threshold,
|
||||||
|
info.soft_nms_sigma,
|
||||||
|
selected_indices.data(),
|
||||||
|
info.out_shape,
|
||||||
|
selected_scores.data(),
|
||||||
|
info.out_shape,
|
||||||
|
&valid_outputs,
|
||||||
|
info.sort_result_descending);
|
||||||
|
|
||||||
|
auto selected_scores_type = (inputs.size() < 4) ? element::f32 : inputs[3]->get_element_type();
|
||||||
|
|
||||||
|
runtime::reference::nms5_postprocessing(outputs,
|
||||||
|
info.output_type,
|
||||||
|
selected_indices,
|
||||||
|
selected_scores,
|
||||||
|
valid_outputs,
|
||||||
|
selected_scores_type);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace nms_v3 {
|
||||||
|
using V3BoxEncoding = op::v3::NonMaxSuppression::BoxEncodingType;
|
||||||
|
|
||||||
|
struct InfoForNMS3 {
|
||||||
|
int64_t max_output_boxes_per_class;
|
||||||
|
float iou_threshold;
|
||||||
|
float score_threshold;
|
||||||
|
float soft_nms_sigma;
|
||||||
|
Shape out_shape;
|
||||||
|
Shape boxes_shape;
|
||||||
|
Shape scores_shape;
|
||||||
|
std::vector<float> boxes_data;
|
||||||
|
std::vector<float> scores_data;
|
||||||
|
size_t out_shape_size;
|
||||||
|
bool sort_result_descending;
|
||||||
|
ngraph::element::Type output_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t boxes_port = 0;
|
||||||
|
constexpr size_t scores_port = 1;
|
||||||
|
|
||||||
|
PartialShape infer_selected_indices_shape(const std::vector<std::shared_ptr<HostTensor>>& inputs,
|
||||||
|
int64_t max_output_boxes_per_class) {
|
||||||
|
const auto boxes_ps = inputs[boxes_port]->get_partial_shape();
|
||||||
|
const auto scores_ps = inputs[scores_port]->get_partial_shape();
|
||||||
|
|
||||||
|
// NonMaxSuppression produces triplets
|
||||||
|
// that have the following format: [batch_index, class_index, box_index]
|
||||||
|
PartialShape result = {Dimension::dynamic(), 3};
|
||||||
|
|
||||||
|
if (boxes_ps.rank().is_static() && scores_ps.rank().is_static()) {
|
||||||
|
const auto num_boxes_boxes = boxes_ps[1];
|
||||||
|
if (num_boxes_boxes.is_static() && scores_ps[0].is_static() && scores_ps[1].is_static()) {
|
||||||
|
const auto num_boxes = num_boxes_boxes.get_length();
|
||||||
|
const auto num_classes = scores_ps[1].get_length();
|
||||||
|
|
||||||
|
result[0] = std::min(num_boxes, max_output_boxes_per_class * num_classes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_corner(float* boxes, const Shape& boxes_shape) {
|
||||||
|
size_t total_num_of_boxes = shape_size(boxes_shape) / 4;
|
||||||
|
for (size_t i = 0; i < total_num_of_boxes; ++i) {
|
||||||
|
float* current_box = boxes + 4 * i;
|
||||||
|
|
||||||
|
float y1 = current_box[0];
|
||||||
|
float x1 = current_box[1];
|
||||||
|
float y2 = current_box[2];
|
||||||
|
float x2 = current_box[3];
|
||||||
|
|
||||||
|
float ymin = std::min(y1, y2);
|
||||||
|
float ymax = std::max(y1, y2);
|
||||||
|
float xmin = std::min(x1, x2);
|
||||||
|
float xmax = std::max(x1, x2);
|
||||||
|
|
||||||
|
current_box[0] = ymin;
|
||||||
|
current_box[1] = xmin;
|
||||||
|
current_box[2] = ymax;
|
||||||
|
current_box[3] = xmax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_center(float* boxes, const Shape& boxes_shape) {
|
||||||
|
size_t total_num_of_boxes = shape_size(boxes_shape) / 4;
|
||||||
|
for (size_t i = 0; i < total_num_of_boxes; ++i) {
|
||||||
|
float* current_box = boxes + 4 * i;
|
||||||
|
|
||||||
|
float x_center = current_box[0];
|
||||||
|
float y_center = current_box[1];
|
||||||
|
float width = current_box[2];
|
||||||
|
float height = current_box[3];
|
||||||
|
|
||||||
|
float y1 = y_center - height / 2.0;
|
||||||
|
float x1 = x_center - width / 2.0;
|
||||||
|
float y2 = y_center + height / 2.0;
|
||||||
|
float x2 = x_center + width / 2.0;
|
||||||
|
|
||||||
|
current_box[0] = y1;
|
||||||
|
current_box[1] = x1;
|
||||||
|
current_box[2] = y2;
|
||||||
|
current_box[3] = x2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_box_encoding(float* boxes, const Shape& boxes_shape, const V3BoxEncoding box_encoding) {
|
||||||
|
if (box_encoding == V3BoxEncoding::CORNER) {
|
||||||
|
normalize_corner(boxes, boxes_shape);
|
||||||
|
} else {
|
||||||
|
normalize_center(boxes, boxes_shape);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> prepare_boxes_data(const std::shared_ptr<HostTensor>& boxes,
|
||||||
|
const Shape& boxes_shape,
|
||||||
|
const V3BoxEncoding box_encoding) {
|
||||||
|
auto result = get_floats(boxes, boxes_shape);
|
||||||
|
normalize_box_encoding(result.data(), boxes_shape, box_encoding);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> prepare_scores_data(const std::shared_ptr<HostTensor>& scores, const Shape& scores_shape) {
|
||||||
|
auto result = get_floats(scores, scores_shape);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoForNMS3 get_info_for_nms3_eval(const std::shared_ptr<op::v3::NonMaxSuppression>& nms3,
|
||||||
|
const std::vector<std::shared_ptr<HostTensor>>& inputs) {
|
||||||
|
InfoForNMS3 result;
|
||||||
|
|
||||||
|
result.max_output_boxes_per_class = inputs.size() > 2 ? get_integers(inputs[2], Shape({}))[0] : 0;
|
||||||
|
result.iou_threshold = inputs.size() > 3 ? get_floats(inputs[3], Shape({}))[0] : 0.0f;
|
||||||
|
result.score_threshold = inputs.size() > 4 ? get_floats(inputs[4], Shape({}))[0] : 0.0f;
|
||||||
|
result.soft_nms_sigma = inputs.size() > 5 ? get_floats(inputs[5], Shape({}))[0] : 0.0f;
|
||||||
|
|
||||||
|
auto selected_indices_shape = infer_selected_indices_shape(inputs, result.max_output_boxes_per_class);
|
||||||
|
result.out_shape = selected_indices_shape.to_shape();
|
||||||
|
|
||||||
|
result.boxes_shape = inputs[boxes_port]->get_shape();
|
||||||
|
result.scores_shape = inputs[scores_port]->get_shape();
|
||||||
|
|
||||||
|
result.boxes_data = prepare_boxes_data(inputs[boxes_port], result.boxes_shape, nms3->get_box_encoding());
|
||||||
|
result.scores_data = prepare_scores_data(inputs[scores_port], result.scores_shape);
|
||||||
|
|
||||||
|
result.out_shape_size = shape_size(result.out_shape);
|
||||||
|
|
||||||
|
result.sort_result_descending = nms3->get_sort_result_descending();
|
||||||
|
|
||||||
|
result.output_type = nms3->get_output_type();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace nms_v3
|
||||||
|
|
||||||
|
template <element::Type_t ET>
|
||||||
|
bool evaluate(const shared_ptr<op::v3::NonMaxSuppression>& op,
|
||||||
|
const HostTensorVector& outputs,
|
||||||
|
const HostTensorVector& inputs) {
|
||||||
|
auto info = nms_v3::get_info_for_nms3_eval(op, inputs);
|
||||||
|
|
||||||
|
std::vector<int64_t> selected_indices(info.out_shape_size);
|
||||||
|
std::vector<float> selected_scores(info.out_shape_size);
|
||||||
|
int64_t valid_outputs = 0;
|
||||||
|
|
||||||
|
runtime::reference::non_max_suppression(info.boxes_data.data(),
|
||||||
|
info.boxes_shape,
|
||||||
|
info.scores_data.data(),
|
||||||
|
info.scores_shape,
|
||||||
|
info.max_output_boxes_per_class,
|
||||||
|
info.iou_threshold,
|
||||||
|
info.score_threshold,
|
||||||
|
info.soft_nms_sigma,
|
||||||
|
selected_indices.data(),
|
||||||
|
info.out_shape,
|
||||||
|
selected_scores.data(),
|
||||||
|
info.out_shape,
|
||||||
|
&valid_outputs,
|
||||||
|
info.sort_result_descending);
|
||||||
|
|
||||||
|
auto selected_scores_type = (inputs.size() < 4) ? element::f32 : inputs[3]->get_element_type();
|
||||||
|
|
||||||
|
runtime::reference::nms5_postprocessing(outputs,
|
||||||
|
info.output_type,
|
||||||
|
selected_indices,
|
||||||
|
selected_scores,
|
||||||
|
valid_outputs,
|
||||||
|
selected_scores_type);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace nms_v1 {
|
||||||
|
using V1BoxEncoding = op::v1::NonMaxSuppression::BoxEncodingType;
|
||||||
|
|
||||||
|
struct InfoForNMS1 {
|
||||||
|
int64_t max_output_boxes_per_class;
|
||||||
|
float iou_threshold;
|
||||||
|
float score_threshold;
|
||||||
|
float soft_nms_sigma;
|
||||||
|
Shape out_shape;
|
||||||
|
Shape boxes_shape;
|
||||||
|
Shape scores_shape;
|
||||||
|
std::vector<float> boxes_data;
|
||||||
|
std::vector<float> scores_data;
|
||||||
|
size_t out_shape_size;
|
||||||
|
bool sort_result_descending;
|
||||||
|
ngraph::element::Type output_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t boxes_port = 0;
|
||||||
|
constexpr size_t scores_port = 1;
|
||||||
|
|
||||||
|
PartialShape infer_selected_indices_shape(const std::vector<std::shared_ptr<HostTensor>>& inputs,
|
||||||
|
int64_t max_output_boxes_per_class) {
|
||||||
|
const auto boxes_ps = inputs[boxes_port]->get_partial_shape();
|
||||||
|
const auto scores_ps = inputs[scores_port]->get_partial_shape();
|
||||||
|
|
||||||
|
// NonMaxSuppression produces triplets
|
||||||
|
// that have the following format: [batch_index, class_index, box_index]
|
||||||
|
PartialShape result = {Dimension::dynamic(), 3};
|
||||||
|
|
||||||
|
if (boxes_ps.rank().is_static() && scores_ps.rank().is_static()) {
|
||||||
|
const auto num_boxes_boxes = boxes_ps[1];
|
||||||
|
if (num_boxes_boxes.is_static() && scores_ps[0].is_static() && scores_ps[1].is_static()) {
|
||||||
|
const auto num_boxes = num_boxes_boxes.get_length();
|
||||||
|
const auto num_classes = scores_ps[1].get_length();
|
||||||
|
|
||||||
|
result[0] = std::min(num_boxes, max_output_boxes_per_class * num_classes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_corner(float* boxes, const Shape& boxes_shape) {
|
||||||
|
size_t total_num_of_boxes = shape_size(boxes_shape) / 4;
|
||||||
|
for (size_t i = 0; i < total_num_of_boxes; ++i) {
|
||||||
|
float* current_box = boxes + 4 * i;
|
||||||
|
|
||||||
|
float y1 = current_box[0];
|
||||||
|
float x1 = current_box[1];
|
||||||
|
float y2 = current_box[2];
|
||||||
|
float x2 = current_box[3];
|
||||||
|
|
||||||
|
float ymin = std::min(y1, y2);
|
||||||
|
float ymax = std::max(y1, y2);
|
||||||
|
float xmin = std::min(x1, x2);
|
||||||
|
float xmax = std::max(x1, x2);
|
||||||
|
|
||||||
|
current_box[0] = ymin;
|
||||||
|
current_box[1] = xmin;
|
||||||
|
current_box[2] = ymax;
|
||||||
|
current_box[3] = xmax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_center(float* boxes, const Shape& boxes_shape) {
|
||||||
|
size_t total_num_of_boxes = shape_size(boxes_shape) / 4;
|
||||||
|
for (size_t i = 0; i < total_num_of_boxes; ++i) {
|
||||||
|
float* current_box = boxes + 4 * i;
|
||||||
|
|
||||||
|
float x_center = current_box[0];
|
||||||
|
float y_center = current_box[1];
|
||||||
|
float width = current_box[2];
|
||||||
|
float height = current_box[3];
|
||||||
|
|
||||||
|
float y1 = y_center - height / 2.0;
|
||||||
|
float x1 = x_center - width / 2.0;
|
||||||
|
float y2 = y_center + height / 2.0;
|
||||||
|
float x2 = x_center + width / 2.0;
|
||||||
|
|
||||||
|
current_box[0] = y1;
|
||||||
|
current_box[1] = x1;
|
||||||
|
current_box[2] = y2;
|
||||||
|
current_box[3] = x2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize_box_encoding(float* boxes, const Shape& boxes_shape, const V1BoxEncoding box_encoding) {
|
||||||
|
if (box_encoding == V1BoxEncoding::CORNER) {
|
||||||
|
normalize_corner(boxes, boxes_shape);
|
||||||
|
} else {
|
||||||
|
normalize_center(boxes, boxes_shape);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> prepare_boxes_data(const std::shared_ptr<HostTensor>& boxes,
|
||||||
|
const Shape& boxes_shape,
|
||||||
|
const V1BoxEncoding box_encoding) {
|
||||||
|
auto result = get_floats(boxes, boxes_shape);
|
||||||
|
normalize_box_encoding(result.data(), boxes_shape, box_encoding);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> prepare_scores_data(const std::shared_ptr<HostTensor>& scores, const Shape& scores_shape) {
|
||||||
|
auto result = get_floats(scores, scores_shape);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoForNMS1 get_info_for_nms1_eval(const std::shared_ptr<op::v1::NonMaxSuppression>& nms1,
|
||||||
|
const std::vector<std::shared_ptr<HostTensor>>& inputs) {
|
||||||
|
InfoForNMS1 result;
|
||||||
|
|
||||||
|
result.max_output_boxes_per_class = inputs.size() > 2 ? get_integers(inputs[2], Shape({}))[0] : 0;
|
||||||
|
result.iou_threshold = inputs.size() > 3 ? get_floats(inputs[3], Shape({}))[0] : 0.0f;
|
||||||
|
result.score_threshold = inputs.size() > 4 ? get_floats(inputs[4], Shape({}))[0] : 0.0f;
|
||||||
|
result.soft_nms_sigma = inputs.size() > 5 ? get_floats(inputs[5], Shape({}))[0] : 0.0f;
|
||||||
|
|
||||||
|
auto selected_indices_shape = infer_selected_indices_shape(inputs, result.max_output_boxes_per_class);
|
||||||
|
result.out_shape = selected_indices_shape.to_shape();
|
||||||
|
|
||||||
|
result.boxes_shape = inputs[boxes_port]->get_shape();
|
||||||
|
result.scores_shape = inputs[scores_port]->get_shape();
|
||||||
|
|
||||||
|
result.boxes_data = prepare_boxes_data(inputs[boxes_port], result.boxes_shape, nms1->get_box_encoding());
|
||||||
|
result.scores_data = prepare_scores_data(inputs[scores_port], result.scores_shape);
|
||||||
|
|
||||||
|
result.out_shape_size = shape_size(result.out_shape);
|
||||||
|
|
||||||
|
result.sort_result_descending = nms1->get_sort_result_descending();
|
||||||
|
|
||||||
|
result.output_type = ov::element::i64;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace nms_v1
|
||||||
|
|
||||||
|
template <element::Type_t ET>
|
||||||
|
bool evaluate(const shared_ptr<op::v1::NonMaxSuppression>& op,
|
||||||
|
const HostTensorVector& outputs,
|
||||||
|
const HostTensorVector& inputs) {
|
||||||
|
auto info = nms_v1::get_info_for_nms1_eval(op, inputs);
|
||||||
|
|
||||||
|
std::vector<int64_t> selected_indices(info.out_shape_size);
|
||||||
|
std::vector<float> selected_scores(info.out_shape_size);
|
||||||
|
int64_t valid_outputs = 0;
|
||||||
|
|
||||||
|
runtime::reference::non_max_suppression(info.boxes_data.data(),
|
||||||
|
info.boxes_shape,
|
||||||
|
info.scores_data.data(),
|
||||||
|
info.scores_shape,
|
||||||
|
info.max_output_boxes_per_class,
|
||||||
|
info.iou_threshold,
|
||||||
|
info.score_threshold,
|
||||||
|
info.soft_nms_sigma,
|
||||||
|
selected_indices.data(),
|
||||||
|
info.out_shape,
|
||||||
|
selected_scores.data(),
|
||||||
|
info.out_shape,
|
||||||
|
&valid_outputs,
|
||||||
|
info.sort_result_descending);
|
||||||
|
|
||||||
|
auto selected_scores_type = (inputs.size() < 4) ? element::f32 : inputs[3]->get_element_type();
|
||||||
|
|
||||||
|
runtime::reference::nms5_postprocessing(outputs,
|
||||||
|
info.output_type,
|
||||||
|
selected_indices,
|
||||||
|
selected_scores,
|
||||||
|
valid_outputs,
|
||||||
|
selected_scores_type);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
namespace matrix_nms_v8 {
|
namespace matrix_nms_v8 {
|
||||||
using SortResultType = op::v8::MatrixNms::SortResultType;
|
using SortResultType = op::v8::MatrixNms::SortResultType;
|
||||||
struct InfoForNMS {
|
struct InfoForNMS {
|
||||||
|
@ -53,6 +53,7 @@ NGRAPH_OP(LogicalXor, op::v1)
|
|||||||
NGRAPH_OP(LogicalNot, op::v1)
|
NGRAPH_OP(LogicalNot, op::v1)
|
||||||
NGRAPH_OP(MaxPool, op::v1)
|
NGRAPH_OP(MaxPool, op::v1)
|
||||||
NGRAPH_OP(Mod, op::v1)
|
NGRAPH_OP(Mod, op::v1)
|
||||||
|
NGRAPH_OP(NonMaxSuppression, op::v1)
|
||||||
NGRAPH_OP(OneHot, op::v1)
|
NGRAPH_OP(OneHot, op::v1)
|
||||||
NGRAPH_OP(Pad, op::v1)
|
NGRAPH_OP(Pad, op::v1)
|
||||||
NGRAPH_OP(Split, op::v1)
|
NGRAPH_OP(Split, op::v1)
|
||||||
@ -66,12 +67,14 @@ NGRAPH_OP(EmbeddingBagPackedSum, ngraph::op::v3)
|
|||||||
NGRAPH_OP(ExtractImagePatches, op::v3)
|
NGRAPH_OP(ExtractImagePatches, op::v3)
|
||||||
NGRAPH_OP(EmbeddingSegmentsSum, ngraph::op::v3)
|
NGRAPH_OP(EmbeddingSegmentsSum, ngraph::op::v3)
|
||||||
NGRAPH_OP(GRUCell, ngraph::op::v3)
|
NGRAPH_OP(GRUCell, ngraph::op::v3)
|
||||||
|
NGRAPH_OP(NonMaxSuppression, op::v3)
|
||||||
NGRAPH_OP(NonZero, op::v3)
|
NGRAPH_OP(NonZero, op::v3)
|
||||||
NGRAPH_OP(ScatterNDUpdate, op::v3)
|
NGRAPH_OP(ScatterNDUpdate, op::v3)
|
||||||
NGRAPH_OP(ShapeOf, op::v3)
|
NGRAPH_OP(ShapeOf, op::v3)
|
||||||
|
|
||||||
NGRAPH_OP(CTCLoss, op::v4)
|
NGRAPH_OP(CTCLoss, op::v4)
|
||||||
NGRAPH_OP(LSTMCell, op::v4)
|
NGRAPH_OP(LSTMCell, op::v4)
|
||||||
|
NGRAPH_OP(NonMaxSuppression, op::v4)
|
||||||
NGRAPH_OP(Proposal, op::v4)
|
NGRAPH_OP(Proposal, op::v4)
|
||||||
|
|
||||||
NGRAPH_OP(BatchNormInference, op::v5)
|
NGRAPH_OP(BatchNormInference, op::v5)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -106,6 +106,12 @@ std::vector<std::string> disabledTestPatterns() {
|
|||||||
R"(.*ReferenceMulticlassNmsTest.*esiType=i64.*evoType=i64.*)",
|
R"(.*ReferenceMulticlassNmsTest.*esiType=i64.*evoType=i64.*)",
|
||||||
// CVS-64096
|
// CVS-64096
|
||||||
R"(.*ReferenceNonMaxSuppressionTest.*esiType=i32.*evoType=i32.*)",
|
R"(.*ReferenceNonMaxSuppressionTest.*esiType=i32.*evoType=i32.*)",
|
||||||
|
// CVS-64081
|
||||||
|
R"(.*ReferenceNonMaxSuppression4Test.*esiType=i32.*)",
|
||||||
|
// CVS-64067
|
||||||
|
R"(.*ReferenceNonMaxSuppression3Test.*esiType=i32.*)",
|
||||||
|
// CVS-64034
|
||||||
|
R"(.*ReferenceNonMaxSuppression1Test.*esiType=i32.*)",
|
||||||
// CVS-64102
|
// CVS-64102
|
||||||
R"(.*ReferenceExperimentalPGGLayerTest.*iType=bf16.*stride_x=(32|64).*)",
|
R"(.*ReferenceExperimentalPGGLayerTest.*iType=bf16.*stride_x=(32|64).*)",
|
||||||
// CVS-72215
|
// CVS-72215
|
||||||
|
Loading…
Reference in New Issue
Block a user