ClikaRT::ops::cross_entropy
function
cross_entropy()
Tensor cross_entropy(
Tensor input,
Tensor target,
OptionalTensor weight = {},
std::optional<int64_t> ignore_index = std::nullopt,
Reduction reduction = Reduction::Mean
)
Cross-entropy loss over class LOGITS; the class dim is LAST.
Equivalent to log_softmax over the class axis followed by negative-log-likelihood:
Parameters
input: logits[.., C](channels-last class axis).target: class indices[..](integer dtype).weight: optional per-class weight[C].ignore_index: optional target value whose positions contribute no loss; absent = no masking.reduction:None/Mean/Sum; defaultMean.
Returns: the loss (0-D under Mean/Sum; [..] under None).
Throws
ClikaRT::Error: (INVALID_ARGUMENT) whentarget's shape is notinput's minus the class axis, or a target index is out of range.
auto loss = ClikaRT::ops::cross_entropy(logits, labels); // 0-D mean
Declared in ClikaRT/compute/ops.h, line 2940