Research on mechanical automatic food packaging defect detection model based on improved YOLOv5 algorithm
- PMID: 40273275
- PMCID: PMC12021230
- DOI: 10.1371/journal.pone.0321971
Research on mechanical automatic food packaging defect detection model based on improved YOLOv5 algorithm
Abstract
With the rapid development of industrial automation, traditional manual detection methods are inefficient and error-prone, which cannot meet the needs of modern production for high efficiency and high precision. Therefore, it is particularly important to develop a mechanical automatic inspection system that can automatically identify food packaging defects. In this study, aiming at the limitations of existing technologies in identifying small targets and subtle defects, an enhanced YOLOv5-based model for detecting food packaging flaws is introduced. Firstly, we integrated a Convolutional Attention module (CBAM) to enhance the model's attention on crucial image features. This mechanism prioritizes significant features by weighting the feature map in channel and spatial dimensions, which improves accuracy in detecting minor defects and small objects. Secondly, feature fusion across scales is achieved with pyramid and aggregation networks, so that the model can capture defects of different sizes at the same time, which enhances the recognition ability of diverse defects in food packaging. In addition, this study also optimizes the backbone network structure of YOLOv5. By integrating the streamlined YOLOv5s model and adding an Adaptive Spatial Feature Fusion module (ASFF), the model's ability to blend features from different scales was enhanced. In this study, 7400 images with 512×512 resolutions were applied to develop the proposed model. The experimental results show that the improved model outperforms the original YOLOv5 model in terms of Accuracy (Ac), Recall (Re), and F1 score, with values of 0.96, 0.94, and 0.94, respectively, effectively improving the automation and accuracy of food packaging defect detection when compared with YOLOv5+ASFF (Ac=0.94, Re=0.95, and F1=0.94), original YOLOv5 (Ac=0.82, Re=0.85, and F1=0.88), and YOLOv5+CBAM (Ac=0.88, Re=0.9, and F1=0.89). Additionally, the present performance of an improved YOLOv5 model (CBAM+Fusion Pyramid Network (FPN)+Path Aggregation network (PANet)+ASFF) was significantly comparable to the related research works.
Copyright: © 2025 Liu et al. This is an open access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
Conflict of interest statement
The authors have declared that no competing interests exist.
Figures













Similar articles
-
Bearing defect detection based on the improved YOLOv5 algorithm.PLoS One. 2024 Oct 28;19(10):e0310007. doi: 10.1371/journal.pone.0310007. eCollection 2024. PLoS One. 2024. PMID: 39466760 Free PMC article.
-
Recognition of terminal buds of densely-planted Chinese fir seedlings using improved YOLOv5 by integrating attention mechanism.Front Plant Sci. 2022 Oct 10;13:991929. doi: 10.3389/fpls.2022.991929. eCollection 2022. Front Plant Sci. 2022. PMID: 36299793 Free PMC article.
-
Defect Detection in Steel Using a Hybrid Attention Network.Sensors (Basel). 2023 Aug 6;23(15):6982. doi: 10.3390/s23156982. Sensors (Basel). 2023. PMID: 37571764 Free PMC article.
-
ASG-YOLOv5: Improved YOLOv5 unmanned aerial vehicle remote sensing aerial images scenario for small object detection based on attention and spatial gating.PLoS One. 2024 Jun 3;19(6):e0298698. doi: 10.1371/journal.pone.0298698. eCollection 2024. PLoS One. 2024. PMID: 38829850 Free PMC article.
-
An Improved YOLOv5 Model: Application to Mixed Impurities Detection for Walnut Kernels.Foods. 2023 Feb 1;12(3):624. doi: 10.3390/foods12030624. Foods. 2023. PMID: 36766152 Free PMC article.
References
-
- Pham D, Chang TW. A YOLO-based real-time packaging defect detection system. Procedia Computer Science. 2023;217:886–94.
-
- Zhu X, Liu S, Wang X, et al.. TPH-YOLOv5: Improved YOLOv5 Based on Transformer Prediction Head for Object Detection on Drone-captured Scenarios. IEEE/CVF International Conference on Computer Vision Workshops (ICCVW). Montreal, BC, Canada, 11-17 October. 2021.
-
- Zhang H, Peng L, Yu S. Detection of surface defects in ceramic tiles with complex texture. IEEE Access. 2021;9:92788–97.
-
- Wang W, Lu X, Shen J, Crandall DJ, Luo J. Deep cosine metric learning for person re-identification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2018.
-
- Hou M, Li P, Cheng S, Yv J. CNN-based defect detection in manufacturing. Advanced Control for Applications: Engineering and Industrial Systems. 2024;6(4). doi: 10.1002/adc2.196 - DOI
MeSH terms
LinkOut - more resources
Full Text Sources