def __init__(self, num_convs=4, prior_prob=0.01, in_channels=256): """ Arguments: in_channels (int): number of channels of the input feature """ super(FCOSRectangleHead, self).__init__() self.in_channels = in_channels self.focus_tower = nn.Sequential( *([FCOSTowerBlock(in_channels) for _ in range(num_convs)] + [ nn.Conv2d(in_channels, 4, kernel_size=3, stride=1, padding=1), Scale(init_value=1.0) ])) self.regression_tower = nn.Sequential( *([FCOSTowerBlock(in_channels) for _ in range(num_convs)] + [ nn.Conv2d(in_channels, 4, kernel_size=3, stride=1, padding=1), Scale(init_value=1.0) ])) # initialization for modules in [self.focus_tower, self.regression_tower]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0)
def __init__(self, cfg, in_channels): """ Arguments: in_channels (int): number of channels of the input feature """ super(FCOSSharedHead, self).__init__() # TODO: Implement the sigmoid version first. num_classes = cfg.MODEL.FCOS.NUM_CLASSES - 1 self.identity = cfg.MODEL.FCOS.RESIDUAL_CONNECTION shared_tower = [] for i in range(cfg.MODEL.FCOS.NUM_CONVS): shared_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) shared_tower.append(nn.GroupNorm(32, in_channels)) shared_tower.append(nn.ReLU()) self.add_module('shared_tower', nn.Sequential(*shared_tower)) self.dense_points = cfg.MODEL.FCOS.DENSE_POINTS self.cls_logits = nn.Conv2d(in_channels, num_classes * self.dense_points, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(in_channels, 4 * self.dense_points, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels, 1 * self.dense_points, kernel_size=3, stride=1, padding=1) # initialization for modules in [ self.shared_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss prior_prob = cfg.MODEL.FCOS.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)])
def __init__(self, cfg, in_channels): """ Arguments: in_channels (int): number of channels of the input feature """ super(RFCOSHead, self).__init__() # TODO: Implement the sigmoid version first. num_classes = cfg.MODEL.FCOS.NUM_CLASSES - 1 self.num_pts = cfg.MODEL.FCOS.NUM_PTS cls_tower = [] bbox_tower = [] for i in range(cfg.MODEL.FCOS.NUM_CONVS): cls_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) cls_tower.append(nn.GroupNorm(32, in_channels)) cls_tower.append(nn.ReLU()) bbox_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) bbox_tower.append(nn.GroupNorm(32, in_channels)) bbox_tower.append(nn.ReLU()) self.add_module('cls_tower', nn.Sequential(*cls_tower)) self.add_module('bbox_tower', nn.Sequential(*bbox_tower)) self.cls_logits = nn.Conv2d(in_channels, self.num_pts * num_classes, kernel_size=3, stride=1, padding=1) # x1y1 x2y2 h # self.bbox_pred = nn.Conv2d( # in_channels, self.num_pts, kernel_size=3, stride=1, # padding=1 # ) # x1y1 x2y2 h self.bbox_pred = nn.Conv2d(in_channels, self.num_pts * 5, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels, self.num_pts * 1, kernel_size=3, stride=1, padding=1) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss prior_prob = cfg.MODEL.FCOS.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)])
def __init__(self, cfg, in_channels): """ Arguments: in_channels (int): number of channels of the input feature """ super(FCOSHead, self).__init__() # TODO: Implement the sigmoid version first. num_classes = cfg.MODEL.FCOS.NUM_CLASSES - 1 cls_tower = [] bbox_tower = [] for i in range(cfg.MODEL.FCOS.NUM_CONVS): cls_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) cls_tower.append(nn.GroupNorm(32, in_channels)) cls_tower.append(nn.ReLU()) bbox_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) bbox_tower.append(nn.GroupNorm(32, in_channels)) bbox_tower.append(nn.ReLU()) self.add_module('cls_tower', nn.Sequential(*cls_tower)) self.add_module('bbox_tower', nn.Sequential(*bbox_tower)) self.cls_logits = nn.Conv2d(in_channels, num_classes, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(in_channels, 4, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels, 1, kernel_size=3, stride=1, padding=1) # pdb.set_trace() # (Pdb) self.cls_tower # Sequential( # (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (1): GroupNorm(32, 256, eps=1e-05, affine=True) # (2): ReLU() # (3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (4): GroupNorm(32, 256, eps=1e-05, affine=True) # (5): ReLU() # (6): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (7): GroupNorm(32, 256, eps=1e-05, affine=True) # (8): ReLU() # (9): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (10): GroupNorm(32, 256, eps=1e-05, affine=True) # (11): ReLU() # ) # (Pdb) self.bbox_tower # Sequential( # (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (1): GroupNorm(32, 256, eps=1e-05, affine=True) # (2): ReLU() # (3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (4): GroupNorm(32, 256, eps=1e-05, affine=True) # (5): ReLU() # (6): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (7): GroupNorm(32, 256, eps=1e-05, affine=True) # (8): ReLU() # (9): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (10): GroupNorm(32, 256, eps=1e-05, affine=True) # (11): ReLU() # ) # (Pdb) self.cls_logits # Conv2d(256, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (Pdb) self.bbox_pred # Conv2d(256, 4, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (Pdb) self.centerness # Conv2d(256, 1, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss prior_prob = cfg.MODEL.FCOS.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) if cfg.MODEL.BACKBONE.USE_P2: self.scales = nn.ModuleList( [Scale(init_value=1.0) for _ in range(6)]) else: self.scales = nn.ModuleList( [Scale(init_value=1.0) for _ in range(5)])
def __init__(self, cfg): """ Arguments: in_channels (int): number of channels of the input feature """ super(DenseBoxHead, self).__init__() # TODO: Implement the sigmoid version first. # assert cfg.MODEL.BACKBONE.OUT_CHANNELS == cfg.SEARCH.DECODER.AGG_SIZE num_classes = cfg.MODEL.RETINANET.NUM_CLASSES - 1 in_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS cls_tower = [] bbox_tower = [] for i in range(cfg.MODEL.RETINANET.NUM_CONVS): cls_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) cls_tower.append(nn.GroupNorm(32, in_channels)) cls_tower.append(nn.ReLU()) bbox_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) bbox_tower.append(nn.GroupNorm(32, in_channels)) bbox_tower.append(nn.ReLU()) self.add_module('cls_tower', nn.Sequential(*cls_tower)) self.add_module('bbox_tower', nn.Sequential(*bbox_tower)) self.cls_logits = nn.Conv2d(in_channels, num_classes, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(in_channels, 4, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels, 1, kernel_size=3, stride=1, padding=1) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # retinanet_bias_init prior_prob = cfg.MODEL.RETINANET.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)])
def __init__(self, share_weights_layer, head_config, repeats, cfg): """ Arguments: head_config: head arch sampled by controller cfg: global setting info """ super(MicroHead_v2, self).__init__() self.num_classes = cfg.MODEL.RETINANET.NUM_CLASSES - 1 self.in_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS self.num_head_layers = cfg.SEARCH.HEAD.NUM_HEAD_LAYERS self.num_head = 5 self.output_concat = cfg.SEARCH.HEAD.OUTPUT_CONCAT self.fpn_strides = cfg.MODEL.RETINANET.ANCHOR_STRIDES self.dense_points = 1 self.norm_reg_targets = False self.centerness_on_reg = False self.share_weights_layer = share_weights_layer assert self.share_weights_layer >= 0 assert self.share_weights_layer <= self.num_head_layers # judge whether to have split_weights if self.share_weights_layer == 0: self.has_split_weights = False else: self.has_split_weights = True # judge whether to have shared_weights if self.share_weights_layer == self.num_head_layers: self.has_shared_weights = False else: self.has_shared_weights = True if self.has_split_weights: self._cls_head_split_ops = nn.ModuleList() self._reg_head_split_ops = nn.ModuleList() for ind in range(self.num_head): cls_empty_head_layer = nn.ModuleList() reg_empty_head_layer = nn.ModuleList() self._cls_head_split_ops.append(cls_empty_head_layer) self._reg_head_split_ops.append(reg_empty_head_layer) if self.has_shared_weights: self._cls_head_global_ops = nn.ModuleList() self._reg_head_global_ops = nn.ModuleList() agg_size = self.in_channels for ind, cell in enumerate(head_config): op_index = cell op_name = HEAD_OP_NAMES[op_index] _cls_ops = HEAD_OPS[op_name](agg_size, 1, True, repeats=repeats) _reg_ops = HEAD_OPS[op_name](agg_size, 1, True, repeats=repeats) if ind < self.share_weights_layer: # do not share weights for ind2 in range(self.num_head): self._cls_head_split_ops[ind2].append( copy.deepcopy(_cls_ops)) self._reg_head_split_ops[ind2].append( copy.deepcopy(_reg_ops)) else: # share weights self._cls_head_global_ops.append(_cls_ops) self._reg_head_global_ops.append(_reg_ops) final_channel = self.in_channels self.cls_logits = nn.Conv2d(final_channel, self.num_classes * self.dense_points, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(final_channel, 4 * self.dense_points, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(final_channel, 1 * self.dense_points, kernel_size=3, stride=1, padding=1) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)]) # initialization for modules in [self.cls_logits, self.bbox_pred, self.centerness]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # retinanet_bias_init prior_prob = cfg.MODEL.RETINANET.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value)
def __init__(self, cfg, in_channels): """ Arguments: in_channels (int): number of channels of the input feature """ super(FCOSHead, self).__init__() # TODO: Implement the sigmoid version first. num_classes = cfg.MODEL.FCOS.NUM_CLASSES - 1 self.fpn_strides = cfg.MODEL.FCOS.FPN_STRIDES self.norm_reg_targets = cfg.MODEL.FCOS.NORM_REG_TARGETS self.centerness_on_reg = cfg.MODEL.FCOS.CENTERNESS_ON_REG self.use_dcn_in_tower = cfg.MODEL.FCOS.USE_DCN_IN_TOWER cls_tower = [] bbox_tower = [] for i in range(cfg.MODEL.FCOS.NUM_CONVS): if self.use_dcn_in_tower and \ i == cfg.MODEL.FCOS.NUM_CONVS - 1: conv_func = DFConv2d else: conv_func = nn.Conv2d cls_tower.append( conv_func(in_channels, in_channels, kernel_size=3, stride=1, padding=1, bias=True)) cls_tower.append(nn.GroupNorm(32, in_channels)) cls_tower.append(nn.ReLU()) bbox_tower.append( conv_func(in_channels, in_channels, kernel_size=3, stride=1, padding=1, bias=True)) bbox_tower.append(nn.GroupNorm(32, in_channels)) bbox_tower.append(nn.ReLU()) self.add_module('cls_tower', nn.Sequential(*cls_tower)) self.add_module('bbox_tower', nn.Sequential(*bbox_tower)) self.cls_logits = nn.Conv2d(in_channels, num_classes, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(in_channels, 4, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels, 1, kernel_size=3, stride=1, padding=1) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss prior_prob = cfg.MODEL.FCOS.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)])
def __init__(self, cfg, in_channels): """ Arguments: in_channels (int): number of channels of the input feature """ super(FCOSHead, self).__init__() # TODO: Implement the sigmoid version first. num_classes = cfg.MODEL.FCOS.NUM_CLASSES - 1 cls_tower = [] bbox_tower = [] eval_tower = [] cls_tower.append( nn.Conv2d(in_channels + cfg.MODEL.SEG_ON_ADD_CHANEL, in_channels // 2, kernel_size=3, stride=1, padding=1)) cls_tower.append(nn.GroupNorm(32, in_channels // 2)) cls_tower.append(nn.ReLU()) bbox_tower.append( nn.Conv2d(in_channels + cfg.MODEL.SEG_ON_ADD_CHANEL, in_channels // 2, kernel_size=3, stride=1, padding=1)) bbox_tower.append(nn.GroupNorm(32, in_channels // 2)) bbox_tower.append(nn.ReLU()) for i in range(cfg.MODEL.FCOS.NUM_CONVS - 1): cls_tower.append( nn.Conv2d(in_channels // 2, in_channels // 2, kernel_size=3, stride=1, padding=1)) cls_tower.append(nn.GroupNorm(32, in_channels // 2)) cls_tower.append(nn.ReLU()) bbox_tower.append( nn.Conv2d(in_channels // 2, in_channels // 2, kernel_size=3, stride=1, padding=1)) bbox_tower.append(nn.GroupNorm(32, in_channels // 2)) bbox_tower.append(nn.ReLU()) if cfg.MODEL.FCOS.EVAL_HEAD: eval_tower.append(nn.GroupNorm(32, in_channels)) eval_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) eval_tower.append(nn.GroupNorm(32, in_channels)) eval_tower.append(nn.ReLU()) else: self.eval_tower = None self.add_module('cls_tower', nn.Sequential(*cls_tower)) self.add_module('bbox_tower', nn.Sequential(*bbox_tower)) self.cls_logits = nn.Conv2d(in_channels // 2, num_classes, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(in_channels // 2, 4, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels // 2, 1, kernel_size=3, stride=1, padding=1) if cfg.MODEL.FCOS.EVAL_HEAD: self.add_module('eval_tower', nn.Sequential(*eval_tower)) self.eval_pred = nn.Conv2d( in_channels, 4, kernel_size=3, stride=1, padding=1, ) for modules in [self.eval_tower, self.eval_pred]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss prior_prob = cfg.MODEL.FCOS.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(6)])
def __init__(self, num_classes=80, num_convs=4, prior_prob=0.01, in_channels=256): """ Arguments: in_channels (int): number of channels of the input feature """ super(FCOSHead, self).__init__() # TODO: Implement the sigmoid version first. self.in_channels = in_channels cls_tower = [] bbox_tower = [] for i in range(num_convs): cls_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) cls_tower.append(nn.GroupNorm(32, in_channels)) cls_tower.append(nn.ReLU()) bbox_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) bbox_tower.append(nn.GroupNorm(32, in_channels)) bbox_tower.append(nn.ReLU()) self.cls_tower = nn.Sequential(*cls_tower) self.bbox_tower = nn.Sequential(*bbox_tower) self.cls_logits = nn.Conv2d(in_channels, num_classes, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(in_channels, 4, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels, 1, kernel_size=3, stride=1, padding=1) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)])
def __init__(self, cfg, in_channels): """ Arguments: in_channels (int): number of channels of the input feature """ super(CascadeFCOSHead, self).__init__() # TODO: Implement the sigmoid version first. num_classes = cfg.MODEL.FCOS.NUM_CLASSES - 1 cascade_area_th = cfg.MODEL.FCOS.CASCADE_AREA_TH self.no_centerness = no_centerness = cfg.MODEL.FCOS.CASCADE_NO_CENTERNESS cls_tower = [] bbox_tower = [] for i in range(cfg.MODEL.FCOS.NUM_CONVS): cls_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) cls_tower.append(nn.GroupNorm(32, in_channels)) cls_tower.append(nn.ReLU()) bbox_tower.append( nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1)) bbox_tower.append(nn.GroupNorm(32, in_channels)) bbox_tower.append(nn.ReLU()) self.add_module('cls_tower', nn.Sequential(*cls_tower)) self.add_module('bbox_tower', nn.Sequential(*bbox_tower)) self.cls_logits_set = nn.ModuleDict() for area_th in cascade_area_th: self.cls_logits_set.add_module( "cls_logits_{}%".format(int(area_th * 100)), nn.Conv2d(in_channels, num_classes, kernel_size=3, stride=1, padding=1)) self.bbox_pred = nn.Conv2d(in_channels, 4, kernel_size=3, stride=1, padding=1) if not no_centerness: self.centerness = nn.Conv2d(in_channels, 1, kernel_size=3, stride=1, padding=1) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.bbox_pred, # self.centerness ] + [m for m in self.cls_logits_set.values()]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss prior_prob = cfg.MODEL.FCOS.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) for m in self.cls_logits_set.values(): torch.nn.init.constant_(m.bias, bias_value) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)])
def __init__(self, cfg, in_channels): super(ATSSHead, self).__init__() self.cfg = cfg num_classes = cfg.MODEL.ATSS.NUM_CLASSES - 1 num_anchors = len( cfg.MODEL.ATSS.ASPECT_RATIOS) * cfg.MODEL.ATSS.SCALES_PER_OCTAVE cls_tower = [] bbox_tower = [] for i in range(cfg.MODEL.ATSS.NUM_CONVS): if self.cfg.MODEL.ATSS.USE_DCN_IN_TOWER and \ i == cfg.MODEL.ATSS.NUM_CONVS - 1: conv_func = DFConv2d else: conv_func = nn.Conv2d cls_tower.append( conv_func(in_channels, in_channels, kernel_size=3, stride=1, padding=1, bias=True)) cls_tower.append(nn.GroupNorm(32, in_channels)) cls_tower.append(nn.ReLU()) bbox_tower.append( conv_func(in_channels, in_channels, kernel_size=3, stride=1, padding=1, bias=True)) bbox_tower.append(nn.GroupNorm(32, in_channels)) bbox_tower.append(nn.ReLU()) self.add_module('cls_tower', nn.Sequential(*cls_tower)) self.add_module('bbox_tower', nn.Sequential(*bbox_tower)) self.cls_logits = nn.Conv2d(in_channels, num_anchors * num_classes, kernel_size=3, stride=1, padding=1) self.bbox_pred = nn.Conv2d(in_channels, num_anchors * 4, kernel_size=3, stride=1, padding=1) self.centerness = nn.Conv2d(in_channels, num_anchors * 1, kernel_size=3, stride=1, padding=1) # initialization for modules in [ self.cls_tower, self.bbox_tower, self.cls_logits, self.bbox_pred, self.centerness ]: for l in modules.modules(): if isinstance(l, nn.Conv2d): torch.nn.init.normal_(l.weight, std=0.01) torch.nn.init.constant_(l.bias, 0) # initialize the bias for focal loss prior_prob = cfg.MODEL.ATSS.PRIOR_PROB bias_value = -math.log((1 - prior_prob) / prior_prob) torch.nn.init.constant_(self.cls_logits.bias, bias_value) if self.cfg.MODEL.ATSS.REGRESSION_TYPE == 'POINT': assert num_anchors == 1, "regressing from a point only support num_anchors == 1" torch.nn.init.constant_(self.bbox_pred.bias, 4) self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(5)])