Vgg-Face-Fine-tune icon indicating copy to clipboard operation
Vgg-Face-Fine-tune copied to clipboard

loss qusetion?

Open chenkingwen opened this issue 6 years ago • 9 comments

is it loss = positive_distance - negative_distance?and you useloss = negative_distance - positive_distance

chenkingwen avatar May 19 '18 08:05 chenkingwen

in the triplet framework, a batch of training data consists of 3 parts: (anchor, pos, neg) positive_distance means the l2 distances between anchor and pos. anchor and pos are embeddings that belogs to the same person, so we hope them to be as small as possible. similarly, we want negative_distance to be as large as possible

loss = max( 0, positive_distance - negative_distance + 1). this is a svm-like loss that what we want is L2_distance(emb(anchor), emb(pos)) is greater than L2_distance(emb(anchor), emb(pos)) by a safe margin of 1, where anchor, pos, neg are images, and emb function means the neural network that transfer images into a high-dimentional embeddings

Ao-Lee avatar May 25 '18 02:05 Ao-Lee

image Hi, I have changed margin to 0.3. As shown in the figure, there are always some validation losss = 0.3. Do you know why?

antipink avatar May 31 '18 11:05 antipink

if all the layers is learnable, try a smaller learning rate. For the first time, I usually froze all the layers except the last layer, train the last layer with a big learning rate until converged, then unfreze all the layers and set the learning rate to a small value

Ao-Lee avatar Jun 08 '18 02:06 Ao-Lee

@antipink try to use the model to predict somthing, if the prediction looks wierd (for example, the network predicts the same vector no matter what input is), then the learning rate might be too high

Ao-Lee avatar Jun 08 '18 02:06 Ao-Lee

@Ao-Lee Yeah, I have frozen all the layers except last 2 layer. But no matter what the learning rate is, it is still weird that few epochs have their validation loss equal to the margin that we chose. In my case, when validation loss = 0.3 means that positive_distance - negative_distance = 0 for each triplet, the change of this is just too low. How could it happen?

antipink avatar Jun 08 '18 13:06 antipink

this should be a fine-tuning process, it assumes that a pre-trained face network (vgg-face) was loaded before training. I dont think initializing an empty vgg or image-net vgg would work here. (vgg is very hard to train from scratch, since there are more params in vgg and vgg doesn't have BN or residual-like structure)

this project try to solve the issue that pre-trained model doesn't work well on asian faces.

Ao-Lee avatar Jun 11 '18 08:06 Ao-Lee

@antipink, I also have the same problem, when changing the margin value, val_loss value will only decrease to the value of margin, then val_loss will not change. Did you solve this problem, can you guide me to solve this problem? I use VGGFace Resnet50. Thank you very much!

TuanAnhNguyen14111998 avatar Aug 23 '19 10:08 TuanAnhNguyen14111998

@Ao-Lee, thank you very much, your repo gives me a lot of inspiration!

TuanAnhNguyen14111998 avatar Aug 23 '19 10:08 TuanAnhNguyen14111998

@antipink, I also have the same problem, when changing the margin value, val_loss value will only decrease to the value of margin, then val_loss will not change. Did you solve this problem, can you guide me to solve this problem? I use VGGFace Resnet50. Thank you very much!

It has been a long time, I can't remember. I am currently using https://github.com/ageitgey/face_recognition

rayli-anti avatar Aug 30 '19 08:08 rayli-anti