def __init__(self, backbone, return_layers, anchor_nums=3):
     super(RetinaFace, self).__init__()
     # if backbone_name == 'resnet50':
     #     self.backbone = resnet.resnet50(pretrained)
     # self.backbone = resnet.__dict__[backbone_name](pretrained=pretrained)
     # self.return_layers = {'layer1': 0, 'layer2': 1, 'layer3': 2, 'layer4': 3}
     assert backbone, 'Backbone can not be none!'
     assert len(
         return_layers) > 0, 'There must be at least one return layers'
     self.body = _utils.IntermediateLayerGetter(backbone, return_layers)
     in_channels_stage2 = 256
     # in_channels_stage2 = 64
     in_channels_list = [
         #in_channels_stage2,
         in_channels_stage2 * 2,
         in_channels_stage2 * 4,
         in_channels_stage2 * 8,
     ]
     out_channels = 256
     self.fpn = FeaturePyramidNetwork(in_channels_list, out_channels)
     # self.ClassHead = ClassHead()
     # self.BboxHead = BboxHead()
     # self.LandmarkHead = LandmarkHead()
     self.ClassHead = self._make_class_head()
     self.BboxHead = self._make_bbox_head()
     self.LandmarkHead = self._make_landmark_head()
     self.anchors = Anchors()
     self.regressBoxes = RegressionTransform()
     self.losslayer = losses.LossLayer()
    def __init__(self, num_classes, block, layers, num_anchors=3):
        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.layer1[layers[0] - 1].conv2.out_channels,
                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.layer1[layers[0] - 1].conv3.out_channels,
                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],
                                   fpn_sizes[3])

        self.context = self._make_contextlayer()

        self.clsHead = ClassHead_()
        self.bboxHead = BboxHead_()
        self.ldmHead = LandmarkHead_()

        # self.clsHead = self._make_class_head()
        # self.bboxHead = self._make_bbox_head()
        # self.ldmHead = self._make_landmark_head()

        self.anchors = Anchors()

        self.regressBoxes = RegressionTransform()

        self.losslayer = losses.LossLayer()

        self.freeze_bn()

        # initialize head
        # self.clsHead.apply(initialize_layer)
        # self.bboxHead.apply(initialize_layer)
        # self.ldmHead.apply(initialize_layer)

        # initialize context
        for layer in self.context:
            for m in layer.modules():
                if isinstance(m, nn.Conv2d):
                    nn.init.normal_(m.weight, std=0.01)
                    if m.bias is not None:
                        nn.init.constant_(m.bias, 0)
                if isinstance(m, nn.BatchNorm2d):
                    nn.init.constant_(m.weight, 1)
                    nn.init.constant_(m.bias, 0)