Please wait a minute...
浙江大学学报(工学版)  2025, Vol. 59 Issue (3): 523-534    DOI: 10.3785/j.issn.1008-973X.2025.03.010
计算机技术     
基于改进YOLOv7-tiny的铝型材表面缺陷检测方法
王浚银1,2(),文斌1,2,*(),沈艳军1,张俊1,王子豪1
1. 三峡大学 电气与新能源学院,湖北 宜昌 443002
2. 湖北省输电线路工程技术研究中心,湖北 宜昌 443002
Surface defect detection method for aluminum profiles based on improved YOLOv7-tiny
Junyin WANG1,2(),Bin WEN1,2,*(),Yanjun SHEN1,Jun ZHANG1,Zihao WANG1
1. School of Electrical and New Energy, China Three Gorges University, Yichang 443002, China
2. Hubei Provincial Engineering Technology Research Center for Power Transmission Line, Yichang 443002, China
 全文: PDF(4334 KB)   HTML
摘要:

针对铝型材表面缺陷具有种类多样、缺陷尺度差异大和小目标缺陷漏检的问题,提出改进的YOLOv7-tiny检测算法. 利用残差结构、无参注意力机制(SimAM)、激活函数(FReLU)和裁剪卷积等重构空间金字塔池化模块,捕捉更多的细节信息,加强网络多尺度学习能力. 优化检测层获取更多小目标特征和位置信息,提高网络多尺度缺陷检测能力. 引入部分卷积替换高效层聚合网络(ELAN)中的3×3卷积建立轻量化模型,减少计算和训练负担. 结合归一化 Wasserstein 距离(NWD)损失度量相似度,加速网络收敛并提升小目标缺陷检测能力. 在天池铝型材数据集上进行测试,结果表明,改进YOLOv7-tiny算法在置信度阈值为0.25时,精确度达到95.0%,召回率达到91.8%,均值平均精度mAP@0.5达到94.5%,检测速度为45帧/s. 相较于原算法,改进算法的mAP@0.5提高4.2个百分点,在脏点缺陷上的平均精度AP提高13.1个百分点;改进算法对于低分辨率图像和被干扰图像有更好的检测结果,表明其具备更好的泛化性和抗干扰能力.

关键词: 铝型材表面缺陷小目标检测SPPCSPC重构残差结构YOLOv7-tiny归一化Wasserstein距离(NWD)损失    
Abstract:

An improved YOLOv7-tiny detection algorithm was proposed to address the problems such as various types of surface defects in aluminum profiles, large differences in defect scales and missed detection of small target defects. The spatial pyramid pooling module was reconstructed by utilizing the residual structure, parameter-free attention mechanism (SimAM), activation function (FReLU) and clipping convolution to capture more detailed information and strengthen the multi-scale learning ability of the network. The optimized detection layer was used to obtain more small target features and location information, and improve the detection ability of network multi-scale defect. Partial convolution was introduced to replace the 3×3 convolution in the efficient layer aggregation network (ELAN), then the lightweight model was used to reduce the computing and training burden. Combined with the similarity of normalized Wasserstein distance (NWD) loss measurement, the network convergence was accelerated and the detection ability of small target defects was improved. Test was conducted on the Tianchi aluminium profile dataset, and the results showed that the improved YOLOv7-tiny algorithm achieved the accuracy, recall, mean average accuracy (mAP@0.5) and detection speed of 95.0%, 91.8%, 94.5% and 45 frames per second, respectively, when the confidence threshold was 0.25. Compared with the original algorithm, the mAP@0.5 of the improved algorithm was increased by 4.2 percentage point as a whole, the average accuracy (AP) of the dirty spot defect was increased by 13.1 percentage point; the detection results of the improved algorithm for low-resolution images and interfered images was better than of the original algorithm, which showed that the proposed method had better generalization and anti-interference ability.

