问题描述:预测框的中心位置正常,但是预测的框的width和height不正常。

解决方法:使得训练的配置cfg和测试中cfg的输入width, height, anchorbox保持一致!

问题是我在修改anchorbox时遇到的,当时训练和测试不在同一环境下,测试端没有及时更新cfg文件造成的,如下图所示:

mAP也是极低的。

修改后,检测框正常,如下图所示:

下面做下boundingbox来源分析:

首先是yolo(you only look once)中是这样定义的:

算法中明确告诉我们:boundingbox只和cell(featuremap中的)位置(Cx,Cy)以及anchorbox的(Pw,Ph)直接相关。所以我们可以重点关注这两个量。

对应到源代码中的实现主要是以下两个函数:

yolo_layer.c
...
box get_yolo_box(float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, int stride)
/*
输入参数解析:(*x 预测数据),(*biases 存放anchor数据),
(i、j 对应在feature map上的坐标),
(n 表示anchor数组的mask,为了让三个yolo_layer能取到自己对应的三组anchor, 小尺寸feature map对应大size anchor,比较好理解小尺寸特征图负责检查大尺寸目标),
(index,当前bbox对应的数据的起始下标),
(lw lh,特征图的w h),
(w h, 网络输入的w h),
(同一个bbox数据之间的stride lw*lh)
*/
{
box b; // 网络为了每一个bbox都给出了4个坐标预测值: tx ty tw ty
/*
其中tx 和 ty是相对于当前feature map坐标的偏移
除以lw&&lh 是计算出bbox坐标在图像中的比例
*/
b.x = (i + x[index + 0*stride]) / lw;
b.y = (j + x[index + 1*stride]) / lh;
/*
e^tw * biases[2*n] 表示学习到的w回归值和对应prior bbox(anchor) w的乘积得到
bbox在网络输入size基础上的w size, 除以 net_w得到相对于网络输入图像的比例
h的计算同理, 这部分的内容涉及到yolov3论文中的图二
*/
b.w = exp(x[index + 2*stride]) * biases[2*n] / w;
b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h;
return b;
/*补充一下,这里算出的x,y,w,h都是相对于net input size的比例*/
}
此不分为转载:
https://blog.csdn.net/wwwhp/article/details/84718089
...
int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets)
{
int i,j,n;
float *predictions = l.output;
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;
//printf("get_yolo_detections:i =%d,row = i / l.w=%d, col = i % l.w;\n",i, row, col);
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];//objectness:有框的
//printf("objectness:%f\n",objectness);
if(objectness <= thresh) continue;
printf("obj_index = %d,objectness:%f, thresh:%f\n",obj_index,objectness,thresh);
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;
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];//predictions[class_index]:框中物体是class的概率,prob:置信度
printf("get_yolo_detections1:prob=objectness*predictions[class_index] = %f * predictions[%d] = %f * %f = %f;\n",objectness,class_index,objectness,predictions[class_index],prob);
dets[count].prob[j] = (prob > thresh) ? prob : 0;
printf("get_yolo_detections2:[dets[count].prob[j] = (prob > thresh) ? prob : 0] = [ %f = (%f > %f) ? %f : 0];\n",dets[count].prob[j],prob,thresh,prob);
}
++count;
}
}
correct_yolo_boxes(dets, count, w, h, netw, neth, relative);
return count;
}
...

如有疑问可以留言。

希望可以帮到困惑的你!

最新文章

  1. mysql 数据库可以非本地访问
  2. c#接口
  3. fabric upgrade from old crashlystic stuck in build
  4. python中split函数的使用
  5. 关于Toad连接DB2的sqlstate=08001错误
  6. 对象的类型转换P109
  7. BaseAdapter中重写getview的心得以及发现convertView回收的机制
  8. extends 与 implements 的区别
  9. Serv-U软件在64位操作系统下使用不了odbc解决方法
  10. 在YII中使用Redis等缓存
  11. 用powerdesigner建模工具生成数据库
  12. 一个C/C++结构体初始化有趣的现象
  13. 算法精解(C语言描述) 第4章 读书笔记
  14. php简单数据缓存类
  15. SHELL中,如何分割字符串
  16. 数组的map方法
  17. 解决No enclosing instance of type * is accessible
  18. Spring Boot 读取 resource 下文件
  19. Java多线程学习(四)---控制线程
  20. [JSOI2008]Blue Mary的战役地图(二分+哈希)

热门文章

  1. 移动端自动化==&gt;Windows-Android-Appium环境搭建
  2. Application.CreateForm()和TForm.Create()创建的窗体有什么区别么?二者在使用上各有什么技巧?(50分)
  3. yum 下载rpm包 安装rpm包依赖关系
  4. 深入理解java:1.2. 字节码执行引擎
  5. 使用Dockerfile制作镜像
  6. mysql学习记录(一)
  7. org.apache.httpcomponents:httpclient 工具类
  8. python学习第五十四天hashlib模块的使用
  9. html5移动端Meta的设置
  10. 【学习总结】快速上手Linux玩转典型应用-第5章-远程连接SSH专题