當前位置: 首頁>>代碼示例>>Python>>正文


Python nn.SoftMarginLoss方法代碼示例

本文整理匯總了Python中torch.nn.SoftMarginLoss方法的典型用法代碼示例。如果您正苦於以下問題:Python nn.SoftMarginLoss方法的具體用法?Python nn.SoftMarginLoss怎麽用?Python nn.SoftMarginLoss使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.nn的用法示例。


在下文中一共展示了nn.SoftMarginLoss方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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 
開發者ID:varunagrawal,項目名稱:tiny-faces-pytorch,代碼行數:19,代碼來源:loss.py

示例2: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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) 
開發者ID:p768lwy3,項目名稱:torecsys,代碼行數:21,代碼來源:pairwise_ranking_loss.py

示例3: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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() 
開發者ID:zhangxinyu-xyz,項目名稱:PAST-ReID,代碼行數:19,代碼來源:triplet_loss.py

示例4: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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() 
開發者ID:hwang1996,項目名稱:ACME,代碼行數:9,代碼來源:triplet_loss.py

示例5: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
def __init__(self):
        super(TripletLoss_WRT, self).__init__()
        self.ranking_loss = nn.SoftMarginLoss() 
開發者ID:mangye16,項目名稱:Cross-Modal-Re-ID-baseline,代碼行數:5,代碼來源:loss.py

示例6: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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() 
開發者ID:yujheli,項目名稱:ARN,代碼行數:8,代碼來源:reid_loss.py

示例7: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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) 
開發者ID:CoinCheung,項目名稱:triplet-reid-pytorch,代碼行數:9,代碼來源:loss.py

示例8: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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() 
開發者ID:microsoft,項目名稱:Relation-Aware-Global-Attention-Networks,代碼行數:9,代碼來源:loss_set.py

示例9: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import SoftMarginLoss [as 別名]
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) 
開發者ID:CoinCheung,項目名稱:pytorch-loss,代碼行數:9,代碼來源:triplet_loss.py


注:本文中的torch.nn.SoftMarginLoss方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。