set_dl_classifier_paramT_set_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param (算子)

名称

set_dl_classifier_paramT_set_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param — 设置基于深度学习的分类器的参数。

警告

set_dl_classifier_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param 已过时,仅出于向后兼容性考虑而保留。 New applications should use the common CNN-based operator set_dl_model_paramset_dl_model_paramSetDlModelParamSetDlModelParamSetDlModelParamset_dl_model_param instead.

签名

set_dl_classifier_param( : : DLClassifierHandle, GenParamName, GenParamValue : )

Herror T_set_dl_classifier_param(const Htuple DLClassifierHandle, const Htuple GenParamName, const Htuple GenParamValue)

void SetDlClassifierParam(const HTuple& DLClassifierHandle, const HTuple& GenParamName, const HTuple& GenParamValue)

void HDlClassifier::SetDlClassifierParam(const HTuple& GenParamName, const HTuple& GenParamValue) const

void HDlClassifier::SetDlClassifierParam(const HString& GenParamName, const HString& GenParamValue) const

void HDlClassifier::SetDlClassifierParam(const char* GenParamName, const char* GenParamValue) const

void HDlClassifier::SetDlClassifierParam(const wchar_t* GenParamName, const wchar_t* GenParamValue) const   ( Windows only)

static void HOperatorSet.SetDlClassifierParam(HTuple DLClassifierHandle, HTuple genParamName, HTuple genParamValue)

void HDlClassifier.SetDlClassifierParam(HTuple genParamName, HTuple genParamValue)

void HDlClassifier.SetDlClassifierParam(string genParamName, string genParamValue)

def set_dl_classifier_param(dlclassifier_handle: HHandle, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[str, float, int]]) -> None

描述

set_dl_classifier_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param sets the parameters and hyperparameters GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name of the neural network DLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandledlclassifier_handle to the values GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value

The pretrained classifiers are trained for their default image dimensions, see read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier

The network architectures allow different image dimensions. But for networks with at least one fully connected layer such a change makes a retraining necessary. Networks without fully connected layers are directly applicable to different image sizes. However, images with a size differing from the size with which the classifier has been trained, are likely to show a reduced classification accuracy.

GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name can attain the following values:

'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size"
Number of images (and corresponding labels) in a batch that is transferred to device memory. The batch of images which are processed simultaneously in a single training iteration contains a number of images which is equal to 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size" times 'batch_size_multiplier'"batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier". Please refer to train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch for further details. The parameter 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size" is stored in the pretrained classifier. Per default, the 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size" is set such that a training of the pretrained classifier with up to 100 classes can be easily performed on a device with 8 gigabyte of memory. For the pretrained classifiers, the default values are hence given as follows:
pretrained classifier default value of 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size"
'pretrained_dl_classifier_compact.hdl'"pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl" 160
'pretrained_dl_classifier_enhanced.hdl'"pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl" 96
'pretrained_dl_classifier_resnet18.hdl'"pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl" 24
'pretrained_dl_classifier_resnet50.hdl'"pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl" 23
For inference, the 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size" can be generally set independently from the number of input images. See apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier for details on how to set this parameter for greater efficiency.
'batch_size_multiplier'"batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier"

Multiplier for 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size" to enable training with larger numbers of images in one step which would otherwise not be possible due to GPU memory limitations. For detailed information see train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch。This model parameter does not have any impact during evaluation and inference. For the pretrained classifiers, the default value of 'batch_size_multiplier'"batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier" is set to 1.

'classes'"classes""classes""classes""classes""classes"

Tuple of labels corresponding to the classes of objects which are to be recognized. The order of the class names remains unchanged after the setting.

'gpu'"gpu""gpu""gpu""gpu""gpu"

Identifier of the GPU where the training and inference operators (train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch and apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier) are executed. Per default, the first available GPU is used. get_systemget_systemGetSystemGetSystemGetSystemget_system with 'cuda_devices'"cuda_devices""cuda_devices""cuda_devices""cuda_devices""cuda_devices" can be used to retrieve a list of available GPUs. Pass the index in this list to 'gpu'"gpu""gpu""gpu""gpu""gpu".

'image_width'"image_width""image_width""image_width""image_width""image_width"

Width of the images the network will process. The default value is given by the network, see read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier

'image_height'"image_height""image_height""image_height""image_height""image_height"

Height of the images the network will process. The default value is given by the network, see read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier

