cross_entropy_loss
anomaly_match.utils.cross_entropy_loss
¶
Cross-entropy loss functions for classification.
cross_entropy_loss(logits, targets, use_hard_labels=True, reduction='none')
¶
Cross entropy loss that supports both hard and soft labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Model output logits with shape [batch_size, num_classes] |
required |
targets
|
Tensor
|
Target values, which can be either: - Class indices with shape [batch_size] if use_hard_labels=True - Class probabilities with shape [batch_size, num_classes] if use_hard_labels=False |
required |
use_hard_labels
|
bool
|
If True, targets are treated as class indices If False, targets are treated as probability distributions |
True
|
reduction
|
str
|
Specifies the reduction to apply to the output: 'none': no reduction will be applied 'mean': the sum of the output will be divided by the number of elements 'sum': the output will be summed |
'none'
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Loss tensor with shape determined by the reduction mode |