Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
		BACKBONE = mobilenet()
	elif BACKBONE_NAME == 'Mobilenetv2':
		BACKBONE = mobilenetv2()
	elif BACKBONE_NAME == 'mobileface':
		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()
Ejemplo n.º 3
0
        'IR_152': IR_152(INPUT_SIZE),
        'IR_SE_50': IR_SE_50(INPUT_SIZE),
        'IR_SE_101': IR_SE_101(INPUT_SIZE),
        'IR_SE_152': IR_SE_152(INPUT_SIZE)
    }
    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)