How to implement triplet loss in Keras?

I am trying to embed a Google Facenet document:

enter image description here

First of all, is it possible to implement this article using the Keras Sequential API or do I need to switch to the Graph API?

In any case, could you tell me how to pass the tripletLoss custom loss tripletLoss to model compilation and how can I get the anchor embedding , positive embedding and negative embedding parameters as parameters for calculating the loss?

Also, what should be the second parameter Y in model.fit (), I do not have in this case ...

+8
python keras
source share
1 answer

This question explains how to create a custom goal (loss) in Keras:

 def dummy_objective(y_true, y_pred): return 0.5 # your implem of tripletLoss here model.compile(loss=dummy_objective, optimizer='adadelta') 

As for the y .fit() parameter, since you are the one that processes it at the end (the y_true parameter of the target function is extracted from it), I would say that you can pass everything you need, it can fit into Keras plumbing. And perhaps a dummy vector to pass the dimension checks to see if you really don't need any observation.

In the end, on how to implement this particular paper, looking for a triplet or facenet in Keras doc didn’t return anything. Thus, you probably have to either implement it yourself or find someone who has it.

+2
source share

All Articles