def __init__(self, dim_in, spatial_scale, stage=1): super().__init__() self.dim_in = dim_in[-1] method = cfg.FAST_RCNN.ROI_XFORM_METHOD resolution = cfg.FAST_RCNN.ROI_XFORM_RESOLUTION sampling_ratio = cfg.FAST_RCNN.ROI_XFORM_SAMPLING_RATIO pooler = Pooler( method=method, output_size=resolution, scales=spatial_scale, sampling_ratio=sampling_ratio, ) self.pooler = pooler use_lite = cfg.FAST_RCNN.CONVFC_HEAD.USE_LITE use_bn = cfg.FAST_RCNN.CONVFC_HEAD.USE_BN use_gn = cfg.FAST_RCNN.CONVFC_HEAD.USE_GN conv_dim = cfg.FAST_RCNN.CONVFC_HEAD.CONV_DIM num_stacked_convs = cfg.FAST_RCNN.CONVFC_HEAD.NUM_STACKED_CONVS dilation = cfg.FAST_RCNN.CONVFC_HEAD.DILATION xconvs = [] for ix in range(num_stacked_convs): xconvs.append( make_conv(self.dim_in, conv_dim, kernel=3, stride=1, dilation=dilation, use_dwconv=use_lite, use_bn=use_bn, use_gn=use_gn, suffix_1x1=use_lite, use_relu=True)) self.dim_in = conv_dim self.add_module("xconvs", nn.Sequential(*xconvs)) input_size = self.dim_in * resolution[0] * resolution[1] mlp_dim = cfg.FAST_RCNN.CONVFC_HEAD.MLP_DIM self.fc6 = make_fc(input_size, mlp_dim, use_bn=False, use_gn=False) self.dim_out = mlp_dim self.stage = stage if cfg.FAST_RCNN.CONVFC_HEAD.USE_WS: self = convert_conv2convws_model(self)
def __init__(self, dim_in, spatial_scale): super().__init__() self.dim_in = dim_in[-1] method = cfg.GRID_RCNN.ROI_XFORM_METHOD resolution = cfg.GRID_RCNN.ROI_XFORM_RESOLUTION_CLS sampling_ratio = cfg.GRID_RCNN.ROI_XFORM_SAMPLING_RATIO pooler = Pooler( method=method, output_size=resolution, scales=spatial_scale, sampling_ratio=sampling_ratio, ) input_size = self.dim_in * resolution[0] * resolution[1] mlp_dim = cfg.GRID_RCNN.MLP_HEAD.MLP_DIM use_bn = cfg.GRID_RCNN.MLP_HEAD.USE_BN use_gn = cfg.GRID_RCNN.MLP_HEAD.USE_GN self.pooler = pooler self.fc6 = make_fc(input_size, mlp_dim, use_bn, use_gn) self.fc7 = make_fc(mlp_dim, mlp_dim, use_bn, use_gn) self.dim_out = mlp_dim if cfg.GRID_RCNN.MLP_HEAD.USE_WS: self = convert_conv2convws_model(self)
def resnet(): model = ResNet(norm=get_norm(), stride=16) if cfg.BACKBONE.RESNET.USE_WS: model = convert_conv2convws_model(model) return model
def resnet_2mlp_head(dim_in, spatial_scale): model = ResNet_2mlp_Head(dim_in, spatial_scale, norm=get_norm()) if cfg.BACKBONE.RESNET.USE_WS: model = convert_conv2convws_model(model) return model
def __init__(self, dim_in, spatial_scale): super().__init__() self.dim_in = dim_in[-1] # 2048 self.spatial_scale = spatial_scale fpn_dim = cfg.FPN.DIM # 256 use_lite = cfg.FPN.USE_LITE use_bn = cfg.FPN.USE_BN use_gn = cfg.FPN.USE_GN min_level, max_level = get_min_max_levels() # 2, 6 self.num_backbone_stages = len(dim_in) - ( min_level - cfg.FPN.LOWEST_BACKBONE_LVL ) # 4 (cfg.FPN.LOWEST_BACKBONE_LVL=2) # P5 in self.p5_in = make_conv(self.dim_in, fpn_dim, kernel=1, use_bn=use_bn, use_gn=use_gn) # P5 out self.p5_out = make_conv(fpn_dim, fpn_dim, kernel=3, use_dwconv=use_lite, use_bn=use_bn, use_gn=use_gn, suffix_1x1=use_lite) # fpn module self.fpn_in = [] self.fpn_out = [] for i in range(self.num_backbone_stages - 1): # skip the top layer px_in = make_conv(dim_in[-i - 2], fpn_dim, kernel=1, use_bn=use_bn, use_gn=use_gn) # from P4 to P2 px_out = make_conv(fpn_dim, fpn_dim, kernel=3, use_dwconv=use_lite, use_bn=use_bn, use_gn=use_gn, suffix_1x1=use_lite) self.fpn_in.append(px_in) self.fpn_out.append(px_out) self.fpn_in = nn.ModuleList(self.fpn_in) # [P4, P3, P2] self.fpn_out = nn.ModuleList(self.fpn_out) self.dim_in = fpn_dim # P6. Original FPN P6 level implementation from CVPR'17 FPN paper. if not cfg.FPN.EXTRA_CONV_LEVELS and max_level == cfg.FPN.HIGHEST_BACKBONE_LVL + 1: self.maxpool_p6 = nn.MaxPool2d(kernel_size=1, stride=2, padding=0) self.spatial_scale.append(self.spatial_scale[-1] * 0.5) # Coarser FPN levels introduced for RetinaNet if cfg.FPN.EXTRA_CONV_LEVELS and max_level > cfg.FPN.HIGHEST_BACKBONE_LVL: self.extra_pyramid_modules = nn.ModuleList() if cfg.FPN.USE_C5: self.dim_in = dim_in[-1] for i in range(cfg.FPN.HIGHEST_BACKBONE_LVL + 1, max_level + 1): self.extra_pyramid_modules.append( make_conv(self.dim_in, fpn_dim, kernel=3, stride=2, use_dwconv=use_lite, use_bn=use_bn, use_gn=use_gn, suffix_1x1=use_lite)) self.dim_in = fpn_dim self.spatial_scale.append(self.spatial_scale[-1] * 0.5) # self.spatial_scale.reverse() # [1/64, 1/32, 1/16, 1/8, 1/4] # self.dim_out = [self.dim_in] num_roi_levels = cfg.FPN.ROI_MAX_LEVEL - cfg.FPN.ROI_MIN_LEVEL + 1 # Retain only the spatial scales that will be used for RoI heads. `self.spatial_scale` # may include extra scales that are used for RPN proposals, but not for RoI heads. self.spatial_scale = self.spatial_scale[:num_roi_levels] self.dim_out = [self.dim_in for _ in range(num_roi_levels)] if cfg.FPN.USE_WS: self = convert_conv2convws_model(self) self._init_weights()