def __init__(self, cfg, phase, size, num_classes): super(SSD, self).__init__() self.phase = phase self.num_classes = num_classes self.size = size self.prior_layer = PriorLayer(cfg) self.priorbox = PriorBox(cfg) self.priors = self.priorbox.forward() self.extractor = SSDarknet53(size) self.in_channels = cfg['in_channels_darknet'] self.num_anchors = cfg['num_anchors'] self.input_fixed = cfg['input_fixed'] self.loc = nn.ModuleList() self.conf = nn.ModuleList() for i in range(len(self.in_channels)): self.loc += [ nn.Conv2d(self.in_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.conf += [ nn.Conv2d(self.in_channels[i], self.num_anchors[i] * self.num_classes, kernel_size=3, padding=1) ]
def __init__(self, cfg, phase, num_classes, size, channel_size='48'): super(SSD, self).__init__() self.phase = phase self.num_classes = num_classes self.arm_num_classes = 2 self.size = size self.prior_layer = PriorLayer(cfg) self.priorbox = PriorBox(cfg) self.priors = self.priorbox.forward() self.extractor = VGG16Extractor(size, channel_size) self.arm_channels = cfg["arm_channels"] self.odm_channels = cfg["odm_channels"] self.num_anchors = cfg["num_anchors"] self.input_fixed = cfg['input_fixed'] self.loc = nn.ModuleList() self.conf = nn.ModuleList() self.arm_loc = nn.ModuleList() self.arm_conf = nn.ModuleList() for i in range(len(self.arm_channels)): self.loc += [ nn.Conv2d(self.odm_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.arm_loc += [ nn.Conv2d(self.arm_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.conf += [ nn.Conv2d(self.odm_channels[i], self.num_anchors[i] * self.num_classes, kernel_size=3, padding=1) ] self.arm_conf += [ nn.Conv2d(self.arm_channels[i], self.num_anchors[i] * self.arm_num_classes, kernel_size=3, padding=1) ]
def __init__(self, cfg): super(SSD, self).__init__() self.cfg = cfg self.size = cfg.MODEL.SIZE if self.size == '300': size_cfg = cfg.SMALL else: size_cfg = cfg.BIG self.num_classes = cfg.MODEL.NUM_CLASSES self.prior_layer = PriorLayer(cfg) self.priorbox = PriorBox(cfg) self.priors = self.priorbox.forward() self.extractor = get_func(cfg.MODEL.CONV_BODY)(self.size, cfg.TRAIN.CHANNEL_SIZE) if cfg.MODEL.REFINE: self.odm_channels = size_cfg.ODM_CHANNELS self.arm_num_classes = 2 self.odm_loc = nn.ModuleList() self.odm_conf = nn.ModuleList() self.loc_offset_conv = nn.ModuleList() self.dcn_convs = nn.ModuleList(add_dcn_dilas()) self.bn_layers = nn.ModuleList(BN_layers()) self.arm_loc = nn.ModuleList() self.arm_conf = nn.ModuleList() self.arm_channels = size_cfg.ARM_CHANNELS self.num_anchors = size_cfg.NUM_ANCHORS self.input_fixed = size_cfg.INPUT_FIXED self.arm_loc = nn.ModuleList() self.arm_conf = nn.ModuleList() for i in range(len(self.arm_channels)): if cfg.MODEL.REFINE: self.arm_loc += [ nn.Conv2d( self.arm_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.arm_conf += [ nn.Conv2d( self.arm_channels[i], self.num_anchors[i] * self.arm_num_classes, kernel_size=3, padding=1) ] self.loc_offset_conv +=[BasicConv(self.num_anchors[i] * 2, 18, kernel_size=1)] self.odm_loc += [ nn.Conv2d( self.odm_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.odm_conf += [ nn.Conv2d( self.odm_channels[i], self.num_anchors[i] * self.num_classes, kernel_size=3, padding=1) ] else: self.arm_loc += [ nn.Conv2d( self.arm_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.arm_conf += [ nn.Conv2d( self.arm_channels[i], self.num_anchors[i] * self.num_classes, kernel_size=3, padding=1) ] if cfg.TRAIN.TRAIN_ON: self._init_modules()
def __init__(self, cfg): super(SSD, self).__init__() self.cfg = cfg self.size = cfg.MODEL.SIZE if self.size == '300': size_cfg = cfg.SMALL else: size_cfg = cfg.BIG self.num_classes = cfg.MODEL.NUM_CLASSES self.prior_layer = PriorLayer(cfg) self.priorbox = PriorBox(cfg) self.priors = self.priorbox.forward() self.extractor = get_func(cfg.MODEL.CONV_BODY)(self.size) if cfg.MODEL.CASCADE: self.odm_channels = size_cfg.ODM_CHANNELS self.arm_num_classes = 2 self.arm_loc = nn.ModuleList() self.arm_conf = nn.ModuleList() self.arm_channels = size_cfg.ARM_CHANNELS self.num_anchors = size_cfg.NUM_ANCHORS self.input_fixed = size_cfg.INPUT_FIXED self.arm_loc = nn.ModuleList() self.arm_conf = nn.ModuleList() self.deform_conv_c = nn.ModuleList() self.deform_conv_l1 = nn.ModuleList() self.deform_conv_c1 = nn.ModuleList() self.offset = nn.ModuleList() self.offset1 = nn.ModuleList() self.offlat1 = nn.ModuleList() self.offlat = nn.ModuleList() for i in range(len(self.arm_channels)): if cfg.MODEL.CASCADE: self.arm_loc += [ nn.Conv2d(self.arm_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.arm_conf += [ nn.Conv2d(self.arm_channels[i], self.num_anchors[i] * self.arm_num_classes, kernel_size=3, padding=1) ] self.deform_conv_c += [ ConvOffset2d(256 * 3, self.num_anchors[i] * self.arm_num_classes, 3, stride=1, padding=1, num_deformable_groups=3) ] self.deform_conv_c1 += [ ConvOffset2d(256 * 3, self.num_anchors[i] * self.num_classes, 3, stride=1, padding=1, num_deformable_groups=3) ] self.deform_conv_l1 += [ ConvOffset2d(256 * 3, self.num_anchors[i] * 4, 3, stride=1, padding=1, num_deformable_groups=3) ] self.offset += [ nn.Conv2d(36, 2 * 3 * 3 * 3, kernel_size=1, stride=1, padding=0, bias=False, groups=3) ] self.offset1 += [ nn.Conv2d(36, 2 * 3 * 3 * 3, kernel_size=1, stride=1, padding=0, bias=False, groups=3) ] self.offlat += [ nn.Sequential( nn.Conv2d(12, 36, kernel_size=1, stride=1, padding=0, groups=3), nn.ReLU()) ] self.offlat1 += [ nn.Sequential( nn.Conv2d(12, 36, kernel_size=1, stride=1, padding=0, groups=3), nn.ReLU()) ] else: self.arm_loc += [ nn.Conv2d(self.arm_channels[i], self.num_anchors[i] * 4, kernel_size=3, padding=1) ] self.arm_conf += [ nn.Conv2d(self.arm_channels[i], self.num_anchors[i] * self.num_classes, kernel_size=3, padding=1) ] self.deform_conv_c += [ ConvOffset2d(256 * 3, self.num_anchors[i] * self.num_classes, 3, stride=1, padding=1, num_deformable_groups=3) ] self.offset += [ nn.Conv2d(36, 2 * 3 * 3 * 3, kernel_size=1, stride=1, padding=0, bias=False, groups=3) ] self.offlat += [ nn.Sequential( nn.Conv2d(12, 36, kernel_size=1, stride=1, padding=0, groups=3), nn.ReLU()) ] if cfg.TRAIN.TRAIN_ON: self._init_modules()