Key words: surface defect    aluminum profile    small target detection    SPPCSPC refactoring    residual structure    YOLOv7-tiny    normalized Wasserstein distance (NWD) loss
收稿日期: 2024-01-25 出版日期: 2025-03-10
CLC:  TP 391.41  
基金资助: 国家自然科学基金资助项目(62273200,61876097);湖北省输电线路工程技术研究中心(三峡大学)开放研究基金资助项目(2022KXL03);湖北省自然科学基金联合基金资助项目(2024AFD409).
通讯作者: 文斌     E-mail: wjy2024011@126.com;wenbin@ctgu.edu.cn
作者简介: 王浚银(2000—),男,硕士生,从事图像处理研究. orcid.org/0009-0008-4037-1371. E-mail:wjy2024011@126.com
服务  
把本文推荐给朋友
加入引用管理器
E-mail Alert
作者相关文章  
王浚银
文斌
沈艳军
张俊
王子豪

引用本文:

王浚银,文斌,沈艳军,张俊,王子豪. 基于改进YOLOv7-tiny的铝型材表面缺陷检测方法[J]. 浙江大学学报(工学版), 2025, 59(3): 523-534.

Junyin WANG,Bin WEN,Yanjun SHEN,Jun ZHANG,Zihao WANG. Surface defect detection method for aluminum profiles based on improved YOLOv7-tiny. Journal of ZheJiang University (Engineering Science), 2025, 59(3): 523-534.

链接本文:

https://www.zjujournals.com/eng/CN/10.3785/j.issn.1008-973X.2025.03.010        https://www.zjujournals.com/eng/CN/Y2025/V59/I3/523

