//预测输出中置信度超过阈值的 box 个数
int yolo_num_detections(layer l, float thresh)
{
int i, n;
int count = 0;
for (i = 0; i < l.w*l.h; ++i){
for(n = 0; n < l.n; ++n){
//获得置信度偏移位置
int obj_index = entry_index(l, 0, n*l.w*l.h + i, 4);
//置信度超过阈值
if(l.output[obj_index] > thresh){
++count;
}
}
}
return count;
}
//获取预测输出bbox中各个类别的概率
void get_yolo_class_probability(layer l, float thresh)
{
int i, j, n;
float *predictions = l.output;
for (i = 0; i < l.w*l.h; ++i)
{
for(n = 0; n < l.n; ++n)
{
for (j=0; j<l.classes; ++j)
{
int class_index = entry_index(l, 0, n*l.w*l.h+i, 4+1+j);
float prob = predictions[class_index];// 某一个框中某一个类别的概率
cout<<"prob:"<<prob<<endl;
}
}
}
}
//从l.output中解析出来预测的bounding box
for (b = 0; b < l.batch; ++b)
{
for (j = 0; j < l.h; ++j)
{
for (i = 0; i < l.w; ++i)
{
for (n = 0; n < l.n; ++n)
{
int box_index = entry_index(l, b, n*l.w*l.h + j*l.w + i, 0);
box pred = get_yolo_box(l.output, l.biases, l.mask[n], box_index, i, j, l.w, l.h, net.w, net.h, l.w*l.h);
}
}
}
}
int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets, int letter)
{
//printf("\n l.batch = %d, l.w = %d, l.h = %d, l.n = %d \n", l.batch, l.w, l.h, l.n);
int i,j,n;
float *predictions = l.output;
// This snippet below is not necessary
// Need to comment it in order to batch processing >= 2 images
//if (l.batch == 2) avg_flipped_yolo(l);
int count = 0;
for (i = 0; i < l.w*l.h; ++i){
int row = i / l.w;
int col = i % l.w;
for(n = 0; n < l.n; ++n){
int obj_index = entry_index(l, 0, n*l.w*l.h + i, 4);
float objectness = predictions[obj_index];
//if(objectness <= thresh) continue; // incorrect behavior for Nan values
if (objectness > thresh) {
//printf("\n objectness = %f, thresh = %f, i = %d, n = %d \n", objectness, thresh, i, n);
int box_index = entry_index(l, 0, n*l.w*l.h + i, 0);
dets[count].bbox = get_yolo_box(predictions, l.biases, l.mask[n], box_index, col, row, l.w, l.h, netw, neth, l.w*l.h);
dets[count].objectness = objectness;
dets[count].classes = l.classes;
if (l.embedding_output) {
get_embedding(l.embedding_output, l.w, l.h, l.n*l.embedding_size, l.embedding_size, col, row, n, 0, dets[count].embeddings);
}
for (j = 0; j < l.classes; ++j) {
int class_index = entry_index(l, 0, n*l.w*l.h + i, 4 + 1 + j);
float prob = objectness*predictions[class_index];
dets[count].prob[j] = (prob > thresh) ? prob : 0;
}
++count;
}
}
}
correct_yolo_boxes(dets, count, w, h, netw, neth, relative, letter);
return count;
}