Skip to content

create_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropycreate_dl_layer_loss_cross_entropyT_create_dl_layer_loss_cross_entropy🔗

Short description🔗

create_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropycreate_dl_layer_loss_cross_entropyT_create_dl_layer_loss_cross_entropy — Create a cross entropy loss layer.

Signature🔗

create_dl_layer_loss_cross_entropy( dl_layer DLLayerInput, dl_layer DLLayerTarget, dl_layer DLLayerWeights, string LayerName, number LossWeight, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer 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 )static void HOperatorSet.CreateDlLayerLossCrossEntropy( HTuple DLLayerInput, HTuple DLLayerTarget, HTuple DLLayerWeights, HTuple layerName, HTuple lossWeight, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerLossCrossEntropy )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

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 )

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)

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 )

Description🔗

The operator create_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropy creates a cross entropy loss layer whose handle is returned in DLLayerLossCrossEntropyDLLayerLossCrossEntropydllayer_loss_cross_entropy. This layer computes the two dimensional cross entropy loss on the input (provided by DLLayerInputDLLayerInputdllayer_input) given the corresponding target (provided by DLLayerTargetDLLayerTargetdllayer_target) and weight (provided by DLLayerWeightsDLLayerWeightsdllayer_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 \(\mathbf{x}=[0.7, 0.1, 0.2]\) (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 \(\mathbf{t}=[1.0, 0.0, 0.0]\) 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 \(t=0\).

    The cross entropy is then simply the value of the input vector at the target class index, hence \(\mathbf{x}[t]=0.7\). Using this simplification, the cross entropy loss function over an input image can be defined by

    \[\begin{eqnarray*} L_{cross\_entropy}(\mathbf{x}, \mathbf{t}, \mathbf{w}) &:=& -\frac{1}{W}\sum_{i=0}^{N-1} w_{i} \cdot \mathbf{x}_{i}[t_{i}], \end{eqnarray*}\]

    where the input \(\mathbf{x}\) consists of one prediction vector \(\mathbf{x}_{i}\) for each pixel, the target \(\mathbf{t}\) and weight \(\mathbf{w}\) consist of one value \(t_{i}\) and \(w_{i}\) for each input pixel, \(N\) is the number of pixels and \(W = \sum_{i=0}^{N-1} w_{i}\) is the sum over all weights.

Hence, this layer expects multiple incoming layers:

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

The parameter LossWeightlossWeightloss_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 GenParamNamegenParamNamegen_param_name and the corresponding values GenParamValuegenParamValuegen_param_value are supported:

  • 'is_inference_output'"is_inference_output": Determines whether apply_dl_modelApplyDlModel will include the output of this layer in the dictionary DLResultBatchDLResultBatchdlresult_batch even without specifying this layer in Outputsoutputsoutputs ('true'"true") or not ('false'"false").

    Default: 'false'"false"

Certain parameters of layers created using this operator create_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropy can be set and retrieved using further operators. The following tables give an overview, which parameters can be set using set_dl_model_layer_paramSetDlModelLayerParam and which ones can be retrieved using get_dl_model_layer_paramGetDlModelLayerParam or get_dl_layer_paramGetDlLayerParam. Note, the operators set_dl_model_layer_paramSetDlModelLayerParam and get_dl_model_layer_paramGetDlModelLayerParam require a model created by create_dl_modelCreateDlModel.

Layer Parameters set get
'input_layer'"input_layer" (DLLayerInputDLLayerInputdllayer_input, DLLayerTargetDLLayerTargetdllayer_target, and/or DLLayerWeightsDLLayerWeightsdllayer_weights) x
'loss_weight'"loss_weight" (LossWeightlossWeightloss_weight) x x
'name'"name" (LayerNamelayerNamelayer_name) x x
'output_layer'"output_layer" (DLLayerLossCrossEntropyDLLayerLossCrossEntropydllayer_loss_cross_entropy) x
'shape'"shape" x
'type'"type" x
Generic Layer Parameters set get
'is_inference_output'"is_inference_output" x x
'num_trainable_params'"num_trainable_params" x

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

DLLayerInputDLLayerInputdllayer_input (input_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Input layer.

DLLayerTargetDLLayerTargetdllayer_target (input_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Target layer.

DLLayerWeightsDLLayerWeightsdllayer_weights (input_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Weights layer.

LayerNamelayerNamelayer_name (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Name of the output layer.

LossWeightlossWeightloss_weight (input_control) number → (real)HTuple (double)HTuple (double)floatHtuple (double)

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

Default: 1.01.0

GenParamNamegenParamNamegen_param_name (input_control) attribute.name(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Generic input parameter names.

Default: [][]
List of values: 'is_inference_output'"is_inference_output"

GenParamValuegenParamValuegen_param_value (input_control) attribute.value(-array) → (string / integer / real)HTuple (HString / Hlong / double)HTuple (string / int / long / double)MaybeSequence[Union[int, float, str]]Htuple (char* / Hlong / double)

Generic input parameter values.

Default: [][]
Suggested values: 'true', 'false'"true", "false"

DLLayerLossCrossEntropyDLLayerLossCrossEntropydllayer_loss_cross_entropy (output_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Cross entropy loss layer.

Module🔗

Deep Learning Professional