Glass Defect Detection Methods
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 山东瑞翼德科技股份有限公司
- Filing Date
- 2026-02-04
- Publication Date
- 2026-05-26
Smart Images

Figure CN122089672A_ABST
Abstract
Description
Technical Field
[0002] This invention relates to the field of product defect detection technology, specifically a method for detecting glass defects. Background Technology
[0004] With the continuous improvement of industrial standards, the industry has increasingly higher requirements for the quality of glass and other products. Strict quality inspection of glass before it leaves the factory or is used has become a key link in ensuring product quality. However, the surface inspection methods commonly used in the industry at present still have insufficient automated inspection capabilities. These devices usually take images of the glass surface with a camera and then use relatively simple algorithms (such as the fixed threshold method) to identify defects. That is, by setting one or more grayscale thresholds, areas in the image with grayscale values exceeding the threshold are judged as defects. This method can capture large defects with obvious contrast, but it is difficult to identify small defects with low contrast. As a result, the screening of such defects still needs to rely on manual judgment, and stable and reliable fully automated inspection cannot be achieved. This results in the quality and efficiency of inspection failing to meet the high standards required by the industry.
[0005] Therefore, improving existing glass defect detection methods, enhancing the level of automation and reliability of detection, and improving the quality of glass inspection are of urgent and important practical significance. Summary of the Invention
[0007] The purpose of this invention is to overcome the shortcomings of the prior art and provide a glass defect detection method that achieves automated detection, improves detection efficiency and quality.
[0008] The technical solution adopted by this invention to solve its technical problem is:
[0009] A method for detecting glass defects, characterized in that: Step S1: The image acquisition platform acquires images and inputs the acquired images into the image preprocessing module; Step S2: The image preprocessing module preprocesses the acquired images; Step S3: Input the preprocessed image into the defect detection model to perform defect detection and obtain defect information; Step S4: Upload the obtained defect information to the automatic sorting module, and the automatic sorting module sorts the glass according to the defect information; It achieves fully automated, high-precision, and real-time defect detection, avoiding the subjectivity of traditional manual inspection, improving inspection efficiency and quality, and reducing labor costs.
[0010] The defect detection model described in this invention is based on the YOLOv8 model and incorporates an efficient multi-scale attention (EMA) module, a coordinate attention (CA) module, a soft nonmaximum suppression algorithm (Soft-NMS), and a focused efficient cross-union ratio loss function (Focal-EIoU Loss) to construct an improved YOLOv8-ECSFe defect detection model. The image to be detected is input into the YOLOv8-ECSFe defect detection model for defect detection.
[0011] The defect detection model construction method described in this invention is as follows: Historical glass surface defect images labeled with glass defect categories are used as the training image set. The defect detection model is trained using the Focal-EIoU Loss function on the training image set. The model parameters are optimized by minimizing the Focal-EIoU Loss function, so that the improved YOLOv8 defect detection model gradually converges, and the trained defect detection model is obtained. The Focus-EioULoss (Focal-EioULoss) loss function is defined as follows: ; Where N is the number of training samples; i represents the i-th sample; Modulation factor; Based on the distance from the center point, the difference between width and height, and Combined composition; ; in, The distance is Euclidean. The center point of the prediction box; The center point of the true bounding box; w c h is the width of the minimum bounding rectangle that covers both the predicted and ground truth bounding boxes. c The height of the minimum bounding rectangle that covers both the predicted and ground truth bounding boxes; The width of the prediction box; The width of the actual bounding box; The height of the predicted bounding box; The actual height of the bounding box; This is the intersection-union ratio (IU) between the predicted bounding box and the ground truth bounding box.
[0012] In this invention, the glass image preprocessed in step S2 is input into a pre-trained defect detection model. The defect detection model outputs multiple initial prediction boxes, each of which includes its position coordinates (x, y, w, h) and defect category confidence s. Where x is the x-coordinate of the center point b of the prediction box; y is the y-coordinate of the center point b of the prediction box; w is the width of the prediction box; and h is the height of the prediction box. For the multiple predicted boxes output by the defect detection model, the Soft Non-Maximum Suppression (Soft-NMS) algorithm is used for filtering to reduce the redundancy of adjacent predicted boxes and reduce the problem of missed or false detection of defects. Sort all initial prediction boxes from high to low according to the defect category confidence s; Select the highest-scoring frame from the list that has not yet been processed as the baseline frame. ; calculate and each subsequent prediction box Intersection over Union (IoU); ; when At that time, the algorithm is based on and The degree of overlap is reduced. confidence level The update rules are as follows: ; in, Represents the prediction box With prediction box The intersection and union ratio; , There are two prediction boxes; For prediction boxes Confidence level of defect category; For prediction boxes The confidence level of the defect category, and It is a natural constant; The smoothing coefficient for nonmaximum suppression; The threshold for intersection-union ratio; After all predicted boxes have been processed, all predicted boxes with a confidence level s of all defect categories below a set threshold are filtered out, and the remaining boxes are the final defect detection results.
[0013] Step S3 of this invention is a defect determination step. This step processes the high-confidence defect results output by the model inference. The defect results include defect category and defect location. The defect category includes stains, scratches, bubbles, impurities, and cracks. In this step, the size information of the defect is first calculated based on the bounding box coordinates of the defect result (for linear defects such as scratches and cracks, the defect length is calculated; for stains, bubbles, and impurities, the defect area is calculated). Subsequently, based on the defect category and the calculated dimensional information, it is determined whether the glass has unacceptable defects. The determination rules are as follows: When the detected defect category is scratch or crack, if its calculated length is greater than L millimeters, it is determined that the glass has an unacceptable defect. When the detected defect category is stain, bubble, or impurity, if its calculated area is greater than S square millimeters, it is determined that the glass has an unacceptable defect.
[0014] The defect detection model of this invention includes a backbone network, a neck network, and a detection head. The backbone network, from input to output, includes, in sequence, a first-layer CBS-EMA module, a second-layer CBS-EMA module, a first C2f feature fusion module, a third-layer CBS-EMA module, a second C2f feature fusion module, a fourth-layer CBS-EMA module, a third C2f feature fusion module, a fifth-layer CBS-EMA module, a fourth C2f feature fusion module, a coordinate attention (CA) module, and a spatial pyramid fast pooling (SPPF) module. The neck network includes a first upsampling module, a second upsampling module, a first channel stitching module, a second channel stitching module, a third channel stitching module, a fourth channel stitching module, a first neck C2f feature fusion module, a second neck C2f feature fusion module, a third neck C2f feature fusion module, a fourth neck C2f feature fusion module, a first neck CBS module, and a second neck CBS module. The connection relationships between the modules are as follows: The output of the SPPF module of the backbone network is connected to the input of the first upsampling module; The output of the first upsampling module and the output of the third C2f feature fusion module of the backbone network are spliced by the first channel splicing module and then input into the first neck C2f feature fusion module for feature fusion. The output of the first neck C2f feature fusion module is connected to the input of the second upsampling module; The output of the second upsampling module and the output of the second C2f feature fusion module of the backbone network are concatenated by the second channel splicing module and then input into the second neck C2f feature fusion module for feature fusion. The output of the second neck C2f feature fusion module is connected to the first neck CBS module; The output of the first neck CBS module and the output of the first neck C2f feature fusion module are spliced by the third channel splicing module and then input to the third neck C2f feature fusion module for feature fusion. The output of the third neck C2f feature fusion module is connected to the second neck CBS module; The output of the second neck CBS module and the output of the backbone network SPPF module are spliced by the fourth channel splicing module and then input to the fourth neck C2f feature fusion module for feature fusion. The detection head includes a small target detection head, a medium target detection head, and a large target detection head; the input of the small target detection head is connected to the output of the second neck C2f feature fusion module; The input of the target detection head is connected to the output of the third neck C2f feature fusion module; The input of the large target detection head is connected to the output of the fourth neck C2f feature fusion module; The backbone network is responsible for feature extraction. It receives the input image and transforms it into a series of feature maps that characterize the image content through a series of hierarchical convolutional calculations. The backbone network introduces the CBS-EMA module (i.e., embedding the efficient multi-scale attention module EMA within the standard Conv-BatchNorm-SiLU module). This module utilizes the multi-scale feature fusion and cross-channel interaction capabilities of EMA to enhance the model's attention to defects such as tiny scratches and bubbles on the glass surface from the initial stage of feature extraction. While maintaining computational efficiency, it effectively enhances the model's ability to perceive defects of different sizes on the glass surface, enabling the system to simultaneously focus on large-scale background features and tiny defect features; and simultaneously effectively Suppressing background noise interference such as glass reflection significantly improves the ability to distinguish defect features from background features; the backbone network introduces a CA attention module. The CA attention mechanism captures spatial position information in the horizontal and vertical directions respectively, accurately models the spatial distribution characteristics of defects on the glass surface, enabling the network to accurately identify the boundary and shape features of defects; the synergistic effect of CBS-EMA and CA achieves dual fine-grained feature recalibration of channel dimension and spatial coordinates, enabling the network to adaptively enhance the feature response related to glass defects while suppressing irrelevant background noise, significantly improving the ability to identify glass surface defects (such as scratches, bubbles, impurities, etc.), and is particularly suitable for high-precision, high-speed glass surface defect detection scenarios; The neck network is responsible for multi-scale feature fusion, integrating feature maps of different scales output by the backbone network to generate enhanced feature maps with richer information and more optimized structure, ensuring high-quality feature representation for defects of different sizes. The detection head is responsible for the final prediction. Based on the multi-scale feature maps generated by the neck network, the detection head performs specific logical operations to accurately regress the bounding box position of the defect and determine the specific defect category, completing the end-to-end detection process.
[0015] The efficient multi-scale attention (EMA) module described in this invention applies to the input feature map. The attention weight α is calculated as follows: ; Where R represents the set of real numbers, C is the number of channels in the feature map, H is the height of the feature map, and W is the width of the feature map; GAP represents global average pooling. , For learnable weights, Activated for Sigmoid, compression ratio is .
[0016] The specific processing steps of the coordinate attention (CA) module described in this invention include: Coordinate information embedding: For a given input feature map X (of dimension C) H W), a one-dimensional global average pooling operation is performed along the horizontal direction (X-axis) using a pooling kernel of size (H, 1); One-dimensional global average pooling is performed along the vertical direction (Y-axis) using a pooling kernel of size (1, W). The horizontal pooling operation aggregates features in the vertical direction; for the c-th channel, the output at width w... The calculation formula is: ; Where j is the coordinate index in the height direction, i.e., the position subscript of the height dimension of the feature map; H is the height of the feature map; yes The feature value at the corresponding position; The vertical pooling operation aggregates features in the width direction; for the c-th channel, the output at height h... The calculation formula is: ; Where i is the coordinate index in the width direction, i.e., the position subscript of the width dimension of the feature map; W is the width of the feature map; The feature value at the corresponding position; Through the above operations, a pair of direction-aware feature vectors were obtained respectively; Coordinate attention generation: The vertical and horizontal feature vectors obtained in the above steps are concatenated to form an intermediate feature map; Take advantage of 1 The first convolutional layer performs channel dimensionality reduction on the intermediate feature map by a reduction ratio of r, and generates intermediate encoded features containing spatial information through a non-linear activation function (such as the h-swish function). ; intermediate encoded features Split into two independent tensors along the spatial dimension and Using two independent Convolutional layers will and The number of channels is restored to the original number of channels. Finally, after processing with the Sigmoid activation function, attention weights in the vertical direction are generated. Attention weights in the horizontal direction The calculation formula is as follows: ; in, This indicates a splicing operation performed along a spatial dimension; yes Convolution transform function; It is an intermediate feature mapping; It is a non-linear activation function (e.g., the h-swish function); Feature reweighting: Vertical attention weights And horizontal attention weights Compared with the original input feature map Element-wise product operations are performed to obtain the final output feature map. The calculation formula is as follows: ; in, Represents the original input feature map In the Each channel, spatial coordinates Eigenvalues at; Indicates the first Each channel, corresponding height Vertical attention weights at the location, Indicates the first Each channel, corresponding width Horizontal attention weights at the location; The introduction of the coordinate attention (CA) module is used to enhance the expressive power of the feature map for key regions and suppress background noise, while preserving the spatial location information of the target.
[0017] In the backbone network described in this invention, the first, second, third, fourth, and fifth CBS-EMA modules have the same structure, each consisting of a feature processing unit composed of a convolutional layer, a batch normalization layer, an activation function layer, and an EMA module connected sequentially. Glass surface defects (such as micro-scratches and microbubbles) typically have low contrast and are easily confused with the reflective or translucent background of the glass itself. By integrating an efficient multi-scale attention (EMA) module into the CBS module of the backbone network, attention weighting begins at the very beginning of feature extraction (the lowest feature stage). This allows for the priority preservation and enhancement of weak but crucial defect texture information before downsampling, while simultaneously suppressing noise such as bright background reflections at the source. This achieves feature correction from the source, avoiding... The diffusion of minute defect information in deep networks; the EMA attention module, through grouped convolution and cross-dimensional information interaction, can efficiently fuse multi-scale contextual information and deeply integrate it into the CBS module. This allows the backbone network to dynamically adjust the weights of the convolution output in real time by combining this multi-scale contextual information while extracting local features through convolution kernels. This deep coupling mechanism significantly improves the model's ability to represent glass surface defects with varying shapes and sizes. By improving the basic CBS module to a CBS-EMA module, attention enhancement and feature extraction capabilities are enhanced across the entire network layer without significantly increasing network depth and computational complexity (FLOPs). This ensures the coherence of feature flow during transmission, enabling the model to maintain its original inference speed advantage while significantly improving the recall and localization accuracy of minute defects on transparent material surfaces. The first and second upsampling modules of the neck network have the same structure; they are used to perform upsampling operations on the input feature map to achieve scale matching. The large target detection head, medium target detection head, and small target detection head all adopt a decoupled architecture, with each detection head including a regression branch and a classification branch. The regression branch is used to predict the precise location of the defect and includes two consecutive convolutional layers and a 1×1 convolutional output layer; the branch outputs the predicted bounding box information corresponding to each feature map location; The classification branch is used to predict the category probability of the defect, and includes two consecutive convolutional layers and a 1×1 convolutional output layer; the output dimension of this branch is the number of categories of the target, which is used to determine the specific category of the defect. The convolutional layer structures of the regression branch and the classification branch are set independently to achieve decoupling of the localization task and the classification task, thereby reducing gradient interference between tasks. Furthermore, the detection head is based on an anchor-free design, directly predicting the target's center offset and size information relative to each feature map location; it does not rely on preset anchor boxes, simplifying the training process and improving model flexibility.
[0018] The image acquisition platform in step S1 of this invention includes a shooting module and a light source module. The shooting module includes a camera, and the light source module includes a coaxial light source. The coaxial light source is positioned directly below the camera and is coaxial with the camera's optical path. The coaxial light source works in conjunction with the camera to further highlight defects on the glass surface. The image preprocessing method in step S2 is as follows: Step S2.1: Perform dark channel dehazing on the image; Step S2.2: Perform adaptive histogram equalization. Step S2.3: Perform Gaussian sharpening; To highlight the characteristics of glass defects; The image acquisition platform, image preprocessing module, defect detection model, and automatic sorting module can be integrated into a single system and interact through internal data flow; or they can be independent entities that work collaboratively through communication protocols.
[0019] The beneficial effects of this invention are: it achieves fully automated, high-precision, and real-time defect detection, avoids the subjectivity of traditional manual inspection, improves inspection efficiency and quality, and reduces labor costs. Attached Figure Description
[0021] Figure 1 This is a schematic diagram of a glass testing structure.
[0022] Figure 2 This is a schematic diagram of a defect detection model.
[0023] Figure 3 This is a schematic diagram of the CBS-EMA module.
[0024] Figure reference numerals: First layer CBS-EMA module-1011, Second layer CBS-EMA module-1012, Third layer CBS-EMA module-1013, Fourth layer CBS-EMA module-1014, Fifth layer CBS-EMA module-1015; First C2f feature fusion module-1021, second C2f feature fusion module-1022, third C2f feature fusion module-1023, fourth C2f feature fusion module-1024; Coordinate Attention (CA) module - 103; Space Pyramid Fast Pooling (SPPF) module - 104; First upsampling module-2011, Second upsampling module-2012; First channel splicing module - 2021, second channel splicing module - 2022, third channel splicing module - 2023, fourth channel splicing module - 2024; First neck C2f feature fusion module-2031, second neck C2f feature fusion module-2032, third neck C2f feature fusion module-2033, fourth neck C2f feature fusion module-2034; First neck CBS module-2041, second neck CBS module-2042; Conveyor Belt-3; Glass-4; Shooting Module -5; Light source module -6; Robotic Arm-7; Defect Detection Model-8; Central control computer-9. Detailed Implementation
[0026] The present invention will now be described in conjunction with the accompanying drawings and embodiments.
[0027] A method for detecting glass defects, characterized in that: Step S1: The image acquisition platform acquires images and inputs the acquired images into the image preprocessing module; As attached Figure 1 The image acquisition platform includes a shooting module 5 and a light source module 6. In this embodiment, the shooting module 5 includes a camera, and the light source module 6 includes a coaxial light source. The coaxial light source is located directly below the camera and is coaxial with the camera's optical path. The coaxial light source works with the camera to further highlight defects on the glass surface. In this embodiment, the imaging module uses a camera, but it is not limited to this. Depending on the different detection scenarios and accuracy requirements, image sensors such as infrared thermal imagers can also be used. The light source module is not limited to using a coaxial light source. Backlights, strobe light sources, etc. can also be selected for different types of glass. In this step, conveyor belt 3 transports glass 4, and the camera captures images of the glass.
[0028] Step S2: The image preprocessing module preprocesses the acquired images; Step S2.1: Perform dark channel dehazing on the image; Step S2.2: Perform adaptive histogram equalization. Step S2.3: Perform Gaussian sharpening; The above steps are used to normalize the size of the acquired images and perform data augmentation to highlight the characteristics of glass defects.
[0029] Step S3: Input the preprocessed image into the defect detection model 8 for defect detection to obtain defect information; the defect detection model is based on the YOLOv8 model framework, incorporating an efficient multi-scale attention (EMA) module, a coordinate attention (CA) module, a soft non-maximum suppression algorithm (Soft-NMS), and a focused efficient cross-union ratio loss function (Focal-EioU Loss) to construct an improved YOLOv8-ECSFe defect detection model. The image to be detected is input into the YOLOv8-ECSFe defect detection model for defect detection; in the YOLOv8-ECSFe defect detection model, E represents EMA, C represents CA, S represents Soft-NMS, and Fe represents Focal-EioU Loss;
[0030] The defect detection model construction method is as follows: Historical glass surface defect images labeled with glass defect categories are used as the training image set. The defect detection model is trained using the Focal-EIoU Loss function on the training image set. The model parameters are optimized by minimizing the Focal-EIoU Loss function, so that the improved YOLOv8 defect detection model gradually converges, and the trained defect detection model is obtained. The Focal-EIoU Loss function is defined as follows: ; Where N is the number of training samples; i represents the i-th sample; Modulation factor; Based on the distance from the center point, the difference between width and height, and Combined composition; ; in, The distance is Euclidean. The center point of the prediction box; The center point of the true bounding box; w c h is the width of the minimum bounding rectangle that covers both the predicted and ground truth bounding boxes. c The height of the minimum bounding rectangle that covers both the predicted and ground truth bounding boxes; The width of the prediction box; The width of the actual bounding box; The height of the predicted bounding box; The actual height of the bounding box; This is the intersection-union ratio (IU) between the predicted bounding box and the ground truth bounding box. In this embodiment, during the training phase, a training set consisting of historical glass surface defect images is used. The input image resolution is uniformly 640*640 pixels. The training process consists of 300 rounds, using the Focal-EIoU Loss function as the optimization objective, and the initial learning rate is set to 3×10. −4 And dynamically adjust the learning rate in conjunction with the cosine annealing strategy; The model inference method is as follows: The glass 4 image after preprocessing in step S2 is input into the trained defect detection model 8. The defect detection model 8 outputs multiple initial prediction boxes, each of which includes its position coordinates (x, y, w, h) and defect category confidence s. Where x is the x-coordinate of the center point b of the prediction box; y is the y-coordinate of the center point b of the prediction box; w is the width of the prediction box; and h is the height of the prediction box. For the multiple predicted boxes output by defect detection model 8, the soft nonmaximum suppression (Soft-NMS) algorithm is used for filtering to reduce the redundancy of adjacent predicted boxes and reduce the problem of missed or false detection of defects. Sort all initial prediction boxes from high to low according to the defect category confidence s; Select the highest-scoring frame from the list that has not yet been processed as the baseline frame. ; calculate and each subsequent prediction box Intersection over Union (IoU); ; when At that time, the algorithm is based on and The degree of overlap is reduced. confidence level The update rules are as follows: ; in, Represents the prediction box With prediction box The intersection and union ratio; , There are two prediction boxes; For prediction boxes Confidence level of defect category; For prediction boxes The confidence level of the defect category, and It is a natural constant; The smoothing coefficient for nonmaximum suppression; The threshold for intersection-union ratio; After all predicted boxes are processed, all predicted boxes with a defect category confidence s lower than a set threshold (set to 0.35 in this embodiment) are filtered out, and the remaining boxes are the final defect detection results. The high-confidence defect results output by the model inference are processed. The defect results include defect category and defect location. The defect category includes stains, scratches, bubbles, impurities, and cracks. In this step, the size information of the defect is first calculated based on the bounding box coordinates of the defect result (for linear defects such as scratches and cracks, the defect length is calculated; for stains, bubbles, and impurities, the defect area is calculated). Subsequently, based on the defect category and the calculated dimensional information, it is determined whether the glass has unacceptable defects. The determination rules are as follows: When the detected defect category is scratch or crack, if its calculated length is greater than L mm (set to 0.5 mm in this embodiment), it is determined that the glass has an unacceptable defect. When the detected defect category is stain, bubble, or impurity, if its calculated area is greater than S square millimeters (set to 0.01 square millimeters in this embodiment), it is determined that the glass has an unacceptable defect.
[0031] Step S4: Upload the obtained defect information to the automatic sorting module, and the automatic sorting module sorts the glass according to the defect information; The automatic sorting module includes a robotic arm 7. Based on the glass defect detection results, the controller controls the robotic arm 7 to sort the glass.
[0032] Through the above steps, fully automated, high-precision, and real-time defect detection is achieved, avoiding the subjectivity of traditional manual inspection, improving inspection efficiency and quality, and reducing labor costs.
[0033] The system's actuators (conveyor belt 3 and robotic arm 7) are driven and controlled by a controller. In this embodiment, the controller is a PLC controller. The central control computer 9, as the upper-level management unit, will issue sorting instructions to the PLC controller after receiving the glass defect detection results. The PLC controls the robotic arm to complete the sorting action of the unqualified glass.
[0034] As attached Figure 2As shown, the defect detection model 8 in this embodiment includes a backbone network, a neck network, and a detection head. The backbone network, from input to output, includes a first-layer CBS-EMA module 1011, a second-layer CBS-EMA module 1012, a first C2f feature fusion module 1021, a third-layer CBS-EMA module 1013, a second C2f feature fusion module 1022, a fourth-layer CBS-EMA module 1014, a third C2f feature fusion module 1023, a fifth-layer CBS-EMA module 1015, a fourth C2f feature fusion module 1024, a coordinate attention (CA) module 103, and a spatial pyramid fast pooling (SPPF) module 104. The neck network includes a first upsampling module 2011, a second upsampling module 2012, a first channel stitching module 2021, a second channel stitching module 2022, a third channel stitching module 2023, a fourth channel stitching module 2024, a first neck C2f feature fusion module 2031, a second neck C2f feature fusion module 2032, a third neck C2f feature fusion module 2033, a fourth neck C2f feature fusion module 2034, a first neck CBS module 2041, and a second neck CBS module 2042; The connection relationships between the modules are as follows: The output of the SPPF module 104 of the backbone network is connected to the input of the first upsampling module 2011; The output of the first upsampling module 2011 and the output of the third C2f feature fusion module 1023 of the backbone network are spliced by the first channel splicing module 2021 and then input to the first neck C2f feature fusion module 2031 for feature fusion. The output of the first neck C2f feature fusion module 2031 is connected to the input of the second upsampling module 2012; The output of the second upsampling module 2012 and the output of the second C2f feature fusion module 1022 of the backbone network are spliced by the second channel splicing module 2022 and then input to the second neck C2f feature fusion module 2032 for feature fusion. The output of the second neck C2f feature fusion module 2032 is connected to the first neck CBS module 2041; The output of the first neck CBS module 2041 and the output of the first neck C2f feature fusion module 2031 are spliced by the third channel splicing module 2023 and then input to the third neck C2f feature fusion module 2033 for feature fusion. The output of the third neck C2f feature fusion module 2033 is connected to the second neck CBS module 2042; The output of the second neck CBS module 2042 and the output of the backbone network SPPF module 104 are spliced by the fourth channel splicing module 2024 and then input to the fourth neck C2f feature fusion module 2034 for feature fusion. The detection head includes a small target detection head, a medium target detection head, and a large target detection head; the input of the small target detection head is connected to the output of the second neck C2f feature fusion module 2032; The input of the target detection head is connected to the output of the third neck C2f feature fusion module 2033; The input of the large target detection head is connected to the output of the fourth neck C2f feature fusion module 2034; The backbone network incorporates a CBS-EMA module (i.e., an efficient multi-scale attention (EMA) module embedded within the standard Conv-BatchNorm-SiLU module). This module leverages the multi-scale feature fusion and cross-channel interaction capabilities of EMA to enhance the model's attention to defects such as minute scratches and bubbles on the glass surface from the initial stage of feature extraction. While maintaining computational efficiency, it effectively enhances the model's ability to perceive defects of different sizes on the glass surface, enabling the system to simultaneously focus on both large-scale background features and minute defect features. Simultaneously, it effectively suppresses background noise interference such as glass reflection, significantly improving the ability to distinguish between defect features and background features. The backbone network incorporates a coordinate attention (CA) module. The CA attention mechanism captures spatial position information in the horizontal and vertical directions respectively, accurately modeling the spatial distribution characteristics of defects on the glass surface, enabling the network to accurately identify the boundary and shape features of defects. The synergistic effect of CBS-EMA and CA achieves dual fine-grained feature recalibration of channel dimension and spatial coordinates, enabling the network to adaptively enhance feature responses related to glass defects while suppressing irrelevant background noise, significantly improving the ability to identify glass surface defects (such as scratches, bubbles, impurities, etc.), making it particularly suitable for high-precision, high-speed glass surface defect detection scenarios. The neck network is responsible for multi-scale feature fusion, integrating feature maps of different scales output by the backbone network to generate enhanced feature maps with richer information and more optimized structure, ensuring high-quality feature representation for defects of different sizes. The detection head is responsible for the final prediction. Based on the multi-scale feature maps generated by the neck network, the detection head performs specific logical operations to accurately regress the bounding box position of the defect and determine the specific defect category, completing the end-to-end detection process.
[0035] The EMA module processes the input feature map. The attention weight α is calculated as follows: ; Where R represents the set of real numbers, C is the number of channels in the feature map, H is the height of the feature map, and W is the width of the feature map; GAP represents global average pooling. , For learnable weights, Activated for Sigmoid, compression ratio is .
[0036] In the backbone network, the first layer CBS-EMA module 1011, the second layer CBS-EMA module 1012, the third layer CBS-EMA module 1013, the fourth layer CBS-EMA module 1014, and the fifth layer CBS-EMA module 1015 have the same structure. They are all feature processing units composed of convolutional layers, batch normalization layers, activation function layers, and EMA modules connected in sequence. Glass surface defects (such as micro-scratches and micro-bubbles) usually have low contrast and are easily confused with the reflective or translucent background of the glass itself. By integrating the efficient multi-scale attention module (EMA) into the CBS module of the backbone network, attention weighting begins at the very beginning of feature extraction (the lowest feature stage). This allows for the priority preservation and enhancement of those weak but crucial defect texture information before downsampling, while suppressing noise such as bright background reflections at the source, thus achieving a solution from the source. Feature correction avoids the diffusion of minute defect information in deep networks; the EMA attention module can efficiently fuse multi-scale contextual information through grouped convolution and cross-dimensional information interaction, deeply integrating it into the CBS module. This allows the backbone network to dynamically adjust the weights of the convolution output in real time by combining this multi-scale contextual information while extracting local features through convolution kernels. This deep coupling mechanism significantly improves the model's ability to represent glass surface defects with varying shapes and sizes; by improving the basic CBS module to a CBS-EMA module, attention enhancement and feature extraction capabilities are enhanced across the entire network layer without significantly increasing network depth and computational complexity (FLOPs). This ensures the continuity of feature flow during transmission, allowing the model to maintain its original inference speed advantage while significantly improving the recall and localization accuracy of minute defects on transparent material surfaces.
[0037] The specific processing steps of the coordinate attention (CA) module include: Coordinate information embedding: For a given input feature map X (of dimension C) H W), a one-dimensional global average pooling operation is performed along the horizontal direction (X-axis) using a pooling kernel of size (H, 1); One-dimensional global average pooling is performed along the vertical direction (Y-axis) using a pooling kernel of size (1, W). The horizontal pooling operation aggregates features in the vertical direction; for the c-th channel, the output at width w... The calculation formula is: ; Where j is the coordinate index in the height direction, i.e., the position subscript of the height dimension of the feature map; H is the height of the feature map; yes The feature value at the corresponding position; The vertical pooling operation aggregates features in the width direction; for the c-th channel, the output at height h... The calculation formula is: ; Where i is the coordinate index in the width direction, i.e., the position subscript of the width dimension of the feature map; W is the width of the feature map; The feature value at the corresponding position; Through the above operations, a pair of direction-aware feature vectors were obtained respectively; Coordinate attention generation: Step S2.1: Concatenate the vertical and horizontal feature vectors obtained in step S1 to form an intermediate feature map; Step S2.2: Using 1 The first convolutional layer performs channel dimensionality reduction on the intermediate feature map by a reduction ratio of r, and generates intermediate encoded features containing spatial information through a non-linear activation function (such as the h-swish function). ; Step S2.3: Encode intermediate features Split into two independent tensors along the spatial dimension and Using two independent Convolutional layers will and The number of channels is restored to the original number of channels. Finally, after processing with the Sigmoid activation function, attention weights in the vertical direction are generated. Attention weights in the horizontal direction The calculation formula is as follows: ; in, This indicates a splicing operation performed along a spatial dimension; yes Convolution transform function; It is an intermediate feature mapping; It is a non-linear activation function (e.g., the h-swish function); Feature reweighting: Vertical attention weights And horizontal attention weights Compared with the original input feature map Element-wise product operations are performed to obtain the final output feature map. The calculation formula is as follows: ; in, Represents the original input feature map In the Each channel, spatial coordinates Eigenvalues at; Indicates the first Each channel, corresponding height Vertical attention weights at the location, Indicates the first Each channel, corresponding width Horizontal attention weights at the location; The introduction of the coordinate attention (CA) module is used to enhance the expressive power of the feature map for key regions and suppress background noise, while preserving the spatial location information of the target.
[0038] The first upsampling module 2011 and the second upsampling module 2012 of the neck network have the same structure; they are used to perform upsampling operations on the input feature map to achieve scale matching. The large target detection head, medium target detection head, and small target detection head all adopt a decoupled architecture, with each detection head including a regression branch and a classification branch. The regression branch is used to predict the precise location of the defect and includes two consecutive convolutional layers and a 1×1 convolutional output layer; the branch outputs the predicted bounding box information corresponding to each feature map location; The classification branch is used to predict the category probability of the defect, and includes two consecutive convolutional layers and a 1×1 convolutional output layer; the output dimension of this branch is the number of categories of the target, which is used to determine the specific category of the defect. The convolutional layer structures of the regression branch and the classification branch are set independently to achieve decoupling of the localization task and the classification task, thereby reducing gradient interference between tasks. Furthermore, the detection head is based on an anchor-free design, directly predicting the target's center offset and size information relative to each feature map location; it does not rely on preset anchor boxes, simplifying the training process and improving model flexibility.
[0039] In this embodiment, the small target detection head corresponds to small-scale targets, the medium target detection head corresponds to medium-scale targets, and the large target detection head corresponds to large-scale targets. The small-scale target refers to a target whose prediction box pixel area is less than 32*32 pixels; The mesoscale target refers to a target whose predicted bounding box pixel area is greater than or equal to 32*32 pixels and less than 96*96 pixels. The large-scale target refers to a target whose prediction box pixel area is greater than or equal to 96*96 pixels.
[0040] The image acquisition platform, image preprocessing module, defect detection model, and automatic sorting module can be integrated into a single system and interact through internal data flow; or they can be independent entities that work collaboratively through communication protocols.
Claims
1. A method for detecting glass defects, characterized in that: Step S1: The image acquisition platform acquires images and inputs the acquired images into the image preprocessing module; Step S2: The image preprocessing module preprocesses the acquired images; Step S3: Input the preprocessed image into the defect detection model to perform defect detection and obtain defect information; Step S4: Upload the obtained defect information to the automatic sorting module, and the automatic sorting module sorts the glass according to the defect information.
2. The glass defect detection method according to claim 1, characterized in that: The defect detection model is based on the YOLOv8 model, incorporating an efficient multi-scale attention (EMA) module, a coordinate attention (CA) module, a soft nonmaximum suppression (Soft-NMS) algorithm, and a focus-efficient cross-union ratio (CUI) loss function (Focal-EIoU Loss) to construct an improved YOLOv8-ECSFe defect detection model. The image to be detected is input into the YOLOv8-ECSFe defect detection model for defect detection.
3. A glass defect detection method according to claim 1 or 2, characterized in that: The defect detection model construction method is as follows: Historical glass surface defect images labeled with glass defect categories are used as the training image set. The defect detection model is trained using the Focal-EIoU Loss function on the training image set. The model parameters are optimized by minimizing the Focal-EIoU Loss function, so that the improved YOLOv8 defect detection model gradually converges, and the trained defect detection model is obtained. The Focal-EIoU Loss function, which focuses on efficient intersection-union ratio (IUU) loss, is defined as follows: ; Where N is the number of training samples; i represents the i-th sample; Modulation factor; Based on the distance from the center point, the difference between width and height, and Combined composition; ; in, The distance is Euclidean. The center point of the prediction box; The center point of the true bounding box; w c h is the width of the minimum bounding rectangle that covers both the predicted and ground truth bounding boxes. c The height of the minimum bounding rectangle that covers both the predicted and ground truth bounding boxes; The width of the prediction box; The width of the actual bounding box; The height of the predicted bounding box; The actual height of the bounding box; This is the intersection-union ratio (IU) between the predicted bounding box and the ground truth bounding box.
4. The glass defect detection method according to claim 3, characterized in that: The glass image preprocessed in step S2 is input into the trained defect detection model. The defect detection model outputs multiple initial prediction boxes, each of which includes its location coordinates (x, y, w, h) and defect category confidence s. Where x is the x-coordinate of the center point b of the prediction box; y is the y-coordinate of the center point b of the prediction box; w is the width of the prediction box; and h is the height of the prediction box. For the multiple predicted bounding boxes output by the defect detection model, the Soft Non-Maximum Suppression (Soft-NMS) algorithm is used for filtering. Sort all initial prediction boxes from high to low according to the defect category confidence s; Select the highest-scoring frame from the list that has not yet been processed as the baseline frame. ; calculate and each subsequent prediction box The intersection and union ratio of IoU; ; when At that time, the algorithm is based on and The degree of overlap is reduced. confidence level The update rules are as follows: ; in, Represents the prediction box With prediction box The intersection and union ratio; , There are two prediction boxes; For prediction boxes Confidence level of defect category; For prediction boxes The confidence level of the defect category, and It is a natural constant; The smoothing coefficient for nonmaximum suppression; The threshold for intersection-union ratio; After all predicted boxes have been processed, all predicted boxes with a confidence level s of all defect categories below a set threshold are filtered out, and the remaining boxes are the final defect detection results.
5. The glass defect detection method according to claim 4, characterized in that: Step S3 is the defect determination step. This step processes the high-confidence defect results output by the model inference. The defect results include defect category and defect location. The defect category includes stains, scratches, bubbles, impurities, and cracks. In this step, the size information of the defect is first calculated based on the bounding box coordinates of the defect result. For linear defects such as scratches and cracks, the defect length is calculated, and for stains, bubbles, and impurities, the defect area is calculated. Subsequently, based on the defect category and the calculated dimensional information, it is determined whether the glass has unacceptable defects. The determination rules are as follows: When the detected defect category is scratch or crack, if its calculated length is greater than L millimeters, it is determined that the glass has an unacceptable defect. When the detected defect category is stain, bubble, or impurity, if its calculated area is greater than S square millimeters, it is determined that the glass has an unacceptable defect.
6. A glass defect detection method according to claim 1, 2, 4, or 5, characterized in that: The defect detection model includes a backbone network, a neck network, and a detection head. The backbone network, from input to output, includes a first-layer CBS-EMA module, a second-layer CBS-EMA module, a first C2f feature fusion module, a third-layer CBS-EMA module, a second C2f feature fusion module, a fourth-layer CBS-EMA module, a third C2f feature fusion module, a fifth-layer CBS-EMA module, a fourth C2f feature fusion module, a coordinate attention (CA) module, and a spatial pyramid fast pooling (SPPF) module. The neck network includes a first upsampling module, a second upsampling module, a first channel stitching module, a second channel stitching module, a third channel stitching module, a fourth channel stitching module, a first neck C2f feature fusion module, a second neck C2f feature fusion module, a third neck C2f feature fusion module, a fourth neck C2f feature fusion module, a first neck CBS module, and a second neck CBS module. The connection relationships between the modules are as follows: The output of the SPPF module of the backbone network is connected to the input of the first upsampling module; The output of the first upsampling module and the output of the third C2f feature fusion module of the backbone network are spliced by the first channel splicing module and then input into the first neck C2f feature fusion module for feature fusion. The output of the first neck C2f feature fusion module is connected to the input of the second upsampling module; The output of the second upsampling module and the output of the second C2f feature fusion module of the backbone network are concatenated by the second channel splicing module and then input into the second neck C2f feature fusion module for feature fusion. The output of the second neck C2f feature fusion module is connected to the first neck CBS module; The output of the first neck CBS module and the output of the first neck C2f feature fusion module are spliced by the third channel splicing module and then input to the third neck C2f feature fusion module for feature fusion. The output of the third neck C2f feature fusion module is connected to the second neck CBS module; The output of the second neck CBS module and the output of the backbone network SPPF module are spliced by the fourth channel splicing module and then input to the fourth neck C2f feature fusion module for feature fusion. The detection head includes a small target detection head, a medium target detection head, and a large target detection head; the input of the small target detection head is connected to the output of the second neck C2f feature fusion module; The input of the target detection head is connected to the output of the third neck C2f feature fusion module; The input of the large target detection head is connected to the output of the fourth neck C2f feature fusion module.
7. The glass defect detection method according to claim 6, characterized in that: The efficient multi-scale attention EMA module processes the input feature map. The attention weight α is calculated as follows: ; Where R represents the set of real numbers, C is the number of channels in the feature map, H is the height of the feature map, and W is the width of the feature map; GAP represents global average pooling. , For learnable weights, Activated for Sigmoid .
8. A glass defect detection method according to claim 6, characterized in that: The specific processing steps of the coordinate attention (CA) module include: Coordinate information embedding: For a given input feature map X (of dimension C) H W), a one-dimensional global average pooling operation is performed along the horizontal direction (X-axis) using a pooling kernel of size (H, 1); One-dimensional global average pooling is performed along the vertical direction (Y-axis) using a pooling kernel of size (1, W). The horizontal pooling operation aggregates features in the vertical direction; for the c-th channel, the output at width w... The calculation formula is: ; Where j is the coordinate index in the height direction, i.e., the position subscript of the height dimension of the feature map; H is the height of the feature map; yes The feature value at the corresponding position; The vertical pooling operation aggregates features in the width direction; for the c-th channel, the output at height h... The calculation formula is: ; Where i is the coordinate index in the width direction, i.e., the position subscript of the width dimension of the feature map; W is the width of the feature map; The feature value at the corresponding position; Through the above operations, a pair of direction-aware feature vectors were obtained respectively; Coordinate attention generation: The vertical and horizontal feature vectors obtained in the above steps are concatenated to form an intermediate feature map; Take advantage of 1 The first convolutional layer performs channel dimensionality reduction on the intermediate feature map by a reduction ratio of r, and generates intermediate encoded features containing spatial information through a non-linear activation function (such as the h-swish function). ; intermediate encoded features Split into two independent tensors along the spatial dimension and Using two independent Convolutional layers will and The number of channels is restored to the original number of channels. Finally, after processing with the Sigmoid activation function, attention weights in the vertical direction are generated. Attention weights in the horizontal direction The calculation formula is as follows: ; in, This indicates a splicing operation performed along a spatial dimension; yes Convolution transform function; It is an intermediate feature mapping; It is a non-linear activation function (e.g., the h-swish function); Feature reweighting: Vertical attention weights And horizontal attention weights Compared with the original input feature map Element-wise product operations are performed to obtain the final output feature map. The calculation formula is as follows: ; in, Represents the original input feature map In the Each channel, spatial coordinates Eigenvalues at; Indicates the first Each channel, corresponding height Vertical attention weights at the location, Indicates the first Each channel, corresponding width The horizontal attention weight at the location.
9. A glass defect detection method according to claim 6, characterized in that: The first, second, third, fourth, and fifth CBS-EMA modules have the same structure, each consisting of a feature processing unit formed by sequentially connecting a convolutional layer, a batch normalization layer, an activation function layer, and an EMA module. The first and second upsampling modules of the neck network have the same structure; The large target detection head, medium target detection head, and small target detection head all adopt a decoupled architecture, with each detection head including a regression branch and a classification branch. The regression branch is used to predict the precise location of the defect and includes two consecutive convolutional layers and a 1×1 convolutional output layer. The classification branch is used to predict the category probability of the defect and includes two consecutive convolutional layers and a 1×1 convolutional output layer. The convolutional layer structures of the regression branch and the classification branch are set independently; Furthermore, the detection head is based on an anchorless design, directly predicting the target's center offset and size information relative to each feature map location.
10. A glass defect detection method according to claim 1, 2, 4, 5, 7, 8, or 9, characterized in that: Step S1 The image acquisition platform includes a shooting module and a light source module. The shooting module includes a camera, and the light source module includes a coaxial light source. The coaxial light source is located directly below the camera and is coaxial with the camera's optical path. The image preprocessing method in step S2 is as follows: Step S2.1: Perform dark channel dehazing on the image; Step S2.2: Perform adaptive histogram equalization. Step S2.3: Perform Gaussian sharpening; The image acquisition platform, image preprocessing module, defect detection model, and automatic sorting module can be integrated into a single system and interact through internal data flow; or they can be independent entities that work collaboratively through communication protocols.