【Detectron2】入门05 Schedules Faster R-CNN

Detectron2的Learning Rate和Schedules

1x and 3x schedules

1x = 16 images / iterations * 90,000 iterations in total with the LR reduced at 60k and 80k
3x = 16 images / iteration * 270,000 iterations in total with the LR reduced at 210k and 250k

在60k和80k迭代衰减*0.1,在90k次迭代终止。

cfg.SOLVER.BASE_LR = 0.001
cfg.SOLVER.STEPS = (300, 400)
cfg.SOLVER.MAX_ITER = 500

设置最大迭代次数为500次,前面300次按照线性增长,增长到BASE_LR,然后在300,400分别下降

因此,如果改小BatchSize,应该对应的修改上述参数。

 

Detectron2中的Faster RCNN

分为两个版本,C4的backbone是ResNet的Conv_1到Conv_4,而FPN则是FPN,其本质上是MaskRCNN如下图所示:

C4的整体框架如下图:

C4的ROI_HEAD是接ResNet的Conv_5,然后通过AveragePooling得到2048维特征,送入class和box分支。

FPN的ROI_HEAD是直接Flatten然后通过两个全连接层来embedding为1024维,然后再接class和box分支。

对应到Detectron2中:

C4的ROI_HEADS在Res5ROIHeads,而FPN的ROI_HEADS则在box_head.py的FastRCNNConvFCHead。两者共用fast_rcnn.py中的FastRCNNOutputLayers进行最后的分类和bbox回归。

 

Detectron2中的冻结参数进行训练

冻结除roi_heads.box_preditor之外的所有参数进行训练。

from tools.train_net import Trainer

trainer = Trainer(cfg)
model = trainer.model
layer = 'roi_heads.box_predictor'
for name, value in model.named_parameters():
    if layer not in name:
        value.requires_grad = False
trainer.resume_or_load(resume = False)
trainer.train()

 

# 考虑将VC RCNN改为目标检测模型,尝试。

def Causal(x):
    length = x.size(0)
    dic_z = self.dic.cuda()
    prior = self.prior.cuda()
    embeded_prior = prior.unsqueeze(0).repeat(length, 1)
    attention = torch.mm(x, dic_z.t()) / (1024 ** 0.5)
    attention = F.softmax(attention, 0)
    
    attention = torch.mm(attention, dic_z)
    attention = self.attention(attention)
    attention = F.softmax(attention, 0)
    
    xz = attention * x
    xz = self.attention_relu(xz)

    return xz

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值