facenet triplet loss with keras

后端 未结 4 1786
野趣味
野趣味 2021-01-31 09:50

I am trying to implement facenet in Keras with Thensorflow backend and I have some problem with the triplet loss.

I call the fit function with 3*n number of images and t

4条回答
  •  长发绾君心
    2021-01-31 10:42

    the loss function in tensorflow requires a list of labels, i.e. list of integers. I think you are passing a 2D matrix, i.e. one hot encoding.

    Try this

    import keras.backend as K
    from tf.contrib.losses.metric_learning import triplet_semihard_loss
    
    def loss(y_true, y_pred):
        y_true = K.argmax(y_true, axis = -1)
        return triplet_semihard_loss(labels=y_true, embeddings=y_pred, margin=1.)
    

提交回复
热议问题