CÃlimos 2023-02-28 10:34 采纳率: 64.4%
浏览 44
已结题

halcon深度学习模型训练无反应

之前的预处理程序已经成功生成了dataset文件 里面包含dl_ Preprocess_param.hdict和dl_dataset.hdict和sample文件夹
但现在的模型训练程序没反应 什么都没显示 也没显示报错

以下是完整程序


*总输出文件夹
ExampleDataDir := 'defects_data'

*模型类型
ModelFileName:='pretrained_dl_classifier_compact.hdl'

*预处理文件存放路径
DataDirectory := ExampleDataDir + '/dldataset'
DLDatasetFileName := DataDirectory + '/dl_dataset.hdict'
*预处理参数信息
DLPreprocessParamFileName := DataDirectory +'/dl_ Preprocess_param.hdict'

*best模型(实际部署的时候使用)
BestModelBaseName := ExampleDataDir+'/best_dl_model_classification'
*final(避免训练过程中意外停止)
FinalModelBaseName := ExampleDataDir+'/final_dl_model_classification'

*批次大小(GPU限制)
BatchSize := 16
*学习率
 InitialLearningRate:=0.001
*动量
 Momentum:=0.9
*训练周期
 NumEpochs:=80
*每隔多少周期训练一次
 EvaluationIntervalEpochs:=1
*不改变学习率
 ChangeLearningRateEpochs:=[]
 ChangeLearningRateValues:= InitialLearningRate*[0.1,0.01,0.001]
*权重
 WeightPrior:=0.0005
 
 *显示评估结果
DisplayEvaluation := true
RandomSeed := 42
*超参数
GenParamName := []
GenParamValue := []

* Halcon迷你版的数据增强
create_dict (AugmentationParam)
* Percentage of samples to be augmented.
set_dict_tuple (AugmentationParam, 'augmentation_percentage', 10)
* Mirror images along row and column.
set_dict_tuple (AugmentationParam, 'mirror', 'rc')
GenParamName := [GenParamName,'augment']
GenParamValue := [GenParamValue,AugmentationParam]

* 改变学习率
if (|ChangeLearningRateEpochs| > 0)
    create_dict (ChangeStrategy)
    * Specify the model parameter to be changed, here the learning rate.
    set_dict_tuple (ChangeStrategy, 'model_param', 'learning_rate')
    * Start the parameter value at 'initial_value'.
    set_dict_tuple (ChangeStrategy, 'initial_value', InitialLearningRate)
    * Reduce the learning rate in the following epochs.
    set_dict_tuple (ChangeStrategy, 'epochs', ChangeLearningRateEpochs)
    * Reduce the learning rate to the following values.
    set_dict_tuple (ChangeStrategy, 'values', ChangeLearningRateValues)
    * Collect all change strategies as input.
    GenParamName := [GenParamName,'change']
    GenParamValue := [GenParamValue,ChangeStrategy]
endif

* 'best'模型
create_dict (SerializationStrategy)
set_dict_tuple (SerializationStrategy, 'type', 'best')
set_dict_tuple (SerializationStrategy, 'basename', BestModelBaseName)
GenParamName := [GenParamName,'serialize']
GenParamValue := [GenParamValue,SerializationStrategy]

*'final'模型
create_dict (SerializationStrategy)
set_dict_tuple (SerializationStrategy, 'type', 'final')
set_dict_tuple (SerializationStrategy, 'basename', FinalModelBaseName)
GenParamName := [GenParamName,'serialize']
GenParamValue := [GenParamValue,SerializationStrategy]

*显示训练集中的准确率
*在本例中,选择20%的训练分割来显示
*训练过程中减少训练分裂的评价措施。较低的百分比
*有助于加快评估/培训,如果培训部门的评估措施
*不显示,将该值设置为0(默认值)
SelectedPercentageTrainSamples := 20
create_dict (DisplayParam)
set_dict_tuple (DisplayParam, 'selected_percentage_train_samples', SelectedPercentageTrainSamples)
GenParamName := [GenParamName,'display']
GenParamValue := [GenParamValue,DisplayParam]

*检查是否存在所有必要的文件。

check_data_availability (ExampleDataDir, DLDatasetFileName, DLPreprocessParamFileName)
* 

return ()
read_dl_model (ModelFileName, DLModelHandle)
*读入预处理的DLDataset文件。
read_dict (DLDatasetFileName, [], [], DLDataset)

* Set model hyper-parameters as specified in the settings above.
set_dl_model_param (DLModelHandle, 'learning_rate', InitialLearningRate)
set_dl_model_param (DLModelHandle, 'momentum', Momentum)
* Set the class names for the model.
get_dict_tuple (DLDataset, 'class_names', ClassNames)
set_dl_model_param (DLModelHandle, 'class_names', ClassNames)
* Get image dimensions from preprocess parameters and set them for the model.
read_dict (DLPreprocessParamFileName, [], [], DLPreprocessParam)
get_dict_tuple (DLPreprocessParam, 'image_width', ImageWidth)
get_dict_tuple (DLPreprocessParam, 'image_height', ImageHeight)
get_dict_tuple (DLPreprocessParam, 'image_num_channels', ImageNumChannels)
set_dl_model_param (DLModelHandle, 'image_dimensions', [ImageWidth,ImageHeight,ImageNumChannels])

*设置BatchSize
if (BatchSize == 'maximum')
    set_dl_model_param_max_gpu_batch_size (DLModelHandle, 100)
else
    set_dl_model_param (DLModelHandle, 'batch_size', BatchSize)
endif

*加载权重
if (|WeightPrior| > 0)
    set_dl_model_param (DLModelHandle, 'weight_prior', WeightPrior)
endif
*GPU不足会报错
stop()
*设置'runtime_init'框架,'immediately'默认为GPU运行
set_dl_model_param (DLModelHandle, 'runtime_init', 'immediately')
*创建可训练参数
create_dl_train_param (DLModelHandle, NumEpochs, EvaluationIntervalEpochs, DisplayEvaluation, RandomSeed, GenParamName, GenParamValue, TrainParam)
*halcon训练
train_dl_model (DLDataset, DLModelHandle, TrainParam, 0, TrainResults, TrainInfos, EvaluationInfos)

dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop()

dev_close_window()


  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-02-28 12:18
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月8日
  • 已采纳回答 2月28日
  • 修改了问题 2月28日
  • 创建了问题 2月28日

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的