哪里可以看到pytorch的MSELoss的源码?
Where can I see the source code for pytorch's MSELoss?
我使用 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
我找不到任何有用的东西。
好了:https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py#L1423 但是,它调用了 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)
我使用 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
我找不到任何有用的东西。
好了:https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py#L1423 但是,它调用了 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)