create_dl_layer_loss_cross_entropyT_create_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropycreate_dl_layer_loss_cross_entropy (Operator)

Name

create_dl_layer_loss_cross_entropyT_create_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropycreate_dl_layer_loss_cross_entropy — Create a cross entropy loss layer.

Signature

create_dl_layer_loss_cross_entropy( : : DLLayerInput, DLLayerTarget, DLLayerWeights, LayerName, LossWeight, GenParamName, GenParamValue : DLLayerLossCrossEntropy)

Herror T_create_dl_layer_loss_cross_entropy(const Htuple DLLayerInput, const Htuple DLLayerTarget, const Htuple DLLayerWeights, const Htuple LayerName, const Htuple LossWeight, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerLossCrossEntropy)

void CreateDlLayerLossCrossEntropy(const HTuple& DLLayerInput, const HTuple& DLLayerTarget, const HTuple& DLLayerWeights, const HTuple& LayerName, const HTuple& LossWeight, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerLossCrossEntropy)

HDlLayer HDlLayer::CreateDlLayerLossCrossEntropy(const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const HString& LayerName, double LossWeight, const HTuple& GenParamName, const HTuple& GenParamValue) const

HDlLayer HDlLayer::CreateDlLayerLossCrossEntropy(const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const HString& LayerName, double LossWeight, const HString& GenParamName, const HString& GenParamValue) const

HDlLayer HDlLayer::CreateDlLayerLossCrossEntropy(const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const char* LayerName, double LossWeight, const char* GenParamName, const char* GenParamValue) const

HDlLayer HDlLayer::CreateDlLayerLossCrossEntropy(const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const wchar_t* LayerName, double LossWeight, const wchar_t* GenParamName, const wchar_t* GenParamValue) const   ( Windows only)

static void HOperatorSet.CreateDlLayerLossCrossEntropy(HTuple DLLayerInput, HTuple DLLayerTarget, HTuple DLLayerWeights, HTuple layerName, HTuple lossWeight, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerLossCrossEntropy)

HDlLayer HDlLayer.CreateDlLayerLossCrossEntropy(HDlLayer DLLayerTarget, HDlLayer DLLayerWeights, string layerName, double lossWeight, HTuple genParamName, HTuple genParamValue)

HDlLayer HDlLayer.CreateDlLayerLossCrossEntropy(HDlLayer DLLayerTarget, HDlLayer DLLayerWeights, string layerName, double lossWeight, string genParamName, string genParamValue)

def create_dl_layer_loss_cross_entropy(dllayer_input: HHandle, dllayer_target: HHandle, dllayer_weights: HHandle, layer_name: str, loss_weight: float, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]]) -> HHandle

Description

The operator create_dl_layer_loss_cross_entropycreate_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropycreate_dl_layer_loss_cross_entropy creates a cross entropy loss layer whose handle is returned in DLLayerLossCrossEntropyDLLayerLossCrossEntropyDLLayerLossCrossEntropyDLLayerLossCrossEntropydllayer_loss_cross_entropy. This layer computes the two dimensional cross entropy loss on the input (provided by DLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input) given the corresponding target (provided by DLLayerTargetDLLayerTargetDLLayerTargetDLLayerTargetdllayer_target) and weight (provided by DLLayerWeightsDLLayerWeightsDLLayerWeightsDLLayerWeightsdllayer_weights).

Cross entropy is commonly used to measure the similarity between two vectors.

Example:

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:

The parameter LayerNameLayerNameLayerNamelayerNamelayer_name sets an individual layer name. Note that if creating a model using create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelcreate_dl_model each layer of the created network must have a unique name.

The parameter LossWeightLossWeightLossWeightlossWeightloss_weight 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 GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name and the corresponding values GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value are supported:

'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output":

Determines whether apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelapply_dl_model will include the output of this layer in the dictionary DLResultBatchDLResultBatchDLResultBatchDLResultBatchdlresult_batch even without specifying this layer in OutputsOutputsOutputsoutputsoutputs ('true'"true""true""true""true") or not ('false'"false""false""false""false").

Default: 'false'"false""false""false""false"

Certain parameters of layers created using this operator create_dl_layer_loss_cross_entropycreate_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropycreate_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_paramset_dl_model_layer_paramSetDlModelLayerParamSetDlModelLayerParamset_dl_model_layer_param and which ones can be retrieved using get_dl_model_layer_paramget_dl_model_layer_paramGetDlModelLayerParamGetDlModelLayerParamget_dl_model_layer_param or get_dl_layer_paramget_dl_layer_paramGetDlLayerParamGetDlLayerParamget_dl_layer_param. Note, the operators set_dl_model_layer_paramset_dl_model_layer_paramSetDlModelLayerParamSetDlModelLayerParamset_dl_model_layer_param and get_dl_model_layer_paramget_dl_model_layer_paramGetDlModelLayerParamGetDlModelLayerParamget_dl_model_layer_param require a model created by create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelcreate_dl_model.

Layer Parameters set get
'input_layer'"input_layer""input_layer""input_layer""input_layer" (DLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input, DLLayerTargetDLLayerTargetDLLayerTargetDLLayerTargetdllayer_target, and/or DLLayerWeightsDLLayerWeightsDLLayerWeightsDLLayerWeightsdllayer_weights) x
'loss_weight'"loss_weight""loss_weight""loss_weight""loss_weight" (LossWeightLossWeightLossWeightlossWeightloss_weight) x x
'name'"name""name""name""name" (LayerNameLayerNameLayerNamelayerNamelayer_name) x x
'output_layer'"output_layer""output_layer""output_layer""output_layer" (DLLayerLossCrossEntropyDLLayerLossCrossEntropyDLLayerLossCrossEntropyDLLayerLossCrossEntropydllayer_loss_cross_entropy) x
'shape'"shape""shape""shape""shape" x
'type'"type""type""type""type" x
Generic Layer Parameters set get
'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output" x x
'num_trainable_params'"num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params" x

Execution Information

Parameters

DLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input (input_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Input layer.

DLLayerTargetDLLayerTargetDLLayerTargetDLLayerTargetdllayer_target (input_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Target layer.

DLLayerWeightsDLLayerWeightsDLLayerWeightsDLLayerWeightsdllayer_weights (input_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Weights layer.

LayerNameLayerNameLayerNamelayerNamelayer_name (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Name of the output layer.

LossWeightLossWeightLossWeightlossWeightloss_weight (input_control)  number HTuplefloatHTupleHtuple (real) (double) (double) (double)

Overall loss weight if there are multiple losses in the network.

Default: 1.0

GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name (input_control)  attribute.name(-array) HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)

Generic input parameter names.

Default: []

List of values: 'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output"

GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value (input_control)  attribute.value(-array) HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)

Generic input parameter values.

Default: []

Suggested values: 'true'"true""true""true""true", 'false'"false""false""false""false"

DLLayerLossCrossEntropyDLLayerLossCrossEntropyDLLayerLossCrossEntropyDLLayerLossCrossEntropydllayer_loss_cross_entropy (output_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Cross entropy loss layer.

Module

Deep Learning Training