MCPcopy Create free account
hub / github.com/MegEngine/MegCC / postpreprocess

Function postpreprocess

yolox_example/main.cpp:200–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200static void postpreprocess(
201 const float* output_ptr, std::vector<OutputInfo>& output_infos, float scale,
202 const int img_w, const int img_h) {
203 std::vector<OutputInfo> valid_output_info;
204 std::vector<BaseAnchor> base_anchors;
205
206 // get base anchor
207 for (auto stride : {8, 16, 32}) {
208 int num_anchor = INPUT_W / stride;
209 for (int g1 = 0; g1 < num_anchor; g1++) {
210 for (int g0 = 0; g0 < num_anchor; g0++) {
211 base_anchors.push_back((BaseAnchor){g0, g1, stride});
212 }
213 }
214 }
215 // get valid output information
216 const int num_class = 80;
217 const int num_anchors = base_anchors.size();
218 for (int anchor_idx = 0; anchor_idx < num_anchors; anchor_idx++) {
219 const int grid0 = base_anchors[anchor_idx].grid0;
220 const int grid1 = base_anchors[anchor_idx].grid1;
221 const int stride = base_anchors[anchor_idx].stride;
222
223 const int basic_pos = anchor_idx * 85;
224
225 float x_center = (output_ptr[basic_pos + 0] + grid0) * stride;
226 float y_center = (output_ptr[basic_pos + 1] + grid1) * stride;
227 float w = exp(output_ptr[basic_pos + 2]) * stride;
228 float h = exp(output_ptr[basic_pos + 3]) * stride;
229 float x0 = x_center - w * 0.5f;
230 float y0 = y_center - h * 0.5f;
231
232 float box_objectness = output_ptr[basic_pos + 4];
233 for (int class_idx = 0; class_idx < num_class; class_idx++) {
234 float box_cls_score = output_ptr[basic_pos + 5 + class_idx];
235 float box_prob = box_objectness * box_cls_score;
236 if (box_prob > BBOX_CONF_THRESH) {
237 OutputInfo obj;
238 obj.rect.x = x0;
239 obj.rect.y = y0;
240 obj.rect.width = w;
241 obj.rect.height = h;
242 obj.label = class_idx;
243 obj.prob = box_prob;
244
245 valid_output_info.push_back(obj);
246 }
247
248 } // class loop
249
250 } // point anchor loop
251
252 qsort_descent_inplace(valid_output_info);
253
254 std::vector<int> picked_output;
255 nms_sorted_bboxes(valid_output_info, picked_output, NMS_THRESH);
256 int count = picked_output.size();
257 output_infos.resize(count);

Callers 1

mainFunction · 0.85

Calls 4

qsort_descent_inplaceFunction · 0.85
nms_sorted_bboxesFunction · 0.85
maxFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected