Python torch.nn.SoftMarginLoss() Examples
The following are 12
code examples of torch.nn.SoftMarginLoss().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.nn
, or try the search function
.
Example #1
Source File: loss.py From tiny-faces-pytorch with MIT License | 6 votes |
def __init__(self, n_templates=25, reg_weight=1, pos_fraction=0.5): super().__init__() # We don't want per element averaging. # We want to normalize over the batch or positive samples. self.regression_criterion = nn.SmoothL1Loss(reduction='none') self.classification_criterion = nn.SoftMarginLoss(reduction='none') self.n_templates = n_templates self.reg_weight = reg_weight self.pos_fraction = pos_fraction self.class_average = AvgMeter() self.reg_average = AvgMeter() self.masked_class_loss = None self.masked_reg_loss = None self.total_loss = None
Example #2
Source File: pairwise_ranking_loss.py From torecsys with MIT License | 6 votes |
def __init__(self, margin : float = 1.0, reduction : str = None): r"""Initialize TripletLoss Args: margin (float, optional): size of margin. Defaults to 1.0. reduction (str, optional): method of reduction. Defaults to None. """ # Refer to parent class super(TripletLoss, self).__init__() # Initialize module with input margin if margin: self.parser = margin_ranking_loss_parser self.loss = nn.MarginRankingLoss(margin=margin, reduction=reduction) else: self.parser = soft_margin_loss_parser self.loss = nn.SoftMarginLoss(reduction=reduction)
Example #3
Source File: triplet_loss.py From PAST-ReID with MIT License | 6 votes |
def __init__(self, args, margin=None, name=None, tri_sampler_type='CTL'): self.margin = margin self.args = args self.name = name self.tri_sampler_type = tri_sampler_type if margin is not None: if self.tri_sampler_type == 'CTL': self.ranking_loss = nn.MarginRankingLoss(margin=self.margin) elif self.tri_sampler_type == 'RTL': self.ranking_loss = SoftMarginTriplet(margin=self.margin) elif self.tri_sampler_type == 'CTL_RTL': if '_CTL' in name: self.ranking_loss = nn.MarginRankingLoss(margin=self.margin) if '_RTL' in name: self.ranking_loss = SoftMarginTriplet(margin=self.margin) else: self.ranking_loss = nn.SoftMarginLoss()
Example #4
Source File: triplet_loss.py From ACME with GNU General Public License v3.0 | 5 votes |
def __init__(self, device, margin=None): self.margin = margin self.device = device if margin is not None: self.ranking_loss = nn.MarginRankingLoss(margin=margin) else: self.ranking_loss = nn.SoftMarginLoss()
Example #5
Source File: loss.py From Cross-Modal-Re-ID-baseline with MIT License | 5 votes |
def __init__(self): super(TripletLoss_WRT, self).__init__() self.ranking_loss = nn.SoftMarginLoss()
Example #6
Source File: reid_loss.py From ARN with MIT License | 5 votes |
def __init__(self, margin=None): self.margin = margin if margin is not None: self.ranking_loss = nn.MarginRankingLoss(margin=margin) else: self.ranking_loss = nn.SoftMarginLoss()
Example #7
Source File: triplet_loss.py From reid_baseline_with_syncbn with MIT License | 5 votes |
def __init__(self, margin=None): self.margin = margin if margin is not None: self.ranking_loss = nn.MarginRankingLoss(margin=margin) else: self.ranking_loss = nn.SoftMarginLoss()
Example #8
Source File: loss.py From triplet-reid-pytorch with Apache License 2.0 | 5 votes |
def __init__(self, margin = None): super(TripletLoss, self).__init__() self.margin = margin if self.margin is None: # use soft-margin self.Loss = nn.SoftMarginLoss() else: self.Loss = nn.TripletMarginLoss(margin = margin, p = 2)
Example #9
Source File: loss_set.py From Relation-Aware-Global-Attention-Networks with MIT License | 5 votes |
def __init__(self, margin=None, metric="euclidean"): self.margin = margin self.metric = metric if margin is not None: self.ranking_loss = nn.MarginRankingLoss(margin=margin) else: self.ranking_loss = nn.SoftMarginLoss()
Example #10
Source File: triplet_loss.py From CVWC2019-Amur-Tiger-Re-ID with Apache License 2.0 | 5 votes |
def __init__(self, margin=None): self.margin = margin if margin is not None: self.ranking_loss = nn.MarginRankingLoss(margin=margin) else: self.ranking_loss = nn.SoftMarginLoss()
Example #11
Source File: triplet_loss.py From pytorch-loss with MIT License | 5 votes |
def __init__(self, margin=None): super(TripletLoss, self).__init__() self.margin = margin if self.margin is None: # if no margin assigned, use soft-margin self.Loss = nn.SoftMarginLoss() else: self.Loss = nn.TripletMarginLoss(margin=margin, p=2)
Example #12
Source File: loss.py From batch-dropblock-network with MIT License | 5 votes |
def __init__(self, margin=None): self.margin = margin if margin is not None: self.ranking_loss = nn.MarginRankingLoss(margin=margin) else: self.ranking_loss = nn.SoftMarginLoss()