A firmware weld joint identification method based on YOLO and gray template matching
Patent Information
- Application Number
- CN202610751204.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-28
- Publication Date
- 2026-08-18
AI Technical Summary
一类是基于边缘检测的传统图像处理方法,对光照变化和表面污染敏感,铁锈等干扰物会产生明显边缘响应导致大量误检,曲面光照不均还会使边缘断裂造成漏检
[0039] 1. The firmware weld seam identification method of the present invention introduces geometric distance similarity. As a mandatory constraint feature, the constraint is reset to zero when the spatial deviation between the YOLO detection box and the template matching position exceeds a preset threshold, thereby suppressing false detections from a mechanism perspective.
Smart Images

Figure CN122597343A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to weld identification, and in particular to a firmware weld identification method based on YOLO and grayscale template matching. Background Technology
[0002] The weld quality of cylindrical iron molds directly affects the structural strength of the product, requiring rapid and accurate identification of weld locations during production. However, this inspection scenario faces a series of unique industry challenges. Iron surfaces are prone to oxidation, forming an oxide scale, and cylinders easily accumulate rust during storage and use. This rust and oxide scale exhibit textures and grayscale characteristics highly similar to the weld in visual images, causing significant visual interference. The curved surface of the cylinder, with the weld located in the arc region, easily leads to shape distortion and uneven lighting during imaging, further increasing the inspection difficulty. Limited by production line cycle time, inspection must be real-time. Furthermore, the weld direction and width vary among different mold specifications, making it difficult for a single algorithm to cover all working conditions.
[0003] Existing technologies mainly employ two types of methods. One type is traditional image processing methods based on edge detection, which are sensitive to changes in lighting and surface contamination. Interference such as rust produces obvious edge responses, leading to numerous false detections. Uneven lighting on curved surfaces can also cause edge breaks, resulting in missed detections. The other type is detection methods based on deep learning networks such as YOLO, which can learn the semantic features of welds. However, they also face challenges: rust and welds have highly similar visual features, making it difficult for the network to accurately distinguish them based solely on appearance; industrial sites often lack sufficient high-quality labeled samples, severely limiting the network's generalization ability under small sample conditions, easily leading to misclassification of rust areas as welds. Some researchers have attempted to combine template matching with deep learning, but existing combinations are mostly simple concatenation or voting mechanisms. When the results of the two methods contradict each other, there is a lack of effective decision-making strategies, especially when there is a large spatial deviation, making it difficult to determine which should prevail.
[0004] Therefore, designing a detection method that can effectively integrate multi-source information and has adaptive decision-making capabilities to address the unique challenges in the inspection of weld seams in iron cylinders, such as rust interference, curved surface imaging distortion, and small sample constraints, is a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a firmware weld seam identification method based on YOLO and grayscale template matching.
[0006] The objective of this invention is achieved through the following technical solution: a firmware weld seam identification method based on YOLO and grayscale template matching, comprising the following steps:
[0007] S01: Construct an image dataset by collecting several weld seam images of a cylindrical mold. Divide the collected images into a training set (70%) and a validation set (30%). Use annotation tools to annotate each image in both the training and validation sets. The annotation target is only the weld seam area. After annotation, convert the JSON format annotation file into a YOLO format TXT annotation file. Each TXT file contains a category number, normalized coordinates of the bounding box center point, and normalized width and height of the bounding box in each line. Finally, organize the files according to the specified directory structure and generate a dataset configuration file.
[0008] S02: Perform data augmentation. Each time a training image is read, the following augmentation operations are applied in a random combination.
[0009] Enhancement Strategy 1: Horizontal Flip, flip the image horizontally with a 50% probability, and adjust the coordinates of the annotation box accordingly;
[0010] Enhancement Strategy 2: Random brightness adjustment. The brightness value of the image is randomly adjusted within the range of [0.5, 1.5] to simulate different lighting conditions;
[0011] Enhancement Strategy 3: Mosaic stitching, which randomly scales four images and stitches them into a new image while merging their respective bounding boxes;
[0012] S03: Create a weld template. From the original image dataset, select an image with the highest contrast between the weld area and the base material background and a complete weld shape as the template source image. Extract the weld area from the image as the standard template. Convert the cropped template image to grayscale. Record the height and width of the template and save it as a file named "weld_template.jpg" in the "templates" directory.
[0013] S04: Train the YOLO benchmark detection network, using YOLOv8n as the base detection network, with an input image size of [size missing]. The batch size was set to 4 pixels, the number of training epochs was set to 50 to 100, the SGD optimizer was used, the initial learning rate was 0.01, the momentum was 0.937, and the weight decay was 0.0005. During training, the data augmentation strategy in step S02 was applied in real time. After each training epoch, the mAP@0.5 metric was calculated on the validation set, and the weight file of the best-performing model on the validation set was saved as "". best.pt After training, the YOLO model becomes a baseline detector capable of initially locating weld seam regions, and its output includes the confidence score of each candidate weld seam frame. and bounding box coordinates ;
[0014] S05: Perform YOLO detection and template matching in parallel. For any input image to be detected, start the following two parallel branches simultaneously:
[0015] Branch 1: YOLO detection, loading the trained "..." from step S04 best.pt "Model weights, read in the image to be detected, and scale it to..." After pixel normalization, the data is input into the network for forward inference. The prediction results output by the network are filtered by confidence, retaining only the predicted bounding boxes with a confidence score greater than or equal to 0.25. Then, non-maximum suppression is performed to restore the coordinates of the retained bounding boxes to the original image size, and a list of detection results is output, where each detection result includes a YOLO confidence score. and bounding box coordinates If the detection result list is empty, the YOLO branch outputs the "no detection result" flag;
[0016] Branch 2: Template matching. The same image to be detected is converted to grayscale. A normalized cross-correlation matching method is used. The weld template generated in step S03 is traversed through a sliding window on the image to be detected. After traversal, the maximum matching score and its corresponding position are found. The output result is: Template Matching Similarity. and the center point of the best matching position .
[0017] S06: Constructing a feature vector. This involves feature extraction and representation of the YOLO detection results and template matching results obtained in S05 before fusion. For each candidate weld seam box output by the YOLO detection branch, the following three feature components are calculated to form a three-dimensional feature vector. ;
[0018] Feature component 1: YOLO detection confidence ; directly taken from the YOLO confidence score of branch S05. ;;
[0019] Feature component two: Template matching similarity The matching similarity is directly taken from branch 2 of S05. ;
[0020] Feature component three: Geometric distance similarity The calculation formula is as follows: Where D is the Euclidean distance between the center point of the YOLO detection box and the center point of the best template matching position.
[0021]
[0022] in, The coordinates of the center point of the YOLO detection box. Match the center point coordinates of the template to the optimal position. The preset maximum reasonable distance threshold,
[0023] After normalizing feature component one, feature component two, and feature component three, the feature vector V is obtained.
[0024] S07: Run the adaptive fusion network. Build and run a lightweight multilayer perceptron as the adaptive fusion network, and train it on the original image dataset. After training, extract the 3D feature vector for each image to be detected in the actual production line. The three-dimensional feature vector V is input into the pre-trained adaptive fusion network. The adaptive fusion network propagates forward and outputs the final fusion confidence score. ;
[0025] S08: Output the final recognition result and the fusion confidence score from step S07. If the detection is successful, the adaptive fusion network-recommended bounding box is output. If no reliable weld is detected, a "detection failed" message is output. Finally, the detection results are plotted on the original image for manual review and system debugging.
[0026] Optionally, in step S01, when annotating the image, an axis-aligned rectangle is used for annotation. The rectangle should completely surround the weld and the width of the white space around it should not exceed half the width of the weld.
[0027] Optionally, in step S03, the cut-off range is 30% to 50% of the weld length and 1.5 to 2.0 times the weld width.
[0028] Optionally, in step S07, the adaptive fusion network adopts an MLP network, which has the following three-layer structure:
[0029] The input layer has 3 nodes, corresponding to the 3D feature vector generated in step S06. ;
[0030] Hidden layers: 4 to 8 nodes, using ReLU activation function to learn non-linear interactions between features;
[0031] Output layer: 1 node, Sigmoid activation function, output value range This represents the final fusion confidence level. .
[0032] Optionally, the MLP network also includes an output head for fine-tuning the position of the YOLO detection frame, with the output target position being... .
[0033] Optionally, in step S07, the training process of the adaptive fusion network is as follows:
[0034] S11: Prepare training samples. Using the original training set images constructed in step S01, perform YOLO detection and template matching in step S05 on each image to obtain the training samples for each image. Triples and their corresponding actual annotation results;
[0035] S12: Supervised Learning: [The sentence is incomplete and requires more context to be translated accurately.] As input, the real labeling results are used as supervision signals to train the MLP network to continuously adjust its internal weight parameters, so as to minimize the cross-entropy loss between the final fusion confidence of the MLP network output and the real label, and at the same time minimize the IoU loss between the output position and the real position.
[0036] S13: Training Results: After sufficient training, the MLP network learned in which environments it should trust YOLO results more and in which environments it should trust template matching results more.
[0037] In step S08, a decision threshold is set. ,like If the test is successful, then the test is considered successful. No reliable weld was detected.
[0038] The present invention has the following advantages:
[0039] 1. The firmware weld seam identification method of the present invention introduces geometric distance similarity. As a mandatory constraint feature, the constraint is reset to zero when the spatial deviation between the YOLO detection box and the template matching position exceeds a preset threshold, thereby suppressing false detections from a mechanism perspective.
[0040] 2. To address the characteristic of weld imaging deformation caused by the curvature of the cylindrical surface, a specific template cutting ratio (30%-50% of the weld length and 1.5-2.0 times the width) was adopted, so that the template could retain the geometric structural features of the weld while avoiding the introduction of interference information from the curved surface edges.
[0041] 3. To address the practical constraints of diverse iron mold specifications and difficulties in collecting weld samples, horizontal flipping, brightness adjustment, and Mosaic stitching are made into mandatory steps in the training phase. This allows the limited samples to generate sufficient variation during training, supporting the detection network to achieve effective generalization under data-constrained conditions. Attached Figure Description
[0042] Figure 1 A flowchart illustrating the process of building a dataset;
[0043] Figure 2This is a schematic diagram of the YOLOv8n network structure;
[0044] Figure 3 This is a schematic diagram illustrating the principle of template matching.
[0045] Figure 4 This is a schematic diagram of the adaptive fusion network structure and its input / output.
[0046] Figure 5 Example images showing the original framework and the final detection results. Detailed Implementation
[0047] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0048] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0049] It should be noted that, unless otherwise specified, the embodiments and features described in this invention can be combined with each other.
[0050] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0051] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship commonly used when the product of this invention is in use, or the orientation or positional relationship commonly understood by those skilled in the art. They are only used for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this invention. In addition, the terms "first," "second," etc., are only used to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0052] In the description of this invention, it should also be noted that, unless otherwise explicitly specified and limited, the terms "set," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0053] A firmware weld seam identification method based on YOLO and grayscale template matching includes the following steps:
[0054] S01: Construct an image dataset, such as Figure 1 As shown, several weld seam images of a cylindrical mold were collected. The collected images were divided into a training set (70%) and a validation set (30%). Each image in both the training and validation sets was labeled using a labeling tool. The labeling target was only the weld seam area. After labeling, the JSON format labeling file was converted into a YOLO format TXT labeling file. Each line of the TXT file contained the category number, the normalized coordinates of the bounding box center point, and the normalized width and height of the bounding box. Finally, the files were organized according to the specified directory structure, and a dataset configuration file was generated. In this embodiment, when labeling the images, axis-aligned rectangles were used for labeling. The rectangles should completely surround the weld seam, and the white space around them should not exceed half the width of the weld seam.
[0055] S02: Perform data augmentation. Each time a training image is read, the following augmentation operations are applied in a random combination.
[0056] Enhancement Strategy 1: Horizontal Flip, flip the image horizontally with a 50% probability, and adjust the coordinates of the annotation box accordingly;
[0057] Enhancement Strategy Two: Randomly adjust brightness. The brightness value of the image is randomly adjusted within a range to simulate different lighting conditions;
[0058] Enhancement Strategy 3: Mosaic stitching, which randomly scales four images and stitches them into a new image while merging their respective bounding boxes;
[0059] In this embodiment, the three enhancement strategies described above are dynamically applied in each iteration of YOLO model training. That is, each time a training image is read, the enhancement operations are applied in a random combination. In this way, the original 20 training images can generate almost infinitely diverse variations during training, forcing the model to learn robust features such as illumination invariance and flip invariance.
[0060] S03: Create a weld template. From the original image dataset (the original image before data augmentation), select an image with the highest contrast between the weld area and the base material background and a complete weld shape as the template source image. Crop the weld area from it as the standard template. The cropping range is 30% to 50% of the weld length and 1.5 to 2.0 times the weld width. Convert the cropped template image to grayscale, record the height and width of the template, and save it as a "weld_template.jpg" file in the "templates" directory.
[0061] S04: Train the YOLO benchmark detection network, such as Figure 2 As shown, YOLOv8n is used as the basic detection network, and the input image size is [size missing]. The batch size was set to 4 pixels, and the number of training epochs was set to 50 to 100. The SGD optimizer was used with an initial learning rate of 0.01, momentum of 0.937, and weight decay of 0.0005. During training, the data augmentation strategies from step S02 were applied in real time, including random adjustments to hue, saturation, and brightness, horizontal flipping, random translation and scaling, and Mosaic enhancement. After each training epoch, the mAP@0.5 metric was calculated on the validation set, and the best-performing model weight file on the validation set was saved as "best.pt". After training, the YOLO model became a baseline detector capable of initially locating weld seam regions, and its output included the confidence score of each candidate weld seam bounding box. Range of values and bounding box coordinates Bounding box coordinates Includes center point x, y, width w, and height h;
[0062] S05: Perform YOLO detection and template matching in parallel. For any input image to be detected, start the following two parallel branches simultaneously:
[0063] Branch 1: YOLO detection, loading the trained "..." from step S04 best.pt "Model weights, read in the image to be detected, and scale it to..." After pixel normalization, the data is input into the network for forward inference. The prediction results output by the network are filtered by confidence, retaining only the predicted bounding boxes with a confidence score greater than or equal to 0.25. Then, non-maximum suppression is performed to restore the coordinates of the retained bounding boxes to the original image size, and a list of detection results is output, where each detection result includes a YOLO confidence score. and bounding box coordinates If the detection result list is empty, the YOLO branch outputs the "no detection result" flag;
[0064] Branch 2: Template matching, such as Figure 3As shown, the same image to be detected is converted into a grayscale image. Using the normalized cross-correlation matching method, the weld template generated in step S03 is traversed through a sliding window on the image to be detected. After the traversal is complete, the maximum matching score and its corresponding position are found. The output result is: template matching similarity. and the center point of the best matching position ,exist Figure 3 In the diagram, red, blue, and green represent matching processes with different starting positions in different rounds.
[0065] S06: Constructing a feature vector. This involves feature extraction and representation of the YOLO detection results and template matching results obtained in S05 before fusion. For each candidate weld seam box output by the YOLO detection branch, the following three feature components are calculated to form a three-dimensional feature vector. ;
[0066] Feature component 1: YOLO detection confidence ; directly taken from the YOLO confidence score of branch S05. ;;
[0067] Feature component two: Template matching similarity The matching similarity is directly taken from branch 2 of S05. ;
[0068] Feature component three: Geometric distance similarity The calculation formula is as follows: Where D is the Euclidean distance between the center point of the YOLO detection box and the center point of the best template matching position.
[0069]
[0070] in, The coordinates of the center point of the YOLO detection box. Match the center point coordinates of the template to the optimal position. The maximum reasonable distance threshold is set based on the typical size of the weld in the image, for example, 10% of the image diagonal length.
[0071] After normalizing feature component one, feature component two, and feature component three, the feature vector V is obtained.
[0072] Geometric distance similarity According to the calculation formula, when the center of the YOLO detection box completely coincides with the template matching position, As the distance between the two gradually increases, Linearly decreasing; when the distance exceeds a preset threshold... The role of this feature component is to allow the fusion network to clearly perceive the degree of consistency between the YOLO detection result and the template matching result in spatial location. If the two deviate too much, the fusion network has sufficient grounds to reduce its trust in the detection result.
[0073] S07: Run the adaptive fusion network. Build and run a lightweight multilayer perceptron as the adaptive fusion network, and train it on the original image dataset. After training, extract the 3D feature vector for each image to be detected in the actual production line. The three-dimensional feature vector V is input into the pre-trained adaptive fusion network. The adaptive fusion network propagates forward and outputs the final fusion confidence score. ;
[0074] S08: Output the final recognition result and the fusion confidence score from step S07. If the detection is successful, the adaptive fusion network-recommended bounding box is output. If no reliable weld is detected, a "Detection Failed" message will be output. Finally, if... Figure 5 As shown, the detection results are plotted on the original image to facilitate manual review and system debugging. In this embodiment, a decision threshold is set. ,like If the test is successful, then the test is considered successful. No reliable weld was detected.
[0075] In this embodiment, the adaptive fusion network adopts an MLP network, which has the following three-layer structure:
[0076] The input layer has 3 nodes, corresponding to the 3D feature vector generated in step S06. ;
[0077] Hidden layers: 4 to 8 nodes, using ReLU activation function to learn non-linear interactions between features;
[0078] Output layer: 1 node, Sigmoid activation function, output value range This represents the final fusion confidence level. .
[0079] In this embodiment, the MLP network also includes an output head for fine-tuning the position of the YOLO detection box, with the output target position being... .
[0080] like Figure 4 As shown, the training process of the adaptive fusion network is as follows:
[0081] S11: Prepare training samples. Using the original training set images constructed in step S01, perform YOLO detection and template matching in step S05 on each image to obtain the training samples for each image. Triples and their corresponding actual annotation results;
[0082] S12: Supervised Learning: [The sentence is incomplete and requires more context to be translated accurately.] As input, the real labeling results are used as supervision signals to train the MLP network to continuously adjust its internal weight parameters, so as to minimize the cross-entropy loss between the final fusion confidence of the MLP network output and the real label, and at the same time minimize the IoU loss between the output position and the real position.
[0083] S13: Training Results: After sufficient training, the MLP network learned in which environments it should trust YOLO results more and in which environments it should trust template matching results more.
[0084] Using the identification of weld seams in cylindrical iron molds as an application scenario, 20 images of the molds were collected from the production line, covering different lighting conditions, shooting angles, and surface conditions. These images were divided into a training set of 14 images and a validation set of 6. The LabelMe annotation tool was used to annotate the weld seam region in each image using axis-aligned rectangles, with the category label "weld". After annotation, the images were converted into YOLO format TXT files. Then, step S02, data augmentation, was performed. In each iteration of the YOLO model training, three augmentation strategies were applied online to the training set images: horizontal flipping, random brightness adjustment, and Mosaic stitching, to increase the diversity of effective training samples. Following step S03, an image with the highest contrast between the weld seam and background was selected from the original training set. The core region of the weld seam was cropped as a grayscale template, with a cropping range of 30% to 50% of the weld seam length and 1.5 to 2.0 times the weld seam width, and saved as "weld_template.jpg". Following step S04, the YOLOv8n benchmark detection network was trained, with the input image size being [missing information]. The batch size is set to 4 pixels, and the training is conducted for 50 rounds. The SGD optimizer is used, with an initial learning rate of 0.01, momentum of 0.937, and weight decay of 0.0005. The data augmentation strategy of step S02 is applied in real time during training. After each round, the mAP@0.5 metric is calculated on the validation set, and the best model weights are saved as best.pt.
[0085] During the inference phase, two parallel branches, YOLO detection and template matching, are executed simultaneously on the image to be detected. The YOLO branch loads the weights from the best.pt model, and the input image is scaled to... After each pixel, forward inference is performed, and the output result is subjected to confidence filtering (threshold 0.25) and non-maximum suppression to output the YOLO confidence score. and bounding box coordinates The template matching branch converts the same image to grayscale and uses a normalized cross-correlation matching method to slide the weld_template.jpg template across the image to obtain the matching similarity. and the center point P of the best matching position tm Then, a three-dimensional feature vector is constructed. ,in Geometric distance similarity is calculated using the following formula: D is the Euclidean distance between the center of the YOLO detection box and the center of the best matching position of the template. The default value is 10% of the image diagonal length. This feature vector is then input into a pre-trained lightweight multilayer perceptron fusion network, which contains 3 input layer nodes, 6 hidden layer nodes, and 1 output layer node. The activation functions used are ReLU and Sigmoid, and the final fusion confidence score is output. The decision threshold is set at 0.5. If the detection is successful, the weld location is output; otherwise, a detection failure message is output. In this embodiment, the processing time for a single image on a standard PC platform is approximately 28 milliseconds, meeting the real-time requirements of industrial environments.
[0086] Based on the above-described baseline embodiments, the present invention can also adjust parameters according to specific application scenarios. For example, when the lighting conditions on the production line vary significantly, the range of random brightness adjustment in data augmentation can be appropriately increased; when the weld morphology is relatively consistent, the search step size for template matching can be increased to improve processing speed; when the detection accuracy requirement is higher than the real-time requirement, the number of YOLO training rounds can be increased to 100 rounds.
[0087] Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A YOLO and gray template matching-based firmware weld joint identification method, characterized in that: Includes the following steps: S01: Construct an image dataset by collecting several weld seam images of a cylindrical mold, and then categorizing the collected images according to the training set... , verification set The proportions were divided, and each image in the training and validation sets was labeled using a labeling tool. The labeling target was only the weld area. After the labeling was completed, the JSON format labeling file was converted into a YOLO format TXT labeling file. Each TXT file contained the category number, the normalized coordinates of the bounding box center point, and the normalized width and height of the bounding box in each line. Finally, the files were organized according to the specified directory structure, and a dataset configuration file was generated. S02: Perform data augmentation. Each time a training image is read, the following augmentation operations are applied in a random combination. Enhancement Strategy 1: Horizontal Flip, to The image is flipped horizontally with a certain probability, and the coordinates of the annotation box are adjusted accordingly. Enhancement Strategy Two: Randomly adjust brightness. The brightness value of the image is randomly adjusted within a range to simulate different lighting conditions; Enhancement Strategy 3: Mosaic stitching, which randomly scales four images and stitches them into a new image while merging their respective bounding boxes; S03: Create a weld template. From the original image dataset, select an image with the highest contrast between the weld area and the base material background and a complete weld shape as the template source image. Extract the weld area from the image as the standard template. Convert the cropped template image to grayscale. Record the height and width of the template and save it as a "weld_template.jpg" file in the "templates" directory. S04: Train the YOLO benchmark detection network, using YOLOv8n as the base detection network, with an input image size of [size missing]. The batch size is set to 4 pixels, the number of training epochs is set to 50 to 100, the SGD optimizer is used, the initial learning rate is 0.01, the momentum is 0.937, and the weight decay is 0.0005. During training, the data augmentation strategy in step S02 is applied in real time. After each training epoch, the mAP@0.5 metric is calculated on the validation set, and the weight file of the best-performing model on the validation set is saved as "". best.pt After training, the YOLO model becomes a baseline detector capable of initially locating weld seam regions, and its output includes the confidence score of each candidate weld seam frame. and bounding box coordinates ; S05: Perform YOLO detection and template matching in parallel. For any input image to be detected, start the following two parallel branches simultaneously: Branch 1: YOLO detection, loading the pre-trained code from step S04. best.pt "Model weights, read in the image to be detected, and scale it to..." After pixel normalization, the data is input into the network for forward inference. The prediction results output by the network are filtered by confidence, retaining only the predicted bounding boxes with a confidence score greater than or equal to 0.
25. Then, non-maximum suppression is performed to restore the coordinates of the retained bounding boxes to the original image size, and a list of detection results is output, where each detection result includes a YOLO confidence score. and bounding box coordinates If the list of detection results is empty, the YOLO branch outputs the "No detection results" flag. Branch 2: Template matching. The same image to be detected is converted to grayscale. A normalized cross-correlation matching method is used. The weld template generated in step S03 is traversed through a sliding window on the image to be detected. After traversal, the maximum matching score and its corresponding position are found. The output result is: Template Matching Similarity. and the center point of the best matching position ; S06: Constructing a feature vector. This involves feature extraction and representation of the YOLO detection results and template matching results obtained in S05 before fusion. For each candidate weld seam box output by the YOLO detection branch, the following three feature components are calculated to form a three-dimensional feature vector. Feature component 1: YOLO detection confidence The YOLO confidence score is directly taken from branch S05. ;; Feature component two: Template matching similarity The matching similarity is directly taken from branch 2 of S05. ; Feature component three: Geometric distance similarity The calculation formula is as follows: Where D is the Euclidean distance between the center point of the YOLO detection box and the center point of the best template matching position. ; in, The coordinates of the center point of the YOLO detection box. Match the center point coordinates of the template to the optimal position. The preset maximum reasonable distance threshold, After normalizing feature component one, feature component two, and feature component three, the feature vector V is obtained. S07: Run the adaptive fusion network. Build and run a lightweight multilayer perceptron as the adaptive fusion network, and train it on the original image dataset. After training, extract the 3D feature vector for each image to be detected in the actual production line. The three-dimensional feature vector V is input into the pre-trained adaptive fusion network. The adaptive fusion network propagates forward and outputs the final fusion confidence score. ; S08: Output the final recognition result and the fusion confidence score from step S07. If the detection is successful, the adaptive fusion network-recommended bounding box is output. If no reliable weld is detected, a "detection failed" message is output. Finally, the detection results are plotted on the original image for manual review and system debugging.
2. The firmware weld seam identification method based on YOLO and grayscale template matching according to claim 1, characterized in that: In step S01, when annotating the image, an axis-aligned rectangle is used for annotation. The rectangle should completely surround the weld and the width of the white space around it should not exceed half the width of the weld.
3. The firmware weld seam identification method based on YOLO and grayscale template matching according to claim 1, characterized in that: In step S03, the cut-off range is 30% to 50% of the weld length and 1.5 to 2.0 times the weld width.
4. The firmware weld seam identification method based on YOLO and grayscale template matching according to claim 1, characterized in that: In step S07, the adaptive fusion network adopts an MLP network, which has the following three-layer structure: The input layer has 3 nodes, corresponding to the 3D feature vector generated in step S06. ; Hidden layers: 4 to 8 nodes, using ReLU activation function to learn non-linear interactions between features; Output layer: 1 node, Sigmoid activation function, output value range This represents the final fusion confidence level. .
5. The firmware weld seam identification method based on YOLO and grayscale template matching according to claim 1, characterized in that: The MLP network also includes an output head for fine-tuning the position of the YOLO detection frame during regression analysis; the output target position is... .
6. The firmware weld seam identification method based on YOLO and grayscale template matching according to claim 1, characterized in that: In step S07, the training process of the adaptive fusion network is as follows: S11: Prepare training samples. Using the original training set images constructed in step S01, perform YOLO detection and template matching in step S05 on each image to obtain the training samples for each image. Triples and their corresponding actual annotation results; S12: Supervised Learning: [The sentence is incomplete and requires more context to be translated accurately.] As input, the real labeling results are used as supervision signals to train the MLP network to continuously adjust its internal weight parameters, so as to minimize the cross-entropy loss between the final fusion confidence of the MLP network output and the real label, and at the same time minimize the IoU loss between the output position and the real position. S13: Training Results: After sufficient training, the MLP network learned in which environments it should trust YOLO results more and in which environments it should trust template matching results more.
7. The firmware weld seam identification method based on YOLO and grayscale template matching according to claim 1, characterized in that: In step S08, a decision threshold is set. ,like If the test is successful, then the test is considered successful. No reliable weld was detected.
