Halcon 深度学习缺陷检测

文章目录

深度学习标注

>

获取图片路径

c 复制代码
C:\Users\Administrator\AppData\Roaming\MVTec\HALCON-23.11-Progress\examples\images

必须要有Good或者是OK文件夹做标注,剩下两个为逻辑异常和结构异常
点击检查选择good可以获取所有good图像的照片

点击创建应用和拆分

训练

点击训练
> 点击创建训练点击保存更改

设置完成后点击开始训练

点击评估

通过阈值可以调整判定的区间
滑动热图可以看出误判结果

导出训练文件

推理


已经用 DLT做好标注,训练,和评估,只需修改推理代码

推理代码示例

c 复制代码
* 获取文件图像路径包含合格和不合格图像
list_files ('C:/Users/Administrator/AppData/Roaming/MVTec/HALCON-23.11-Progress/examples/images/juice_bottle/logical_anomaly', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)

* 读取模型
read_dl_model (TrainedModel, DLModelHandle)
* 设置硬件
 query_available_dl_devices (['runtime', 'runtime', 'id'], ['gpu', 'cpu', 0], DLDeviceHandles)
 set_dl_model_param (DLModelHandle, 'device', DLDeviceHandles[0])

* 创建预处理参数
create_dl_preprocess_param_from_model (DLModelHandle, 'none', 'full_domain', [], [], [], DLPreprocessParam)
* 获取模型参数
get_dl_model_param(DLModelHandle,'meta_data',MetaData)
* 异常值分类阈值
ClassificationThreshold := number(MetaData.anomaly_classification_threshold)
SegmentationThreshold := number(MetaData.anomaly_segmentation_threshold)
* 
* Create a dictionary with dataset parameters used for display.
DLDatasetInfo := dict{class_names: ['ok', 'nok'], class_ids: [0, 1]}
* 
* Apply the model to test images.
WindowDict := dict{}
for IndexInference := 0 to |ImageFiles| - 1 by 1
    * 
    read_image (Image, ImageFiles[IndexInference])
    gen_dl_samples_from_images (Image, DLSample)
    * 获取预处理参数
    preprocess_dl_samples (DLSample, DLPreprocessParam)
    * 分类检测
    apply_dl_model (DLModelHandle, DLSample, [], DLResult)
    * 
    *阈值处理
    threshold_dl_anomaly_results (SegmentationThreshold, ClassificationThreshold, DLResult)
    * 显示结果
    dev_display_dl_data (DLSample, DLResult, DLDatasetInfo, ['anomaly_result', 'anomaly_image'], [], WindowDict)
    dev_disp_text ('Press F5 (continue)', 'window', 'bottom', 'center', 'black', [], [])
    stop ()
endfor
dev_close_window_dict (WindowDict)
return ()
相关推荐
user44651179179126 分钟前
Agent 也能「过安检」:AgentScope 权限系统设计拆解
人工智能
烟小栀40 分钟前
Windows下的深度学习环境配置参考及配置教程
人工智能
tellmewhoisi1 小时前
深度学习0:数学知识:最大似然推导过程
人工智能·深度学习·概率论
oil欧哟1 小时前
从产品经理视角拆解 DeepSeek Super-agent:双层路由与异步调度架构
人工智能
张张123y1 小时前
个人助手型 Agent 的六个工程细节:Hermes 与 OpenClaw 的审批、委派、上下文与调度
网络·人工智能·开源·后端开发·ai agent
Dawson Zhu2 小时前
【模型量化⑦】W4A8与GPTQ-Int4:极限压缩与MLC-LLM部署实战
人工智能·语言模型·架构·aigc·agi
千寻技术帮2 小时前
50055_基于AI的互帮互助小程序(源码+文档+数据库脚本+部署教程)
数据库·人工智能·小程序·毕业设计·springboot·课程设计
天树星智源2 小时前
KV 剪枝的同一个误差,模型确定时只改 1.4% 的 token,不确定时改 65%:接上不确定性,AIME25 端到端快 1.27 倍
人工智能·大模型
AI英德西牛仔2 小时前
PC 用户的效率革命:腾讯元宝导出 Word 指令与“AI 导出鸭”的底层逻辑
人工智能·word·excel·deepseek·ai导出鸭
Flynn Liang3 小时前
多智能体协同不再复杂:Redis Stream 消费者组、幂等与故障恢复
数据库·人工智能·redis·缓存·ai agent·智能体