Skip to content

Commit 48ec21b

Browse files
committed
fix generate_yolox_proposals
1 parent e7b57a0 commit 48ec21b

File tree

1 file changed

+11
-14
lines changed
  • yolox_ros_cpp/yolox_cpp/include/yolox_cpp

1 file changed

+11
-14
lines changed

yolox_ros_cpp/yolox_cpp/include/yolox_cpp/core.hpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,15 @@ namespace yolox_cpp
157157

158158
const int basic_pos = anchor_idx * (num_classes_ + 5);
159159

160-
const float box_objectness = feat_ptr[basic_pos + 4];
161160
int class_id = 0;
162-
float max_class_score = 0.0;
163-
for (int class_idx = 0; class_idx < num_classes_; ++class_idx)
161+
float max_class_score = 0.0f;
164162
{
165-
const float box_cls_score = feat_ptr[basic_pos + 5 + class_idx];
166-
const float box_prob = box_objectness * box_cls_score;
167-
if (box_prob > max_class_score)
168-
{
169-
class_id = class_idx;
170-
max_class_score = box_prob;
171-
}
163+
const float box_objectness = feat_ptr[basic_pos + 4];
164+
auto begin = feat_ptr + (basic_pos + 5);
165+
auto end = feat_ptr + (basic_pos + 5 + num_classes_);
166+
auto max_elem = std::max_element(begin, end);
167+
class_id = max_elem - begin;
168+
max_class_score = (*max_elem) * box_objectness;
172169
}
173170
if (max_class_score > prob_threshold)
174171
{
@@ -263,10 +260,10 @@ namespace yolox_cpp
263260
objects[i] = proposals[picked[i]];
264261

265262
// adjust offset to original unpadded
266-
float x0 = static_cast<float>(objects[i].rect.x) / scale;
267-
float y0 = static_cast<float>(objects[i].rect.y) / scale;
268-
float x1 = static_cast<float>(objects[i].rect.x + objects[i].rect.width) / scale;
269-
float y1 = static_cast<float>(objects[i].rect.y + objects[i].rect.height) / scale;
263+
float x0 = objects[i].rect.x / scale;
264+
float y0 = objects[i].rect.y / scale;
265+
float x1 = (objects[i].rect.x + objects[i].rect.width) / scale;
266+
float y1 = (objects[i].rect.y + objects[i].rect.height) / scale;
270267

271268
// clip
272269
x0 = std::max(std::min(x0, max_x), 0.f);

0 commit comments

Comments
 (0)