Skip to content

create_dl_layer_loss_focalCreateDlLayerLossFocalCreateDlLayerLossFocalcreate_dl_layer_loss_focalT_create_dl_layer_loss_focalπŸ”—

Short descriptionπŸ”—

create_dl_layer_loss_focalCreateDlLayerLossFocalCreateDlLayerLossFocalcreate_dl_layer_loss_focalT_create_dl_layer_loss_focal β€” Create a focal loss layer.

SignatureπŸ”—

create_dl_layer_loss_focal( dl_layer DLLayerInput, dl_layer DLLayerTarget, dl_layer DLLayerWeights, dl_layer DLLayerNormalization, string LayerName, number LossWeight, number Gamma, number ClassWeights, string Type, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer DLLayerLossFocal )void CreateDlLayerLossFocal( const HTuple& DLLayerInput, const HTuple& DLLayerTarget, const HTuple& DLLayerWeights, const HTuple& DLLayerNormalization, const HTuple& LayerName, const HTuple& LossWeight, const HTuple& Gamma, const HTuple& ClassWeights, const HTuple& Type, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerLossFocal )static void HOperatorSet.CreateDlLayerLossFocal( HTuple DLLayerInput, HTuple DLLayerTarget, HTuple DLLayerWeights, HTuple DLLayerNormalization, HTuple layerName, HTuple lossWeight, HTuple gamma, HTuple classWeights, HTuple type, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerLossFocal )def create_dl_layer_loss_focal( dllayer_input: HHandle, dllayer_target: HHandle, dllayer_weights: HHandle, dllayer_normalization: HHandle, layer_name: str, loss_weight: Union[int, float], gamma: Union[int, float], class_weights: MaybeSequence[Union[int, float]], type: str, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[str] ) -> HHandle

Herror T_create_dl_layer_loss_focal( const Htuple DLLayerInput, const Htuple DLLayerTarget, const Htuple DLLayerWeights, const Htuple DLLayerNormalization, const Htuple LayerName, const Htuple LossWeight, const Htuple Gamma, const Htuple ClassWeights, const Htuple Type, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerLossFocal )

HDlLayer HDlLayer::CreateDlLayerLossFocal( const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const HDlLayer& DLLayerNormalization, const HString& LayerName, const HTuple& LossWeight, const HTuple& Gamma, const HTuple& ClassWeights, const HString& Type, const HTuple& GenParamName, const HTuple& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerLossFocal( const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const HDlLayer& DLLayerNormalization, const HString& LayerName, double LossWeight, double Gamma, double ClassWeights, const HString& Type, const HString& GenParamName, const HString& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerLossFocal( const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const HDlLayer& DLLayerNormalization, const char* LayerName, double LossWeight, double Gamma, double ClassWeights, const char* Type, const char* GenParamName, const char* GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerLossFocal( const HDlLayer& DLLayerTarget, const HDlLayer& DLLayerWeights, const HDlLayer& DLLayerNormalization, const wchar_t* LayerName, double LossWeight, double Gamma, double ClassWeights, const wchar_t* Type, const wchar_t* GenParamName, const wchar_t* GenParamValue ) const (Windows only)

HDlLayer HDlLayer.CreateDlLayerLossFocal( HDlLayer DLLayerTarget, HDlLayer DLLayerWeights, HDlLayer DLLayerNormalization, string layerName, HTuple lossWeight, HTuple gamma, HTuple classWeights, string type, HTuple genParamName, HTuple genParamValue )

HDlLayer HDlLayer.CreateDlLayerLossFocal( HDlLayer DLLayerTarget, HDlLayer DLLayerWeights, HDlLayer DLLayerNormalization, string layerName, double lossWeight, double gamma, double classWeights, string type, string genParamName, string genParamValue )

DescriptionπŸ”—

The operator create_dl_layer_loss_focalCreateDlLayerLossFocal creates a focal loss layer whose handle is returned in DLLayerLossFocalDLLayerLossFocaldllayer_loss_focal. See the reference cited below for further information about its definition and parameter meanings.

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

The parameter Gammagammagamma is the exponent of the focal factor.

The parameter ClassWeightsclassWeightsclass_weights defines class specific weights. All loss contributions of foreground samples of a class are weighted with the given factor. The background samples are weighted by 1 - ClassWeightsclassWeightsclass_weights. Typically, this is set to 1.0/(Number of samples of the class). Note, the length of this array has to be either 1, then its broadcasted to the number of classes, or it has to correspond to the number of classes. The default value [][] corresponds to a factor of 0.50.5 for all classes. Note, if the number of classes are changed on a network then the number of class specific weights are also adapted and reset with the default value 0.50.5 for each class.

The parameter Typetypetype sets the focal loss options:

  • 'focal_binary'"focal_binary": Focal loss.

  • 'sigmoid_focal_binary'"sigmoid_focal_binary": Focal loss fused with sigmoid.

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_focalCreateDlLayerLossFocal 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
'focal_type'"focal_type" (Typetypetype) x
'gamma'"gamma" (Gammagammagamma) x x
'input_layer'"input_layer" (DLLayerInputDLLayerInputdllayer_input, DLLayerTargetDLLayerTargetdllayer_target, DLLayerWeightsDLLayerWeightsdllayer_weights, and/or DLLayerNormalizationDLLayerNormalizationdllayer_normalization) x
'loss_weight'"loss_weight" (LossWeightlossWeightloss_weight) x x
'name'"name" (LayerNamelayerNamelayer_name) x x
'output_layer'"output_layer" (DLLayerLossFocalDLLayerLossFocaldllayer_loss_focal) 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.

DLLayerNormalizationDLLayerNormalizationdllayer_normalization (input_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Normalization layer.

Default: [][]

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

Name of the output layer.

LossWeightlossWeightloss_weight (input_control) number β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[int, float]Htuple (double / Hlong)

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

Default: 1.01.0

Gammagammagamma (input_control) number β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[int, float]Htuple (double / Hlong)

Exponent of the focal factor.

Default: 2.02.0

ClassWeightsclassWeightsclass_weights (input_control) number(-array) β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)MaybeSequence[Union[int, float]]Htuple (double / Hlong)

Class specific weight.

Default: [][]

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

Focal loss type.

Default: 'focal_binary'"focal_binary"
List of values: 'focal_binary', 'sigmoid_focal_binary'"focal_binary", "sigmoid_focal_binary"

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)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Generic input parameter values.

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

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

Focal loss layer.

ReferencesπŸ”—

T. Lin, P. Goyal, R. Girshick, K. He and P. Dollar, β€œFocal Loss for Dense Object Detection,” in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 42, no. 2, pp. 318-327, 1 Feb. 2020, doi: 10.1109/TPAMI.2018.2858826.

ModuleπŸ”—

Deep Learning Professional