insightface icon indicating copy to clipboard operation
insightface copied to clipboard

scale issue of embedding vector in arcface_pytorch

Open jarammm opened this issue 2 years ago • 6 comments

I trained a pre-trained ArcFace model using a custom dataset. I downloaded the pre-trained model from this link (folder: ms1mv3_arcface_r100_fp16). The training code I used was train.py. And I prepared custom dataset according to the instructions on this page. However, when I ran inference.py and printed the maximum and minimum values from the resulting identity embedding vector, the scale of values was significantly different between the downloaded model and my fine-tuned model.

Additionally, I used a model that was pre-trained with the glint360k dataset using the ArcFace loss function. This model also resulted in very small scale values, as shown below.

# maximum value of embedding vector, minimum value of embedding vector
origin ms1mv3_arcface_r100_fp16 pretrained model : 3.0835645 -3.1708715
fine-tuned ms1mv3_arcface_r100_fp16 with arcface loss : 0.98196155 -0.92735183
origin glint360k pretrained model : 0.35392997 -0.46031702
fine-tuned glint360k with arcface loss : 0.15978588 -0.13729438

I want to know why this difference occurs and ultimately obtain embedding vector values that are similar to the range of values generated in the pretrained ArcFace model in the fine-tuned ArcFace model.

jarammm avatar Mar 12 '23 18:03 jarammm

how about the test accuracy?

nttstar avatar Mar 22 '23 08:03 nttstar

In my experience, if we train for numerous epochs, the scale of feature vector will decrease.

nttstar avatar Mar 22 '23 08:03 nttstar

@nttstar last epoch(20th)'s accuracy is as follow.

Training: 2023-03-21 08:05:00,085-[lfw][82000]XNorm: 10.092418
Training: 2023-03-21 08:05:00,085-[lfw][82000]Accuracy-Flip: 0.98850+-0.00431
Training: 2023-03-21 08:05:00,086-[lfw][82000]Accuracy-Highest: 0.99033
Training: 2023-03-21 08:07:01,235-[cfp_fp][82000]XNorm: 10.469364
Training: 2023-03-21 08:07:01,235-[cfp_fp][82000]Accuracy-Flip: 0.94371+-0.01017
Training: 2023-03-21 08:07:01,236-[cfp_fp][82000]Accuracy-Highest: 0.94800
Training: 2023-03-21 08:08:45,358-[agedb_30][82000]XNorm: 9.623387
Training: 2023-03-21 08:08:45,359-[agedb_30][82000]Accuracy-Flip: 0.86133+-0.02337
Training: 2023-03-21 08:08:45,359-[agedb_30][82000]Accuracy-Highest: 0.91717

And scale of feature vector was significantly decreased. How can I fine-tune/training arcface model properly?

jarammm avatar Mar 22 '23 10:03 jarammm

I think if the accuracy increase, the scale doesn't matter.

nttstar avatar Mar 25 '23 03:03 nttstar

@nttstar Thank you for your answer. Then how do I use this model I trained myself to get the right embedding vector for inference.py ? Is there a formula for transforming the computed embedding vector? This is because the scale is too small, so when the embedding vector for different faces is extracted, the difference is too small to utilize.

jarammm avatar Mar 25 '23 12:03 jarammm

use the embedding after l2-normalization

nttstar avatar Mar 25 '23 15:03 nttstar