Still from the film "Ivan Vasilievich Changes His Profession"
? , - . — , . . — , , , .
- .
:
- (backbone) — , , , — , . InsightFace — Open Source .
- (embedding) — , . 128 512. , 512. : . , , , — . , ( ) 1, — -1 ( 0).
- Embedding- — , , ( ) .
- — , ( ) , — , — . , — ( ), — , — . softmax.
, , . — , , . — ( — ), — . .
: (metric learning) .
, . — Triplet Loss:
:
- — anchor, , ;
- — positive, ;
- — negative, ;
- — , .
, , - .
, ( — ), , , embedding- .
Triplet Loss , “ ”, , , SotA , . , Triplet Loss (fine-tuning) . , .
, , , , , . :
— , ( 512), — ( , ). — () , . , “ ” . : , , . . , :
: , , , . , . , , Triplet Loss — , , (hard sampling), .
— , , : Softmax Cross Entropy — . Softmax Loss.
Softmax Loss
Softmax, . :
- — ()
- — embedding-,
- — bias,
, ( , embedding- ): . Softmax( ) :
— Cross Entropy, Softmax Loss :
— . , , 42, 42- .
— , .
: — : , . , . :
- , — ( ), — ( 512).
- , — .
, .
, :
, : — , . , , ( ), s (scale), :
Scale is our first of two hyperparameters. Fixing it for all vectors leads to the fact that they are now located on the hypersphere. In a 2D version, it looks like this (one color - one class):
Image from the ArcFace article , a toy example for demonstration: each class is highlighted with its own color, each point on the circle is a separately taken image, the middle vector of each class is connected to the center for clarity. Note that the classes are connected "without gaps".
Let's rewrite Softmax Loss (now called Normalized Softmax Loss, N-Softmax) with these observations in mind:
. N-Softmax .
Margin-Based Loss
, , — . softmax loss, . , (decision boundary), ( ). . ? () , . — (decision margin). — margin — , : scale — . 2D ( ArcFace):
— margin, — margin
, .
, margin ( ) :
. . : Large-Margin Softmax Loss SphereFace. , , Margin-based loss. :
margin . . : AM-Softmax CosFace , , , . :
margin : → . ArcFace. ArcFace :
, ArcFace AirFace. Margin , ArcFace, , ( ). , , ( — ), , , , :
margin — , — ( ArcFace).
Margin & Scale
- , , — scale (s) margin (m), . , AM Softmax , , ArcFace — , a , CosFace (, , AM Softmax) , a . , , “ ”, .
— AdaCos, — scale margin . :
- Margin scale — , .
- scale margin, margin scale.
- scale .
- — scale
2 20 , , Y — , , X — . , , , :
scale ( , , margin 0), — margin scale=30. , scale, “” , margin X. , — scale margin, - , ? AdaCos scale ( ). , : , — . s [10, 25], .
AdaCos — scale. , scale , . , , .
margin , , , ? . X , Y — ( N-softmax ):
: CosFace N-softmax , ArcFace — . SphereFace, , . ArcFace — target logit, , , . , , ( ). , (, ) , :
# cosine - cos(theta) # phi - cos(theta + m) # th - cos(math.pi - m) # mm - sin(math.pi - m) * m if easy_margin: phi = torch.where(cosine > 0, phi, cosine) else: phi = torch.where(cosine > th, phi, cosine - mm)
easy_margin , :
Easy margin , N-Softmax ( ), not easy margin . , , , , “”, , , .
Loss LFW MegaFace, Rank1 @ MegaFace, Tar @ Far AM-Softmax/CosFace 99.33 0.9833 0.9841 ArcFace 99.83 0.9836 0.9848 SphereFace 99.42 0.9743 0.9766
Loss Resnet50-MSC MobileNet-MSC Resnet50-Casia MobileNet-Casia AM-Softmax/CosFace 99.3 97.65 99.34 98.46 ArcFace 99.15 98.43 99.35 99.01 SphereFace 99.02 96.86 99.1 97.83
, ArcFace SotA .
. (margin) , . AM Softmax ( ) ArcFace ( ). , , , AirFace.
:
SphereFace https://arxiv.org/abs/1704.08063
AM Softmax https://arxiv.org/abs/1801.05599
CosFace https://arxiv.org/abs/1801.09414
ArcFace https://arxiv.org/abs/1801.07698
AirFace https://arxiv.org/abs/1907.12256
:
Deep Face Recognition: A Survey https://arxiv.org/abs/1804.06655
A Performance Evaluation of Loss Functions for Deep Face Recognition https://arxiv.org/abs/1901.05903