之前的预处理程序已经成功生成了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()