torch.nn.CrossEntropyLoss中的参数

torch.nn.CrossEntropyLoss(weight: Optional[torch.Tensor] = None, size_average=None, ignore_index: int = -100, reduce=None, reduction: str = ‘mean’)

weight:(张量,可选)可以指定一个一维的Tensor,用来设置每个类别的权重。用C表示类别的个数,Tensor的长度应该为C。当训练集不平衡时该参数十分有用。
size_average:(最新的版本已弃用)(bool,可选) 默认情况下为True,此时损失是每个minibatch的平均;如果设置成False,则对每个minibatch求和。这个属性只有当reduce参数设置成True时才生效。
reduce:(最新的版本已弃用) (bool,可选)默认情况下为True,此时损失为根据size_average参数的值计算每个minibatch的和或者是平均;如果设置成False,忽略size_average参数的值,并返回每个元素的损失。
ignore_index:(int,可选)可以设置一个被忽略值,使这个值不会影响到输入的梯度的计算。当size_average为True时,loss的平均值也会忽略该值。
reduction: (string,可选)”none”:不应用任何缩减,“mean”:取输出的加权平均值,“sum”:输出将被求和。注意:size_average和reduce正在被弃用,同时,指定这两个参数之一将覆盖reduction。默认:‘mean’

下面时pytorch官网上的文档:

Parameters
weight (Tensor, optional) – a manual rescaling weight given to each class. If given, has to be a Tensor of size C

size_average (bool, optional) – Deprecated (see reduction). By default, the losses are averaged over each loss element in the batch. Note that for some losses, there are multiple elements per sample. If the field size_average is set to False, the losses are instead summed for each minibatch. Ignored when reduce is False. Default: True

ignore_index (int, optional) – Specifies a target value that is ignored and does not contribute to the input gradient. When size_average is True, the loss is averaged over non-ignored targets.

reduce (bool, optional) – Deprecated (see reduction). By default, the losses are averaged or summed over observations for each minibatch depending on size_average. When reduce is False, returns a loss per batch element instead and ignores size_average. Default: True

reduction (string, optional) – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the weighted mean of the output is taken, ‘sum’: the output will be summed. Note: size_average and reduce are in the process of being deprecated, and in the meantime, specifying either of those two args will override reduction. Default: ‘mean’

  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值