在缺陷检测领域中,越来越多看到AI的身影,路面缺陷、生产缺陷、PCB缺陷、瓶装酒缺陷检测等等,目标检测等模型发挥着越来越多的作用,像瓷砖缺陷和布匹缺陷这类平面类型的缺陷也不例外,最近做的项目中大多和这类型的数据有关系,今天抽时间基于YOLO来实践布匹缺陷检测。
首先看下效果:

这里我使用的是官方原生的项目,地址在这里,首页截图如下所示:

截至目前已经有超过34.1k的star量了,很出色的项目。

目前已经迭代更新到了7.0版本,全系也都支持图像分割了。
接下来看下数据集,如下所示:


这里为了清晰看下图像数据,随机可视化了几张如下所示:



全部缺陷类别如下所示:
-
'xiuyin',
'jiandong',
'houduan',
'houbaoduan',
'diaogong',
'diaowei',
'diaojing',
'huibian',
-
'jiama',
'qianjie',
'gongsha',
'zhashu',
'zhadong',
'zhasha',
'cashang',
'camao',
'cadong',
-
'mingqianxian',
'lengduan',
'maoban',
'maodong',
'maoli',
'wuzi',
'youzi',
'podong',
'pobian',
-
'cusha',
'jinsha',
'weicusha',
'xianyin',
'zhiru',
'zhixi',
'jingcusha',
'jingtiaohua',
'jiedong',
-
'quewei',
'weujing',
'erduo',
'zhengneyin',
'tiaohua',
'bianzhadong',
'bianbaiyin',
'bianquewei',
-
'bianquejing',
'bianzhenyan',
'huangzi'
模型这里使用的是轻量级的s系列的模型,yaml文件如下:
-
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
-
-
# Parameters
-
nc:
46
# number of classes
-
depth_multiple:
0.33
# model depth multiple
-
width_multiple:
0.50
# layer channel multiple
-
anchors:
-
- [
10,
13,
16,
30,
33,
23]
# P3/8
-
- [
30,
61,
62,
45,
59,
119]
# P4/16
-
- [
116,
90,
156,
198,
373,
326]
# P5/32
-
-
# YOLOv5 v6.0 backbone
-
backbone:
-
# [from, number, module, args]
-
[[-
1,
1, Conv, [
64,
6,
2,
2]],
# 0-P1/2
-
[-
1,
1, Conv, [
128,
3,
2]],
# 1-P2/4
-
[-
1,
3, C3, [
128]],
-
[-
1,
1, Conv, [
256,
3,
2]],
# 3-P3/8
-
[-
1,
6, C3, [
256]],
-
[-
1,
1, Conv, [
512,
3,
2]],
# 5-P4/16
-
[-
1,
9, C3, [
512]],
-
[-
1,
1, Conv, [
1024,
3,
2]],
# 7-P5/32
-
[-
1,
3, C3, [
1024]],
-
[-
1,
1, SPPF, [
1024,
5]],
# 9
-
]
-
-
# YOLOv5 v6.0 head
-
head:
-
[[-
1,
1, Conv, [
512,
1,
1]],
-
[-
1,
1, nn.Upsample, [
None,
2,
'nearest']],
-
[[-
1,
6],
1, Concat, [
1]],
# cat backbone P4
-
[-
1,
3, C3, [
512,
False]],
# 13
-
-
[-
1,
1, Conv, [
256,
1,
1]],
-
[-
1,
1, nn.Upsample, [
None,
2,
'nearest']],
-
[[-
1,
4],
1, Concat, [
1]],
# cat backbone P3
-
[-
1,
3, C3, [
256,
False]],
# 17 (P3/8-small)
-
-
[-
1,
1, Conv, [
256,
3,
2]],
-
[[-
1,
14],
1, Concat, [
1]],
# cat head P4
-
[-
1,
3, C3, [
512,
False]],
# 20 (P4/16-medium)
-
-
[-
1,
1, Conv, [
512,
3,
2]],
-
[[-
1,
10],
1, Concat, [
1]],
# cat head P5
-
[-
1,
3, C3, [
1024,
False]],
# 23 (P5/32-large)
-
-
[[
17,
20,
23],
1, Detect, [nc, anchors]],
# Detect(P3, P4, P5)
-
]
可以看到:这里一共有46种不同类别的缺陷种类。
启动训练,默认100次epoch迭代计算,输出如下:

数据量本身不大,最终训练的效果也没有很好,看下结果。



为了直观可视化推理,这里编写了对应的界面模块,如下:

上传图像:

推理检测

这是2023年的头第一篇博文,写的时候发现CSDN改版了,多多少少有些用不习惯吧,估计适应一段时间就好了,祝大家2023心想事成,身体健康!
转载:https://blog.csdn.net/Together_CZ/article/details/128543810
查看评论