I'm trying to implement Google's Facenet paper:
First of all, is it possible to implement this paper using the Sequential API of Keras or should I go for the Graph API?
In either case, could you please tell me how do I pass the custom loss function tripletLoss
to the model compile and how do I receive the anchor embedding
, positive embedding
and the negative embedding
as parameters to calculate the loss?
Also, what should be the second parameter Y in model.fit(), I do not have any in this case...
Training Data Preparation: For Triplet Loss, the objective is to build triplets <anchor, positive, negative> consisting of an anchor image, a positive image (which is similar to the anchor image), and a negative image (which is dissimilar to the anchor image).
Triplet Loss can be implemented directly as a loss function in the compile method, or it can be implemented as a merge mode with the anchor, positive and negative embeddings of three individual images as the three branches of the merge function.
This issue explains how to create a custom objective (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')
Regarding the y
parameter of .fit()
, since you are the one handling it in the end (the y_true
parameter of the objective function is taken from it), I would say you can pass whatever you need that can fit through Keras plumbing. And maybe a dummy vector to pass dimension checks if your really don't need any supervision.
Eventually, as to how to implement this particular paper, looking for triplet
or facenet
in Keras doc didn't return anything. So you'll probably have to either implement it yourself or find someone who has.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With