Industrial part surface defect detection method and device based on YOLOv5n
By introducing CA attention mechanism and dynamic snake convolution in the YOLOv5n detection algorithm, combined with the Gold-YOLO structure and feature pyramid network, the problems of low detection accuracy and insufficient feature fusion capability in the existing technology are solved, and a higher Detection accuracy and greater robustness.
Patent Information
- Application Number
- CN202411574344.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2024-11-01
- Filing Date
- 2024-11-06
- Publication Date
- 2025-02-11
AI Technical Summary
The existing industrial component surface defect detection algorithms have problems such as low detection accuracy, easy to miss and miss detection, and insufficient feature extraction and fusion capabilities, making it difficult to effectively deal with multi-scale targets.
Using YOLOv5n-based surface defect detection method for industrial parts, combined with CA attention mechanism and dynamic snake convolution, enhance feature extraction capabilities, and optimize feature fusion through Gold-YOLO structure and feature pyramid network to reduce interference information and improve detection accuracy .
It significantly improves the accuracy of multi-scale object detection, reduces the impact of interfering information, improves the detection accuracy of small-size objects and the performance and robustness of the overall defect detection system.
Smart Images

Figure CN119418128A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of industrial parts surface defect detection, and in particular to a method and device for industrial parts surface defect detection based on YOLOv5n. Background Art
[0002] In the production process of an enterprise, surface defect detection of industrial components is a key link in improving product quality, reducing operating costs and ensuring production safety. If industrial components with surface defects are put into the production line, it will cause irreversible safety problems and serious economic losses. Therefore, it is of great significance to explore an efficient and accurate algorithm for surface defect detection of industrial components.
[0003] In view of the low detection accuracy, easy omission and false detection of existing defect detection algorithms, in order to meet the actual application needs of defect detection, enhancing feature extraction and optimizing feature fusion are two mainstream improvement strategies. Introducing attention mechanisms and deepening network structures are usually used to enhance the model's feature extraction capabilities and improve the ability to capture key features and high-level semantic information; various feature pyramid networks are often used as feature fusion structures to better handle targets of different scales and optimize the model's feature fusion capabilities through the full fusion of multi-scale features. Although additional modules such as attention can enhance feature extraction capabilities to a certain extent, there are still certain limitations. Some information may have been lost before enhancement, and even if it is enhanced, it may be lost again in subsequent networks. Although designing a new propagation path in the feature fusion network can effectively improve the detection effect of multi-scale targets, it should be noted that the interference information will also increase after fusion, which will increase the difficulty of detecting small-sized targets.
[0004] Therefore, it is necessary to design a defect detection method that combines the advantages of enhanced feature extraction and optimized feature fusion strategies to highlight important information while reducing interference information to solve the above technical problems. Summary of the invention
[0005] The present invention provides a method and device for detecting surface defects of industrial parts based on YOLOv5n (target detection algorithm). The present invention has higher detection accuracy for surface defects of industrial parts and is more in line with the monitoring and maintenance needs of the health of parts in industrial production. See the following description for details:
[0006] In the first aspect, a method for detecting surface defects of industrial parts based on YOLOv5n is provided, the method comprising:
[0007] The attention mechanism is embedded into the convolutional layer of the backbone network, and dynamic snake convolution is introduced to capture cross-channel information, direction perception and position perception information. The industrial parts surface defect image dataset is input into the backbone network for feature extraction, and feature maps of three different scales are obtained.
[0008] The Gold-YOLO structure is introduced to generate a feature map that highlights global information by globally fusing multiple layers of features and injecting global information into a higher level.
[0009] The obtained feature map is input into the feature pyramid network, and the feature map is gradually weighted and fused at different scales through downsampling and upsampling methods; the defect detection result is output, and the detection box, defect type and confidence are marked.
[0010] The method of embedding the attention mechanism into the convolutional layer of the backbone network is as follows:
[0011] The CA attention mechanism first encodes the channel through two average pooling operations. The output expression of the Cth channel with height H and width W is as follows:
[0012]
[0013] Where i and j represent the position index in the feature map. Where i represents the index in the width direction and j represents the index in the height direction; The output expression of the Cth channel with height H; The output expression of the Cth channel with a width of W; x c Represents the input feature map of channel c;
[0014] After channel-level splicing operations and convolution smoothing, an information representation with a global receptive field is generated:
[0015] f=δ(F1[Z h ,Z w ])
[0016] Among them, F1 is F1 transformation, Z h is the channel output expression with height h, Z w is the channel output expression with width w; δ is the nonlinear activation function;
[0017] Then through batch normalization and nonlinear mapping transformation, the weight expansion is finally performed as the final weight of attention, and the output is as follows:
[0018]
[0019] in, is the feature map of the cth channel with height h, is the feature map of the cth channel with width w.
[0020] The Gold-YOLO structure is introduced as follows:
[0021] Collect and align features from each level through the feature alignment module;
[0022] The aligned features are fused through the information fusion module to generate global information;
[0023] After obtaining the fused global information from the collection process, the injection module Inject distributes this global information to each level and injects it using attention operations to enhance the detection ability of branches.
[0024] The method adds continuity constraints to the design of the convolution kernel, each convolution position is based on its previous position, the swing direction is selected, and the active contour model dynamically adjusts its shape to match the object boundary.
[0025] In the second aspect, a device for detecting surface defects of industrial parts based on YOLOv5n is provided, the device comprising: a processor and a memory, the memory storing program instructions, the processor calling the program instructions stored in the memory to enable the device to execute any one of the methods described in the first aspect.
[0026] In a third aspect, a computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes any one of the methods described in the first aspect.
[0027] The beneficial effects of the technical solution provided by the present invention are:
[0028] 1. Compared with other defect detection algorithms, the present invention combines CA (channel attention) mechanism and dynamic snake convolution, which not only enhances the ability of feature extraction, but also optimizes the process of feature fusion, making the model perform better in multi-scale target detection; at the same time, this combination can effectively reduce the influence of interference information, improve the detection accuracy of small-size targets, and thus improve the performance and robustness of the overall defect detection system;
[0029] 2. Aiming at the low feature extraction capability of existing algorithms, the present invention proposes a DS-CA (dynamic snake-attention mechanism) module, which improves the feature expression capability by encoding spatial information and channel information, so that the model can capture key features more accurately; Aiming at the insufficient utilization of information of different feature layers by existing feature fusion networks, the present invention introduces a GOLD-YOLO (efficient real-time object detector) structure, which fully integrates features of different scales, reduces information loss and information conflict in the feature fusion process, and improves the detection accuracy of small-sized and irregular-shaped defects;
[0030] 3. The present invention shows good detection effect on defect data sets and has good generalization ability. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 This is a flow chart of the surface defect detection method for industrial parts based on YOLOv5n;
[0032] Figure 2 This is a schematic diagram of the structure of surface defect detection of industrial parts based on YOLOv5n;
[0033] Figure 3 It is a schematic diagram of the structure of GOLD-YOLO;
[0034] Figure 4 This is a schematic diagram of the improved backbone network structure;
[0035] Figure 5 Schematic diagram of the CA attention mechanism structure;
[0036] Figure 6 Schematic diagram of the stateful snake convolution structure. DETAILED DESCRIPTION
[0037] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention are described in further detail below.
[0038] Example 1
[0039] A method for detecting surface defects of industrial parts based on YOLOv5n, see Figure 1 , the method comprising:
[0040] S1: Collecting industrial parts surface defect image dataset;
[0041] S2: The attention mechanism CA is embedded into the convolutional layer of the backbone network, and dynamic snake convolution is introduced to capture cross-channel information as well as direction perception and position perception information. The surface defect image dataset of industrial parts is input into the backbone network for feature extraction, and feature maps of three different scales are obtained;
[0042] S3: Introducing the Gold-YOLO structure, by globally fusing multiple layers of features and injecting global information into a higher level, a feature map that highlights global information is generated;
[0043] S4: Input the obtained feature map into the feature pyramid network, and gradually perform weighted fusion on the feature map at different scales through downsampling and upsampling;
[0044] S5: Output defect detection results, mark the detection box, defect type and confidence level.
[0045] Among them, a backbone network that is more suitable for detecting scratches, cracks and other defects is:
[0046] The DS-CA (Dynamic Snake-Attention Mechanism) module is proposed, which introduces dynamic snake convolution and dynamically adjusts the receptive field to enhance the detection ability of convolutional neural network (CNN) for complex object shapes and dynamic contours, which is more conducive to accurately detecting defects in long strip shapes. The C3CA attention mechanism module is introduced, which can significantly improve the feature extraction ability of convolutional neural network by combining cross-stage cascade and channel attention.
[0047] Among them, the original model neck path aggregation network (PANet) structure is replaced with the Gold-YOLO structure as follows:
[0048] GOLD-YOLO is a novel collection and distribution mechanism (GD) based on the expansion of TopFormer theory. It realizes effective information exchange in YOLO by globally fusing multi-level features and injecting global information into higher levels. Such a structure significantly enhances the information fusion capability of the neck without increasing latency, thus improving the detection performance of the model. GOLD-YOLO is mainly divided into three modules: Feature Alignment Module (FAM), Information Fusion Module (IFM) and Information Injection Module (Inject). First, FAM collects and aligns features from each level. Second, IFM fuses the aligned features to generate global information. After obtaining the fused global information from the collection process, the injection module Inject distributes this information to each level and injects it using a simple attention operation, thereby enhancing the detection capability of the branch. It contains two branches, low-order collection and distribution branch (Low-GD) and high-order collection and distribution branch (High-GD). These branches extract and fuse large-scale and small-scale feature maps respectively, and extract and fuse feature information through convolution-based blocks and attention-based blocks.
[0049] In the low-stage feature alignment module (Low-FAM), average pooling operation is used to downsample the input features to achieve the unification of feature size. The Low-FAM technology ensures the effective aggregation of information while reducing the computational complexity. The information injection module (Inject) injects information into different levels through attention operations. At the end of each attention fusion, RepBlock is added to further extract and fuse information. The high-stage feature alignment module (High-FAM) consists of average pooling (Avgpool) to achieve the unification of feature size, which helps information aggregation and reduces the computational complexity of the transformer module. The high-stage information fusion module (High-IFM) includes the transformer module and the split operation. The information injection module in the high-order collection and distribution branch (High-GD) is exactly the same as that in the low-order collection and distribution branch (Low-GD).
[0050] Among them, the replacement loss function is SIOU. In order to speed up the convergence of the model and make the model more suitable for small target detection, the SIoU loss function is used. The SIoU loss function further considers the vector angle between the predicted box and the true box, and comprehensively considers the location and category information of the target, so that the model can more comprehensively evaluate the accuracy of the detection results. SIoU consists of four parts: angle cost, distance cost, shape cost, and IoU cost.
[0051] In summary, based on the existing target detection model YOLOv5n, the embodiment of the present invention fully considers the defect characteristics of the surface of industrial parts and proposes a detection model that is more suitable for detecting long strip defects such as scratches on industrial parts. The target detection model of the embodiment of the present invention has achieved the best detection effect on the steel defect and aluminum defect data sets.
[0052] Example 2
[0053] The scheme in Example 1 is further introduced below in combination with a specific calculation formula, as described below for details:
[0054] In step S2, the specific method of embedding the attention mechanism CA into the convolutional layer of the backbone network is as follows:
[0055] S211: For the input channel (C) × height (H) × width (W) data, the CA attention mechanism first encodes the channel through two average pooling operations. The output expression of the Cth channel with a height of H and a width of W is as follows:
[0056]
[0057] In the formula, H and W represent the height and width of the Cth channel feature map, respectively, i represents the traversal condition, and j represents the traversal condition. Aggregating information in the two dimensions of width and height helps the network to more accurately locate the target of perception interest.
[0058] S212: After channel-level concatenation operation (Concat) and convolution smoothing processing, an information representation with a global receptive field is generated, as shown in Formula 2:
[0059] f=δ(F1[Z h ,Z w ]) (2)
[0060] Among them, F1 is F1 transformation, Z h is the channel output expression with height h, Z w Output expression for channels of width w.
[0061] S213: Then through batch normalization and nonlinear mapping transformation, and with the same number of channels as the input data, the weight expansion is finally performed as the final weight of attention. The final output is as follows:
[0062]
[0063] in, is the feature map of the cth channel with height h, is the feature map of the cth channel with width w.
[0064] In step S2, the specific method of introducing dynamic snake convolution and dynamically adjusting the receptive field to enhance the detection ability of the convolutional neural network (CNN) for complex object shapes and dynamic contours is as follows:
[0065] When YOLO detects steel surface defects of complex shapes and different directions, its performance is often limited by the fixed geometric transformation of its convolution kernel. Inspired by the active contour model, the dynamic snake convolution layer is integrated into the C3 module in the YOLO architecture, which can significantly improve the feature extraction capability and adapt to multi-scale targets, especially for irregular defects in the shape of long strips. The improvement can significantly improve the detection accuracy. The traditional convolution operation applies the same convolution kernel in a fixed window, which is a static and uniformly distributed grid structure in two-dimensional space. This rigid structure limits the network's ability to adapt to objects with complex and changeable shapes. Dynamic Snake Convolution is an adaptive convolution method that dynamically adjusts the receptive field by introducing a deformable convolution kernel to enhance the detection capability of convolutional neural networks (CNNs) for complex object shapes and dynamic contours. Adding continuity constraints to the design of the convolution kernel allows the convolution kernel to "wander" the input feature map in a non-rigid, deformable manner during feature extraction, allowing the convolution kernel to form a curved or stretched shape to better adapt to the curved and stretched structures in the image. Each convolution position is based on its previous position and is free to choose the swing direction, thereby ensuring the continuity of perception while freely choosing. The active contour model (snake) shows strong adaptability to complex geometric shapes by dynamically adjusting its shape to match the object boundary.
[0066] The specific process is as follows: The local features of the tubular structure are extracted through dynamic snake convolution (DSConv). Assuming that the given convolution center coordinates are Ki = (xi, yi), A is a 3*3 convolution kernel, then K can be expressed as:
[0067] K=(X-1,Y-1)·(Y-1,Y),…,(X+1,Y+1) (4)
[0068] In order to provide the convolution kernel with greater focusing flexibility, deformation offset is introduced. In the thin tubular structure, deformation offset can be learned freely. The concept field often has a target offset, so an iterative strategy is used to observe the target to be processed in turn, thereby ensuring the continuity of attention without distracting attention from large to small deformation offsets. In DSConv, a convolution kernel of size 9 is selected. Taking the X axis as an example, the position information of each convolution kernel is expressed as K i ±c=(x i ±c,y i ±c), where C = {0, 1, 2, 3, 4}, from the center position K i , the position K far away from the center grid iCompared with +1, an offset Δ={δ|δ∈[-1,1]} is added to ensure that the offset ∑ of the convolution kernel conforms to the linear form. The expressions on the X-axis and Y-axis are:
[0069]
[0070] Since the offset is usually fractional, bilinear interpolation is implemented as:
[0071]
[0072] Among them, K′ is the enumeration of all complete spatial positions, and B is the bilinear interpolation kernel, which is divided into two one-dimensional kernels:
[0073] B(K·K′)=b(K x ,K′ x )·b(K y ,K′ y ) (7)
[0074] In order to make the convolution kernel more adaptable to the complex geometric features of the image, a deformation offset is introduced. If the model randomly learns the deformation offset, the perception area may deviate from the target. This strategy matches each target to the observable position in sequence, ensuring continuous feature attention without over-dispersing the perception area due to large deformation offsets.
[0075] In step S3, the specific method of the GOLD-YOLO structure is as follows:
[0076] S311: First, FAM (Feature Alignment Module) collects and aligns features from each level;
[0077] S312: Secondly, the IFM (Information Fusion Module) fuses the aligned features to generate global information;
[0078] S313: After obtaining the fused global information from the collection process, the injection module Inject distributes this global information to each level and injects it using a simple attention operation, thereby enhancing the detection ability of the branch.
[0079] In step S4, the specific method of replacing the loss function with SIoU is as follows:
[0080] S411: Calculate angle loss:
[0081]
[0082] Among them, C h is the height difference between the center point of the real box and the predicted box, σ is the distance between the center point of the real box and the predicted box, is the center coordinate of the real frame, is the center coordinate of the prediction box.
[0083] S412: Calculate distance loss:
[0084]
[0085] Among them, C w , C h is the width and height of the minimum bounding rectangle of the real box and the predicted box, ρ x , y , t All are intermediate parameters.
[0086] S413: Calculate shape loss:
[0087]
[0088] Among them, w, h, w gt ,h gt are the width and height of the predicted box and the real box respectively, w t It is an intermediate parameter, θ, which is used to control the degree of attention paid to the shape loss, avoiding paying too much attention to the shape loss and reducing the movement of the prediction box.
[0089] S414: Calculate IoU loss:
[0090] Among them, IoU is the intersection over union ratio between the predicted box (prediction, Pre) and the real box (ground truth, GT). It is defined as follows:
[0091]
[0092] To sum up, the final SIoU loss formula is:
[0093]
[0094] In summary, the embodiments of the present invention have higher detection accuracy for surface defects of industrial parts and components, and are more in line with the needs of monitoring and maintaining the health of parts and components in industrial production.
[0095] Example 3
[0096] In order to comprehensively evaluate the accuracy of the model, the embodiment of the present invention adopts the most commonly used indicators such as precision (P), recall (R), average precision (AP) and mean average precision (mAP). Average precision (AP) is the average value of the accuracy under different recall rates, which is generally used to evaluate the detection accuracy of a certain category. Mean average precision (mAP) is the average detection accuracy of all target categories, which is usually used to evaluate the overall performance of the network model.
[0097] The above indicators are defined as:
[0098]
[0099] Among them, TP is the number of positive samples correctly identified by the model; FP is the number of negative samples judged as positive samples by the model; FN is the number of positive samples judged as negative samples by the model; p(r) represents precision as a function of recall, n represents the number of categories, AP i Indicates the average detection accuracy of the i-th category. In addition, in order to evaluate the size and computational complexity of the model, the number of parameters and GFLOPS (billion floating-point operations per second) are used to reflect the size and computational complexity of the model.
[0100] In order to illustrate the accuracy of the method, the prediction results of the steel surface defect dataset NEU-DET are compared with those of other models, and the model prediction results in Table 1 are obtained. The last row is the experimental result of the model proposed in the embodiment of the present invention, and the others are some common and latest network model experimental results. mAP50 is usually used to evaluate the overall performance of the network model. It can be seen that the overall performance of the model proposed in the embodiment of the present invention has obvious advantages. Compared with YOLOv5n, it has been improved by 4.3% on the dataset, which is more suitable for surface defect detection of industrial parts in real scenes.
[0101] Table 1 Performance comparison of different detection algorithms
[0102]
[0103]
[0104] In order to better illustrate the contribution of each improvement to the performance of the model proposed in the embodiment of the present invention, the performance of a single module is listed in Table 2. It can be seen that each module improves mAP50 to varying degrees, which fully demonstrates the effectiveness of each module proposed in the embodiment of the present invention in enhancing the performance of the model.
[0105] Table 2 Performance of individual modules on NEU-DET
[0106]
[0107] Example 4
[0108] A device for detecting surface defects of industrial parts based on YOLOv5n, the device comprising: a processor and a memory, wherein program instructions are stored in the memory, and the processor calls the program instructions stored in the memory to enable the device to execute the following method steps in Example 1:
[0109] The attention mechanism is embedded into the convolutional layer of the backbone network, and dynamic snake convolution is introduced to capture cross-channel information, direction perception and position perception information. The industrial parts surface defect image dataset is input into the backbone network for feature extraction, and feature maps of three different scales are obtained.
[0110] The Gold-YOLO structure is introduced to generate a feature map that highlights global information by globally fusing multiple layers of features and injecting global information into a higher level.
[0111] The obtained feature map is input into the feature pyramid network, and the feature map is gradually weighted and fused at different scales through downsampling and upsampling methods; the defect detection result is output, and the detection box, defect type and confidence are marked.
[0112] Among them, the attention mechanism is embedded into the convolutional layer of the backbone network as follows:
[0113] The CA attention mechanism first encodes the channel through two average pooling operations. The output expression of the Cth channel with height H and width W is as follows:
[0114]
[0115] Where i and j represent the position index in the feature map. Where i represents the index in the width direction and j represents the index in the height direction; The output expression of the Cth channel with height H; The output expression of the Cth channel with a width of W; x c Represents the input feature map of channel c;
[0116] After channel-level splicing operations and convolution smoothing, an information representation with a global receptive field is generated:
[0117] f=δ(F1[Z h ,Z w ])
[0118] Among them, F1 is F1 transformation, Z h is the channel output expression with height h, Z wis the channel output expression with width w; δ is the nonlinear activation function;
[0119] Then through batch normalization and nonlinear mapping transformation, the weight expansion is finally performed as the final weight of attention, and the output is as follows:
[0120]
[0121] in, is the feature map of the cth channel with height h, is the feature map of the cth channel with width w.
[0122] Among them, the introduction of Gold-YOLO structure is specific as follows:
[0123] Collect and align features from each level through the feature alignment module;
[0124] The aligned features are fused through the information fusion module to generate global information;
[0125] After obtaining the fused global information from the collection process, the injection module Inject distributes this global information to each level and injects it using attention operations to enhance the detection ability of branches.
[0126] The device also includes: adding continuity constraints to the design of the convolution kernel, each convolution position is based on its previous position, the swing direction is selected, and the active contour model dynamically adjusts its shape to match the object boundary.
[0127] It should be pointed out here that the device description in the above embodiment corresponds to the method description in the embodiment, and the embodiment of the present invention will not be described in detail here.
[0128] The execution subjects of the above-mentioned processor and memory can be devices with computing functions such as computers, single-chip microcomputers, and microcontrollers. In specific implementation, the embodiments of the present invention do not limit the execution subjects and are selected according to the needs of actual applications.
[0129] The data signal is transmitted between the memory and the processor via a bus, which is not described in detail in the embodiment of the present invention.
[0130] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium, the storage medium includes a stored program, and when the program is running, the device where the storage medium is located is controlled to execute the method steps in the above embodiment.
[0131] The computer-readable storage medium includes but is not limited to a flash memory, a hard disk, a solid-state drive, and the like.
[0132] It should be pointed out here that the description of the readable storage medium in the above embodiment corresponds to the description of the method in the embodiment, and the embodiment of the present invention will not be described in detail here.
[0133] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions according to the embodiments of the present invention are generated.
[0134] The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions may be stored in a computer-readable storage medium or transmitted via a computer-readable storage medium. The computer-readable storage medium may be any available medium that can be accessed by the computer or a data storage device such as a server or a data center that includes one or more available media. The available medium may be a magnetic medium or a semiconductor medium, etc.
[0135] Unless otherwise specified, the models of the components in the embodiments of the present invention are not limited, and any device that can perform the above functions may be used.
[0136] Those skilled in the art will appreciate that the accompanying drawing is only a schematic diagram of a preferred embodiment, and the serial numbers of the embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0137] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for detecting surface defects of industrial parts based on YOLOv5n, characterized in that: The method comprises: The attention mechanism is embedded into the convolutional layer of the backbone network, and dynamic snake convolution is introduced to capture cross-channel information, direction perception and position perception information. The industrial parts surface defect image dataset is input into the backbone network for feature extraction, and feature maps of three different scales are obtained. The Gold-YOLO structure is introduced to generate a feature map that highlights global information by globally fusing multiple layers of features and injecting global information into a higher level. The obtained feature map is input into the feature pyramid network, and the feature map is gradually weighted and fused at different scales through downsampling and upsampling methods; the defect detection result is output, and the detection box, defect type and confidence are marked.
2. A method for detecting surface defects of industrial parts based on YOLOv5n according to claim 1, characterized in that: The specific method of embedding the attention mechanism into the convolutional layer of the backbone network is as follows: The CA attention mechanism first encodes the channel through two average pooling operations. The output expression of the Cth channel with height H and width W is as follows: Where i and j represent the position index in the feature map. Where i represents the index in the width direction and j represents the index in the height direction; The output expression of the Cth channel with height H; The output expression of the Cth channel with a width of W; x c Represents the input feature map of channel c; After channel-level splicing operations and convolution smoothing, an information representation with a global receptive field is generated: f=δ(F1[Z h ,Z w ]) Among them, F1 is F1 transformation, Z h is the channel output expression with height h, Z w is the channel output expression with width w; δ is the nonlinear activation function; Then through batch normalization and nonlinear mapping transformation, the weight expansion is finally performed as the final weight of attention, and the output is as follows: in, is the feature map of the cth channel with height h, is the feature map of the cth channel with width w.
3. A method for detecting surface defects of industrial parts based on YOLOv5n according to claim 1, characterized in that: The introduction of the Gold-YOLO structure is specifically as follows: Collect and align features from each level through the feature alignment module; The aligned features are fused through the information fusion module to generate global information; After obtaining the fused global information from the collection process, the injection module Inject distributes this global information to each level and injects it using attention operations to enhance the detection ability of branches.
4. A method for detecting surface defects of industrial parts based on YOLOv5n according to claim 1, characterized in that: The method adds continuity constraints to the design of the convolution kernel. Each convolution position is based on its previous position to select the swing direction. The active contour model dynamically adjusts its shape to match the object boundary.
5. A surface defect detection device for industrial parts based on YOLOv5n, characterized in that: The device comprises: a processor and a memory, wherein program instructions are stored in the memory, and the processor calls the program instructions stored in the memory to enable the device to execute the method according to any one of claims 1 to 4.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is enabled to perform the method according to any one of claims 1 to 4.
Citation Information
Cited By
Electric control part appearance detection method and device based on deep learning
CN120198439A
Tomato fruit maturity detection method based on YOLOv11
CN120472453A
Industrial part abnormal target detection method and system
CN120563807A