Skip to content

automan000/SoftMarginTripletLoss_PyTorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SoftMarginTripletLoss_Pytorch

This repository is based on previous works from Part_ReID.

Please refer to In Defense of the Triplet Loss for Person Re-Identification and Deeply-Learned Part-Aligned Representations for Person Re-Identification for more details.

Formulation

install

cd online_triplet_loss
sh ./mask.sh

Usage

definition

from online_triplet_loss.online_triplet_loss import OnlineTripletLoss as LossFunction

triplet_loss_fun = LossFunction(all_triplets=False,
                                positive_type=LossFunction.SampleMethod_ALL,
                                negative_type=LossFunction.SampleMethod_ALL,
                                margin_type=LossFunction.MarginType_SOFTMARGIN,
                                margin=0.3, mu=1.)

Foward

loss = triplet_loss_fun(features, labels)
accuracy = triplet_loss_fun.accuracy

optional arguments

sample strategy:

  • SampleMethod_ALL
  • SampleMethod_HARD
  • SampleMethod_MODERATE

margin type:

  • hard margin
  • soft margin

mu

  • This parameter is adopted for keep a balance between the intra-class loss for postive pairs and the triplet distance.
  • mu=1. is highly recommend, which means that we ignore the intra-class loss.

About

A triplet loss implementation for PyTorch.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published