最近学习深度学习时的一些总结和看法,参照深度学习的自带案例(segment_pill_deep_learning_1_preprocess.hdev)
每个类型中分为3种:contamination(污染)、crack(裂纹)、good(正常)
contamination(污染)
crack(裂纹)
good(正常)
每个类型中分为3种:contamination(污染)、crack(裂纹)、good(正常)
contamination(污染)、crack(裂纹)、good(正常)
*** 设置输入输出路径 ***
*总路径
AllDir := 'E:/视觉/halcon_深度学习/DeepLearning/缺陷检测/'
*图片路径
ImageDir := AllDir + 'images'
*分割图片路径
DivisionImagesDir := AllDir + 'divisionImages'
*存放数据总路径
DataDir := AllDir + 'data'
*预处理后的路径
DataDirectoryBaseName := DataDir + '/dldataset'
*存储预处理参数
PreprocessParamFileBaseName := DataDir + '/dl_preprocess_param'
*** 设置参数 ***
*类别名称
ClassNames := ['good','contamination','crack']
*类别ID
ClassIDs := [0,1,2]
*拆分数据集
TrainingPercent := 70
ValidationPercent := 15
*图片尺寸参数
ImageWidth := 400
ImageHeight := 400
ImageNumChannels := 3
*图片灰度范围
ImageRangeMin := -127
ImageRangeMax := 128
*图像预处理的进一步参数
ContrastNormalization := 'false'
DomainHandling := 'full_domain'
IgnoreClassIDs := []
SetBackgroundID := []
ClassIDsBackground := []
*随机种子
SeedRand := 42
*** 处理图片并进行拆分 ***
*设置随机种子
set_system ('seed_rand', SeedRand)
*通过参数将文件夹中数据分割为数据集 参数:图像路径、分割图像路径、类别名称、类别ID、图像路径列表、分割图像路径列表、字典、生成的数据集
read_dl_dataset_segmentation (ImageDir, DivisionImagesDir, ClassNames, ClassIDs, [], [], [], DLDataset)
*拆分数据集
split_dl_dataset (DLDataset, TrainingPercent, ValidationPercent, [])
*** 预处理数据集 ***
file_exists (DataDir, FileExists)
if (not FileExists)
make_dir (DataDir)
endif
*创建预处理参数
create_dl_preprocess_param ('segmentation', ImageWidth, ImageHeight, ImageNumChannels, ImageRangeMin, ImageRangeMax, ContrastNormalization, DomainHandling, IgnoreClassIDs, SetBackgroundID, ClassIDsBackground, [], DLPreprocessParam)
*预处理后的数据集路径
PreprocessParamFile := PreprocessParamFileBaseName +'.hdict'
*将参数写入
write_dict (DLPreprocessParam, PreprocessParamFile, [], [])
*创建字典
create_dict (GenParam)
set_dict_tuple (GenParam, 'overwrite_files', true)
*预处理
preprocess_dl_dataset (DLDataset, DataDirectoryBaseName, DLPreprocessParam, GenParam, DLDatasetFilename)
*** 测试 ***
*随机选取10张图像
get_dict_tuple (DLDataset, 'samples', DatasetSamples)
find_dl_samples (DatasetSamples, 'split', 'train', 'match', SampleIndices)
tuple_shuffle (SampleIndices, ShuffledIndices)
read_dl_samples (DLDataset, ShuffledIndices[0:9], DLSampleBatchDisplay)
*
create_dict (WindowHandleDict)
for Index := 0 to |DLSampleBatchDisplay| - 1 by 1
*可视化不同的图像、注释和推理结果
dev_display_dl_data (DLSampleBatchDisplay[Index], [], DLDataset, ['image','segmentation_image_ground_truth'], [], WindowHandleDict)
get_dict_tuple (WindowHandleDict, 'segmentation_image_ground_truth', WindowHandleImage)
dev_set_window (WindowHandleImage[1])
Text := 'Press Run (F5) to continue'
dev_disp_text (Text, 'window', 400, 40, 'black', [], [])
stop ()
endfor
*关闭窗体
dev_display_dl_data_close_windows (WindowHandleDict)
很多人找我要源码,Github又不太好上传大文件,我就把我的网站新增了下载功能,如果下载接口出现问题请大家评论区回复一下,谢谢。
地址:https://zhoujinyong.com/index.aspx/Files/缺陷检测.rar