没有合适的资源?快使用搜索试试~ 我知道了~
首页FCOS官方代码的解析,从测试到训练
FCOS官方代码的解析,从测试到训练
5星 · 超过95%的资源 需积分: 46 63 下载量 17 浏览量
更新于2023-03-03
评论 5
收藏 923KB PDF 举报
这是我自己梳理的FCOS目标检测代码,给大家省点时间去debug。FCOS的head部分:cls分支和bbox分支其实是和retinanet一样的,只不过没有了A这个anchor的数量,以及回归的对象不一样,但是网络的整体结构还是和retinanet一样。 在计算流程上不一样的地方我觉得不一样的点是:retinanet是将每个rpn网络的输出concate起来,而FCOS是每层单独预测,之后将每一层的结果concat起来,可能是因为FCOS在concate的时候不方便,因为网络中多出了一个centerness的分支,下面我将从FCOS的测试代码和训练代码开始解析记录,解析中省去了backbone以及FPN网络的解析,主要在head部分。
资源详情
资源评论
资源推荐
FCOS的head部分:cls分支和bbox分支其实是和retinanet一样的,只不过没有了A这
个anchor的数量,以及回归的对象不一样,但是网络的整体结构还是和retinanet一样。
在计算流程上不一样的地方我觉得不一样的点是:retinanet是将每个rpn网络的输出
concate起来,而FCOS是每层单独预测,之后将每一层的结果concat起来,可能是因为
FCOS在concate的时候不方便,因为网络中多出了一个centerness的分支,下面我将从
FCOS的测试代码和训练代码开始解析记录,解析中省去了backbone以及FPN网络的解
析,主要在head部分。
测试代码流程:
1.先经过backbone:resnet50+FPN,得到features
1 features=self.backbone(images.tensors)
1 FPN头网络输出
2 features[0].shape
3 torch.Size([1,256,100,136])
4 features[1].shape
5 torch.Size([1,256,50,68])
6 features[2].shape
7 torch.Size([1,256,25,34])
8 features[3].shape
9 torch.Size([1,256,13,17])
10 features[4].shape
11 torch.Size([1,256,7,9])
2.介入rpn网络
1 proposals,proposal_losses=self.rpn(images,features,targets)
3.经过FCOSModule()类中的head网络结构,得到cls,reg,centerness输出
box_cls:
1 box_cls[0].shape
2 torch.Size([1,80,100,136])
3 box_cls[1].shape
4 torch.Size([1,80,50,68])
5 box_cls[2].shape
6 torch.Size([1,80,25,34])
7 box_cls[3].shape
8 torch.Size([1,80,13,17])
9 box_cls[4].shape
10 torch.Size([1,80,7,9])
box_reg:
1 box_regression[0].shape
2 torch.Size([1,4,100,136])
3 box_regression[1].shape
4 torch.Size([1,4,50,68])
5 box_regression[2].shape
6 torch.Size([1,4,25,34])
7 box_regression[3].shape
8 torch.Size([1,4,13,17])
9 box_regression[4].shape
10 torch.Size([1,4,7,9])
centerness:
1 centerness[0].shape
2 torch.Size([1,1,100,136])
3 centerness[1].shape
4 torch.Size([1,1,50,68])
5 centerness[2].shape
6 torch.Size([1,1,25,34])
7 centerness[3].shape
8 torch.Size([1,1,13,17])
9 centerness[4].shape
10 torch.Size([1,1,7,9])
4.计算locations
locations通过backbone经过FPN后得到的features得到,下面用第一层FPN分析:
1 locations=self.compute_locations(features)
1 defcompute_locations(self,features):
2 locations=[]
3 forlevel,featureinenumerate(features):
4 h,w=feature.size()[‐2:]
5 locations_per_level=self.compute_locations_per_level(
6 h,w,self.fpn_strides[level],
7 feature.device
8 )
9 locations.append(locations_per_level)
10 returnlocations
传入的参数只要有featuremap的H,W,网络的步长,通过H,W可以得到有多少个感受野的中
心点,通过步长就可以得到以这个感受野的中心点为中心的矩形框大小
1 locations_per_level=self.compute_locations_per_level(
2 h,w,self.fpn_strides[level],
3 feature.device
4 )
具体的过程如下:
1 defcompute_locations_per_level(self,h,w,stride,device):
2 shifts_x=torch.arange(
3 0,w*stride,step=stride,
4 dtype=torch.float32,device=device
5 )
6 shifts_y=torch.arange(
7 0,h*stride,step=stride,
8 dtype=torch.float32,device=device
9 )
10 shift_y,shift_x=torch.meshgrid(shifts_y,shifts_x)
11 shift_x=shift_x.reshape(‐1)
12 shift_y=shift_y.reshape(‐1)
13 locations=torch.stack((shift_x,shift_y),dim=1)+stride//2
14 returnlocations
stride=8,所以横向的每个中心点相距8个像素的单位
1 shifts_x
2 tensor([0.,8.,16.,24.,32.,40.,48.,56.,64.,72.,80.,88.,
3 96.,104.,112.,120.,128.,136.,144.,152.,160.,168.,176.,184.,
4 192.,200.,208.,216.,224.,232.,240.,248.,256.,264.,272.,280.,
5 288.,296.,304.,312.,320.,328.,336.,344.,352.,360.,368.,376.,
6 384.,392.,400.,408.,416.,424.,432.,440.,448.,456.,464.,472.,
7 480.,488.,496.,504.,512.,520.,528.,536.,544.,552.,560.,568.,
8 576.,584.,592.,600.,608.,616.,624.,632.,640.,648.,656.,664.,
9 672.,680.,688.,696.,704.,712.,720.,728.,736.,744.,752.,760.,
10 768.,776.,784.,792.],device='cuda:0')
1 shifts_y
2 tensor([0.,8.,16.,24.,32.,40.,48.,56.,64.,72.,80.,88.,
3 96.,104.,112.,120.,128.,136.,144.,152.,160.,168.,176.,184.,
4 192.,200.,208.,216.,224.,232.,240.,248.,256.,264.,272.,280.,
5 288.,296.,304.,312.,320.,328.,336.,344.,352.,360.,368.,376.,
6 384.,392.,400.,408.,416.,424.,432.,440.,448.,456.,464.,472.,
7 480.,488.,496.,504.,512.,520.,528.,536.,544.,552.,560.,568.,
8 576.,584.,592.,600.,608.,616.,624.,632.,640.,648.,656.,664.,
9 672.,680.,688.,696.,704.,712.,720.,728.,736.,744.,752.,760.,
10 768.,776.,784.,792.],device='cuda:0')
得到locations坐标:
1 locations
2 tensor([[4.,4.],
3 [12.,4.],
剩余15页未读,继续阅读
爱乐城的鸟儿
- 粉丝: 17
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5