Faster RCNN anchor大小及数量计算
anchors 值的含义为
在 feature maps 上进行滑窗操作(sliding window). 滑窗尺寸为 n×n, 如 3×3.
对于每个滑窗, 会生成 9 个 anchors, anchors 具有相同的中心 center=xa,center=ya, 但 anchors 具有 3 种不同的长宽比(aspect ratios) 和 3 种不同的尺度(scales)。 最终,9个anchor的四个数值分别代表矩形框的左下角x,y,右上角x,y。计算是相对于原始图片尺寸的.
anchor的值是由如下步骤计算得来的:
主要包括两步:
保持 anchor 面积固定不变, 改变长宽比 aspect ratio = [0.5, 1, 2] (函数_ratio_enum(anchor, ratios))
保持 anchor 长宽比固定不变,缩放尺度 scale = [8,16,32] (函数_scale_enum(anchor, scales))
1. 先设置基础anchor,base=16,base_anchor为[0,0,15,15],anchor中心(7.5,7.5),以及面积(size=256)。
2. 计算基础anchor的面积,分别除以ratio[0.5,1,2],得到 [512,256,128]
3. anchor的宽度w由三个面积的平方根值确定,得到 w[23,16,11]
4. anchor的高度h由[23,16,11]*[0.5,1,2]确定,得到 h[12,16,22]。
5. 由anchor的中心以及不同的宽和高可以得到此时的anchors。此处为[-3.5, 2. , 18.5, 13. ], [ 0. , 0. , 15. , 15. ], [ 2.5, -3. , 12.5, 18. ]
例 xa=7.5, ya=7.5,w=23,h=12,
x_left = xa-(w-1)/2=-3.5, y_left = ya-(h-1)/2 = 2,
x_right = xa+(w-1)/2 = 18.5, y_right = ya+(h-1)/2=13
6. 利用三种不同的scales[8,16,32]分别去扩大anchors,扩大的方法是先计算出来上一步的anchor的中心以及宽高,使宽高分别乘以scale,然后再利用中心和新的宽高计算出最终所要的anchors
例如: xa=7.5, ya=7.5, w=23*8, h=12*8, x_min=xa-(w*scale-1)/2 = 7.5-(23*8-1)/2=84 ==> -83 -39 100 56
"""
generate_anchors.py
"""
import numpy as np# Verify that we compute the same anchors as Shaoqing's matlab implementation:
#
# >> load output/rpn_cachedir/faster_rcnn_VOC2007_ZF_stage1_rpn/anchors.mat
# >> anchors
#
# anchors =
#
# -83 -39 100 56
# -175 -87 192 104
# -359 -183 376 200
# -55 -55 72 72
# -119 -119 136 136
# -247 -247 264 264
# -35 -79 52 96
# -79 -167 96 184
# -167 -343 184 360# array([[ -83., -39., 100., 56.],
# [-175., -87., 192., 104.],
# [-359., -183., 376., 200.],
# [ -55., -55., 72., 72.],
# [-119., -119., 136., 136.],
# [-247., -247., 264., 264.],
# [ -35., -79., 52., 96.],
# [ -79., -167., 96., 184.],
# [-167., -343., 184., 360.]])def generate_anchors(stride=16, sizes=(32, 64, 128, 256, 512), aspect_ratios=(0.5, 1, 2)):"""生成 anchor boxes 矩阵,其格式为 (x1, y1, x2, y2).Anchors 是以 stride / 2 的中心,逼近指定大小的平方根面积(sqrt areas),长宽比Anchors are centered on stride / 2, have (approximate) sqrt areas of the specifiedsizes, and aspect ratios as given."""return _generate_anchors(stride,np.array(sizes, dtype=np.float) / stride,np.array(aspect_ratios, dtype=np.float) )def _generate_anchors(base_size, scales, aspect_ratios):"""通过枚举关于参考窗口window (0, 0, base_size - 1, base_size - 1) 的长宽比(aspect ratios) X scales,来生成 anchore 窗口(参考窗口 reference windows)."""anchor = np.array([1, 1, base_size, base_size], dtype=np.float) - 1anchors = _ratio_enum(anchor, aspect_ratios)anchors = np.vstack([_scale_enum(anchors[i, :], scales) for i in range(anchors.shape[0])])return anchorsdef _whctrs(anchor):"""返回 anchor 窗口的 width, height, x center, y center."""w = anchor[2] - anchor[0] + 1h = anchor[3] - anchor[1] + 1x_ctr = anchor[0] + 0.5 * (w - 1)y_ctr = anchor[1] + 0.5 * (h - 1)return w, h, x_ctr, y_ctrdef _mkanchors(ws, hs, x_ctr, y_ctr):"""给定 center(x_ctr, y_ctr) 及 widths (ws),heights (hs) 向量,输出 anchors窗口window 集合."""ws = ws[:, np.newaxis]hs = hs[:, np.newaxis]anchors = np.hstack( (x_ctr - 0.5 * (ws - 1), y_ctr - 0.5 * (hs - 1),x_ctr + 0.5 * (ws - 1), y_ctr + 0.5 * (hs - 1) ) )return anchorsdef _ratio_enum(anchor, ratios):"""对于每个关于一个 anchor 的长宽比aspect ratio,枚举 anchors 集合."""w, h, x_ctr, y_ctr = _whctrs(anchor)size = w * hsize_ratios = size / ratiosws = np.round(np.sqrt(size_ratios))hs = np.round(ws * ratios)anchors = _mkanchors(ws, hs, x_ctr, y_ctr)return anchorsdef _scale_enum(anchor, scales):"""对于每个关于一个 anchor 的尺度scale,枚举 anchors 集合.Enumerate a set of anchors for each scale wrt an anchor."""w, h, x_ctr, y_ctr = _whctrs(anchor)ws = w * scaleshs = h * scalesanchors = _mkanchors(ws, hs, x_ctr, y_ctr)return anchorsif __name__ == '__main__':print 'Anchor Generating ...'anchors = generate_anchors()print anchorsprint 'Done.'
参考:
https://blog.csdn.net/zziahgf/article/details/79895804
https://blog.csdn.net/wphkadn/article/details/87915495
Faster RCNN anchor大小及数量计算相关推荐
- Faster RCNN中anchor的生成过程
主要参考py-faster-rcnn开源代码中的generate_anchors的实现: 首先来看main函数: if __name__ == '__main__':import timet = ti ...
- faster rcnn中anchor的生成
faster rcnn anchor anchors 值的含义为 总共有9个anchor,对于每一个anchor,其四个数值分别代表矩形框的左下角x,y,右上角x,y. anchor的预设值为 # V ...
- faster rcnn中rpn的anchor,sliding windows,proposals的理解
一直对faster rcnn里的rpn以及下图中的上面的那部分的区别不太理解,今天看到了知乎里面的回答,感觉有点明白了,特此记录 作者:马塔 链接:https://www.zhihu.com/ques ...
- 目标检测——Faster R-CNN论文阅读
论文阅读--Faster R-CNN:Towards Real-Time Object Detection with Region Proposal Networks 文章目录 论文阅读--Faste ...
- 目标检测算法Faster R-CNN简介
在博文https://blog.csdn.net/fengbingchun/article/details/87091740 中对Fast R-CNN进行了简单介绍,这里在Fast R-CNN的基础上 ...
- 里程碑式成果Faster RCNN复现难?我们试了一下 | 附完整代码
作者 | 已退逼乎 来源 | 知乎 [导读]2019年以来,除各AI 大厂私有网络范围外,MaskRCNN,CascadeRCNN 成为了支撑很多业务得以开展的基础,而以 Faster RCNN 为基 ...
- 完整代码+实操!手把手教你操作Faster R-CNN和Mask R-CNN
点击上方↑↑↑蓝字关注我们~ 「2019 Python开发者日」全日程揭晓,请扫码咨询 ↑↑↑ 机器视觉领域的核心问题之一就是目标检测(Object Detection),它的任务是找出图像当中所有感 ...
- 深度学习目标检测模型全面综述:Faster R-CNN、R-FCN和SSD
为什么80%的码农都做不了架构师?>>> Faster R-CNN.R-FCN 和 SSD 是三种目前最优且应用最广泛的目标检测模型,其他流行的模型通常与这三者类似.本文介绍了 ...
- 一文读懂Faster RCNN
来源:信息网络工程研究中心本文约7500字,建议阅读10+分钟 本文从四个切入点为你介绍Faster R-CNN网络. 经过R-CNN和Fast RCNN的积淀,Ross B. Girshick在20 ...
最新文章
- android自定义相机预览尺寸,相机在Android中,如何获得最佳尺寸,预览尺寸,图片尺寸,视图尺寸,图像扭曲...
- 使用Skywalking实现全链路监控
- 钜惠来袭丨神策学堂推出 SACA 四季班,留给你的时间不多了
- ZooKeeper: 简介, 配置及运维指南
- iphone计算机快捷键,苹果电脑快捷键大全,最常用的都在这里了
- SQL 盲注GET /POST、布尔型,延时型Python脚本
- 《Python游戏编程快速上手》第五章--龙穴探险
- C语言高级编程:const限定函数形参
- onmouseover-onmouseout
- CodeForces - 233A Perfect Permutation
- Win7 64位系统,使用(IME)模式VS2010 编写 和 安装 输入法 教程(1)
- 「leetcode」本周小结!(回溯算法系列一)
- Deep Learning 深度学习 学习教程网站集锦
- pytorch与街景识别学习笔记
- CentOS6启用密钥登陆
- mysql简历上怎么写_新手程序员简历应该怎么写?
- Java常用关键字查询
- Python笔记03:python中用import导入包的机制原理是什么?
- 如何把多张图片合并成一个PDF?
- 全网最好用的图文识别、证件扫描、PDF转换等工具,已解锁永久会员!
热门文章
- 【微机接口】可编程定时器/计数器8254
- 谷歌G1叫板iPhone
- 飞控pixhawk硬件框架
- 如何不安装ORACLE就可以连接服务器端Oracle
- #009#献给阿尔吉侬的花束
- 计算机耳麦型号及价格,PC耳机也入流五款实用耳机推荐
- java 支持的编码格式_Java支持的编码格式(各个国家的语言)
- 计算机及科学与技术航空方向,沈阳航空航天大学计算机学院计算机科学与技术专业简介...
- 无门槛利用web技术创作8bit音乐(实践篇)
- Radware负载均衡项目配置实战解析之一初识RADWARE(VIP与FARM配置)