| 191 | } |
| 192 | |
| 193 | int ref_dpp_common(const float* input_f, const float* score_f, const float* anchor_f, dpp_param* param, |
| 194 | float* detect_num, float* detect_class, float* detect_score, float* detect_boxes) |
| 195 | { |
| 196 | const int num_classes = param->num_classes + 1; |
| 197 | const int num_boxes = param->num_boxes; |
| 198 | const int max_detections = param->max_detections; |
| 199 | |
| 200 | struct Dpp_Box* all_boxes = ( struct Dpp_Box* )malloc(num_classes * num_boxes * sizeof(struct Dpp_Box)); |
| 201 | memset(all_boxes, 0, sizeof(struct Dpp_Box) * num_classes * num_boxes); |
| 202 | |
| 203 | get_all_boxes_rect(all_boxes, input_f, score_f, anchor_f, num_boxes, num_classes, param->scales); |
| 204 | |
| 205 | int max_picked_boxes = 2 * max_detections * num_classes; |
| 206 | struct Dpp_Box* picked_boxes = ( struct Dpp_Box* )malloc(max_picked_boxes * sizeof(struct Dpp_Box)); |
| 207 | memset(picked_boxes, 0, sizeof(struct Dpp_Box) * max_picked_boxes); |
| 208 | int all_picked_size = 0; |
| 209 | |
| 210 | for(int i = 1; i < num_classes; i++) |
| 211 | { |
| 212 | struct Dpp_Box* class_box = all_boxes + i * num_boxes; |
| 213 | |
| 214 | // sort |
| 215 | sort_boxes_by_score(class_box, num_boxes); |
| 216 | int box_size = 0; |
| 217 | for(int j = 0; j < num_boxes; j++) |
| 218 | { |
| 219 | if(class_box[j].score < 0.6) |
| 220 | break; |
| 221 | box_size++; |
| 222 | } |
| 223 | if(box_size == 0) |
| 224 | continue; |
| 225 | |
| 226 | if(box_size > max_detections * 2) |
| 227 | box_size = max_detections * 2; |
| 228 | |
| 229 | int picked[num_boxes]; |
| 230 | int picked_size = 0; |
| 231 | |
| 232 | picked[0] = 0; |
| 233 | nms_sorted_bboxes(class_box, box_size, picked, &picked_size, param->nms_iou_threshold); |
| 234 | |
| 235 | // save the survivors |
| 236 | for(int j = 0; j < picked_size; j++) |
| 237 | { |
| 238 | int z = picked[j]; |
| 239 | memcpy(picked_boxes + all_picked_size, class_box + z, sizeof(struct Dpp_Box)); |
| 240 | all_picked_size++; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | sort_boxes_by_score(picked_boxes, max_picked_boxes); |
| 245 | if(all_picked_size > max_detections) |
| 246 | all_picked_size = max_detections; |
| 247 | |
| 248 | // generate output tensors |
| 249 | detect_num[0] = all_picked_size; |
| 250 |
no test coverage detected