'image_num_channels'"image_num_channels""image_num_channels""image_num_channels""image_num_channels""image_num_channels"

Number of channels of the images the network will process. Possible are one channel (gray value image), or three channels (three-channel image). The default value is given by the network, see read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier。Changing to a single channel image modifies the network configuration. This process removes the color information contained in certain layers and is not invertible.

'image_dimensions'"image_dimensions""image_dimensions""image_dimensions""image_dimensions""image_dimensions"

Tuple containing the image dimensions 'image_width'"image_width""image_width""image_width""image_width""image_width", 'image_height'"image_height""image_height""image_height""image_height""image_height", and number of channels 'image_num_channels'"image_num_channels""image_num_channels""image_num_channels""image_num_channels""image_num_channels". The default values are given by the network, see read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier。Concerning the number of channels, the values one (gray value image), or three (three-channel image) are possible. Changing to a single channel image modifies the network configuration. This process removes the color information contained in certain layers and is not invertible.

'learning_rate'"learning_rate""learning_rate""learning_rate""learning_rate""learning_rate"

Initial value of the factor determining the gradient influence during training. Please refer to train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch for further details. The default value depends on the classifier.

'momentum'"momentum""momentum""momentum""momentum""momentum"

When updating the arguments of the loss function, the hyperparameter 'momentum'"momentum""momentum""momentum""momentum""momentum" specifies to which extent previous updating vectors will be added to the current updating vector. Please refer to train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch for further details. Per default, the 'momentum'"momentum""momentum""momentum""momentum""momentum" is set to 0.9.

'runtime'"runtime""runtime""runtime""runtime""runtime"

Defines the device on which the operators will be executed. Per default, the 'runtime'"runtime""runtime""runtime""runtime""runtime" is set to 'gpu'"gpu""gpu""gpu""gpu""gpu".

'cpu'"cpu""cpu""cpu""cpu""cpu"

The operator apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier will be executed on the CPU, whereas the operator train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch is not executable.

In case the GPU has been used before, CPU memory is initialized, and if necessary values stored on the GPU memory are moved to the CPU memory.

On Intel or AMD architectures the 'cpu'"cpu""cpu""cpu""cpu""cpu" runtime uses OpenMP for the parallelization of apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier, where per default, all threads available to the OpenMP runtime are used. You may use the set_systemset_systemSetSystemSetSystemSetSystemset_system parameter 'thread_num'"thread_num""thread_num""thread_num""thread_num""thread_num" to specify the number of threads.

On Arm architectures the 'cpu'"cpu""cpu""cpu""cpu""cpu" runtime uses a global thread pool. You may specify the number of threads with the set_systemset_systemSetSystemSetSystemSetSystemset_system parameter 'thread_num'"thread_num""thread_num""thread_num""thread_num""thread_num".

For both architectures mentioned above, it is not possible to specify a thread-specific number of threads (via the parameter 'tsp_thread_num'"tsp_thread_num""tsp_thread_num""tsp_thread_num""tsp_thread_num""tsp_thread_num" of the operator set_systemset_systemSetSystemSetSystemSetSystemset_system).

'gpu'"gpu""gpu""gpu""gpu""gpu"

The GPU memory is initialized and the corresponding handle created. The operators apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier and train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch will be executed on the GPU. For the specific requirements please refer to the HALCON “Installation Guide”.

'runtime_init'"runtime_init""runtime_init""runtime_init""runtime_init""runtime_init"

If called with 'immediately'"immediately""immediately""immediately""immediately""immediately", the GPU memory is initialized and the corresponding handle created. Otherwise this is done on demand, which may result in significantly larger execution times for the first call of apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier or train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch。If 'gpu'"gpu""gpu""gpu""gpu""gpu" or 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size" is changed with subsequent calls of set_dl_classifier_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param, the GPU memory is reinitialized.

Note, this parameter has no effect if running on CPUs, thus if 'runtime'"runtime""runtime""runtime""runtime""runtime" is set to 'cpu'"cpu""cpu""cpu""cpu""cpu".

'weight_prior'"weight_prior""weight_prior""weight_prior""weight_prior""weight_prior"

