Reinforcing steel bar image segmentation method based on improved YOLOv5 network model, product, medium and equipment
By improving the YOLOv5 network model, combining the C3R module and CBAM module, and using the attention mechanism and perspective transformation technology, the problem of low accuracy of steel bar image segmentation is solved, and more efficient steel bar detection and identification are achieved.
Patent Information
- Application Number
- CN202410888503.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-09-10
AI Technical Summary
At the engineering site, due to the influence of light during the binding process of steel bars, it is difficult for traditional image grayscale processing methods to accurately identify the edges of steel bars, resulting in low detection efficiency, and it is difficult to effectively improve the accuracy of steel bar image segmentation with existing technology.
The improved YOLOv5 network model is adopted, and the C3R module and CBAM module are introduced to enhance the network's extraction of multi-scale and multi-feature information, and the attention mechanism is used to reduce the background impact, combined with perspective transformation technology, to improve the accuracy of steel image segmentation.
It significantly improves the accuracy of steel bar image segmentation, reduces shadow interference, enhances the model's ability to detect steel bars, can better identify the diameter and spacing of steel bars, and improves the inspection efficiency at the project site.
Smart Images

Figure CN118628748A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image recognition, and in particular to a steel bar image segmentation method, product, medium and equipment based on an improved YOLOv5 network model. Background Art
[0002] At the construction site, steel bars are a concern for construction units and supervision units. The diameter and spacing of steel bars directly affect the force of the structure and bear most of the tensile stress in the structure, so the binding of steel bars and the identification of spacing have become the focus of engineering units. The steel bar binding process in the project is affected by many factors. After the binding is completed, it is easy to fail to meet the requirements of the specifications or deform. At the same time, there are a large number of steel bars on the construction site of ordinary bridges and house buildings, and the area of steel bar projects to be inspected is usually large. At present, due to the limitations of inspection methods, the efficiency of inspection personnel in the acceptance of steel bar projects by visual measurement is low.
[0003] In recent years, the application of technologies such as artificial intelligence and image data has become more and more widespread. Image recognition technology replaces the human eye to search for target content in images. It has fast computing speed, low cost, and can be statistically processed after digitization. It is currently widely used in various industries.
[0004] When identifying steel bars in steel bar processing plants or engineering sites, the traditional technology uses image grayscale processing to extract steel bar images based on the difference in grayscale values between concrete and steel bars. The operation speed is fast and steel bars can be quickly distinguished from cement floors based on the difference in grayscale. However, due to the influence of light, a certain degree of shadow will appear on the edge of the steel bar, which is too close to the color of the steel bar in the grayscale image, affecting the detection of the steel bar edge. Therefore, it is hoped that deep learning can be used to segment and extract steel bar images. Summary of the invention
[0005] The purpose of the present invention is to provide a steel bar image segmentation method, product, medium and equipment based on an improved YOLOv5 network model to improve the accuracy of steel bar image segmentation and extraction.
[0006] To achieve the above object, the present invention provides the following solution.
[0007] On the one hand, the present invention provides a steel bar image segmentation method based on an improved YOLOv5 network model, comprising:
[0008] Obtain a steel bar image dataset;
[0009] Use the C3R module and CBAM module to improve the YOLOv5 algorithm network structure and establish an improved YOLOv5 network model;
[0010] The steel bar image dataset is used to train and improve the YOLOv5 network model, and a steel bar image segmentation model is obtained after the training is completed;
[0011] Performing perspective transformation on the steel bar image to be segmented to obtain a transformed steel bar image;
[0012] The transformed steel bar image is input into the steel bar image segmentation model to segment the steel bars in the image.
[0013] Optionally, the obtaining of the steel bar image dataset specifically includes:
[0014] An original steel bar image dataset with the steel bar positions marked is obtained, and the original steel bar images in the original steel bar image dataset are flipped, rotated, sheared, and denoised to expand the number of images and generate a steel bar image dataset.
[0015] Optionally, the improving the YOLOv5 algorithm network structure by using the C3R module and the CBAM module and establishing the improved YOLOv5 network model specifically includes:
[0016] The C3 module in the backbone network of the YOLOv5 algorithm network structure is replaced with a C3R module, and a CBAM module is added between the last C3R module and the SPPF module after the replacement to construct an improved YOLOv5 network model.
[0017] Optionally, in the Bottle2neck module of the C3R module, the input feature map is first subjected to a 1×1 convolution operation and then divided into four parts Xi, i∈{1,2,3,4}; each part Xi is subjected to different data processing, and except for the first part X1, each part starting from the second part is subjected to a 3×3 convolution process and then added to the next part to continue the 3×3 convolution process together; finally, the output Yi of the four parts Xi after different data processing is subjected to a 1×1 convolution operation and then output.
[0018] Optionally, the CBAM module includes a channel attention module and a spatial attention module, and the algorithm formula of the CBAM module is expressed as Where F represents the input feature map of the CBAM module, F' represents the first point product result, and F" represents the second point product result; M c (F) and M s (F') represents the feature maps processed by the channel attention module and the spatial attention module respectively.
[0019] Optionally, the method of using the steel bar image dataset to train and improve the YOLOv5 network model to obtain a steel bar image segmentation model after the training is completed specifically includes:
[0020] The steel bar image dataset is divided into training set, validation set and test set in the ratio of 8:1:1. The improved YOLOv5 network model is trained, validated and tested respectively. After the training, the steel bar image segmentation model is obtained.
[0021] Optionally, performing perspective transformation on the steel bar image to be segmented to obtain the transformed steel bar image specifically includes:
[0022] If the steel bars in the steel bar image to be segmented are in an inclined state, the steel bar image to be segmented is subjected to perspective transformation so that the steel bars in the image are in a horizontal or vertical state, thereby obtaining a transformed steel bar image.
[0023] On the other hand, the present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements the steel bar image segmentation method based on the improved YOLOv5 network model.
[0024] On the other hand, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steel bar image segmentation method based on the improved YOLOv5 network model.
[0025] On the other hand, the present invention also provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steel bar image segmentation method based on the improved YOLOv5 network model.
[0026] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0027] The present invention proposes a steel bar image segmentation method, product, medium and equipment based on an improved YOLOv5 network model. Improvements are made on the traditional YOLOv5 algorithm network structure, and the C3 module in the backbone network is replaced by the C3R module proposed by the present invention, so as to enhance the network's extraction of multi-scale and multi-feature information and pay attention to the mutual connection between local information; at the same time, the human attention mechanism is simulated, and an attention mechanism module CBAM is added, and the emphasis on steel bar data in the image is enhanced through weighted processing of image data, so as to reduce background influence and improve the accuracy of steel bar detection; after the steel bar image segmentation model is obtained through the YOLOv5 algorithm, and when the model is used to predict the steel bar, perspective transformation is used in advance to restore the image to its original state, so as to enhance the prediction accuracy of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 A flowchart of a steel bar image segmentation method based on an improved YOLOv5 network model provided by the present invention;
[0030] Figure 2 This is a schematic diagram of the YOLOv5 algorithm network structure;
[0031] Figure 3 This is a schematic diagram of the C3 module structure of the YOLOv5 algorithm;
[0032] Figure 4 This is a schematic diagram of the processing process of the Bottle2neck module in the C3 module;
[0033] Figure 5 Schematic diagram of the processing process of the Bottle2neck module in the C3R module of the present invention;
[0034] Figure 6 A schematic diagram of the network structure of the improved YOLOv5 network model of the present invention;
[0035] Figure 7 Schematic diagram of the CBAM attention mechanism structure of the present invention;
[0036] Figure 8 This is a schematic diagram comparing the results of steel bar extraction before and after image perspective transformation;
[0037] Fig. 9 A schematic diagram showing the comparison of steel bar extraction results using the method of the present invention and a traditional grayscale image recognition method;
[0038] Fig.10 The figure is a schematic diagram for comparing the mAP@50-95 indicators of the traditional YOLOv5 algorithm and the improved YOLOv5 algorithm of the present invention. DETAILED DESCRIPTION
[0039] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0040] At present, the application of YOLO algorithm is spread across all walks of life, such as in military technology, it is used to detect aerial infrared targets; in the agricultural field, it is used to detect crops and pests; in the transportation field, it is used to detect traffic signs, etc.; in the engineering field, it is mainly used to detect the wearing of safety helmets by personnel on the engineering site, and through the improvement of the YOLO algorithm, it improves the detection effect of small targets. However, for now, the target detection function of the YOLO algorithm is more concerned in engineering, and the YOLO algorithm is rarely used to segment the steel bar image to obtain the steel bar information in the image. In this regard, the present invention aims to provide an improved method of the YOLOv5 algorithm for image steel bar extraction, which can effectively improve the accuracy of steel bar extraction in the image by adding a multi-scale, multi-level feature extraction module C3R and an attention module CBAM; at the same time, according to the horizontal and vertical morphological characteristics of the steel bar, the steel bar image is transformed in advance to make it appear horizontal and vertical, so that the model can be better recognized, which is helpful for the measurement of the diameter and spacing of the steel bars in the image based on the visual principle in the future.
[0041] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0042] Figure 1 This is a flowchart of the steel bar image segmentation method based on the improved YOLOv5 network model provided by the present invention. Figure 1 The present invention provides a steel bar image segmentation method based on an improved YOLOv5 network model, comprising:
[0043] Step 1: Obtain a steel bar image dataset.
[0044] First, we obtain the original steel bar image dataset with the steel bar positions marked, and then perform operations such as flipping, rotating, shearing, and adding noise to the original steel bar images in the original steel bar image dataset to expand the number of images and generate a steel bar image dataset. The number of images can be expanded using the dataset enhancement function of the roboflow website, which can perform horizontal and vertical flipping, clockwise and counterclockwise rotation of 90°, rotation between -15° and +15°, or horizontal ±10° and vertical ±10° shearing.
[0045] Step 2: Use the C3R module and CBAM module to improve the YOLOv5 algorithm network structure and establish an improved YOLOv5 network model.
[0046] In recent years, deep learning has been developing continuously, and deep learning methods such as convolutional neural networks and recurrent neural networks have been continuously improved and upgraded. Among them, convolutional neural networks are constructed based on the principles of human vision, and achieve accurate distinction by extracting and combining different features of the image. In addition, convolutional neural networks are data processing after the image is digitized, extracting the feature values of each part of the image, so convolutional neural networks have good adaptability in the pixel-level segmentation of image segmentation. The first generation of YOLO algorithm was launched in 2015. Due to its high speed and good accuracy, it quickly became popular and has now become relatively mature. Among them, YOLOv5 has a slightly different improvement direction compared to previous versions. YOLOv5 adopts a lighter network structure. Compared with the network structure of YOLOv4, the model size and computational complexity of YOLOv5 have been greatly reduced. YOLOv8 has a deeper network layer. Considering that there is no unified steel bar image data set network platform at this stage, most steel bar image data needs to be manually taken at the project site, and the number of samples is small, so it cannot meet the YOLOv8 network data requirements and cannot be fully trained; and YOLOv5 has stronger stability and robustness, and has added an image segmentation module in its 6.0 version; therefore, the present invention uses YOLOv5 for improvement to obtain a neural network model for steel bar image segmentation. The network structure of the YOLOv5 algorithm is as follows: Figure 2 shown.
[0047] See also Figure 2 The YOLOv5 algorithm network structure is mainly composed of four parts: input end, backbone network, neck network, and head segmentation. The four parts correspond to image processing, image feature extraction, image feature fusion, and image detection. The input end uses Mosaic data enhancement, which can splice multiple images into a training image, and the spliced image retains the original image information. Through the Mosaic data processing method, the extraction of image information under various complex backgrounds can be effectively simulated, which further increases the diversity of samples and helps the model to better extract image information in various environments.
[0048] The backbone network structure is mainly composed of C3 modules and Conv modules. The first and second Conv modules in the backbone network structure use 6×6 and 3×3 convolution kernels to extract features from the image and reduce the size of the feature map. The C3 module can be understood as using Conv with multiple different convolution kernels to process image data and output a tensor of higher-dimensional features, that is, output a feature map representing further convolution data processing of the image. The function of the SPPF module is to perform multiple pooling operations on the image feature map, then perform feature map splicing, and then further extract the feature map through Conv, and output a feature map to be sent to the neck network structure for further processing. The purpose of the SPPF module is to extract features at different scales, enhance the network's detection ability for objects of different scales, and help improve the performance of the target detection model.
[0049] The neck network structure further performs convolution operations on the feature maps passed in by the SPPF module through the Conv module, and at the same time expands the size of the feature maps through the Upsample module so that the Contact module can be used to integrate feature map information at different levels and scales, thereby improving the model's ability to detect targets.
[0050] The head segmentation structure selects images of different levels and feature dimensions in the neck network structure to complete image prediction segmentation.
[0051] At present, the target detection function of the YOLO algorithm is paid more attention in engineering, and the YOLO algorithm is rarely used to segment the steel bar image and obtain the steel bar information in the image. Because the feature map information obtained by the C3 module of the YOLOv5 algorithm is relatively single, the receptive field is small, the association between information cannot be achieved, and the multi-level and multi-scale feature information cannot be obtained. In addition, the YOLOv5 algorithm pays the same attention to the information and lacks the emphasis on key information. Therefore, the present invention proposes to improve the network structure of the YOLOv5 algorithm, introduce the C3R module of multi-scale and multi-level information, and add the attention mechanism CBAM to increase its weight for key information, enhance its extraction of image data features, and improve image segmentation capabilities.
[0052] The C3 module structure of the YOLOv5 algorithm is as follows Figure 3 As shown in FIG. 1 , it includes a Conv module, a Bottle2neck module and a Contact module. The processing process of the Bottle2neck module in the C3 module is as follows: Figure 4As shown in the figure, a 1×1 convolutional layer is first used to reduce the dimension, and then a 3×3 convolutional layer is used to calculate the data, which can effectively reduce the amount of calculation. However, the receptive field of the Bottle2neck module in the C3 module is also small, and it is impossible to obtain feature information of more levels and scales through only a 3×3 convolutional layer. Therefore, in order to improve YOLOv5's ability to obtain multi-scale features and enhance its perception of the degree of connection between image information, the present invention improves the image feature extraction C3 module of YOLOv5 based on the multi-scale Res2Net, and proposes a C3R module. The difference from the C3 module is that the processing process of the Bottle2neck module is different.
[0053] like Figure 5 As shown, in the Bottle2neck module of the C3R module of the present invention, the input feature map is first subjected to a 1×1 convolution operation and then divided into four parts Xi, i∈{1,2,3,4}; each part Xi is subjected to different data processing, except for the first part X1, each part starting from the second part is subjected to a 3×3 convolution process and then added to the next part to continue to be subjected to a 3×3 convolution process together; finally, the output Yi of each of the four parts Xi after different data processing is subjected to a 1×1 convolution operation and then output. Each 3×3 convolution layer will expand the receptive field of the feature map, and feature perception can be performed in a larger range, thereby improving the degree of association between local information. This process can be understood as associating the steel bars with the surrounding objects to a certain extent during the training process, such as strengthening the connection between the intersection of the steel bars and the steel bars, so that the model understands the existence of the steel bars between the intersections of the adjacent steel bars, and enables the model to better identify the steel bar skeleton. There is no doubt that each part of the data has obtained the information of the previous set of data, and the output of each group has completed the splicing, and obtained more information at the receptive field level. In the backbone network, the feature layer undergoes fewer convolutions, and the receptive field information obtained is not as good as that of the subsequent advanced feature layer. Therefore, the present invention replaces the C3 module in the backbone network with a C3R module. Furthermore, the present invention also adds a CBAM module between the last C3R module after replacement and the SPPF module to construct an improved YOLOv5 network model, whose network structure is as follows: Figure 6 shown.
[0054] The attention mechanism is a learning method proposed by imitating human visual attention. By changing the weight of key data, the model's attention effect on steel bars is improved and the impact on complex environments is reduced. The attention mechanism introduced in this invention is Convolutional Block Attention Module (CBAM). The structure of the CBAM attention mechanism is as follows: Figure 7 As shown, it includes a channel attention module and a spatial attention module. Represents the element-wise multiplication between feature maps. The algorithm formula of the CBAM module can be expressed as:
[0055]
[0056] Where F represents the input feature map of the CBAM module, F' represents the first point product result, and F" represents the second point product result; M c (F) and M s (F') represent the feature maps processed by the channel attention module and the spatial attention module respectively; that is, M c () represents the processing process of the channel attention module, M s () represents the processing process of the spatial attention module.
[0057] The CBAM attention mechanism has a channel attention mechanism and a spatial attention mechanism, which can improve the degree of attention to different channel feature maps and dynamically adjust the weights of different spatial position features during the training process, improve the model's learning ability for the contextual information of the image feature map, make the model pay more attention to steel bars, and improve the image segmentation ability for steel bars. Therefore, the present invention adds a CBAM module after the C3R module of the 9th layer of the backbone network to enhance the performance of the convolutional neural network by paying attention to the important features in the input data. The two submodules of the CBAM module (channel attention module and spatial attention module) pay attention to the channel dimension and spatial dimension of the feature map respectively.
[0058] Step 3: Use the steel bar image dataset to train and improve the YOLOv5 network model. After the training is completed, the steel bar image segmentation model is obtained.
[0059] The steel bar image dataset is divided into training set, validation set and test set in the ratio of 8:1:1. The improved YOLOv5 network model is trained, validated and tested respectively. After the training, the steel bar image segmentation model is obtained.
[0060] Step 4: Perform perspective transformation on the steel bar image to be segmented to obtain the transformed steel bar image.
[0061] Deep learning is based on a large amount of data. Although the steel bar image segmentation model obtained by the present invention is sufficient for steel bar image segmentation, there is currently a lack of sufficient steel bar image data samples on the Internet for deep learning, which makes the steel bar image segmentation performance achieve good results. Therefore, in order to further fit the horizontal and vertical characteristics of steel bars, the present invention uses perspective transformation to restore the image before using the model to extract steel bars from the image, thereby improving the extraction effect of steel bars in the image.
[0062] Specifically, if the steel bars in the steel bar image to be segmented are in an inclined state, a perspective transformation is performed on the steel bar image to be segmented so that the steel bars in the image are in a horizontal or vertical state, thereby obtaining a transformed steel bar image.
[0063] Based on the original horizontal and vertical morphological characteristics of steel bars, the present invention proposes that before performing steel bar image segmentation, the steel bar image with a large tilt angle should be transformed in perspective, so that the steel bars in the image appear horizontal or vertical, which can clearly reflect the morphological characteristics of the steel bars. A steel bar image is selected for image segmentation and comparison, and the steel bar extraction results before and after the image perspective transformation are compared. Figure 8 As shown, Figure 8 Part (a) shows the rebar image before transformation and its rebar extraction result. Figure 8 Part (b) shows the transformed steel bar image and its steel bar extraction result. It can be seen that the steel bar image segmentation model of the present invention can better identify the steel bar for the image after perspective transformation. Due to the complexity of the selected image, the model has a poor recognition effect on the steel bar, but it still reflects the significance of the perspective transformation operation for steel bar extraction.
[0064] Step 5: Input the transformed steel bar image into the steel bar image segmentation model to segment the steel bars in the image.
[0065] The transformed steel bar image is input into the trained steel bar image segmentation model to segment and extract the steel bars in the image. Further, based on the monocular or binocular vision network technology, the diameter and spacing of the steel bars can be quickly measured.
[0066] The method of the present invention mainly includes the following improvements: on the one hand, an improved C3R module is proposed based on Res2Net and added to the YOLOv5 network structure; on the other hand, an attention mechanism CBAM module is introduced into the YOLOv5 algorithm to improve its attention to important information; on the other hand, according to the horizontal and vertical morphological characteristics of the steel bars, the acquired image is obtained by perspective transformation in advance, so that the characteristic information of the steel bar image is more obvious, and a better image segmentation effect is obtained.
[0067] The steel bar extraction results using the method of the present invention and the traditional grayscale image recognition method are as follows: Fig. 9 As shown, Fig. 9 Part (a) is the original image of the steel bar, part (b) is the steel bar image extracted by the traditional grayscale image recognition method, and part (c) is the steel bar image extracted by the method of the present invention. Fig. 9It can be seen from the extraction results that the steel bar image segmentation method based on the improved YOLOv5 network model proposed in the present invention can more effectively avoid the interference of the shadow part and improve the accuracy of steel bar extraction compared with the traditional grayscale image recognition method, thus preparing for engineering units to use visual network technology to measure the size and distance of steel bars in images.
[0068] In order to verify the steel bar image segmentation effect of the method of the present invention, the experimental comparison results are used for illustration below.
[0069] Due to the lack of a unified and authoritative public dataset for rebar detection at this stage, the rebar image dataset for this training is self-annotated and constructed. The rebar image data comes from field shooting at a certain highway engineering site. The sample data in the rebar image dataset totals 201, with 160, 20, and 21 images in the training set, validation set, and test set, respectively, with a ratio of 8:1:1. In order to further expand the training samples, the images of the training set are increased to 480 through preprocessing, and 3 rebar images (including source images) are output for each training set image. In the view of the present invention, since there are relatively few rebar databases at this stage, in order to further improve the rebar recognition effect, the system configuration file (cfg) of YOLOv5X-seg with the deepest network depth is selected, focusing on the segmentation effect of the rebar image.
[0070] The experimental environment: the operating system is window10 home version, the graphics card is GeForceGTX4090, and the python version is 3.8. The image input size is 640×640, the training batch size is 16, the number of training rounds is 300, there is no pre-trained weight, and other training parameters are the default settings of YOLOv57.0 version. Because changing the network structure will affect the pre-trained weights, the pre-trained weights will not play a role in improving the network structure. At the same time, because the pre-trained weight files of the corresponding network structure are difficult and time-consuming to obtain, the pre-trained weight files are not used in this experiment, excluding other factors, and better verifying the effect of the network structure improvement.
[0071] The evaluation indicators of the model are the average precision (mAP), precision (Precision) and recall (Recall) of the image extraction mask (Mask), and the formula is as follows:
[0072]
[0073] Among them, AP iRepresents the area formed by recall and precision as the x-axis and y-axis; K represents the last number in the summation formula, and the specific value depends on mAP@50 or mAP@50-95. For example, mAP@50 represents the area enclosed by precision and recall when the confidence level is 50%. At this time, there is only one AP, and K is 1. mAP@50-95 represents the confidence level from 50% to 95%, and the step size is assumed to be 5%. When the confidence level is 50%, AP1, when the confidence level is 60%, AP2, when the confidence level is 65%, AP3... and so on, there are a total of 9 APs, and K is 9. Formula (2) first calculates AP i The sum of is divided by K, that is, the average value. TP represents a true positive example, FP represents a false positive example, FN represents a false negative example, and TN represents a true negative example. The comparison of the key evaluation indicators before and after the improvement of the YOLOv5 algorithm is shown in Table 1.
[0074] Table 1 Comparison of key evaluation indicators before and after algorithm improvement
[0075] algorithm Precision Recall mAP@50 mAP@50-95 YOLOv5x-seg 78.1% 68.9% 75.0% 38.5% YOLOv5x-seg+C3R 80.3% 66.6% 75.3% 41.4% YOLOv5x-seg+CBAM 76.1% 72.0% 73.1% 38.1% YOLOv5x-seg+C3R+CBAM 81.9% 68.4% 75.7% 42.1%
[0076] In Table 1, mAP@50 represents the average mAP with a probability of more than 50% of steel bars in the image. mAP@50-95 represents the average mAP at different IOU thresholds (from 0.5 to 0.95, with a step size of 0.05). YOLOv5x-seg represents the unimproved YOLOv5 algorithm network structure; YOLOv5x-seg+C3R represents the network structure after the C3 module is replaced by the C3R module based on the YOLOv5 algorithm network structure; YOLOv5x-seg+CBAM represents the network structure after the CBAM module is added to the YOLOv5 algorithm network structure; YOLOv5x-seg+C3R+CBAM represents the improved YOLOv5 network model network structure of the present invention.
[0077] From the data in Table 1, it can be seen that after adding the C3R module, the recall rate of the YOLOv5x-seg+C3R network structure is not ideal, but its precision rate has increased by 2.2%, the key data mAP@50 has increased by 0.3%, and mAP@50-95 has increased by 2.9%. It can be seen that the multi-scale and multi-feature information extraction ability of the C3R module is beneficial to the extraction of steel bars in the image to a certain extent, especially in the high-order data. After adding the CBAM module, the other data of the YOLOv5x-seg+CBAM network structure have decreased to varying degrees, but the recall rate has increased by 3.1%, proving that the CBAM module can be combined with local information to extract steel bars in the image. The improved YOLOv5 network model network structure YOLOv5x-seg+C3R+CBAM of the present invention has an improved recall rate that is not as expected. Compared with the unimproved YOLOv5 algorithm network structure, its precision rate has increased by 3.8%, mAP@50 has increased by 0.7%, and mAP@50-95 has increased by 3.7%. The data results show that the C3R module and CBAM module can improve the image reinforcement extraction effect.
[0078] The above data are all tested by the model obtained by algorithm training. Due to the small amount of test set data, the data obtained is somewhat accidental. Therefore, in order to further verify the effectiveness of the improved algorithm, further verification is carried out in combination with the changes in key data during the training process. Fig.10 As shown, the black curve is the original YOLOv5 algorithm, and the red curve is the improved YOLOv5 algorithm of the present invention. It can be seen from the curve graph that the improved YOLOv5 algorithm of the present invention is more ideal in terms of mAP@50-95 performance.
[0079] In some embodiments, the present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements the steel bar image segmentation method based on the improved YOLOv5 network model.
[0080] Before the computer program is executed by the processor, the following preparations are required:
[0081] S1. Download pycharm software, download and install the YOLOv57.0 version file on github, use conda to create a virtual environment named yolo, specify the python version as 3.8, check the requirements text in the YOLOv5 file directory, install the required correct configuration environment, start the yolo virtual environment on pycharm, run the detect.py file in the segmensts directory, run it successfully and display the segmentation results of the image with pre-trained weights in the runs file; this proves that the YOLOv5 environment is successfully installed and can run normally.
[0082] S2. Create a datasets file in the YOLOv5 file, download the dataset file and place it correctly in it, and specify the dataset path in the data file. Taking the present invention as an example, run the following code in the command line window: python segment / train.py --img 640-batch16 --epochs 10 --datapath / data.yaml, where path should be replaced with the file path. If the program runs normally and outputs results, it proves that the dataset file is feasible.
[0083] S3. Add the code of Bottle2neck module and C3R module to the common.py file. Then search for parse_model function in yolo.py file and add C3R module to the loop. After completion, select the original yolov5x-seg.yaml in segments under models directory and add C3R module and CBAM module as required.
[0084] The code and its interpretation of the Bottle2neck module (named Res2NetBottle2neck()) in the C3R module of the present invention are as follows:
[0085]
[0086]
[0087]
[0088]
[0089] The core steps of the above Bottle2neck module code are as follows:
[0090] Step 1) The input tensor is convolved with 1×1 to obtain out, which is divided into 4 feature map subsets spx[i], Figure 5 In the representation, it is Xi, and the corresponding relationship is: X1=spx[3], X2=spx[0], X3=spx[1], X4=spx[2]).
[0091] Step 2) Use the for loop to determine spx[i]. When i=0, set sp=spx[0]; when i is not equal to 0, add the feature maps and set sp=sp+spx[i]. Perform a convolution operation on each sp and assign the new data to sp again. Then assign the sp obtained for the first time to out, and all subsequent sp feature map data will be concatenated with the out feature map data to obtain new out feature data. Data information at different scales is obtained through different numbers of 3×3 convolution kernel operations, and all are stored in out.
[0092] Step 3) Concatenate the obtained out feature map data with spx[3], and retain the original feature map subset spx[3] data. Continue to use the 1×1 convolution kernel to process the feature map data in out, fuse the information, and finally output the multi-level and multi-scale feature map data information.
[0093] Furthermore, the following code is used to replace the Bottle2neck module in the original C3 module with the Res2NetBottle2neck module proposed in the present invention.
[0094]
[0095]
[0096]
[0097]
[0098]
[0099] With reference to the above codes, the main steps performed by the CBAM module of the present invention can be summarized as follows.
[0100] Step 1) First, perform a convolution operation on the input. Then, concatenate the results of the two different convolution operations as the input of the third convolution. Through the third convolution, the feature map restores the number of channels to the number of input channels. Finally, the obtained feature map passes through multiple CSP Botleneck modules, adding cross-stage information transmission and exchange and the final result is used as the input of the next step.
[0101] Step 2) Perform global average pooling and global maximum pooling on the input feature map to obtain two pooled feature maps. These two feature maps are respectively passed through two convolutional layers and ReLU activation functions to obtain two attention tensors max_out and avg_out. These two attention tensors are then added and passed through the Sigmoid activation function to obtain the final channel attention weight out. Figure XMultiply it with the channel attention weight out to get the weighted feature map.
[0102] Step 3) Perform average pooling and maximum pooling on the input feature map in the channel dimension to obtain two pooled feature maps. Concatenate these two feature maps in the channel dimension to obtain out. Pass the concatenated feature map through a convolution layer and a Sigmoid activation function to obtain the final spatial attention weight and continue to name it out. Multiply the input feature map with the spatial attention weight out to obtain a weighted feature map. Finally, output the feature map.
[0103] S4. Select yolo.py in the models directory and specify the yolov5-seg.yaml constructed in the previous article in the cfg of the main function. Run the yolo.py file, and the network structure output in the command window will show C3R, which means it is complete.
[0104] After the above preparations are completed, run the code to start model training. Other unspecified training parameters are default. After obtaining the trained steel bar image segmentation model, first perform perspective transformation on the steel bar image to be predicted, and then use the model to predict and extract the steel bars in the image.
[0105] In some embodiments, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steel bar image segmentation method based on the improved YOLOv5 network model.
[0106] In some embodiments, the present invention also provides a computer device, which includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Wherein, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Wherein, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store pending transactions. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steel bar image segmentation method based on the improved YOLOv5 network model can be implemented.
[0107] The key point of the improved algorithm of the present invention is to add the C3R module proposed by Res2Net to the YOLOv5 backbone network, and add the attention mechanism CBAM to the network structure to improve the attention to key information; further, the perspective transformation is used to restore the morphological features of the steel bars, and then the steel bars in the image are extracted. At present, the feature map information obtained by the C3 module of the YOLOv5 algorithm is relatively single, and there is a lack of interconnection between the information. In comparison, the improved algorithm of the present invention is based on the C3R module proposed by Res2Net, which can obtain feature information of more levels and scales, effectively combine the surrounding information of the steel bars for auxiliary judgment, and increase the accuracy of steel bar extraction in the image. The current YOLOv5 algorithm does not pay enough attention to the important information of the image. The improved algorithm of the present invention adds the attention mechanism CBAM, which improves the weight of the key information, effectively helps the algorithm to better perform data processing of the image information, and improves the steel bar extraction effect. When the steel bar image is tilted, the image steel bar extraction effect is not ideal. Therefore, the present invention uses perspective transformation to restore the steel bar morphological features, and further improves the steel bar extraction effect.
[0108] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A steel bar image segmentation method based on an improved YOLOv5 network model, characterized in that: include: Obtain a steel bar image dataset; Use the C3R module and CBAM module to improve the YOLOv5 algorithm network structure and establish an improved YOLOv5 network model; The steel bar image dataset is used to train and improve the YOLOv5 network model, and the steel bar image segmentation model is obtained after the training is completed; Performing perspective transformation on the steel bar image to be segmented to obtain a transformed steel bar image; The transformed steel bar image is input into the steel bar image segmentation model to segment the steel bars in the image.
2. The steel bar image segmentation method based on the improved YOLOv5 network model according to claim 1, characterized in that, The obtaining of the steel bar image dataset specifically includes: An original steel bar image dataset with the steel bar positions marked is obtained, and the original steel bar images in the original steel bar image dataset are flipped, rotated, sheared, and denoised to expand the number of images and generate a steel bar image dataset.
3. The steel bar image segmentation method based on the improved YOLOv5 network model according to claim 1, characterized in that, The C3R module and the CBAM module are used to improve the YOLOv5 algorithm network structure and establish an improved YOLOv5 network model, specifically including: The C3 module in the backbone network of the YOLOv5 algorithm network structure is replaced with a C3R module, and a CBAM module is added between the last C3R module and the SPPF module after the replacement to construct an improved YOLOv5 network model.
4. The steel bar image segmentation method based on the improved YOLOv5 network model according to claim 1, characterized in that, In the Bottle2neck module of the C3R module, the input feature map is first subjected to a 1×1 convolution operation and then divided into four parts Xi, i∈{1,2,3,4}; each part Xi is subjected to different data processing, and except for the first part X1, each part starting from the second part is subjected to a 3×3 convolution process and then added to the next part to continue the 3×3 convolution process together; finally, the output Yi of the four parts Xi after different data processing is subjected to a 1×1 convolution operation and then output.
5. The steel bar image segmentation method based on the improved YOLOv5 network model according to claim 1, characterized in that, The CBAM module includes a channel attention module and a spatial attention module. The algorithm formula of the CBAM module is expressed as follows: Where F represents the input feature map of the CBAM module, F' represents the first point product result, and F" represents the second point product result; M c (F) and M s (F') represents the feature maps processed by the channel attention module and the spatial attention module respectively.
6. The steel bar image segmentation method based on the improved YOLOv5 network model according to claim 1, characterized in that, The steel bar image dataset is used to train and improve the YOLOv5 network model, and after the training is completed, a steel bar image segmentation model is obtained, which specifically includes: The steel bar image dataset is divided into training set, validation set and test set in the ratio of 8:1:
1. The improved YOLOv5 network model is trained, validated and tested respectively. After the training, the steel bar image segmentation model is obtained.
7. The steel bar image segmentation method based on the improved YOLOv5 network model according to claim 1, characterized in that, The step of performing perspective transformation on the steel bar image to be segmented to obtain the transformed steel bar image specifically includes: If the steel bars in the steel bar image to be segmented are in an inclined state, the steel bar image to be segmented is subjected to perspective transformation so that the steel bars in the image are in a horizontal or vertical state, thereby obtaining a transformed steel bar image.
8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steel bar image segmentation method based on the improved YOLOv5 network model described in any one of claims 1 to 7 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steel bar image segmentation method based on the improved YOLOv5 network model described in any one of claims 1 to 7 is implemented.
10. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steel bar image segmentation method based on the improved YOLOv5 network model according to any one of claims 1 to 7.
Citation Information
Cited By
Gas edge enhancement method, training method of gas segmentation model, equipment and program product
CN120823387A
