Commit 41663f68 authored by charlie's avatar charlie
Browse files

Use copy elision, remove parameter const

parent c71201f9
...@@ -129,12 +129,13 @@ struct nonmaxsuppression ...@@ -129,12 +129,13 @@ struct nonmaxsuppression
// filter boxes below score_threshold // filter boxes below score_threshold
template <class T> template <class T>
void filter_boxes_by_score(T scores, std::priority_queue<std::pair<float, int64_t>> filter_boxes_by_score(T scores,
std::size_t score_offset_ind, std::size_t score_offset_ind,
std::size_t num_boxes, std::size_t num_boxes,
const float score_threshold, float score_threshold
std::priority_queue<std::pair<float, int64_t>>& boxes_heap) const ) const
{ {
std::priority_queue<std::pair<float, int64_t>> boxes_heap;
auto insert_to_boxes_heap = auto insert_to_boxes_heap =
make_function_output_iterator([&boxes_heap](const auto& x) { boxes_heap.push(x); }); make_function_output_iterator([&boxes_heap](const auto& x) { boxes_heap.push(x); });
int64_t box_idx = 0; int64_t box_idx = 0;
...@@ -147,6 +148,7 @@ struct nonmaxsuppression ...@@ -147,6 +148,7 @@ struct nonmaxsuppression
return sc >= score_threshold; return sc >= score_threshold;
}, },
[&](auto sc) { return std::make_pair(sc, box_idx - 1); }); [&](auto sc) { return std::make_pair(sc, box_idx - 1); });
return boxes_heap;
} }
argument compute(const shape& output_shape, std::vector<argument> args) const argument compute(const shape& output_shape, std::vector<argument> args) const
...@@ -183,9 +185,8 @@ struct nonmaxsuppression ...@@ -183,9 +185,8 @@ struct nonmaxsuppression
(batch_idx * num_classes + class_idx) * num_boxes; (batch_idx * num_classes + class_idx) * num_boxes;
// index to first value of this batch // index to first value of this batch
std::size_t batch_boxes_ind = batch_idx * num_boxes * 4; std::size_t batch_boxes_ind = batch_idx * num_boxes * 4;
std::priority_queue<std::pair<float, int64_t>> boxes_heap; auto boxes_heap = filter_boxes_by_score(
filter_boxes_by_score( scores, score_offset_ind, num_boxes, score_threshold);
scores, score_offset_ind, num_boxes, score_threshold, boxes_heap);
selected_boxes_inside_class.clear(); selected_boxes_inside_class.clear();
// Get the next box with top score, filter by iou_threshold // Get the next box with top score, filter by iou_threshold
while(!boxes_heap.empty() && while(!boxes_heap.empty() &&
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment