deepinsight / insightface

State-of-the-art 2D and 3D Face Analysis Project
https://insightface.ai
23.47k stars 5.42k forks source link

scale issue of embedding vector in arcface_pytorch #2260

Open jarammm opened 1 year ago

jarammm commented 1 year ago

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.

nttstar commented 1 year ago

how about the test accuracy?

nttstar commented 1 year ago

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

jarammm commented 1 year ago

@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?

nttstar commented 1 year ago

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

jarammm commented 1 year ago

@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.

nttstar commented 1 year ago

use the embedding after l2-normalization