# Expecting a face similarity loss function

**URL:** <https://discuss.pytorch.org/t/expecting-a-face-similarity-loss-function/94793>\
**Category:** vision\
**Created:** [September 1, 2020, 8:39am UTC](https://discuss.pytorch.org/t/expecting-a-face-similarity-loss-function/94793 "2020-09-01T08:39:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![weisunding](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/weisunding/32/27081_2.png) [@weisunding](https://discuss.pytorch.org/u/weisunding)\
**Post date:** [September 1, 2020, 8:39am UTC](https://discuss.pytorch.org/t/expecting-a-face-similarity-loss-function/94793/1 "2020-09-01T08:39:33Z")

</div>

Hi gurus

I am finding a face similarity loss function which accepts two tensors as input, any idea?

My goal is to find a loss function which can do backward, as SSIM is very good for replacement of L2, but it detects the global structure, I want to compare the face only.

The expected usage

```auto
loss = 1 - face_similarity(tensor1, tensor2)
loss.backward()

```

I know there is a facenet-pytorch project, MTCNN + ResNet(vggface2) combo which can compare the faces, but it breaks the gradients.

Any clue will be appreciated!
