测试YOLO fastest训练模型命令的时候,有个参数是-thresh,所以需要查看适用这个参数的地方
// Creates array of detections with prob > thresh and fills best_class for them
detection_with_class* get_actual_detections(detection *dets, int dets_num, float thresh, int* selected_detections_num, char **names)
{
int selected_num = 0;
detection_with_class* result_arr = (detection_with_class*)xcalloc(dets_num, sizeof(detection_with_class));
int i;
for (i = 0; i < dets_num; ++i) {//循环遍历检测到的目标
int best_class = -1;
float best_class_prob = thresh;
int j;
for (j = 0; j < dets[i].classes; ++j) {//对检测到的目标的类别概率进行判断,提取最大类别概率及索引
int show = strncmp(names[j], "dont_show", 9);
if (dets[i].prob[j] > best_class_prob && show) {//提取概率大于thresh并且是最大值的检测目标,此处不太清楚show的用意,因为names中不包含"dont_show",所以show恒不等于0
best_class = j;
best_class_prob = dets[i].prob[j];
}
}
if (best_class >= 0) {//如果最大类别概率索引>=0,保存检测目标结构体
result_arr[selected_num].det = dets[i];
result_arr[selected_num].best_class = best_class;
++selected_num;
}
}
if (selected_detections_num)
*selected_detections_num = selected_num;
return result_arr;
}
上层调用的代码:
int selected_detections_num;
detection_with_class* selected_detections = get_actual_detections(dets, num, thresh, &selected_detections_num, names);
// text output
qsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_lefts);
int i;
for (i = 0; i < selected_detections_num; ++i) {
const int best_class = selected_detections[i].best_class;
printf("%s: %.0f%%", names[best_class], selected_detections[i].det.prob[best_class] * 100);
if (ext_output) //如果在测试命令中ext_output为真,打印各个目标的位置
printf("\t(left_x: %4.0f top_y: %4.0f width: %4.0f height: %4.0f)\n",
round((selected_detections[i].det.bbox.x - selected_detections[i].det.bbox.w / 2)*im.w),
round((selected_detections[i].det.bbox.y - selected_detections[i].det.bbox.h / 2)*im.h),
round(selected_detections[i].det.bbox.w*im.w), round(selected_detections[i].det.bbox.h*im.h));
else
printf("\n");
int j;
for (j = 0; j < classes; ++j) {//如何其他不同类别的概率值也大于给定阈值,打印输出相关信息
if (selected_detections[i].det.prob[j] > thresh && j != best_class) {
printf("%s: %.0f%%", names[j], selected_detections[i].det.prob[j] * 100);
if (ext_output)
printf("\t(left_x: %4.0f top_y: %4.0f width: %4.0f height: %4.0f)\n",
round((selected_detections[i].det.bbox.x - selected_detections[i].det.bbox.w / 2)*im.w),
round((selected_detections[i].det.bbox.y - selected_detections[i].det.bbox.h / 2)*im.h),
round(selected_detections[i].det.bbox.w*im.w), round(selected_detections[i].det.bbox.h*im.h));
else
printf("\n");
}
}
}