本文整理汇总了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