Regularization parameter used for regularization of the loss function. Regularization is helpful in the presence of overfitting during the classifier training. If the hyperparameter 'weight_prior'"weight_prior""weight_prior""weight_prior""weight_prior""weight_prior" is non-zero, the regularization term given below is added to the loss function (see also train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch) Here the index k runs over all weights of the network, except for the biases which are not regularized. The regularization term generally penalizes large weights, thus pushing the weights towards zero, which effectively reduces the complexity of the model. Simply put: Regularization favors simpler models that are less likely to learn noise in the data and generalize better. In case the classifier overfits the data, it is strongly recommended to try different values for the parameter 'weight_prior'"weight_prior""weight_prior""weight_prior""weight_prior""weight_prior" to improve the generalization properties of the neural network. Choosing its value is a trade-off between the models ability to generalize, overfitting, and underfitting. If is too small, the model might overfit, if its too large the model might loose its ability to fit the data, because all weights are effectively zero. For finding an ideal value for , we recommend a cross-validation, i.e. to perform the training for a range of values and choose the value that results in the best validation error. For typical applications, we recommend testing the values for 'weight_prior'"weight_prior""weight_prior""weight_prior""weight_prior""weight_prior" on a logarithmic scale between . If the training takes a very long time, one might consider performing the hyperparameter optimization on a reduced amount of data. The default value depends on the classifier.

有关基于深度学习的分类概念的说明,请参阅 深度学习 / 分类 一章的引言。涉及此遗留算子的工作流在 遗留 / 深度学习分类 一章中有详细说明。

注意

To successfully set 'gpu'"gpu""gpu""gpu""gpu""gpu" parameters, cuDNN and cuBLAS are required, i.e., to set the parameter GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name 'runtime'"runtime""runtime""runtime""runtime""runtime" to 'gpu'"gpu""gpu""gpu""gpu""gpu" or to set the GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name 'gpu'"gpu""gpu""gpu""gpu""gpu".更多详细信息,请参阅 “安装指南” 中的“深度学习及基于深度学习方法的要求”一章。

执行信息

参数

DLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandledlclassifier_handle (输入控制)  dl_classifier HDlClassifier, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

基于深度学习分类器的句柄。

GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name (输入控制)  attribute.name(-array) HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)

Name of the generic parameter.

默认值: 'classes' "classes" "classes" "classes" "classes" "classes"

值列表: 'batch_size'"batch_size""batch_size""batch_size""batch_size""batch_size", 'batch_size_multiplier'"batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier""batch_size_multiplier", 'classes'"classes""classes""classes""classes""classes", 'gpu'"gpu""gpu""gpu""gpu""gpu", 'image_dimensions'"image_dimensions""image_dimensions""image_dimensions""image_dimensions""image_dimensions", 'image_height'"image_height""image_height""image_height""image_height""image_height", 'image_num_channels'"image_num_channels""image_num_channels""image_num_channels""image_num_channels""image_num_channels", 'image_width'"image_width""image_width""image_width""image_width""image_width", 'learning_rate'"learning_rate""learning_rate""learning_rate""learning_rate""learning_rate", 'momentum'"momentum""momentum""momentum""momentum""momentum", 'runtime'"runtime""runtime""runtime""runtime""runtime", 'runtime_init'"runtime_init""runtime_init""runtime_init""runtime_init""runtime_init", 'weight_prior'"weight_prior""weight_prior""weight_prior""weight_prior""weight_prior"

GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value (输入控制)  attribute.value(-array) HTupleMaybeSequence[Union[str, float, int]]HTupleHtuple (string / real / integer) (string / double / int / long) (HString / double / Hlong) (char* / double / Hlong)

Value of the generic parameter.

默认值: ['class_1','class_2','class_3'] ["class_1","class_2","class_3"] ["class_1","class_2","class_3"] ["class_1","class_2","class_3"] ["class_1","class_2","class_3"] ["class_1","class_2","class_3"]

建议值: 1, 2, 3, 50, 0.001, 'cpu'"cpu""cpu""cpu""cpu""cpu", 'gpu'"gpu""gpu""gpu""gpu""gpu", 'immediately'"immediately""immediately""immediately""immediately""immediately"

结果

如果参数有效,算子 set_dl_classifier_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param 返回值 2 ( H_MSG_TRUE )。如有必要,则抛出异常。

可能的前趋

read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier

可能的后继

get_dl_classifier_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_dl_classifier_param, apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier, train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch

替代

set_dl_model_paramset_dl_model_paramSetDlModelParamSetDlModelParamSetDlModelParamset_dl_model_param

另见

get_dl_classifier_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_dl_classifier_param

模块

深度学习推理