Skip to content

create_dl_layer_loss_distanceCreateDlLayerLossDistanceCreateDlLayerLossDistancecreate_dl_layer_loss_distanceT_create_dl_layer_loss_distanceπŸ”—

Short descriptionπŸ”—

create_dl_layer_loss_distanceCreateDlLayerLossDistanceCreateDlLayerLossDistancecreate_dl_layer_loss_distanceT_create_dl_layer_loss_distance β€” Create a distance loss layer.

SignatureπŸ”—

create_dl_layer_loss_distance( dl_layer DLLayerInput, dl_layer DLLayerTarget, dl_layer DLLayerWeights, string LayerName, string DistanceType, number LossWeight, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer DLLayerLossDistance )void CreateDlLayerLossDistance( const HTuple& DLLayerInput, const HTuple& DLLayerTarget, const HTuple& DLLayerWeights, const HTuple& LayerName, const HTuple& DistanceType, const HTuple& LossWeight, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerLossDistance )static void HOperatorSet.CreateDlLayerLossDistance( HTuple DLLayerInput, HTuple DLLayerTarget, HTuple DLLayerWeights, HTuple layerName, HTuple distanceType, HTuple lossWeight, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerLossDistance )def create_dl_layer_loss_distance( dllayer_input: HHandle, dllayer_target: HHandle, dllayer_weights: HHandle, layer_name: str, distance_type: str, loss_weight: float, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[str] ) -> HHandle

Herror T_create_dl_layer_loss_distance( const Htuple DLLayerInput, const Htuple DLLayerTarget, const Htuple DLLayerWeights, const Htuple LayerName, const Htuple DistanceType, const Htuple LossWeight, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerLossDistance )

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

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

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

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

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

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

DescriptionπŸ”—

The operator create_dl_layer_loss_distanceCreateDlLayerLossDistance creates a distance loss layer whose handle is returned in DLLayerLossDistanceDLLayerLossDistancedllayer_loss_distance.

This layer expects multiple layers as input:

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 is an overall loss weight if there are multiple losses in the network.

The parameter DistanceTypedistanceTypedistance_type determines which distance measure is applied. Currently, 'l2'"l2" and 'l1'"l1" are implemented. Depending on the generic parameter 'reduce'"reduce" this results in

  • L2 loss distance as a tensor:

    \[\begin{eqnarray*} \textrm{DLLayerLossDistance}[i] &=& 0.5 \cdot \textrm{LossWeight} \cdot \textrm{DLLayerWeights}[i]\\ &~& \cdot (\textrm{DLLayerInput}[i] - \textrm{DLLayerTarget}[i])^{2}, \end{eqnarray*}\]

    in this case loss is the tensor of the same size as DLLayerInputDLLayerInputdllayer_input.

  • L2 loss distance as a scalar:

    \[\begin{eqnarray*} \textrm{DLLayerLossDistance} = \frac{\sum_{i=0}^{N-1} \textrm{DLLayerLossDistance}[i]} {\sum_{i=0}^{N-1} \textrm{DLLayerWeights}[i]}, \end{eqnarray*}\]

    where \(N\) is a number of elements in DLLayerInputDLLayerInputdllayer_input.

  • L1 loss distance as a tensor:

    \[\begin{eqnarray*} \textrm{DLLayerLossDistance}[i] &=& \textrm{LossWeight} \cdot \textrm{DLLayerWeights}[i]\\ &~& \cdot |\textrm{DLLayerInput}[i] - \textrm{DLLayerTarget}[i]|, \end{eqnarray*}\]

    in this case loss is the tensor of the same size as DLLayerInputDLLayerInputdllayer_input.

  • L1 loss distance as a scalar:

    \[\begin{eqnarray*} \textrm{DLLayerLossDistance} = \frac{\sum_{i=0}^{N-1} \textrm{DLLayerLossDistance}[i]} {\sum_{i=0}^{N-1} \textrm{DLLayerWeights}[i]}, \end{eqnarray*}\]

    where \(N\) is a number of elements in DLLayerInputDLLayerInputdllayer_input.

Thus DLLayerInputDLLayerInputdllayer_input, DLLayerTargetDLLayerTargetdllayer_target and DLLayerWeightsDLLayerWeightsdllayer_weights should have the same size. Setting the weights in DLLayerWeightsDLLayerWeightsdllayer_weights to 11 will result in a loss normalized over the number of elements.

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"

  • 'reduce'"reduce": Determines whether the output of the layer is reduced:

    • 'true'"true": The output is reduced to a scalar.

    • 'false'"false": The output of the layer is a tensor, where each element is a β€˜per-pixel’ loss (squared differences).

    Default: 'true'"true".

Certain parameters of layers created using this operator create_dl_layer_loss_distanceCreateDlLayerLossDistance 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" (DLLayerLossDistanceDLLayerLossDistancedllayer_loss_distance) x
'shape'"shape" x
'type'"type" x
'distance_type'"distance_type" (DistanceTypedistanceTypedistance_type) x
Generic Layer Parameters set get
'is_inference_output'"is_inference_output" x x
'num_trainable_params'"num_trainable_params" x
'reduce'"reduce" x 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.

DistanceTypedistanceTypedistance_type (input_control) string β†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Type of distance.

Default: 'l2'"l2"
List of values: 'l1', 'l2'"l1", "l2"

LossWeightlossWeightloss_weight (input_control) number β†’ (real)HTuple (double)HTuple (double)floatHtuple (double)

Loss weight. Applies to all losses, if several losses occur 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', 'reduce'"is_inference_output", "reduce"

GenParamValuegenParamValuegen_param_value (input_control) attribute.value(-array) β†’ (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Generic input parameter values.

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

DLLayerLossDistanceDLLayerLossDistancedllayer_loss_distance (output_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Distance loss layer.

ModuleπŸ”—

Deep Learning Professional