该方法属于无监督式的深度学习方法,优点:
1 无需标注
2 只训练正样本
3 可以在CPU下进行训练
4 具有较快的推断速度
适用场景:适合缺陷较为明显的项目
注意:设置的ImageWidth、ImageHeight ,以及自己采的图,尽量是32的倍数
精确率和召回率说明
https://www.jianshu.com/p/4434ea11c16c
- 读取模型
read_dl_model (‘E:/整条/model_final.hdl’, DLModelHandle) - 设置阈值(模型训练后得到)
InferenceClassificationThreshold := 0.183618
InferenceSegmentationThreshold := 0.236205 - 用模型中已设定的尺寸缩放
get_dl_model_param (DLModelHandle, ‘image_width’, ImageWidth)
get_dl_model_param (DLModelHandle, ‘image_height’, ImageHeight)
create_dl_preprocess_param (‘anomaly_detection’, ImageWidth, ImageHeight, 3, [], [], ‘constant_values’, ‘full_domain’, [], [], [], [], DLPreprocessParam) - 创建类别标签字典(不起作用,但是必须有)
create_dict (DLDatasetInfo)
set_dict_tuple (DLDatasetInfo, ‘class_names’, [‘ok’,‘ng’])
set_dict_tuple (DLDatasetInfo, ‘class_ids’, [‘0’,‘1’]) - 创建字典,承载窗体信息
create_dict (WindowDict) - 读图
list_files (‘E:/整条/ng’, [‘files’,‘follow_links’,‘recursive’], ImageFiles)
tuple_regexp_select (ImageFiles, [’\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$’,‘ignore_case’], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])- Image Acquisition 01: Do something
gen_dl_samples_from_images (Image, DLSample)
preprocess_dl_samples(DLSample, DLPreprocessParam)
preprocess_dl_samples_bottle (DLSample)
apply_dl_model (DLModelHandle, DLSample, [], DLResult)
threshold_dl_anomaly_results (InferenceSegmentationThreshold, InferenceClassificationThreshold, DLResult) - 展示结果
dev_display_dl_data (DLSample, DLResult, DLDatasetInfo, [‘anomaly_result’,‘anomaly_image’], [], WindowDict)
dev_disp_text (‘Press F5 (continue)’, ‘window’, ‘bottom’, ‘center’, ‘black’, [], [])
stop ()
- Image Acquisition 01: Do something
endfor
dev_close_window_dict (WindowDict)