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


Python loss.CrossEntropyLoss方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from torch.nn.modules import loss [as 別名]
# 或者: from torch.nn.modules.loss import CrossEntropyLoss [as 別名]
def __init__(self, num_classes):
        super().__init__()
        self.bn = nn.BatchNorm1d(num_classes)
        self.fc = nn.Linear(num_classes, num_classes)
        self.xent = CrossEntropyLoss() 
開發者ID:facebookresearch,項目名稱:ClassyVision,代碼行數:7,代碼來源:tasks_fine_tuning_task_test.py

示例2: get_criterion

# 需要導入模塊: from torch.nn.modules import loss [as 別名]
# 或者: from torch.nn.modules.loss import CrossEntropyLoss [as 別名]
def get_criterion(cfg):
    return CrossEntropyLoss() 
開發者ID:DingXiaoH,項目名稱:ACNet,代碼行數:4,代碼來源:ding_test.py

示例3: __init__

# 需要導入模塊: from torch.nn.modules import loss [as 別名]
# 或者: from torch.nn.modules.loss import CrossEntropyLoss [as 別名]
def __init__(self, model,init_weight):
        super(RegressionTrain, self).__init__()
        
        self.model = model
        self.weights = torch.nn.Parameter(torch.from_numpy(init_weight).float())
        self.ce_loss = CrossEntropyLoss() 
開發者ID:Xi-L,項目名稱:ParetoMTL,代碼行數:8,代碼來源:model_lenet.py

示例4: __init__

# 需要導入模塊: from torch.nn.modules import loss [as 別名]
# 或者: from torch.nn.modules.loss import CrossEntropyLoss [as 別名]
def __init__(self, model,init_weight):
        super(RegressionTrainResNet, self).__init__()
        
        self.model = model
        self.weights = torch.nn.Parameter(torch.from_numpy(init_weight).float())
        self.ce_loss = CrossEntropyLoss() 
開發者ID:Xi-L,項目名稱:ParetoMTL,代碼行數:8,代碼來源:model_resnet.py

示例5: __init__

# 需要導入模塊: from torch.nn.modules import loss [as 別名]
# 或者: from torch.nn.modules.loss import CrossEntropyLoss [as 別名]
def __init__(self, type='auto', loss_weight=1.0, softmax_loss_weight=1.0):
        """
        :param type: type of loss ('l1', 'l2', 'auto')
        :param loss_weight: weight of loss, for 'l1' and 'l2', try with 0.01.
            For 'auto', try with 1.0.

        Source: https://github.com/Paralysis/ringloss
        """
        super().__init__()
        self.radius = Parameter(torch.Tensor(1))
        self.radius.data.fill_(-1)
        self.loss_weight = loss_weight
        self.type = type
        self.softmax = CrossEntropyLoss()
        self.softmax_loss_weight = softmax_loss_weight 
開發者ID:lightforever,項目名稱:mlcomp,代碼行數:17,代碼來源:ring.py


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