Где я могу увидеть исходный код MSELoss для Pytorch?
Я использую сеть U-NET для обучения своих данных. Но мне нужно изменить функцию потери, чтобы уменьшить потерю пикселей ниже 1, чтобы уменьшить влияние отрицательных случаев на вес сети. Но я открыл исходный код в pycharm MSELOSS, смотрите это:
class MSELoss(_Loss):
r"""Creates a criterion that measures the mean squared error between
`n` elements in the input `x` and target `y`:
:math:`{loss}(x, y) = 1/n \sum |x_i - y_i|^2`
`x` and `y` arbitrary shapes with a total of `n` elements each.
The sum operation still operates over all the elements, and divides by `n`.
The division by `n` can be avoided if one sets the internal variable
`size_average` to `False`.
"""
pass
Я не могу получить ничего полезного.
1 ответ
Вот и вы: https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py Однако он вызывает C api
def mse_loss(input, target, size_average=True, reduce=True):
"""
mse_loss(input, target, size_average=True, reduce=True) -> Variable
Measures the element-wise mean squared error.
See :class:`~torch.nn.MSELoss` for details.
"""
return _pointwise_loss(lambda a, b: (a - b) ** 2, torch._C._nn.mse_loss,
input, target, size_average, reduce)
def own_mse_loss(input, target, size_average=True):
L = (input - target) ** 2
return torch.mean(L) if size_average else torch.sum(L)