Custom accuracy function for triplet loss training

Viewed 373

I'm trying to train a triplet loss model with tensorflow and keras. I'm using the VGG16 model to create a 2622 embeddings from my dateset.

I use the tfa.losses.TripletSemiHardLoss as my loss function. I want to add some kind of accuracy function to the training process because I feel that only tracking the loss is not enough. I know that I can use a custom function with the "metrics" argument in the model "compile" function, but I'm not quiet sure what kind of function do I need for the triplet loss training. I thought of taking the semi_hard_triplet_loss function that tensorflow implements and divide the number of positive triplet by the number of all valid triplets.

accuracy = 1-(positive_triplet/all_valid_triplets)

where positive triplets means all triplets that has loss > 0.

Is that the right way to go?

1 Answers

I think it's one way to go.

Ultimately, when all the triplets have been mined, the number of triplets to be updated will be 0. In your formula, it will translate to progress=1.

So, defining a pseudo-progress (not really an accuracy) like this makes sense to me.

I am not sure how to retrieve this information from TripletSemiHardLoss or TripletHardLoss though.

Related