YOLO v7中显示置信度的代码在哪里
时间: 2023-08-21 17:07:34 浏览: 152
YOLO v7是不存在的,可能是您指的是YOLOv3或YOLOv4。在YOLOv3的代码中,显示置信度的代码在`src/detection_layer.c`文件中的`draw_detections()`函数中,具体实现如下:
```c
void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes)
{
int i,j;
for(i = 0; i < num; ++i){
char labelstr[4096] = {0};
int class_ = -1;
for(j = 0; j < classes; ++j){
if (dets[i].prob[j] > thresh){
if (class_ < 0) {
strcat(labelstr, names[j]);
class_ = j;
} else {
strcat(labelstr, ", ");
strcat(labelstr, names[j]);
}
printf("%s: %.0f%%\n", names[j], dets[i].prob[j]*100);
}
}
if(class_ >= 0){
int width = im.h * .006;
printf("%d %s: %.0f%%\n", i, names[class_], dets[i].prob[class_]*100);
int offset = class_*123457 % classes;
float red = get_color(2,offset,classes);
float green = get_color(1,offset,classes);
float blue = get_color(0,offset,classes);
float rgb[3];
//width = prob*20+2;
rgb[0] = red;
rgb[1] = green;
rgb[2] = blue;
box b = dets[i].bbox;
//printf("%f %f %f %f\n", b.x, b.y, b.w, b.h);
int left = (b.x-b.w/2.)*im.w;
int right = (b.x+b.w/2.)*im.w;
int top = (b.y-b.h/2.)*im.h;
int bot = (b.y+b.h/2.)*im.h;
if(left < 0) left = 0;
if(right > im.w-1) right = im.w-1;
if(top < 0) top = 0;
if(bot > im.h-1) bot = im.h-1;
draw_box_width(im, left, top, right, bot, width, red, green, blue);
if (alphabet) {
image label = get_label(alphabet, labelstr, (im.h*.03));
draw_label(im, top + width, left, label, rgb);
free_image(label);
}
else {
int len = strlen(labelstr) * 10;
if (left < len) left = len;
draw_label(im, top + width, left - len, labelstr, rgb);
}
}
}
}
```
在上述代码中,`printf("%s: %.0f%%\n", names[j], dets[i].prob[j]*100)`就是显示置信度的代码。其中,`names`是类别名称的数组,`dets[i].prob[j]`是第i个检测框中第j个类别的置信度。
阅读全文