Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2025 Apr 24;20(4):e0321971.
doi: 10.1371/journal.pone.0321971. eCollection 2025.

Research on mechanical automatic food packaging defect detection model based on improved YOLOv5 algorithm

Affiliations

Research on mechanical automatic food packaging defect detection model based on improved YOLOv5 algorithm

Guanyong Liu et al. PLoS One. .

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.

PubMed Disclaimer

Conflict of interest statement

The authors have declared that no competing interests exist.

Figures

Fig 1
Fig 1. Overview of the present research.
Fig 2
Fig 2. YOLOv5 architecture diagram.
Fig 3
Fig 3. CBAM module.
Fig 4
Fig 4. FPN+ PANet network.
Fig 5
Fig 5. Network optimization diagram.
Fig 6
Fig 6. Suggested ML model in this study.
Fig 7
Fig 7. Camera.
Fig 8
Fig 8. Arduino MCU.
Fig 9
Fig 9. Load cell.
Fig 10
Fig 10. Moisture sensor.
Fig 11
Fig 11. Input image.
Fig 12
Fig 12. Training loss plot.
Fig 13
Fig 13. Detection diagram.

Similar articles

References

    1. Pham D, Chang TW. A YOLO-based real-time packaging defect detection system. Procedia Computer Science. 2023;217:886–94.
    1. 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.
    1. Zhang H, Peng L, Yu S. Detection of surface defects in ceramic tiles with complex texture. IEEE Access. 2021;9:92788–97.
    1. 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.
    1. 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

LinkOut - more resources