Skip to content

optimize_dl_model_for_inferenceOptimizeDlModelForInferenceOptimizeDlModelForInferenceoptimize_dl_model_for_inferenceT_optimize_dl_model_for_inference๐Ÿ”—

Short description๐Ÿ”—

optimize_dl_model_for_inferenceOptimizeDlModelForInferenceOptimizeDlModelForInferenceoptimize_dl_model_for_inferenceT_optimize_dl_model_for_inference โ€” Optimize a model for inference on a device via the AIยฒ-interface.

Signature๐Ÿ”—

optimize_dl_model_for_inference( dl_model DLModelHandle, dl_device DLDeviceHandle, string Precision, dict DLSamples, dict GenParam, out dl_model DLModelHandleConverted, out dict ConversionReport )void OptimizeDlModelForInference( const HTuple& DLModelHandle, const HTuple& DLDeviceHandle, const HTuple& Precision, const HTuple& DLSamples, const HTuple& GenParam, HTuple* DLModelHandleConverted, HTuple* ConversionReport )static void HOperatorSet.OptimizeDlModelForInference( HTuple DLModelHandle, HTuple DLDeviceHandle, HTuple precision, HTuple DLSamples, HTuple genParam, out HTuple DLModelHandleConverted, out HTuple conversionReport )def optimize_dl_model_for_inference( dlmodel_handle: HHandle, dldevice_handle: MaybeSequence[HHandle], precision: str, dlsamples: Sequence[HHandle], gen_param: HHandle ) -> Tuple[HHandle, HHandle]

Herror T_optimize_dl_model_for_inference( const Htuple DLModelHandle, const Htuple DLDeviceHandle, const Htuple Precision, const Htuple DLSamples, const Htuple GenParam, Htuple* DLModelHandleConverted, Htuple* ConversionReport )

HDlModel HDlModel::OptimizeDlModelForInference( const HDlDeviceArray& DLDeviceHandle, const HString& Precision, const HDictArray& DLSamples, const HDict& GenParam, HDict* ConversionReport ) const

HDlModel HDlModel::OptimizeDlModelForInference( const HDlDevice& DLDeviceHandle, const HString& Precision, const HDictArray& DLSamples, const HDict& GenParam, HDict* ConversionReport ) const

HDlModel HDlModel::OptimizeDlModelForInference( const HDlDevice& DLDeviceHandle, const char* Precision, const HDictArray& DLSamples, const HDict& GenParam, HDict* ConversionReport ) const

HDlModel HDlModel::OptimizeDlModelForInference( const HDlDevice& DLDeviceHandle, const wchar_t* Precision, const HDictArray& DLSamples, const HDict& GenParam, HDict* ConversionReport ) const (Windows only)

HDlModel HDlModel.OptimizeDlModelForInference( HDlDevice[] DLDeviceHandle, string precision, HDict[] DLSamples, HDict genParam, out HDict conversionReport )

HDlModel HDlModel.OptimizeDlModelForInference( HDlDevice DLDeviceHandle, string precision, HDict[] DLSamples, HDict genParam, out HDict conversionReport )

Description๐Ÿ”—

The operator optimize_dl_model_for_inferenceOptimizeDlModelForInference optimizes the input model DLModelHandleDLModelHandledlmodel_handle for inference on the device DLDeviceHandleDLDeviceHandledldevice_handle and returns the optimized model in DLModelHandleConvertedDLModelHandleConverteddlmodel_handle_converted. This operator has two distinct functionalities: Casting the model precision to Precisionprecisionprecision and calibrating the model based on the given samples DLSamplesDLSamplesdlsamples. Additionally in either case the model architecture may be optimized for the DLDeviceHandleDLDeviceHandledldevice_handle.

The parameter DLDeviceHandleDLDeviceHandledldevice_handle specifies the deep learning device for which the model is optimized. Whether the device supports optimization can be determined using get_dl_device_paramGetDlDeviceParam with 'conversion_supported'"conversion_supported". After a successful execution, optimize_dl_model_for_inferenceOptimizeDlModelForInference sets the parameter 'precision_is_converted'"precision_is_converted" to 'true'"true" for the output model DLModelHandleConvertedDLModelHandleConverteddlmodel_handle_converted. In addition, the device in DLDeviceHandleDLDeviceHandledldevice_handle is automatically set for the model if it supports the precision set by the parameter Precisionprecisionprecision. Whether the device supports the requested precision can be determined using get_dl_device_paramGetDlDeviceParam with 'precisions'"precisions".

The parameter Precisionprecisionprecision specifies the precision to which the model should be converted to. By default, models that are delivered by HALCON have the Precisionprecisionprecision 'float32'"float32". The following values are supported for Precisionprecisionprecision:

  • 'bfloat16'"bfloat16"

  • 'float32'"float32"

  • 'float16'"float16"

  • 'int8'"int8"

The parameter DLSamplesDLSamplesdlsamples specifies the samples on which the calibration is based. As a consequence they should be representative. It is recommended to provide them from the training split. For most applications 10-20 samples per class are sufficient to achieve good results.

