create_dl_modelT_create_dl_modelCreateDlModelCreateDlModelcreate_dl_model创建深度学习模型(算子)

名称

create_dl_modelT_create_dl_modelCreateDlModelCreateDlModelcreate_dl_model — 创建深度学习模型。

签名

create_dl_model( : : OutputLayers : DLModelHandle)

Herror T_create_dl_model(const Htuple OutputLayers, Htuple* DLModelHandle)

void CreateDlModel(const HTuple& OutputLayers, HTuple* DLModelHandle)

void HDlModel::HDlModel(const HDlLayerArray& OutputLayers)

void HDlModel::HDlModel(const HDlLayer& OutputLayers)

void HDlModel::CreateDlModel(const HDlLayerArray& OutputLayers)

void HDlModel::CreateDlModel(const HDlLayer& OutputLayers)

static void HOperatorSet.CreateDlModel(HTuple outputLayers, out HTuple DLModelHandle)

public HDlModel(HDlLayer[] outputLayers)

public HDlModel(HDlLayer outputLayers)

void HDlModel.CreateDlModel(HDlLayer[] outputLayers)

void HDlModel.CreateDlModel(HDlLayer outputLayers)

def create_dl_model(output_layers: MaybeSequence[HHandle]) -> HHandle

描述

算子 create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelCreateDlModelcreate_dl_model 可从图(Graph)创建深度学习模型,并通过 DLModelHandleDLModelHandleDLModelHandleDLModelHandleDLModelHandledlmodel_handle 返回句柄。

HALCON 中的深度学习模型主要由有向无环图构成,该图定义了网络架构。HALCON 深度学习模型的其他组件包括 'class_names'"class_names""class_names""class_names""class_names""class_names"'class_ids'"class_ids""class_ids""class_ids""class_ids""class_ids" 等众多参数,以及训练模型所需的超参数,如 'learning_rate'"learning_rate""learning_rate""learning_rate""learning_rate""learning_rate"。虽然模型创建后可通过 set_dl_model_paramset_dl_model_paramSetDlModelParamSetDlModelParamSetDlModelParamset_dl_model_param 设置参数与超参数,但若网络架构以图形式给定,则必须使用 create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelCreateDlModelcreate_dl_model 创建模型。

构建定义模型网络架构的图时,需将网络各层组合起来。通常,图以输入层为起点。输入层(input layer)之后的后续层将输入层(input layer)作为输入层(feeding layer),而新层本身又可能作为下一层的输入层(feeding layer),如此循环往复,直至将图的输出层(output layers)(如软最大化层或损失层)附加到图中。创建层需使用对应的创建算子:例如输入层通过 create_dl_layer_inputcreate_dl_layer_inputCreateDlLayerInputCreateDlLayerInputCreateDlLayerInputcreate_dl_layer_input 创建,卷积层通过 create_dl_layer_convolutioncreate_dl_layer_convolutionCreateDlLayerConvolutionCreateDlLayerConvolutionCreateDlLayerConvolutioncreate_dl_layer_convolution 创建,依此类推。

当图被定义后,可通过 create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelCreateDlModelcreate_dl_model 创建模型,方法是将图的输出层句柄传递至 OutputLayersOutputLayersOutputLayersOutputLayersoutputLayersoutput_layers。需注意的是,输出层句柄在创建过程中会保存所有直接或间接作为输出层的输入层(feeding input layers)的其他层。这意味着输出层句柄完整保留了使用 create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelCreateDlModelcreate_dl_model 创建模型所需的整个网络架构。

创建的模型类型(即模型设计任务:分类、目标检测、分割)仅由网络架构决定。但若网络架构允许,可通过 set_dl_model_paramset_dl_model_paramSetDlModelParamSetDlModelParamSetDlModelParamset_dl_model_param 设置模型类型 'type'"type""type""type""type""type"。指定模型类型可在 HALCON 深度学习工作流中实现更友好的操作体验。支持类型包括:

'generic'"generic""generic""generic""generic""generic"

此为默认模型类型。模型神经网络可处理的任务由其架构决定。当调用 apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model 进行推理时,该算子将返回输出层的激活值。若需使用 train_dl_model_batchtrain_dl_model_batchTrainDlModelBatchTrainDlModelBatchTrainDlModelBatchtrain_dl_model_batch 训练模型,底层图必须包含损失层。

'classification'"classification""classification""classification""classification""classification"

该模型专用于分类任务,所有训练所需层均已适配。当 apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model 用于推理时,输出将根据类型进行适配(详见 apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model 说明)。更多信息请参阅 深度学习 / 分类

此外,可使用 gen_dl_model_heatmapgen_dl_model_heatmapGenDlModelHeatmapGenDlModelHeatmapGenDlModelHeatmapgen_dl_model_heatmap 算子显示模型热图。

'detection'"detection""detection""detection""detection""detection"

模型被指定用于目标检测和实例分割,所有用于训练模型的层和锚点均适配至该模型。当 apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model 用于推理时,输出将根据类型进行适配,详情参见 apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model。更多信息请参阅 深度学习 / 目标检测与实例分割

'segmentation'"segmentation""segmentation""segmentation""segmentation""segmentation"

该模型分别用于语义分割或边缘提取,所有训练所需层均适配至模型。当 apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model 用于推理时,输出将根据类型进行适配,详情参见 apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model。更多信息请参阅 深度学习 / 语义分割与边缘提取

此外,许多深度学习流程在设定模型类型后可提供更多功能。例如,dev_display_dl_data 可用于更美观地展示推理结果。

请注意:设定模型类型需满足特定图结构条件。若需将模型类型设为上述类型之一,建议遵循我们提供的神经网络架构。

执行信息

此算子返回一个句柄。请注意,即使该句柄被用作特定算子的输入参数,这些算子仍可能改变此句柄类型的实例状态。

参数

OutputLayersOutputLayersOutputLayersOutputLayersoutputLayersoutput_layers (输入控制)  dl_layer(-array) HDlLayer, HTupleMaybeSequence[HHandle]HTupleHtuple (handle) (IntPtr) (HHandle) (handle)

图的输出层。

DLModelHandleDLModelHandleDLModelHandleDLModelHandleDLModelHandledlmodel_handle (输出控制)  dl_model HDlModel, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

深度学习模型的句柄。

结果

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

可能的前趋

create_dl_layer_softmaxcreate_dl_layer_softmaxCreateDlLayerSoftmaxCreateDlLayerSoftmaxCreateDlLayerSoftmaxcreate_dl_layer_softmax, create_dl_layer_loss_cross_entropycreate_dl_layer_loss_cross_entropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropyCreateDlLayerLossCrossEntropycreate_dl_layer_loss_cross_entropy, create_dl_layer_loss_focalcreate_dl_layer_loss_focalCreateDlLayerLossFocalCreateDlLayerLossFocalCreateDlLayerLossFocalcreate_dl_layer_loss_focal, create_dl_layer_loss_hubercreate_dl_layer_loss_huberCreateDlLayerLossHuberCreateDlLayerLossHuberCreateDlLayerLossHubercreate_dl_layer_loss_huber

可能的后继

set_dl_model_paramset_dl_model_paramSetDlModelParamSetDlModelParamSetDlModelParamset_dl_model_param

模块

深度学习训练