Skip to content

get_dl_model_layer_weightsGetDlModelLayerWeightsGetDlModelLayerWeightsget_dl_model_layer_weightsT_get_dl_model_layer_weightsπŸ”—

Short descriptionπŸ”—

get_dl_model_layer_weightsGetDlModelLayerWeightsGetDlModelLayerWeightsget_dl_model_layer_weightsT_get_dl_model_layer_weights β€” Get the weights (or values) of a Deep Learning model layer.

SignatureπŸ”—

get_dl_model_layer_weights( out image Weights, dl_model DLModelHandle, string LayerName, string WeightsType )void GetDlModelLayerWeights( HObject* Weights, const HTuple& DLModelHandle, const HTuple& LayerName, const HTuple& WeightsType )static void HOperatorSet.GetDlModelLayerWeights( out HObject weights, HTuple DLModelHandle, HTuple layerName, HTuple weightsType )def get_dl_model_layer_weights( dlmodel_handle: HHandle, layer_name: str, weights_type: str ) -> HObject

Herror T_get_dl_model_layer_weights( Hobject* Weights, const Htuple DLModelHandle, const Htuple LayerName, const Htuple WeightsType )

HImage HDlModel::GetDlModelLayerWeights( const HString& LayerName, const HString& WeightsType ) const

HImage HDlModel::GetDlModelLayerWeights( const char* LayerName, const char* WeightsType ) const

HImage HDlModel::GetDlModelLayerWeights( const wchar_t* LayerName, const wchar_t* WeightsType ) const (Windows only)

HImage HDlModel.GetDlModelLayerWeights( string layerName, string weightsType )

DescriptionπŸ”—

The operator get_dl_model_layer_weightsGetDlModelLayerWeights returns in Weightsweightsweights the values of a LayerNamelayerNamelayer_name of the model DLModelHandleDLModelHandledlmodel_handle.

The parameter WeightsTypeweightsTypeweights_type determines which type of layer values are retrieved. The following values are supported for WeightsTypeweightsTypeweights_type:

  • 'batchnorm_mean'"batchnorm_mean": Batch-wise calculated mean values to normalize the inputs. For further information, please refer to create_dl_layer_batch_normalizationCreateDlLayerBatchNormalization.

    Restriction: This value is only supported if the layer is of type 'batchnorm'"batchnorm".

  • 'batchnorm_mean_avg'"batchnorm_mean_avg": Average of the batch-wise calculated mean values to normalize the inputs. For further information, please refer to create_dl_layer_batch_normalizationCreateDlLayerBatchNormalization.

    Restriction: This value is only supported if the layer is of type 'batchnorm'"batchnorm".

  • 'batchnorm_variance'"batchnorm_variance": Batch-wise calculated variance values to normalize the inputs. For further information, please refer to create_dl_layer_batch_normalizationCreateDlLayerBatchNormalization.

    Restriction: This value is only supported if the layer is of type 'batchnorm'"batchnorm".

  • 'batchnorm_variance_avg'"batchnorm_variance_avg": Average of the batch-wise calculated variance values to normalize the inputs. For further information, please refer to create_dl_layer_batch_normalizationCreateDlLayerBatchNormalization.

    Restriction: This value is only supported if the layer is of type 'batchnorm'"batchnorm".

  • 'bias'"bias": Biases of the layer.

  • 'bias_gradient'"bias_gradient": Gradients of the biases of the layer.

  • 'bias_gradient_norm_l2'"bias_gradient_norm_l2": Gradients of the biases of the layer in terms of L2 norm.

  • 'bias_norm_l2'"bias_norm_l2": Biases of the layer in terms of L2 norm.

  • 'bias_update'"bias_update": Update of the biases of the layer. This is used in e.g., a solver which uses the last update.

  • 'bias_update_norm_l2'"bias_update_norm_l2": Update of the biases of the layer in terms of L2 norm. This is used in a solver which uses the last update.

  • 'weights'"weights": Weights of the layer.

  • 'weights_gradient'"weights_gradient": Gradients of the weights of the layer.

  • 'weights_gradient_norm_l2'"weights_gradient_norm_l2": Gradients of the weights of the layer in terms of L2 norm.

  • 'weights_norm_l2'"weights_norm_l2": Weights of the layer in terms of L2 norm.

  • 'weights_update'"weights_update": Update of the weights of the layer. This is used in a solver which uses the last update.

  • 'weights_update_norm_l2'"weights_update_norm_l2": Update of the weights of the layer in terms of L2 norm. This is used in a solver which uses the last update.

The following tables give an overview, which parameters for WeightsTypeweightsTypeweights_type can be set using set_dl_model_layer_weightsSetDlModelLayerWeights and which ones can be retrieved using get_dl_model_layer_weightsGetDlModelLayerWeights.

