Skip to content

Instantly share code, notes, and snippets.

View wenfahu's full-sized avatar
🎯
Focusing

Bran Stewart wenfahu

🎯
Focusing
  • Intel
  • Beijing
View GitHub Profile
@wenfahu
wenfahu / triplet_loss.py
Last active August 6, 2018 10:30
soft margin smooth hinge
def triplet_loss_soft(anchor, positive, negative, m=1):
"""Calculate the triplet loss according to the FaceNet paper
Args:
anchor: the embeddings for the anchor images.
positive: the embeddings for the positive images.
negative: the embeddings for the negative images.
Returns:
the triplet loss according to the FaceNet paper as a float tensor.
@wenfahu
wenfahu / triplet_loss.py
Last active August 25, 2018 05:53
hard margin smooth hinge triplet loss
def triplet_loss(anchor, positive, negative, alpha):
"""Calculate the triplet loss according to the FaceNet paper
Args:
anchor: the embeddings for the anchor images.
positive: the embeddings for the positive images.
negative: the embeddings for the negative images.
Returns:
the triplet loss according to the FaceNet paper as a float tensor.
layer {
name: "train-data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mirror: true