crumpets.torch.loss module¶
- class crumpets.torch.loss.CrossEntropyLoss(*args: Any, **kwargs: Any)[source]¶
Bases:
torch.nn.
Wrapper for torch.nn.CrossEntropyLoss that accepts dictionaries as input.
- Parameters
output_key – key in given sample dict which maps to the output tensor
target_key – key in given sample dict which maps to the target tensor
weight – a manual rescaling weight given to each class. If given, it has to be a Tensor of size C. Otherwise, it is treated as if having all ones.
reduction – Specifies the reduction to apply to the output:
'none'
|'mean'
|'sum'
.'none'
: no reduction will be applied,'mean'
: the sum of the output will be divided by the number of elements in the output,'sum'
: the output will be summed. Default:'mean'
ignore_index – Specifies a target value that is ignored and does not contribute to the input gradient. When
size_average
isTrue
, the loss is averaged over non-ignored targets.
- class crumpets.torch.loss.L1Loss(*args: Any, **kwargs: Any)[source]¶
Bases:
torch.nn.
Wrapper for torch.nn.L1Loss that accepts dictionaries as input.
- Parameters
output_key – key in given sample dict which maps to the output tensor
target_key – key in given sample dict which maps to the target tensor
reduction – Specifies the reduction to apply to the output:
'none'
|'mean'
|'sum'
.'none'
: no reduction will be applied,'mean'
: the sum of the output will be divided by the number of elements in the output,'sum'
: the output will be summed. Default:'mean'
- class crumpets.torch.loss.LabelSmoothing(*args: Any, **kwargs: Any)[source]¶
Bases:
torch.nn.
Loss for LabelSmoothing based on NLL-Loss
- Parameters
smoothing – label smoothing factor
output_key – key in given sample dict which maps to the output tensor
target_key – key in given sample dict which maps to the target tensor
- class crumpets.torch.loss.MSELoss(*args: Any, **kwargs: Any)[source]¶
Bases:
torch.nn.
Wrapper for torch.nn.MSELoss that accepts dictionaries as input.
- Parameters
output_key – key in given sample dict which maps to the output tensor
target_key – key in given sample dict which maps to the target tensor
reduction – Specifies the reduction to apply to the output:
'none'
|'mean'
|'sum'
.'none'
: no reduction will be applied,'mean'
: the sum of the output will be divided by the number of elements in the output,'sum'
: the output will be summed. Default:'mean'
- class crumpets.torch.loss.NLLLoss(*args: Any, **kwargs: Any)[source]¶
Bases:
torch.nn.
Wrapper for torch.nn.NLLLoss that accepts dictionaries as input.
- Parameters
output_key – key in given sample dict which maps to the output tensor
target_key – key in given sample dict which maps to the target tensor
weight – a manual rescaling weight given to each class. If given, it has to be a Tensor of size C. Otherwise, it is treated as if having all ones.
reduction – Specifies the reduction to apply to the output:
'none'
|'mean'
|'sum'
.'none'
: no reduction will be applied,'mean'
: the sum of the output will be divided by the number of elements in the output,'sum'
: the output will be summed. Default:'mean'
ignore_index – Specifies a target value that is ignored and does not contribute to the input gradient. When
size_average
isTrue
, the loss is averaged over non-ignored targets.
- class crumpets.torch.loss.NSSLoss(*args: Any, **kwargs: Any)[source]¶
Bases:
torch.nn.
Loss for saliency applications that optimizes the normalized scanpath saliency (NSS) metric.
The output of the network is normalized to zero-mean and unit standard deviation. Then the values at gaze locations given by the target image tensor are maximized.
Since with NSS higher values are better and it does not have an upper bound, the output is simply negated. This means the loss will become negative at some point if your network is learning.
- Parameters
output_key – key in given sample dict which maps to the output tensor
target_key – key in given sample dict which maps to the target tensor