tripletnet.py
def selective_margin_loss(pos_samples, neg_samples, margin, has_sample):
    """ pos_samples: Distance between positive pair
        neg_samples: Distance between negative pair
        margin: minimum desired margin between pos and neg samples
        has_sample: Indicates if the sample should be used to calcuate the loss
    """
    margin_diff = torch.clamp((pos_samples - neg_samples) + margin, min=0, max=1e6)
    num_sample = max(torch.sum(has_sample), 1)
    return torch.sum(margin_diff * has_sample) / num_sample
 pos_samples: Distance between positive pair
        neg_samples: Distance between negative pair
        margin: minimum desired margin between pos and neg samples
        has_sample: Indicates if the sample should be used to calcuate the loss
    
Distance between positive pair
neg_samples: Distance between negative pair
margin: minimum desired margin between pos and neg samples
has_sample: Indicates if the sample should be used to calcuate the loss
Distance between positive pair neg_samples : Distance between negative pair margin : minimum desired margin between pos and neg samples has_sample : Indicates if the sample should be used to calcuate the loss
def selective_margin_loss(pos_samples, neg_samples, margin, has_sample):
    margin_diff = torch.clamp((pos_samples - neg_samples) + margin, min=0, max=1e6)
    num_sample = max(torch.sum(has_sample), 1)
    return torch.sum(margin_diff * has_sample) / num_sample
def selective_margin_loss ( pos_samples , neg_samples , margin , has_sample ) : margin_diff = torch . clamp ( ( pos_samples - neg_samples ) + margin , min = 0 , max = 1e6 ) num_sample = max ( torch . sum ( has_sample ) , 1 ) return torch . sum ( margin_diff * has_sample ) / num_sample
pos_samples: Distance between positive pair
neg_samples: Distance between negative pair
margin: minimum desired margin between pos and neg samples
has_sample: Indicates if the sample should be used to calcuate the loss
pos_samples : Distance between positive pair neg_samples : Distance between negative pair margin : minimum desired margin between pos and neg samples has_sample : Indicates if the sample should be used to calcuate the loss
""" pos_samples: Distance between positive pair
        neg_samples: Distance between negative pair
        margin: minimum desired margin between pos and neg samples
        has_sample: Indicates if the sample should be used to calcuate the loss
    """
pos_samples
neg_samples
margin
has_sample