def __init__(self, backbone='res50', hyps=None): super(RetinaNet, self).__init__() self.num_classes = int(hyps['num_classes']) + 1 self.anchor_generator = Anchors(ratios=np.array([0.5, 1, 2]), ) self.num_anchors = self.anchor_generator.num_anchors self.init_backbone(backbone) self.fpn = FPN(in_channels_list=self.fpn_in_channels, out_channels=256, top_blocks=LastLevelP6P7(self.fpn_in_channels[-1], 256), use_asff=False) self.cls_head = CLSHead(in_channels=256, feat_channels=256, num_stacked=4, num_anchors=self.num_anchors, num_classes=self.num_classes) self.reg_head = REGHead( in_channels=256, feat_channels=256, num_stacked=4, num_anchors=self.num_anchors, num_regress=5 # xywha ) self.loss = IntegratedLoss(func='smooth') # self.loss_var = KLLoss() self.box_coder = BoxCoder()
def __init__(self, backbone='res50', num_classes=2, num_refining=1): super(STELA, self).__init__() self.anchor_generator = Anchors() self.num_anchors = self.anchor_generator.num_anchors self.init_backbone(backbone) self.fpn = FPN(in_channels_list=self.fpn_in_channels, out_channels=256, top_blocks=LastLevelP6P7(self.fpn_in_channels[-1], 256)) self.cls_head = CLSHead(in_channels=256, feat_channels=256, num_stacked=1, num_anchors=self.num_anchors, num_classes=num_classes) self.reg_head = REGHead(in_channels=256, feat_channels=256, num_stacked=1, num_anchors=self.num_anchors, num_regress=5) self.num_refining = num_refining if self.num_refining > 0: self.ref_heads = nn.ModuleList([ REGHead(in_channels=256, feat_channels=256, num_stacked=1, num_anchors=self.num_anchors, num_regress=5) for _ in range(self.num_refining) ]) self.loss_ref = RegressLoss(func='smooth') self.loss_cls = FocalLoss() self.loss_reg = RegressLoss(func='smooth') self.box_coder = BoxCoder()
def __init__(self, num_classes, block, layers): self.inplanes = 64 super(ResNet, self).__init__() self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm2d(64) self.relu = nn.ReLU(inplace=True) self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.layer1 = self._make_layer(block, 64, layers[0]) self.layer2 = self._make_layer(block, 128, layers[1], stride=2) self.layer3 = self._make_layer(block, 256, layers[2], stride=2) self.layer4 = self._make_layer(block, 512, layers[3], stride=2) if block == BasicBlock: fpn_sizes = [ self.layer2[layers[1] - 1].conv2.out_channels, self.layer3[layers[2] - 1].conv2.out_channels, self.layer4[layers[3] - 1].conv2.out_channels, ] elif block == Bottleneck: fpn_sizes = [ self.layer2[layers[1] - 1].conv3.out_channels, self.layer3[layers[2] - 1].conv3.out_channels, self.layer4[layers[3] - 1].conv3.out_channels, ] self.fpn = PyramidFeatures(fpn_sizes[0], fpn_sizes[1], fpn_sizes[2]) self.regressionModel = RegressionModel(256) self.classificationModel = ClassificationModel(256, num_classes=num_classes) self.anchors = Anchors() self.regressBoxes = BBoxTransform() self.clipBoxes = ClipBoxes() # self.focalLoss = losses.FocalLoss() for m in self.modules(): if isinstance(m, nn.Conv2d): n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels m.weight.data.normal_(0, math.sqrt(2.0 / n)) elif isinstance(m, nn.BatchNorm2d): m.weight.data.fill_(1) m.bias.data.zero_() prior = 0.01 self.classificationModel.output.weight.data.fill_(0) self.classificationModel.output.bias.data.fill_( -math.log((1.0 - prior) / prior) ) self.regressionModel.output.weight.data.fill_(0) self.regressionModel.output.bias.data.fill_(0)
def __init__(self,backbone='res50',hyps=None): super(RetinaNet, self).__init__() self.num_refining = int(hyps['num_refining']) self.num_classes = int(hyps['num_classes']) + 1 self.anchor_generator = Anchors( ratios = np.array([ 0.5,1, 2]), # scales = np.array([ 2**0, 2 ** 0.333, 2 ** 0.666]), # rotations = np.array([0, 60, 120]) ) self.num_anchors = self.anchor_generator.num_anchors self.init_backbone(backbone) self.fpn = FPN( in_channels_list=self.fpn_in_channels, out_channels=256, top_blocks=LastLevelP6P7(self.fpn_in_channels[-1], 256), use_asff = False ) self.cls_head = CLSHead( in_channels=256, feat_channels=256, num_stacked=4, num_anchors=self.num_anchors, num_classes=self.num_classes ) self.reg_head = REGHead( in_channels=256, feat_channels=256, num_stacked=4, num_anchors=self.num_anchors, num_regress=5 # xywha ) if self.num_refining > 0: self.ref_heads = nn.ModuleList( [REGHead( in_channels=256, feat_channels=256, num_stacked=2, num_anchors=self.num_anchors, num_regress=5, ) for _ in range(self.num_refining)] ) self.loss_ref = RegressLoss(func='smooth') self.loss = IntegratedLoss(func='smooth') self.box_coder = BoxCoder()
def __init__(self, layers, in_channels=3, num_classes=80, fpn_feature_size=256, feature_size=256, planes=[64, 128, 256, 512]): self.in_planes = planes[0] self.planes = planes self.fpn_feature_size = fpn_feature_size self.feature_size = feature_size super(ResNet, self).__init__() self.conv1 = nn.Conv2d(in_channels, self.in_planes, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm2d(self.in_planes) self.relu1 = nn.ReLU(inplace=True) self.maxpool1 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.layer1 = self._make_layer(self.planes[0], layers[0]) self.layer2 = self._make_layer(self.planes[1], layers[1], stride=2) self.layer3 = self._make_layer(self.planes[2], layers[2], stride=2) self.layer4 = self._make_layer(self.planes[3], layers[3], stride=2) fpn_sizes = [ self.layer2[layers[1] - 1].conv3.out_channels, self.layer3[layers[2] - 1].conv3.out_channels, self.layer4[layers[3] - 1].conv3.out_channels ] self.fpn = PyramidFeatures(fpn_sizes[0], fpn_sizes[1], fpn_sizes[2], feature_size=self.fpn_feature_size) self.regressionModel = RegressionModel( fpn_feature_size=self.fpn_feature_size, feature_size=self.feature_size) self.classificationModel = ClassificationModel( feature_size=self.feature_size, num_classes=num_classes) self.anchors = Anchors() self.regressBoxes = BBoxTransform() self.clipBoxes = ClipBoxes()