def __init__(self, device, head_name = cfg['HEAD_NAME'], NUM_CLASS = cfg['NUM_CLASS'], GPU_ID = cfg['GPU_ID'], EMBEDDING_SIZE = cfg['EMBEDDING_SIZE'], HEAD_RESUME_ROOT = cfg['HEAD_RESUME_ROOT']): super().__init__() HEAD_DICT = {'ArcFace': ArcFace(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID), 'CosFace': CosFace(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID), 'SphereFace': SphereFace(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID), 'Am_softmax': Am_softmax(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID)} self.device = device self.head = HEAD_DICT[head_name] self.head.load_state_dict(torch.load(HEAD_RESUME_ROOT)) self.head = self.head.to(device)
BACKBONE = mobileface() else: raise NotImplementedError print("=" * 60) print(BACKBONE) print("{} Backbone Generated".format(BACKBONE_NAME)) print("=" * 60) if HEAD_NAME == 'ArcFace': HEAD = ArcFace(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID) elif HEAD_NAME == 'CosFace': HEAD = CosFace(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID) elif HEAD_NAME == 'SphereFace': HEAD = SphereFace(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID) elif HEAD_NAME == 'Am_softmax': HEAD = Am_softmax(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID) elif HEAD_NAME == 'Softmax': HEAD = Softmax(in_features = EMBEDDING_SIZE, out_features = NUM_CLASS, device_id = GPU_ID) else: raise NotImplementedError print("=" * 60) print(HEAD) print("{} Head Generated".format(HEAD_NAME)) print("=" * 60) if LOSS_NAME == 'Focal': LOSS = FocalLoss() elif LOSS_NAME == 'Softmax': LOSS = nn.CrossEntropyLoss() else: raise NotImplementedError
} BACKBONE = BACKBONE_DICT[BACKBONE_NAME] print("=" * 60) print(BACKBONE) print("{} Backbone Generated".format(BACKBONE_NAME)) print("=" * 60) HEAD_DICT = { 'ArcFace': ArcFace(in_features=EMBEDDING_SIZE, out_features=NUM_CLASS), 'CosFace': CosFace(in_features=EMBEDDING_SIZE, out_features=NUM_CLASS), 'SphereFace': SphereFace(in_features=EMBEDDING_SIZE, out_features=NUM_CLASS), 'Am_softmax': Am_softmax(in_features=EMBEDDING_SIZE, out_features=NUM_CLASS) } HEAD = HEAD_DICT[HEAD_NAME] print("=" * 60) print(HEAD) print("{} Head Generated".format(HEAD_NAME)) print("=" * 60) LOSS_DICT = {'Focal': FocalLoss(), 'Softmax': nn.CrossEntropyLoss()} LOSS = LOSS_DICT[LOSS_NAME] print("=" * 60) print(LOSS) print("{} Loss Generated".format(LOSS_NAME)) print("=" * 60) if BACKBONE_NAME.find("IR") >= 0: