相关疑难解决方法(0)

facenet triplet loss with keras

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 then I define my custom loss function as follows:

def triplet_loss(self, y_true, y_pred):

    embeddings = K.reshape(y_pred, (-1, 3, output_dim))

    positive_distance = K.mean(K.square(embeddings[:,0] - embeddings[:,1]),axis=-1)
    negative_distance = K.mean(K.square(embeddings[:,0] - embeddings[:,2]),axis=-1)
    return K.mean(K.maximum(0.0, positive_distance - negative_distance + _alpha))

self._model.compile(loss=triplet_loss, optimizer="sgd")
self._model.fit(x=x,y=y,nb_epoch=1, batch_size=len(x))
Run Code Online (Sandbox Code Playgroud)

where y is just a dummy array filled with …

neural-network keras tensorflow

21
推荐指数
2
解决办法
1万
查看次数

标签 统计

keras ×1

neural-network ×1

tensorflow ×1