Oil field united station instrument detection algorithm based on improved Yolov5
By adding the CBAM attention mechanism to the backbone part of the oilfield joint station instrument detection algorithm and improving the bounding box regression loss function, the problems of high model complexity and low detection rate in the prior art are solved, and higher detection accuracy and real-time performance are achieved.
Patent Information
- Application Number
- CN202311176136.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-12
- Publication Date
- 2025-03-14
AI Technical Summary
The model complexity of the existing oilfield joint station instrument detection algorithm is high and the detection rate of target detection is low, making it difficult to meet the real-time requirements.
Based on the improved Yolov5 oilfield joint station instrument detection algorithm, the attention mechanism CBAM is added to the backbone part and the border regression of the original model is changed to the α-IoU Loss with better performance.
It improves detection accuracy, reduces the number and size of the model parameters, enhances feature extraction capabilities, improves inspection performance, and meets real-time requirements.
Smart Images

Figure CN119625246A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of information engineering, and in particular to an oilfield joint station instrument detection algorithm based on improved Yolov5. Background Art
[0002] With the vigorous development of social economy, oilfield joint station inspection robots have gradually come into the public eye. As a key technology in this field, target detection algorithms have emerged one after another. Traditional target detection algorithms extract candidate areas and then manually extract features based on color and contour information. Commonly used methods include RGB, HSV, Hough transform and other algorithms, and then classify through classifiers. However, due to complex weather conditions, the detection results are often inaccurate or missed.
[0003] Existing deep learning-based target detection algorithms can be roughly divided into two categories. The first category is the two-stage R-CNN series target detection algorithm, which mainly extracts candidate box areas for classification. Although the detection and positioning effect is good, the immediacy does not meet the requirements in practice. The second category is the one-stage target detection algorithm: SSD and YOLO series, etc. After inputting the picture, the position and category are directly obtained in the network, which greatly reduces the repeated calculations in the detection process and speeds up the detection speed.
[0004] Based on the above analysis, the YOLO series algorithms surpass other first-stage detection algorithms in terms of speed and accuracy. However, in practical applications, due to the high complexity of the algorithm model and the low detection rate of target detection, it is difficult to meet the real-time requirements. Therefore, the present invention provides an oilfield joint station instrument detection algorithm based on improved Yolov5 to solve the shortcomings of the prior art. Summary of the invention
[0005] In view of the shortcomings of the prior art, the present invention provides an oilfield joint station instrument detection algorithm based on improved Yolov5, which solves the problems of the existing oilfield joint station instrument detection algorithm, high model complexity and low target detection rate.
[0006] To achieve the above objectives, the present invention is implemented by the following technical scheme: an oilfield joint station instrument detection algorithm based on improved Yolov5 includes the following steps:
[0007] Step 1: Collect the original images of the instruments at the oilfield joint station and mark the position information of the instrument dials to create a data set of instrument images;
[0008] Step 2: Build the backbone network and add an attention mechanism to the backbone.
[0009] Step 3: Improve the bounding box loss function and use the better-performing α-IoU Loss as the bounding box regression loss function.
[0010] Preferably, in step 1, the self-collection operation process is as follows: dividing the self-collected instrument data set into a final training set, a validation set and a test set;
[0011] Store the dataset according to the file path of the VOC dataset;
[0012] Convert the annotation file of the dataset from txt format to xml format;
[0013] The data set is divided into training set, validation set, and test set in a ratio of 8:1:1.
[0014] Preferably, the file path is stored as follows: label folder Annotations, picture folder PNGImages and directory folder ImageSets; the training set, validation set and test set generate directory txt files of the training set, validation set and test set respectively, named train.txt, val.txt and test.txt.
[0015] Preferably, in step one, based on the oilfield joint station instrument detection algorithm of improved Yolov5, the original image of the oilfield joint station instrument is collected, the oilfield joint station instrument dial detection model of improved Yolov5 as described above is input, and the positioning frame of the instrument dial on the current image is output.
[0016] Preferably, in step 2, the operation of adding an attention mechanism in the backbone part is: adding a CBAM attention mechanism after each C3 module in the backbone part.
[0017] Preferably, in step 2, the attention mechanism is used as a CBAM module, that is, the process of the CBAM module is as follows:
[0018] A1. The input feature map F(H×W×C) is subjected to global maxpooling and global average pooling based on width and height respectively to obtain two 1×1×C feature maps;
[0019] A2. Send them into a two-layer neural network (MLP) respectively. The number of neurons in the first layer is C / r (r is the reduction rate), the activation function is Relu, and the number of neurons in the second layer is C. The two-layer neural network is shared;
[0020] A3. Perform an element-wise sum operation on the features output by MLP, and then perform a sigmoid activation operation to generate the final channel attention feature, i.e. Mc;
[0021] A4. Perform Felement-wise multiplication of Mc and the input feature map to generate the input features required by the Spatial attention module; the input feature map is: F∈R C×H×W ; Use CBAM to derive the one-dimensional channel attention map Mc∈R C×1×1 and the 2D spatial attention map Ms∈R 1×H×W , the overall attention process can be summarized as:
[0022] Preferably, in the step three, the operation of improving the bounding box loss function is: replacing the border regression CIoU Loss of the original model with the α-IoU Loss with better performance.
[0023] Preferably, in step 3, the bounding box regression loss function calculation process is as follows:
[0024] B1. Calculate the intersection-over-union ratio of the IoU real box and the predicted box;
[0025] B2. Calculate the diagonal distance c of the minimum enclosed area that contains both the predicted box and the true box;
[0026] B3. Calculate the parameter v that measures the consistency of the aspect ratio. The calculation formula is as follows:
[0027]
[0028] B4. Calculate the balance factor β that weighs the loss caused by the aspect ratio and the loss caused by the IoU part. The calculation formula is as follows:
[0029]
[0030] B5. Calculate α-IoU Loss. The calculation formula is as follows:
[0031]
[0032] The present invention provides an oilfield joint station instrument detection algorithm based on improved Yolov5. It has the following beneficial effects:
[0033] 1. Based on the YOLOv5 model, the present invention proposes an improved YOLOv5 algorithm for detection to enhance the feature extraction method capability and improve the inspection performance.
[0034] 2. The present invention improves the detection accuracy of the network by adding an attention mechanism CBAM in the backbone part.
[0035] 3. The present invention improves the bounding box loss function by replacing the border regression CIoU Loss of the original model with the α-IoU Loss with better performance.
[0036] 4. The present invention solves the problem that neural networks are difficult to meet real-time requirements in practical applications. By improving the Backbone end of the original network, the number of model parameters and the size of the model are effectively reduced. Adding an attention mechanism can improve the detection accuracy of the network. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 is a flow chart of the method of the present invention;
[0038] Figure 2 This is the network structure diagram of the CBAM attention mechanism of the present invention;
[0039] Figure 3 This is the structural diagram of the improved Yolov5 of the present invention. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the specification 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.
[0041] This application provides an oilfield joint station instrument detection algorithm based on improved Yolov5.
[0042] Please see attached Figure 1 -Attached Figure 3 The present invention provides an oilfield joint station instrument detection algorithm based on improved Yolov5, comprising the following steps:
[0043] Step 1: Collect the original images of the instruments at the oilfield joint station and mark the position information of the instrument dials to create a data set of instrument images;
[0044] Step 2: Build the backbone network and add an attention mechanism to the backbone.
[0045] Step 3: Improve the bounding box loss function and use the better-performing α-IoU Loss as the bounding box regression loss function.
[0046] Compared with the prior art, the oilfield joint station instrument detection algorithm based on improved Yolov5 provided by the present invention, on the one hand, improves the detection accuracy of the network by adding an attention mechanism CBAM in the backbone part, and on the other hand, effectively reduces the number of model parameters and the size of the model by improving the Backbone end of the original network, effectively solving the problems of the existing oilfield joint station instrument detection algorithm with high model complexity and low target detection rate.
[0047] The following describes in detail each step of the oilfield joint station instrument detection algorithm based on improved Yolov5 provided by the present invention.
[0048] Step 1: Collect the original images of the instruments at the oilfield joint station and mark the position information of the instrument dials to create a data set of instrument images;
[0049] In this step, the YOLOv5 model is used as the basis, and the improved YOLOv5 algorithm is used for detection to enhance the feature extraction method capability and improve the inspection performance.
[0050] Step 2: Build the backbone network and add an attention mechanism to the backbone.
[0051] In this step, the full name of the CBAM attention mechanism is Convolutional Block Attention Module. As an attention module, the CBAM module uses fewer parameters, which reduces data loss and effectively captures cross-channel communication, resulting in significant performance improvements. In order to alleviate the loss of position information caused by 2D global pooling, the channel attention is decomposed into two parallel 1D feature encoding processes, effectively integrating spatial coordinate information into the generated attention map.
[0052] Step 3: Improve the bounding box loss function and use the better-performing α-IoU Loss as the bounding box regression loss function.
[0053] In this step, the bounding box loss function is improved by replacing the CIoU Loss of the original model with the α-IoU Loss with better performance, which effectively reduces the number of model parameters and the size of the model.
[0054] In order to analyze the oilfield joint station instrument detection algorithm based on improved Yolov5 provided by the present invention, a detailed description is given below in combination with an embodiment.
[0055] Embodiment 1:
[0056] The present invention provides an oilfield joint station instrument detection algorithm based on improved Yolov5, comprising the following steps:
[0057] Step 1: Collect the original images of the instruments at the oilfield joint station and mark the position information of the instrument dials to create a data set of instrument images;
[0058] Specifically, the self-collection operation process is as follows: the self-collected instrument data set is divided into the final training set, validation set, and test set;
[0059] The dataset is stored in the file path of the VOC dataset. The file paths are as follows: label folder Annotations, image folder PNGImages, and directory folder ImageSets.
[0060] Convert the annotation file of the dataset from txt format to xml format;
[0061] The data set is divided into training set, validation set, and test set in a ratio of 8:1:1. The training set, validation set, and test set generate directory txt files for the training set, validation set, and test set, respectively, named train.txt, val.txt, and test.txt.
[0062] More specifically, based on the improved Yolov5 oilfield joint station instrument detection algorithm, the original image of the oilfield joint station instrument is collected, the oilfield joint station instrument dial detection model of the improved Yolov5 oilfield joint station instrument dial as above is input, and the positioning frame of the instrument dial on the current image is output.
[0063] Step 2: Build the backbone network and add an attention mechanism to the backbone.
[0064] Specifically, the operation of adding the attention mechanism in the backbone part is: add the CBAM attention mechanism after each C3 module in the backbone part.
[0065] More specifically, the attention mechanism as a CBAM module, that is, the process of the CBAM module is as follows:
[0066] A1. The input feature map F(H×W×C) is subjected to global maxpooling and global average pooling based on width and height respectively to obtain two 1×1×C feature maps;
[0067] A2. Send them into a two-layer neural network (MLP) respectively. The number of neurons in the first layer is C / r (r is the reduction rate), the activation function is Relu, and the number of neurons in the second layer is C. The two-layer neural network is shared;
[0068] A3. Perform an element-wise sum operation on the features output by MLP, and then perform a sigmoid activation operation to generate the final channel attention feature, i.e. Mc;
[0069] A4. Perform Felement-wise multiplication of Mc and the input feature map to generate the input features required by the Spatial attention module; the input feature map is: F∈R C×H×W ; Use CBAM to derive the one-dimensional channel attention map Mc∈R C×1×1 and the 2D spatial attention map Ms∈R 1×H×W , the overall attention process can be summarized as:
[0070]
[0071] Step 3: Improve the bounding box loss function and use the better-performing α-IoU Loss as the bounding box regression loss function.
[0072] Specifically, the operation to improve the bounding box loss function is to replace the border regression CIoU Loss of the original model with the α-IoU Loss with better performance.
[0073] More specifically, the bounding box regression loss function calculation process is as follows:
[0074] B1. Calculate the intersection-over-union ratio of the IoU real box and the predicted box;
[0075] B2. Calculate the diagonal distance c of the minimum enclosed area that contains both the predicted box and the true box;
[0076] B3. Calculate the parameter v that measures the consistency of the aspect ratio. The calculation formula is as follows:
[0077]
[0078] B4. Calculate the balance factor β that weighs the loss caused by the aspect ratio and the loss caused by the IoU part. The calculation formula is as follows:
[0079]
[0080] B5. Calculate α-IoU Loss. The calculation formula is as follows:
[0081]
[0082] Comparative Example:
[0083] This comparative example provides an oilfield joint station instrument detection algorithm of Yolov5, which belongs to the existing Yolov5 target detection algorithm, and the analysis is as follows:
[0084] The model definition of Yolov5 is divided into two stages: the basic module design stage and the complete model construction stage. In the basic module design stage, the basic neural network operators based on the pytorch architecture are further constructed into custom neural network modules with specific functions and meanings.
[0085] The complete model building stage is to build a complete neural network model through structured files and basic modules in the form of building blocks. The overall network architecture is mainly composed of standard convolution module, bottleneck structure module, cross-stage local bottleneck module, three-convolution cross-stage local bottleneck module, spatial pyramid pooling module, fast spatial pyramid pooling module, and focusing module.
[0086] By analyzing the above-mentioned existing technologies, it is found that the defects mainly include two aspects: on the one hand, the network model architecture is in a pyramid state, the data is too large and dense, and both detection and maintenance are relatively complex and changeable; on the other hand, only a single feedback is provided for target detection, and the overall detection rate is low.
[0087] For the oilfield joint station instrument detection algorithm based on the improved Yolov5 obtained in Example 1 and the existing YOLOv5 algorithm provided in the comparative example, the two are experimentally compared in terms of network recall rate and average precision, and the comparison results are shown in Table 1 below:
[0088] Table 1:
[0089] Model Precision Recall MAP Yolov5 96.7% 86% 88.1% After Improvement 97.2% 88.5% 91.3%
[0090] In summary, the oilfield joint station instrument detection algorithm based on improved Yolov5 provided by the present invention has advantages over the existing Yolov5 original network structure as shown in Table 1. It can be seen that the improved network has improved the recall rate and average precision by 2.5% and 3.2% respectively. The detection accuracy is improved, solving the problem that neural networks are difficult to meet real-time requirements in practical applications.
[0091] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. The oilfield joint station instrument detection algorithm based on improved Yolov5 is characterized by: The following steps are involved: Step 1: Collect the original images of the instruments at the oilfield joint station and mark the position information of the instrument dials to create a data set of instrument images; Step 2: Build the backbone network and add an attention mechanism to the backbone. Step 3: Improve the bounding box loss function and use the better-performing α-IoU Loss as the bounding box regression loss function.
2. The oilfield joint station instrument detection algorithm based on improved Yolov5 according to claim 1 is characterized in that: In the step 1, the self-collection operation process is as follows: the self-collected instrument data set is divided into a final training set, a validation set and a test set; Store the dataset according to the file path of the VOC dataset; Convert the annotation file of the dataset from txt format to xml format; The data set is divided into training set, validation set, and test set in a ratio of 8:1:
1.
3. The oilfield joint station instrument detection algorithm based on improved Yolov5 according to claim 2 is characterized in that: The file paths are stored as follows: label folder Annotations, picture folder PNGImages and directory folder ImageSets; The training set, validation set, and test set generate directory txt files of the training set, validation set, and test set, respectively, named train.txt, val.txt, and test.txt.
4. The oilfield joint station instrument detection algorithm based on improved Yolov5 according to claim 1 is characterized in that: In the step 1, based on the oilfield joint station instrument detection algorithm of improved Yolov5, the original image of the oilfield joint station instrument is collected, the oilfield joint station instrument dial detection model of improved Yolov5 as described above is input, and the positioning frame of the instrument dial on the current image is output.
5. The oilfield joint station instrument detection algorithm based on improved Yolov5 according to claim 1 is characterized in that: In the step 2, the operation of adding the attention mechanism in the backbone part is: adding the CBAM attention mechanism after each C3 module in the backbone part.
6. The oilfield joint station instrument detection algorithm based on improved Yolov5 according to claim 1 is characterized in that: In step 2, the attention mechanism is used as a CBAM module, that is, the process of the CBAM module is as follows: A1. The input feature map F(H×W×C) is subjected to global maxpooling based on width and global average pooling based on height respectively to obtain two 1×1×C feature maps; A2. Send them into a two-layer neural network (MLP) respectively. The number of neurons in the first layer is C / r (r is the reduction rate), the activation function is Relu, and the number of neurons in the second layer is C. The two-layer neural network is shared; A3. Perform an element-wise sum operation on the features output by MLP, and then perform a sigmoid activation operation to generate the final channel attention feature, i.e. Mc; A4. Perform Felement-wise multiplication of Mc and the input feature map to generate the input features required by the Spatial attention module. The input feature map is: F∈R C×H×W ; Using CBAM, we can derive the one-dimensional channel attention map Mc∈R C×1×1 and the 2D spatial attention map Ms∈R 1×H×W , the overall attention process can be summarized as:
7. The oilfield joint station instrument detection algorithm based on improved Yolov5 according to claim 1 is characterized in that: In the step three, the operation of improving the bounding box loss function is: replacing the border regression CIoU Loss of the original model with the α-IoU Loss with better performance.
8. The oilfield joint station instrument detection algorithm based on improved Yolov5 according to claim 1 is characterized in that: In step 3, the calculation process of the bounding box regression loss function is as follows: B1. Calculate the intersection-over-union ratio of the IoU real box and the predicted box; B2. Calculate the diagonal distance c of the minimum enclosed area that contains both the predicted box and the true box; B3. Calculate the parameter v that measures the consistency of the aspect ratio. The calculation formula is as follows: B4. Calculate the balance factor β that weighs the loss caused by the aspect ratio and the loss caused by the IoU part. The calculation formula is as follows: B5. Calculate α-IoU Loss. The calculation formula is as follows: