在我之前的文章中也写过很多关于生产质检相关的实践文章,一直觉得这块是比较有意思的应用方向,做出来的模型能够以一种更加直观贴切的形式展现出来,瓷砖缺陷问题检测识别也是一个比较老的话题了,今天还是想拿出来具体实践做一下,瓷砖里面的缺陷问题有很多种,名称比较专业化,这里我也不是很懂,直接先看下效果:
包含的缺陷类型如下:
光圈瑕疵
浅色块瑕疵
深色点块瑕疵
白色点瑕疵
角异常
边异常
模型这里使用的是yolov5s系列的模型,如下所示:
#Parameters
nc: 6 # 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
#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
]
#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)
]
训练数据配置文件如下:
# Dataset
path: ./dataset
train:
- images/train
val:
- images/test
test:
- images/test
# Classes
names:
0: GQXC
1: QSKXC
2: SSDXC
3: BSDXC
4: JYC
5: BYC
一共包含6种不同类型的问题缺陷。
简单看下数据集:
YOLO格式标注数据:
实例标注数据如下:
2 0.21875 0.678711 0.011719 0.009766
2 0.403809 0.63916 0.010742 0.010742
VOC格式标注数据如下:
实例标注数据如下:
<annotation>
<folder>CIZHUAN</folder>
<filename>JPEGImages/3412_4914_5733_1024_1024_0_8192_6000.jpg</filename>
<source>
<database>The CIZHUAN Database</database>
<annotation>CIZHUAN</annotation>
<image>CIZHUAN</image>
</source>
<owner>
<name>CGB</name>
</owner>
<size>
<width>1024</width>
<height>1024</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>BSDXC</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>924</xmin>
<ymin>476</ymin>
<xmax>939</xmax>
<ymax>491</ymax>
</bndbox>
</object>
<object>
<name>JYC</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>916</xmin>
<ymin>478</ymin>
<xmax>1008</xmax>
<ymax>503</ymax>
</bndbox>
</object>
</annotation>
修改train.py,如下所示:
默认执行100次epoch的迭代计算,日志输出如下所示:
结果数据目录如下所示:
训练过程loss等指标评估可视化如下:
分类识别的混淆矩阵如下:
标签数据可视化如下:
F1值和PR曲线:
batch实例:
基于界面模块实现推理可视化如下:
上传图像:
检测推理: