本文整理匯總了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()
示例2: get_criterion
# 需要導入模塊: from torch.nn.modules import loss [as 別名]
# 或者: from torch.nn.modules.loss import CrossEntropyLoss [as 別名]
def get_criterion(cfg):
return CrossEntropyLoss()
示例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()
示例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()
示例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