crossentropy
Syntax
Description
The cross-entropy operation computes the cross-entropy loss between network predictions and target values for single-label and multi-label classification tasks.
The crossentropy
function computes the cross-entropy loss between
predictions and targets represented as dlarray
data.
Using dlarray
objects makes working with high
dimensional data easier by allowing you to label the dimensions. For example, you can label
which dimensions correspond to spatial, time, channel, and batch dimensions using the
"S"
, "T"
, "C"
, and
"B"
labels, respectively. For unspecified and other dimensions, use the
"U"
label. For dlarray
object functions that operate
over particular dimensions, you can specify the dimension labels by formatting the
dlarray
object directly, or by using the DataFormat
option.
Note
To calculate the cross-entropy loss within a layerGraph
object
or Layer
array for use
with the trainNetwork
function, use classificationLayer
.
returns the categorical cross-entropy loss between the formatted loss
= crossentropy(Y
,targets
)dlarray
object Y
containing the predictions and the target values
targets
for single-label classification tasks. The output
loss
is an unformatted dlarray
scalar.
For unformatted input data, use the 'DataFormat'
option.
also specifies the dimension format loss
= crossentropy(___,'DataFormat',FMT)FMT
when Y
is not
a formatted dlarray
.
specifies options using one or more name-value pair arguments in addition to the input
arguments in previous syntaxes. For example,
loss
= crossentropy(___,Name,Value
)'TargetCategories','independent'
computes the cross-entropy loss for a
multi-label classification task.
Examples
Input Arguments
Output Arguments
Algorithms
Extended Capabilities
Version History
Introduced in R2019b