Note, the samples are not needed for a pure cast operation. In this case, an empty tuple can be passed over for DLSamplesDLSamplesdlsamples.

The parameter GenParamgenParamgen_param specifies additional, device specific parameters and their values. Which parameters to set for the given DLDeviceHandleDLDeviceHandledldevice_handle in GenParamgenParamgen_param and their default values can be queried via the get_dl_device_paramGetDlDeviceParam operator with the 'optimize_for_inference_params'"optimize_for_inference_params" parameter.

Note, certain devices also expect only an empty dictionary.

The parameter ConversionReportconversionReportconversion_report returns a report dictionary with information about the conversion.

Attention๐Ÿ”—

This operator can only be used via an AIยฒ-interface. Furthermore, after optimization only parameters that do not change the underlying architecture of the model can be set for DLModelHandleConvertedDLModelHandleConverteddlmodel_handle_converted.

For set_dl_model_paramSetDlModelParam, this includes the following parameters:

  • 'Any': 'device'"device", 'meta_data'"meta_data", 'runtime'"runtime"

  • 'anomaly_detection': 'standard_deviation_factor'"standard_deviation_factor"

  • 'classification': 'class_names'"class_names", 'ood_threshold'"ood_threshold"

  • 'ocr_detection': 'min_character_score'"min_character_score", 'min_link_score'"min_link_score", 'min_word_score'"min_word_score", 'orientation'"orientation", 'sort_by_line'"sort_by_line", 'tiling'"tiling", 'tiling_overlap'"tiling_overlap"

  • 'ocr_recognition': 'alphabet'"alphabet", 'alphabet_internal'"alphabet_internal", 'alphabet_mapping'"alphabet_mapping"

  • 'gc_anomaly_detectionโ€™: 'anomaly_score_tolerance'"anomaly_score_tolerance"

  • 'detection': 'class_names'"class_names", 'max_num_detections'"max_num_detections", 'max_overlap'"max_overlap", 'max_overlap_class_agnostic'"max_overlap_class_agnostic", 'min_confidence'"min_confidence"

  • 'segmentation': 'class_names'"class_names", 'tiling_overlap'"tiling_overlap"

For set_deep_ocr_paramSetDeepOcrParam, this includes the following parameters:

  • 'device'"device", 'runtime'"runtime"

  • 'detection_min_character_score'"detection_min_character_score", 'detection_min_link_score'"detection_min_link_score", 'detection_min_word_score'"detection_min_word_score",

  • 'detection_orientation'"detection_orientation", 'detection_sort_by_line'"detection_sort_by_line",

  • 'detection_tiling'"detection_tiling", 'detection_tiling_overlap'"detection_tiling_overlap"

  • 'recognition_alphabet'"recognition_alphabet", 'recognition_alphabet_internal'"recognition_alphabet_internal", 'recognition_alphabet_mapping'"recognition_alphabet_mapping"

For set_deep_counting_model_paramSetDeepCountingModelParam, this includes the following parameters:

  • 'device'"device"

  • 'max_overlap'"max_overlap", 'min_score'"min_score"

Only the AIยฒ-interface that was used to optimize can be set using 'device'"device" or the 'runtime'"runtime". Additional restrictions may apply to these parameters to ensure that the underlying architecture of the model does not change.

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

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

Input model.

DLDeviceHandleDLDeviceHandledldevice_handle (input_control) dl_device(-array) โ†’ (handle)HTuple (HHandle)HDlDevice, HTuple (IntPtr)MaybeSequence[HHandle]Htuple (handle)

Device handle used for optimization.

Precisionprecisionprecision (input_control) string โ†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Precision the model shall be converted to.

DLSamplesDLSamplesdlsamples (input_control) dict-array โ†’ (handle)HTuple (HHandle)HDict, HTuple (IntPtr)Sequence[HHandle]Htuple (handle)

Samples required for optimization.

GenParamgenParamgen_param (input_control) dict โ†’ (handle)HTuple (HHandle)HDict, HTuple (IntPtr)HHandleHtuple (handle)

Parameter dict for optimization.

DLModelHandleConvertedDLModelHandleConverteddlmodel_handle_converted (output_control) dl_model โ†’ (handle)HTuple (HHandle)HDlModel, HTuple (IntPtr)HHandleHtuple (handle)

Output model with new precision.

ConversionReportconversionReportconversion_report (output_control) dict โ†’ (handle)HTuple (HHandle)HDict, HTuple (IntPtr)HHandleHtuple (handle)

Output report for conversion.

Result๐Ÿ”—

If the parameters are valid, the operator optimize_dl_model_for_inferenceOptimizeDlModelForInference returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Combinations with other operators๐Ÿ”—

Combinations

Possible predecessors

train_dl_model_batchTrainDlModelBatch, query_available_dl_devicesQueryAvailableDlDevices

Possible successors

set_dl_model_paramSetDlModelParam, apply_dl_modelApplyDlModel

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:

3D Metrology, OCR/OCV, Deep Learning Enhanced, Deep Learning Professional, Matching