Abstract:To address issues in existing defect detection for irregularly patterned transparent packaging bags—such as multi-scale anomalies, pattern interference, and missed detections, which are caused by low contrast and insufficient sensitivity—an improved YOLOv8s-CBW detection algorithm based on the YOLOv8s framework is proposed. In this algorithm, a coordinate attention (CA) mechanism is embedded into the C2f module of the YOLOv8s backbone network to enhance the model’s spatial feature localization and refined identification capabilities for low-contrast and minute defects. The original PANet structure is replaced with a bidirectional feature pyramid network (BiFPN) to optimize multi-scale feature fusion efficiency. Finally, a dynamic focusing WIoU-v3 loss function is introduced, replacing the traditional CIoU loss function, to improve bounding box regression accuracy for irregularly shaped defects and enhance the model’s overall generalization performance. Experimental results show that, compared to the baseline YOLOv8s model, YOLOv8s-CBW, with only a 0.11×106 increase in parameters and essentially unchanged GFLOPs, achieved an mAP@0.5 of 82.2% (an increase of 1.3%) and an mAP@0.5:0.95 of 49.3% (an increase of 7.1%) in defect detection tasks. Compared to mainstream models such as YOLOv5s and YOLOv6s, our algorithm improved mAP@0.5 by 2.3% and 10.6%, respectively, achieving superior detection accuracy while maintaining essentially the same GFLOPs. This demonstrates that the lightweight improved YOLOv8s-CBW can ensure efficiency and significantly enhance stability in detecting multi-scale defects, providing a reliable solution for automated quality inspection of packaging bags.