create_dl_layer_loss_cross_entropy
— Create a cross entropy loss layer.
create_dl_layer_loss_cross_entropy( : : DLLayerInput, DLLayerTarget, DLLayerWeights, LayerName, LossWeight, GenParamName, GenParamValue : DLLayerLossCrossEntropy)
The operator create_dl_layer_loss_cross_entropy
creates a cross
entropy loss layer whose handle is returned in
DLLayerLossCrossEntropy
.
This layer computes the two dimensional cross entropy loss on the input
(provided by DLLayerInput
) given the corresponding target
(provided by DLLayerTarget
) and weight
(provided by DLLayerWeights
).
Cross entropy is commonly used to measure the similarity between two vectors.
Illustrative example, where we have a pixel-level classification problem with three classes.
The input vector for a single pixel is (e.g., the output of a softmax layer) which means that the predicted value (e.g., probability) is 0.7 for the class at index 0, 0.1 for the class at index 1 and 0.2 for the class at index 2.
The target vector is with a probability of 1.0 for the actual class and 0.0 else. Entropy is calculated by the dot product of these two vectors. Since the target vector has only one non-zero entry, it can be given by the index of the actual class instead of a vector, in this case .
The cross entropy is then simply the value of the input vector at the target class index, hence . Using this simplification, the cross entropy loss function over an input image can be defined by where the input consists of one prediction vector for each pixel, the target and weight consist of one value and for each input pixel, is the number of pixels and is the sum over all weights.
Hence, this layer expects multiple incoming layers:
DLLayerInput
: Specifies the
prediction (e.g., a softmax layer, commonly with logarithmized results).
DLLayerTarget
: Specifies the
target sequences (originating from the ground truth information).
DLLayerWeights
: Specifies the weight sequences. This parameter
is optional. If an empty tuple [] is passed for all values the
weighting factor 1.0 is used.
The parameter LayerName
sets an individual layer name.
Note that if creating a model using create_dl_model
each layer of
the created network must have a unique name.
The parameter LossWeight
determines the scalar weight factor with
which the loss, calculated in this layer, is multiplied.
This parameter can be used to specify the contribution of the cross entropy
loss to the overall network loss in case multiple loss layers are used.
The following generic parameters GenParamName
and the corresponding
values GenParamValue
are supported:
Determines whether apply_dl_model
will include the output of this
layer in the dictionary DLResultBatch
even without specifying this
layer in Outputs
('true' ) or not ('false' ).
Default: 'false'
Certain parameters of layers created using this operator
create_dl_layer_loss_cross_entropy
can be set and retrieved using
further operators.
The following tables give an overview, which parameters can be set
using set_dl_model_layer_param
and which ones can be retrieved
using get_dl_model_layer_param
or get_dl_layer_param
.
Note, the operators set_dl_model_layer_param
and
get_dl_model_layer_param
require a model created by
create_dl_model
.
Layer Parameters | set | get |
---|---|---|
'input_layer' (DLLayerInput , DLLayerTarget , and/or DLLayerWeights ) |
||
'loss_weight' (LossWeight ) |
||
'name' (LayerName ) |
||
'output_layer' (DLLayerLossCrossEntropy ) |
||
'shape' | ||
'type' |
Generic Layer Parameters | set | get |
---|---|---|
'is_inference_output' | ||
'num_trainable_params' |
DLLayerInput
(input_control) dl_layer →
(handle)
Input layer.
DLLayerTarget
(input_control) dl_layer →
(handle)
Target layer.
DLLayerWeights
(input_control) dl_layer →
(handle)
Weights layer.
LayerName
(input_control) string →
(string)
Name of the output layer.
LossWeight
(input_control) number →
(real)
Overall loss weight if there are multiple losses in the network.
Default value: 1.0
GenParamName
(input_control) attribute.name(-array) →
(string)
Generic input parameter names.
Default value: []
List of values: 'is_inference_output'
GenParamValue
(input_control) attribute.value(-array) →
(string / integer / real)
Generic input parameter values.
Default value: []
Suggested values: 'true' , 'false'
DLLayerLossCrossEntropy
(output_control) dl_layer →
(handle)
Cross entropy loss layer.
Deep Learning Training