17 def __init__(self, cfg):
18 super().__init__()
19
20 feat_dim = cfg.MODEL.BACKBONE.FEAT_DIM
21 num_classes = cfg.MODEL.HEADS.NUM_CLASSES
22 pool_type = cfg.MODEL.HEADS.POOL_LAYER
23 cls_type = cfg.MODEL.HEADS.CLS_LAYER
24 with_bnneck = cfg.MODEL.HEADS.WITH_BNNECK
25 norm_type = cfg.MODEL.HEADS.NORM
26
27 if pool_type == 'fastavgpool': self.pool_layer = FastGlobalAvgPool2d()
28 elif pool_type == 'avgpool': self.pool_layer = nn.AdaptiveAvgPool2d(1)
29 elif pool_type == 'maxpool': self.pool_layer = nn.AdaptiveMaxPool2d(1)
30 elif pool_type == 'gempoolP': self.pool_layer = GeneralizedMeanPoolingP()
31 elif pool_type == 'gempool': self.pool_layer = GeneralizedMeanPooling()
32 elif pool_type == "avgmaxpool": self.pool_layer = AdaptiveAvgMaxPool2d()
33 elif pool_type == 'clipavgpool': self.pool_layer = ClipGlobalAvgPool2d()
34 elif pool_type == "identity": self.pool_layer = nn.Identity()
35 elif pool_type == "flatten": self.pool_layer = Flatten()
36 else: raise KeyError(f"{pool_type} is not supported!")
37
38
39 if cls_type == 'linear': self.classifier = nn.Linear(feat_dim, num_classes, bias=False)
40 elif cls_type == 'arcSoftmax': self.classifier = ArcSoftmax(cfg, feat_dim, num_classes)
41 elif cls_type == 'circleSoftmax': self.classifier = CircleSoftmax(cfg, feat_dim, num_classes)
42 elif cls_type == 'amSoftmax': self.classifier = AMSoftmax(cfg, feat_dim, num_classes)
43 else: raise KeyError(f"{cls_type} is not supported!")
44
45
46
47
48
49 bottleneck = [nn.BatchNorm1d(num_classes)]
50
51 self.bottleneck = nn.Sequential(*bottleneck)
52
53 self.bottleneck.apply(weights_init_kaiming)
54 self.classifier.apply(weights_init_classifier)
55