咕咕咕~不催不更
pytorch自带的交叉熵:
- class CrossEntropyLoss(_WeightedLoss):
- __constants__ = ['ignore_index', 'reduction']
- ignore_index: int
-
- def __init__(self, weight: Optional[Tensor] = None, size_average=None, ignore_index: int = -100,
- reduce=None, reduction: str = 'mean') -> None:
- super(CrossEntropyLoss, self).__init__(weight, size_average, reduce, reduction)
- self.ignore_index = ignore_index
-
- def forward(self, input: Tensor, target: Tensor) -> Tensor:
- assert self.weight is None or isinstance(self.weight, Tensor)
- return F.cross_entropy(input, target, weight=self.weight,
- ignore_index=self.ignore_index, reduction=self.re