图 1  YOLOv7-tiny结构
图 2  SPPCSPC-F结构
图 3  RFLB残差结构
图 4  ReLU和FReLU原理
图 5  SimAM结构
图 6  目标宽高占比分布
图 7  改进后Head结构
图 8  ELAN-P结构
图 9  PConv和Conv原理
图 10  改进YOLOv7-tiny结构
图 11  铝型材表面缺陷
种类NoNe
不导电133532
脏点2501000
漏底242968
凹陷145560
总计7703080
表 1  铝型材缺陷数据增强
参数名数值参数名数值
Batch-size48动量因子0.937
Img-size640×640权重衰减系数0.0005
学习率0.01训练轮次300
表 2  改进模型实验参数设置
图 12  算法改进前后的mAP@0.5曲线
图 13  算法改进前后的位置损失曲线
图 14  改进前后算法检测结果对比
模型e/%2560×19201280×960768×576307×230
RFPS/(帧·s?1RFPS/(帧·s?1RFPS/(帧·s?1RFPS/(帧·s?1
本研究模型<117/204517/206917/207817/2089
1~106/86/86/85/8
>104/44/44/42/4
YOLOv7-tiny<114/205014/207714/208613/20101
1~106/86/85/84/8
>104/42/42/42/4
表 3  不同分辨率图像检测对比
模型mAP@0.5/%Q/106FLOPs/109
1)注:括号内为模块参数量.
YOLOv7-tiny+SPPCSPC90.57.27 (1.90)1)14.2
YOLOv7-tiny+SPPCSPC-S88.96.62 (1.25)13.7
YOLOv7-tiny+SPPCSPC-F92.37.73 (2.36)14.6
表 4  SPPCSPC模块对比
图 15  不同SPPCSPC模块热力图对比
组别数据增强SPPCSPC-F优化检测层ELAN-PNWDmAP@0.5/%Q/106FLOPs/109V/MB
1) 注:“√”表示用到该方法.
184.66.0213.212.3
21)90.36.0213.212.3
392.37.7314.615.7
494.07.8814.116.0
588.44.359.39.2
692.46.0213.212.3
794.110.115.120.6
893.46.158.612.7
994.56.158.612.7
表 5  改进模型消融实验结果
模型AP/%mAP@0.5/%R/%Q/106FLOPs/109V/MBFPS/(帧·s?1
不导电脏点漏底凹陷
Faster-RCNN97.472.895.881.886.962.341.30214.0315.016
YOLOv3-tiny52.869.071.881.268.788.48.6713.017.440
YOLOv5-s99.379.999.491.292.588.87.0016.014.445
改进的YOLOv5-s[28]98.872.899.589.090.088.67.2018.615.338
YOLOv7-tiny99.569.699.892.290.388.56.0213.212.350
YOLOv8-s99.478.699.593.592.889.411.1028.722.540
本研究模型99.282.799.796.294.591.86.158.612.745
表 6  不同算法指标对比实验结果
模型AP/%mAP@0.5/%
RSPaCrPSInSc
YOLOv7-tiny64.191.343.083.181.292.875.9
本研究模型64.893.347.286.181.192.877.6
表 7  NEU-DET数据集对比实验结果
1 邓运来, 张新明 铝及铝合金材料进展[J]. 中国有色金属学报, 2019, 29 (9): 2115- 2141
DENG Yunlai, ZHANG Xinming Development of aluminium and aluminium alloy[J]. The Chinese Journal of Nonferrous Metals, 2019, 29 (9): 2115- 2141
2 杨传礼, 张修庆 基于机器视觉和深度学习的材料缺陷检测应用综述[J]. 材料导报, 2022, 36 (16): 226- 234
YANG Chuanli, ZHANG Xiuqing Survey of applications of material defect detection based on machine vision and deep learning[J]. Materials Reports, 2022, 36 (16): 226- 234
doi: 10.11896/cldb.20070136
3 侯占林, 赵京 基于机器视觉的零件外形缺陷检测[J]. 组合机床与自动化加工技术, 2019, (11): 100- 104
HOU Zhanlin, ZHAO Jing Research on part contour defect detection algorithm based on machine vision[J]. Modular Machine Tool and Automatic Manufacturing Technique, 2019, (11): 100- 104
4 郑彬, 王鑫 基于机器视觉的型材表面缺陷图像处理[J]. 机械设计, 2020, 37 (Suppl.1): 95- 97
ZHENG Bin, WANG Xin Research on image processing of section steel surface defect based on machine vision[J]. Journal of Machine Design, 2020, 37 (Suppl.1): 95- 97
5 赵文宏, 周神特, 吕建标, 等. 基于机器视觉的铝型材表面瑕疵检测方法[J]. 浙江工业大学学报, 2021, 49(1): 76–81.
ZHAO Wenhong, ZHOU Shente, LV Jianbiao, et al. Method for detecting surface defects of aluminum profile based on machine vision [J]. Journal of Zhejiang University of Technology . 2021, 49(1): 76–81.
6 GIRSHICK R, DONAHUE J, DARRELL T, et al. Rich feature hierarchies for accurate object detection and semantic segmentation [C]// IEEE Conference on Computer Vision and Pattern Recognition . Columbus: IEEE, 2014: 580–587.
7 GIRSHICK R. Fast R-CNN [C]// IEEE International Conference on Computer Vision . Santiago: IEEE, 2015: 1440–1448.
8 REN S, HE K, GIRSHICK R, et al Faster R-CNN: towards real-time object detection with region proposal networks[J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2017, 39 (6): 1137- 1149
doi: 10.1109/TPAMI.2016.2577031
9 黄凤荣, 李杨, 郭兰申, 等 基于Faster R-CNN的零件表面缺陷检测算法[J]. 计算机辅助设计与图形学学报, 2020, 32 (6): 883- 893
HUANG Fengrong, LI Yang, GUO Lanshen, et al Method for detecting surface defects of engine parts based on Faster R-CNN[J]. Journal of Computer-aided Design and Computer Graphics, 2020, 32 (6): 883- 893
10 向宽, 李松松, 栾明慧, 等 基于改进Faster RCNN的铝材表面缺陷检测方法[J]. 仪器仪表学报, 2021, 42 (1): 191- 198
XIANG Kuan, LI Songsong, LUAN Minghui, et al Aluminum product surface defect detection method based on improved Faster RCNN[J]. Chinese Journal of Scientific Instrument, 2021, 42 (1): 191- 198
11 REDMON J, DIVVALA S, GIRSHICK R, et al. You Only Look Once: unified, real-time object detection [C]// IEEE Conference on Computer Vision and Pattern Recognition . Las Vegas: IEEE, 2016: 779–788.
12 SUN L S , WEI J X , DU H C , et al. MSFF: a multi-Scale feature fusion network for surface defect detection of aluminum profiles [J]. IEICE Transactions on Information and Systems , 2022, 105(9): 1652–1655.
13 杨畅畅, 李慧玲, 潘广通, 等 基于改进YOLOv4算法的铝型材表面缺陷检测[J]. 组合机床与自动化加工技术, 2022, (11): 66- 69
YANG Changchang, LI Huiling, PAN Guangtong, et al Surface defect detection of aluminum profiles based on improved YOLOv4 Algorithm[J]. Modular Machine Tool and Automatic Manufacturing Technique, 2022, (11): 66- 69
14 张建国, 高飞, 莘明星, 等 基于改进YOLOv5s的铝型材表面弱缺陷识别方法[J]. 船舶工程, 2023, 45 (6): 161- 166
ZHANG Jianguo, GAO Fei, XIN Mingxing, et al Weak defect identification method on profile surface based on image enhancement and YOLOv5s[J]. Ship Engineering, 2023, 45 (6): 161- 166
15 曹义亲, 周一纬, 徐露 基于E-YOLOX的实时金属表面缺陷检测算法[J]. 图学学报, 2023, 44 (4): 677- 690
CAO Yiqin, ZHOU Yiwei, XU Lu, et al A real-time metallic surface defect detection algorithm based on E-YOLOX[J]. Journal of Graphics, 2023, 44 (4): 677- 690
16 LV Z, LI Y, QIAN S Real-time and accurate defect segmentation of aluminum strip surface via a lightweight network[J]. Journal of Real-Time Image Processing, 2023, 20 (2): 37
17 KANG X J, LI J F AYOLOv7-tiny: towards efficient defect detection in solid color circular weft fabric[J]. Textile Research Journal, 2024, 94 (1/2): 225- 245
doi: 10.1177/00405175231205898
18 KONG F Y, LI M X, LIU S W, et al. Residual local feature network for efficient super-resolution [C]// Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition . New Orleans: IEEE , 2022: 766–776.
19 MA N N, ZHANG X Y, SUN J. Funnel activation for visual recognition [C]// Computer Vision-ECCV 2020: 16th European Conference . Glasgow: Springer, 2020: 351–368.
20 NING T L, PAN S, ZHOU J. YOLOv7-SIMAM: an effective method for SAR ship detection [C]// 4th International Conference on Neural Networks, Information and Communication . Guangzhou: IEEE, 2024: 754–758.
21 CHEN J R, KAO S H, HE H, et al. Run, don’t walk: chasing higher FLOPS for faster neural networks [C]// Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition . Vancouver: IEEE, 2023: 12021–12031.
22 WANG J W, XU C, YANG W, et al. A normalized gaussian wasserstein distance for tiny object detection [EB/OL]. (2021−10−26) [2024−01−01]. https://arxiv.org/abs/2110.13389.
23 沈晓海, 栗泽昊, 李敏, 等 基于多任务深度学习的铝材表面缺陷检测[J]. 激光与光电子学进展, 2020, 57 (10): 10
SHEN Xiaohai, LI Zehao, LI Min, et al Aluminum surface-defect detection based on multi-Task deep learning[J]. Laser and Optoelectronics Progress, 2020, 57 (10): 10
24 邓丁山, 王昊楠, 赵军杰, 等. 基于改进YOLOv7的风力发电机表面缺陷检测算法[EB/OL]. [2024−01−01]. https://doi.org/10.13196/j.cims.2023.0410.
25 陈乐, 周永霞, 祖佳贞 改进YOLOX-S的偏光片表面缺陷检测算法[J]. 计算机工程与应用, 2024, 60 (2): 295- 303
CHEN Le, ZHOU Yongxia, ZU Jianzhen Surface defect detection of polarizer based on improved YOLOX-S algorithm[J]. Computer Engineering and Applications, 2024, 60 (2): 295- 303
doi: 10.3778/j.issn.1002-8331.2209-0375
26 齐向明, 柴蕊, 高一萌, 等 重构SPPCSPC与优化下采样的小目标检测算法[J]. 计算机工程与应用, 2023, 59 (20): 158- 166
QI Xiangming, CHAI Rui, GAO Yimeng, et al Algorithm of reconstructed SPPCSPC and optimized downsampling for small object detection[J]. Computer Engineering and Applications, 2023, 59 (20): 158- 166
doi: 10.3778/j.issn.1002-8331.2305-0004
27 SELVARAJU R R, COGSWELL M, DAS A, et al Grad-CAM: visual explanations from deep networks via gradient-based localization[J]. International Journal of Computer Vision, 2020, 128 (2): 336- 359
doi: 10.1007/s11263-019-01228-7
28 席凌飞, 伊力哈木·亚尔买买提, 刘雅洁, 等 基于改进YOLOv5的铝型材表面缺陷检测方法[J]. 广西师范大学学报: 自然科学版, 2024, 42 (1): 111- 119
XI Lingfei, YAERMAIMAITI Yilihamu, LIU Yajie et al. Surface defect detection method for aluminum profile based on improved YOLOv5[J]. Journal of Guangxi Normal University: Natural Science Edition, 2024, 42 (1): 111- 119
[1] 唐善成,逯建辉,张莹,金子成,赵安新. 修复缺陷嫌疑区域的无监督磁瓦表面缺陷检测[J]. 浙江大学学报(工学版), 2024, 58(4): 718-728.
[2] 张会娟,李坤鹏,姬淼鑫,刘振江,刘建娟,张弛. 基于空间相关性增强的无人机检测算法[J]. 浙江大学学报(工学版), 2024, 58(3): 468-479.
[3] 宋耀莲,王粲,李大焱,刘欣怡. 基于改进YOLOv5s的无人机小目标检测算法[J]. 浙江大学学报(工学版), 2024, 58(12): 2417-2426.
[4] 莫恒辉,魏霖静. 基于改进YOLOv7的复杂环境下苹果目标检测[J]. 浙江大学学报(工学版), 2024, 58(12): 2447-2458.
[5] 杜丁健,高遵海,陈倬. 基于改进YOLOv5的枸杞虫害检测[J]. 浙江大学学报(工学版), 2024, 58(10): 1992-2000.
[6] 韩俊,袁小平,王准,陈烨. 基于YOLOv5s的无人机密集小目标检测算法[J]. 浙江大学学报(工学版), 2023, 57(6): 1224-1233.
[7] 刘坤,杨晓松. 基于无监督域适应的跨场景带钢表面缺陷识别[J]. 浙江大学学报(工学版), 2023, 57(3): 477-485.
[8] 兰欢,余建波. 基于深度学习三维成型的钢板表面缺陷检测[J]. 浙江大学学报(工学版), 2023, 57(3): 466-476.
[9] 曾耀,高法钦. 基于改进YOLOv5的电子元件表面缺陷检测算法[J]. 浙江大学学报(工学版), 2023, 57(3): 455-465.
[10] 袁天乐,袁巨龙,朱勇建,郑翰辰. 基于改进YOLOv5的推力球轴承表面缺陷检测算法[J]. 浙江大学学报(工学版), 2022, 56(12): 2349-2357.
[11] 徐利锋,黄海帆,丁维龙,范玉雷. 基于改进DenseNet的水果小目标检测[J]. 浙江大学学报(工学版), 2021, 55(2): 377-385.
[12] 冯毅雄,李康杰,高一聪,郑浩,谭建荣. 基于特征与形貌重构的轴件表面缺陷检测方法[J]. 浙江大学学报(工学版), 2020, 54(3): 427-434.
[13] 叶刚,李毅波,马逐曦,成杰. 基于ViBe的端到端铝带表面缺陷检测识别方法[J]. 浙江大学学报(工学版), 2020, 54(10): 1906-1914.
[14] 林志洁,罗壮,赵磊,鲁东明. 特征金字塔多尺度全卷积目标检测算法[J]. 浙江大学学报(工学版), 2019, 53(3): 533-540.
[15] 刘半藤, 骆旭伟, 黄平捷, 侯迪波, 张光新. 导电结构亚表面缺陷电涡流/超声复合检测方法[J]. 浙江大学学报(工学版), 2017, 51(4): 682-690.