Layer Parameters set get
'batchnorm_mean'"batchnorm_mean" x x
'batchnorm_mean_avg'"batchnorm_mean_avg" x x
'batchnorm_variance'"batchnorm_variance" x x
'batchnorm_variance_avg'"batchnorm_variance_avg" x x
'bias'"bias" x x
'bias_gradient'"bias_gradient" x
'bias_gradient_norm_l2'"bias_gradient_norm_l2" x
'bias_norm_l2'"bias_norm_l2" x
'bias_update'"bias_update" x
'bias_update_norm_l2'"bias_update_norm_l2" x
'weights'"weights" x x
'weights_gradient'"weights_gradient" x
'weights_gradient_norm_l2'"weights_gradient_norm_l2" x
'weights_norm_l2'"weights_norm_l2" x
'weights_update'"weights_update" x
'weights_update_norm_l2'"weights_update_norm_l2" x

AttentionπŸ”—

The operator get_dl_model_layer_weightsGetDlModelLayerWeights is only applicable to self-created networks. For networks delivered by HALCON, the operator returns an empty tuple.

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πŸ”—

Weightsweightsweights (output_object) image(-array) β†’ object (real)HObject (real)HImage (real)HObject (real)Hobject * (real)

Output weights.

DLModelHandleDLModelHandledlmodel_handle (input_control) dl_model β†’ (handle)HTuple (HHandle)HDlModel, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the deep learning model.

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

Name of the layer to be queried.

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

Selected type of layer values to be returned.

Default: 'weights'"weights"
List of values: 'batchnorm_mean', 'batchnorm_mean_avg', 'batchnorm_variance', 'batchnorm_variance_avg', 'bias', 'bias_gradient', 'bias_gradient_norm_l2', 'bias_norm_l2', 'bias_update', 'bias_update_norm_l2', 'weights', 'weights_gradient', 'weights_gradient_norm_l2', 'weights_norm_l2', 'weights_update', 'weights_update_norm_l2'"batchnorm_mean", "batchnorm_mean_avg", "batchnorm_variance", "batchnorm_variance_avg", "bias", "bias_gradient", "bias_gradient_norm_l2", "bias_norm_l2", "bias_update", "bias_update_norm_l2", "weights", "weights_gradient", "weights_gradient_norm_l2", "weights_norm_l2", "weights_update", "weights_update_norm_l2"

ExampleπŸ”—

(HDevelop)

set_system ('seed_rand', 42)
* Create a small model network.
create_dl_layer_input ('input', [InputImageSize[0],InputImageSize[1],1], [],\
                       [], DLGraphNodeInput)
create_dl_layer_convolution (DLGraphNodeInput, 'conv', 3, 1, 1, 2, 1, 'none',\
                             'none', [], [], DLGraphNodeConvolution)
create_dl_layer_activation (DLGraphNodeConvolution, 'relu', 'relu', [], [],\
                            DLGraphNodeActivation)
create_dl_layer_dense (DLGraphNodeActivation, 'dense', 3, [], [],\
                       DLGraphNodeDense)
create_dl_layer_softmax (DLGraphNodeDense, 'softmax', [], [],\
                          DLGraphNodeSoftMax)
create_dl_model (DLGraphNodeSoftMax, DLModelHandle)
*
set_dl_model_param (DLModelHandle, 'type', 'classification')
set_dl_model_param (DLModelHandle, 'batch_size', 1)
set_dl_model_param (DLModelHandle, 'runtime', 'gpu')
set_dl_model_param (DLModelHandle, 'runtime_init', 'immediately')
*
* Train for 5 iterations.
for TrainIterations := 1 to NumTrainIterations by 1
    train_dl_model_batch (DLModelHandle, DLSample, DLTrainResult)
endfor
*
* Get the gradients, weights, and activations.
get_dl_model_layer_gradients (GradientsSoftmax, DLModelHandle, 'softmax')
get_dl_model_layer_gradients (GradientsDense, DLModelHandle, 'dense')
get_dl_model_layer_gradients (GradientsConv, DLModelHandle, 'conv')
*
get_dl_model_layer_weights (WeightsDense, DLModelHandle, 'dense',\
                      'weights_gradient')
get_dl_model_layer_weights (WeightsConv, DLModelHandle, 'conv',\
                      'weights_gradient')
*
get_dl_model_layer_activations (ActivationsDense,  DLModelHandle, 'dense')
get_dl_model_layer_activations (ActivationsConv,  DLModelHandle, 'conv')

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

create_dl_modelCreateDlModel, train_dl_model_batchTrainDlModelBatch, set_dl_model_layer_weightsSetDlModelLayerWeights

Possible successors

set_dl_model_layer_weightsSetDlModelLayerWeights

Alternatives

get_dl_model_layer_activationsGetDlModelLayerActivations, get_dl_model_layer_gradientsGetDlModelLayerGradients

ModuleπŸ”—

This operator uses dynamic licensing (see the β€˜Installation Guide’). Which of the following modules is required depends on the specific usage of the operator:

Deep Learning Professional