Object detection method and system based on attention mechanism and feature cross fusion
By introducing attention mechanism and feature cross-fusion technology into maritime target detection, the accuracy and robustness problems of maritime target detection in complex environments are solved, and efficient target positioning and detection are achieved.
Patent Information
- Application Number
- CN202210532337.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-11
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2042-05-11
AI Technical Summary
Under the influence of factors such as complex weather and lighting changes, existing maritime target detection methods have problems such as short monitoring distance, small range, low clarity, and poor night vision, which affects detection accuracy and positioning effects.
Using a target detection method based on attention mechanism and feature cross-fusion, through feature pyramid network, path fusion network and feature cross-fusion module, combined with multiple attention mechanisms such as Transformer and CBAM, features are extracted and fused to improve the accuracy of target detection. and robustness.
It achieves pixel-level maritime target detection, improves the target detection rate, reduces the false detection rate, is suitable for maritime target detection in complex situations, and improves detection accuracy and positioning effects.
Smart Images

Figure CN115035361B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision and deep learning technology, and in particular to a target detection method and system based on attention mechanism and feature cross-fusion. Background Art
[0002] As one of the current research hotspots in the field of computer vision, object detection mainly aims to find objects of interest in images and determine their categories and locations.
[0003] Traditional target detection methods are roughly divided into three parts: region selection (sliding window), feature extraction (SIFT, HOG, etc.), and classifier (SVM, Adaboost, etc.). That is, first select candidate regions on a given image, then extract the features of these regions, and finally use the trained classifier for classification. There are two main problems with traditional target detection: first, the region selection strategy based on the sliding window is not targeted, has high time complexity, and has window redundancy; second, the manually designed features have poor robustness and cannot adapt to changes in diversity.
[0004] In recent years, deep learning has swept across various fields such as speech, image, and vision, and the bottlenecks encountered by traditional methods have been broken with the introduction of deep learning methods. Deep neural networks have powerful expression and data fitting capabilities, can automatically extract and learn key information in images, have strong robustness and information integration capabilities, and can adapt to diverse changes.
[0005] Existing image-based target detection mainly focuses on detecting targets on land, such as face detection in indoor environments, baggage security inspection, outdoor road detection, vehicle detection, pedestrian detection, etc., and there are few detections for targets at sea. However, they are essentially the same, and they all directly predict the target category and its location by extracting features through deep learning models. Therefore, maritime target detection can draw on the methods of other existing target detection tasks. In fact, maritime target detection is of great significance. Designing a sea surface target monitoring system can not only monitor the navigation safety of passing ships in real time and ensure navigation and transportation safety, but also track and judge the intentions of target ships (such as enemy ships and pirate ships), so as to facilitate the timely formulation of countermeasures, which is also of great help to the coastal defense cause.
[0006] At present, my country mainly realizes marine target detection by analyzing and processing satellite remote sensing images, infrared images and radar images. However, these methods are easily affected by factors such as complex weather and light changes at sea in actual applications. They have problems such as short monitoring distance, small monitoring range, low clarity and poor night vision, which greatly affect the detection accuracy and positioning effect. Summary of the invention
[0007] The purpose of the present invention is to overcome the technical defects of existing marine target detection methods, and propose a marine target detection method and system based on attention mechanism and feature cross-fusion. The method can perform pixel-level target detection, realize target positioning, improve target detection rate, reduce false detection rate, and is more suitable for marine target detection in complex situations.
[0008] In order to achieve the above-mentioned purpose, the present invention proposes a target detection method based on attention mechanism and feature cross-fusion. The method first extracts features based on the preprocessed training set images, and cross-refines the extracted features through feature pyramid network, path fusion network and feature cross-fusion module respectively, and introduces multiple attention mechanisms during the refining, thereby obtaining the output features, sending the output features to the detection head to obtain the prediction results, calculating the loss between the prediction results and the true labels, and repeatedly training and adjusting the model parameters according to the calculated losses until the optimal model parameters are obtained. Output the target detection network model, then input the image to be detected into the network model to obtain the prediction results, and finally, decode the prediction results to obtain the position, category and confidence of the target in the image to be detected. Multiple attention mechanisms refer to Transformer structure and CBAM (Convolutional Block Attention Module). The Transformer structure itself also includes an attention mechanism, and CBAM includes two types of attention: channel attention and spatial attention.
[0009] As one of the improvements of the above technical solution, the method includes the following steps when establishing the target detection network model:
[0010] Step 1) Data preprocessing: After scaling and enhancing the images required for training, the images are randomly divided into M groups with B images in each group;
[0011] Step 2) Randomly read a group of pictures, and extract and compress the features of the input pictures layer by layer through the N-layer backbone network to obtain the feature map of each layer, forming the first feature pyramid;
[0012] Step 3) For the hierarchical features of the last layer in step 2), the low-level features of the first feature pyramid are fused one by one from top to bottom through upsampling to obtain features containing more semantic information, thereby forming a second feature pyramid;
[0013] Step 4) For the last layer of features in step 3), the feature map is downsampled through a convolution operation, and the high-level features of the second feature pyramid are fused layer by layer from bottom to top to obtain features containing more positioning information;
[0014] Step 5) The two feature maps with lower resolution in step 4) are cross-fused by upsampling with the feature maps with the same resolution in the respective upper layers to obtain output features;
[0015] Step 6) sending the output features in step 5) to the detection head for detection and decoding to obtain the predicted coordinates of the target on the original input image as well as the predicted category and confidence;
[0016] Step 7) Calculate the loss function between the network prediction and the true value, and use the gradient descent method to update the parameters in the above model; iterate repeatedly until the optimal parameter combination is trained, and output the target detection network model.
[0017] As one of the improvements of the above technical solution, the backbone network in the step 2) includes a shallow feature extraction block, three common convolutional hierarchical feature extraction blocks and a hierarchical feature extraction block based on a Transformer structure and fast spatial pyramid pooling; wherein the shallow feature extraction operation includes 2 downsamplings, and each common convolutional hierarchical feature extraction operation and the hierarchical feature extraction operation based on a Transformer structure and fast spatial pyramid pooling each include only 1 downsampling; the multiple of each downsampling is 2; specifically, the following steps are included:
[0018] Step 2-1) Randomly read a set of images X in , through the shallow feature extraction block, the shallow feature F is obtained s ;
[0019] Step 2-2) The shallow feature F s Through the first ordinary convolutional level feature extraction block, the first layer feature map F of the feature pyramid is obtained. a ;
[0020] Step 2-3) Then add F a Through the second ordinary convolutional level feature extraction block, the second layer feature map F of the feature pyramid is obtained. b , and then F b Through the third ordinary convolutional level feature extraction block, the third layer feature map F of the feature pyramid is obtained c ;
[0021] Step 2-4) F c The top feature map F of the feature pyramid is obtained through the hierarchical feature extraction block based on the Transformer structure and fast spatial pyramid pooling. N-1 .
[0022] As one of the improvements of the above technical solution, the feature pyramid network in step 3) includes a conventional convolution block, two convolution fusion blocks, and a global attention fusion block;
[0023] The convolution fusion block includes: an upsampling layer, a splicing layer, a C3 layer and a Conv layer; the global attention fusion block includes an upsampling layer, a splicing layer, a C3 layer and a global attention layer; the upsampling factor in the upsampling layer is 2; the convolution kernel size in the Conv layer is 1 and the step size is 1; specifically, for the feature map F a 、F b 、F c and F N-1 , perform the following steps from top to bottom:
[0024] Step 3-1) First, N-1 After passing the first regular convolution block, we get the feature map F′ N-1 , then through the first convolution fusion block, F′ N-1 After upsampling, c The concatenation is then performed, and then the features are fused through the C3 layer and the Conv layer to obtain the feature map F′ c ;
[0025] Step 3-2) F′ c F is fused through the second convolutional fusion block b Get the feature map F′ b ;
[0026] Step 3-3) F′ b Fusion of F through the global attention fusion block a Get the feature map F′ a ;
[0027] As one of the improvements of the above technical solution, the path fusion network in step 4) includes two global attention convolution blocks and one multiple attention block;
[0028] The global attention convolution block includes: Conv layer, splicing layer, C3 layer and global attention layer; the multiple attention block includes: Conv layer, splicing layer, C3 layer based on Transformer structure and global attention layer; the convolution kernel size of Conv layer is 3 and the step size is 2; specifically, for the feature map F′ N-1 , F′ c , F′ b and F′ a , perform the following steps from bottom to top:
[0029] Step 4-1) First, F′ a Through the first global attention convolution block, that is, F′ a After downsampling using the Conv layer, b Then, the feature map F is obtained by concatenating the features through the C3 layer and the global attention layer.b ″;
[0030] Step 4-2) F b ″Fused through the second global attention convolutional block F′ c Get the feature map F c ″;
[0031] Step 4-3) F c ″F′ is fused through multiple attention blocks N-1 Get the feature map F″ N-1 .
[0032] As one of the improvements of the above technical solution, the step 5) includes two feature cross-fusion units;
[0033] The feature cross-fusion unit includes: an upsampling layer, a concatenation layer, and a Conv layer; wherein the upsampling factor of the upsampling layer is 4; the convolution kernel size of the Conv layer is 3, and the step size is 1; specifically, for the feature map F′ a 、F b ″、F c ″ and F″ N-1 , perform the following steps:
[0034] Step 5-1) Set feature F c ″Through the first feature cross-fusion unit, F c ″After upsampling, F′ a Concatenate, and then perform feature fusion through the Conv layer to obtain the feature map F″ ca ;
[0035] Step 5-2) Set feature F″ N-1 The feature map F″ is obtained through another feature cross fusion unit (N-1)b .
[0036] As one of the improvements of the above technical solution, the number of detection heads in step 6) corresponds to the number of output features; wherein each detection head comprises a 1×1 Conv layer and two parallel branches, and the parallel branches are two 3×3 Conv layers; the two branches are used for classification tasks and regression tasks respectively; the target branch is added to the regression task branch;
[0037] The final classification prediction, regression prediction and target prediction are obtained through a 1×1 two-dimensional convolution operation; wherein, the classification prediction determines which category the detected target belongs to, and the number of channels is the number of target categories; the regression prediction determines the relative position of the detected target in the image (represented in the form of a rectangular box), and the number of channels is 4, and the 4 channels correspond to the center coordinates (x, y) of the target and the height h and width w of the target respectively; the number of channels for target prediction is 1, and the predicted value is the confidence, wherein the confidence indicates the probability that the prediction is the target; specifically, the output feature map F′ a , F″ b , F″ c , F″ N-1 , F″ ca and F″ (N-1)b , perform the following steps:
[0038] Step 6-1) Pass the feature F′a through the corresponding detection head to obtain three predictions Y a,Reg , Y a,Obj , Y a,Cls , and then concatenate the three predictions in the channel dimension to get the prediction Y a ;
[0039] Step 6-2) Take the predicted Y in step 6-1) a The first 4 channels of are projected onto the input image;
[0040] Step 6-3) For the remaining 5 features F″ b , F″ c F″ N-1 , F″ ca and F″ (N-1)b Carry out steps 6-1) and 6-2) for feature F′ a The predicted Y b , Y c , Y N-1 , Y ca and Y (N-1)b .
[0041] As one of the improvements of the above technical solution, the step 7) specifically includes:
[0042] Step 7-1) Based on the prediction Y a , Y b , Y c , Y N-1 , Y ca and Y (N-1)b The regression loss, target loss and classification loss are calculated respectively; the regression loss is calculated for each target in the image through the regression loss function, and the calculation formula is:
[0043] lossreg =loss iou
[0044] loss iou =-ln(iou)
[0045] Among them, loss reg is the regression loss, loss iou is a regression loss function, iou refers to the intersection-and-union ratio of the predicted box A and the true box B of each target; the predicted box A of the target is the predicted position of the target, and the true box B is the true position of the target;
[0046] The target loss is calculated for each grid of the predicted feature map; the classification loss is calculated for each target; both the target loss and the classification loss are obtained using the binary cross entropy loss function, and the calculation methods are as follows:
[0047] loss obj =loss(x obj ,y obj )
[0048] loss cls =loss(x cls ,y cls )
[0049] loss(x,y)=mean{l n , ..., l N-1}
[0050] l n =-ω n [y n logσ(x n )+(1-y n )·log(1-σ(x n ))]
[0051] Among them, loss obj is the target loss, loss cls is the classification loss, loss(x, y) is the binary cross entropy loss function, x obj is the confidence of each grid of the predicted feature map, y obj is the true confidence of each grid; x cls is the predicted category of the target, y cls is the true category of the target; N represents the number of samples, x n Indicates the score of predicting that the nth sample is a positive example, y n represents the label of the nth sample, σ represents the Sigmoid function, l n is the loss of the nth sample, ω nis the loss weight coefficient of the nth sample;
[0052] The loss between the output of the model and the true label is calculated based on the regression loss, target loss, and classification loss. The calculation formula is:
[0053] loss=loss reg +loss obj +loss cls
[0054] Update model parameters according to the calculated loss;
[0055] Step 7-2) uses the model parameters obtained in step 7-1) as the weight value of this iteration; randomly select a group of pictures from the remaining pictures, and obtain a new parameter combination through steps 2), 3), 4), 5), 6) and 7-1); iterate repeatedly until all M groups of pictures are trained;
[0056] Step 7-3) reshuffles the training images and goes to step 1); repeatedly execute steps 1) to 7-2) until the optimal parameter combination is trained.
[0057] As one of the improvements to the above technical solution, when the image to be detected is input into the target detection network model for detection, the following steps are specifically included:
[0058] Step 8-1) For the image to be tested, use bilinear interpolation to adjust the size of the image to the size required by the model input;
[0059] Step 8-2) Input the adjusted image into the optimal parameter model and obtain the prediction result after forward reasoning;
[0060] Step 8-3) The prediction results are normalized using the Sigmoid function, and then the coordinates of the regression prediction are projected onto the input image;
[0061] Step 8-4) performing non-maximum suppression on the prediction result in step 8-3) to obtain a final prediction result, wherein the final prediction result includes the location of the target in the image, the category and its confidence score;
[0062] Step 8-5) Change another image to be tested, and repeat steps 8-1)-8-4) until all images to be tested are tested;
[0063] For the final prediction results of all images, if they are test images with real labels, quantitative evaluation is performed directly by comparing the prediction results with the real labels; if they are test images without real labels, qualitative evaluation is performed by visualizing the prediction results on the images.
[0064] The present invention also proposes a target detection system based on attention mechanism and feature cross-fusion, which is implemented by a target detection network model constructed according to any of the above methods. The system includes:
[0065] Backbone network, used for multi-level feature extraction of input images;
[0066] The neck layer is used to further fuse the multi-level features extracted by the backbone network, improve more representative context information, and obtain comprehensive semantic fusion features;
[0067] Feature pyramid network, used to convey strong semantic features from top to bottom;
[0068] Path fusion network, used to convey strong localization features from bottom to top;
[0069] A feature cross-fusion module is used to cross-fuse high-level features with low-level features to improve the relevance and information utilization between features; and
[0070] The detection head is used to decode the final features and output the predicted category and location information.
[0071] Compared with the existing methods, the technical advantages of the present invention are:
[0072] The technical solution for marine target detection provided by the present invention extracts multi-level features from the input image in the backbone network; then, in the neck layer, feature pyramid and path fusion network are used to fuse the features of different levels from top to bottom and bottom to top respectively; the feature pyramid network conveys strong semantic features from top to bottom, while the path fusion network conveys strong positioning features from bottom to top, further improving the feature extraction capability of the network; before sending the features to the detection head, upsampling is also used to cross-fuse high-level features with low-level features, further improving the information utilization rate between features; finally, the features are sent to the decoupling detection head, the features are decoded, and the category and position of the target are directly predicted. In addition, in terms of implementation details, the attention mechanism is introduced in the backbone network and the neck layer, which can learn richer semantic information and detail information from pixels, channels and space in an all-round way, so that the deep learning model has stronger learning ability and robustness for marine targets. When tested on the benchmark data set, the present invention achieved performance that exceeds the existing methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] Figure 1 A schematic diagram of a marine target detection network model provided by the present invention;
[0074] Figure 2 A schematic diagram of the feature pyramid network structure provided by the present invention;
[0075] Figure 3A schematic diagram of the path fusion network structure provided by the present invention;
[0076] Figure 4 This is a schematic diagram of the feature cross-fusion module provided by the present invention.
[0077] Figure 5 This is a schematic structural diagram of the detection head module provided by the present invention. DETAILED DESCRIPTION
[0078] The present invention will be further described below in conjunction with the accompanying drawings and specific implementations.
[0079] Figure 1 The marine target detection network shown in the figure is mainly composed of a backbone network, a neck layer composed of a feature pyramid network (FPN) and a path fusion network (PAN), a feature cross-fusion module, and a detection head. The backbone network includes: a shallow feature extraction (SFE) block, three common convolutional hierarchical feature extraction (CFE) blocks, and a hierarchical feature extraction (TFPE) block based on a Transformer structure and fast spatial pyramid pooling. The data processing process of the network specifically includes:
[0080] Step 1) Data preprocessing: randomly divide the images required for training into M groups with B images in each group, and perform corresponding data enhancement;
[0081] Step 2) Randomly read a group of images, and use the backbone network to progressively extract and compress the features of the input images layer by layer to obtain the feature map F of each layer i =B×C i ×H i ×W i , i∈[0,N-1], where F i is the hierarchical feature of the i-th layer, C i is the number of feature channels in the i-th layer, H i is the height of the feature map of the i-th layer, W i is the width of the feature map of the i-th layer; the feature map here refers to F a , F b , F c and F N-1 , this expression is not a calculation formula, but a description of the size.
[0082] Step 3) For the last layer of hierarchical features F in step 2) N-1 , through upsampling, the low-level features F of the first feature pyramid are fused one by one from top to bottom a , F b , F c , 0≤a<b<c≤(N-1), to obtain the feature F containing more semantic information i ′;
[0083] Step 4) For the last layer feature F′ in step 3) a , downsample the feature map through convolution operation, and convolute the high-level features F′ of the second feature pyramid from bottom to top b , F′ c , F′ N-1 Perform layer-by-layer fusion to obtain features containing more positioning information and form the third feature pyramid F′ a , F″ b , F″ c , F″ N-1 ;
[0084] Step 5) For the two feature maps F with lower resolution in step 4) c ″,F″ N-1 The output feature F′ is obtained by upsampling and cross-fusion with the feature maps of the same resolution in the respective upper layers a , F″ ca , F″ b , F″ (N-1)b , F c ″,F″ N-1 ;
[0085] Step 6) sending the output features in step 5) to the detection head for detection and decoding to obtain the predicted coordinates of the target on the original input image as well as the predicted category and confidence;
[0086] Step 7) Calculate the loss function between the network prediction and the true value, and use the gradient descent method to update the parameters in the above model; iterate repeatedly until the optimal parameter combination is trained;
[0087] Step 8) Detect various targets on the sea surface based on the optimal parameter model.
[0088] The step 1) specifically includes:
[0089] Step 1-1) Adaptively scale the read training set images to a size of 1280×1280×3:
[0090] Step 1-2) Mosaic data enhancement is used, that is, for each image, three additional images in the training set are randomly selected, and spliced in a random scaling, random cropping, and random arrangement manner to obtain an enhanced image;
[0091] Steps 1-3) Randomly divide the images into M groups with B images in each group.
[0092] Based on the above embodiment, the backbone network in step 2) includes a shallow feature extraction (SFE) block, three common convolutional hierarchical feature extraction (CFE) blocks, and a hierarchical feature extraction (TFPE) block based on a Transformer structure and fast spatial pyramid pooling. Except that the shallow feature extraction operation includes 2 downsamplings, the remaining steps each include only 1 downsampling, and the multiple of each downsampling is 2. Specifically:
[0093] Step 2-1) Randomly read a set of images X in , F is obtained by shallow feature extraction s , the calculation formula is as follows:
[0094] F s =SFE(X in )
[0095] in, C s is the number of feature channels in the sth layer, s∈[0,N-1], and SFE(·) represents the shallow feature extraction operation.
[0096] Step 2-2) The shallow feature F s Through the first ordinary convolutional level feature extraction block, the first layer feature map F of the feature pyramid is obtained. a ;
[0097] Step 2-3) Then add F a Through the second ordinary convolutional level feature extraction block, the second layer feature map F of the feature pyramid is obtained. b Similarly, we can get the third layer feature map F c , the calculation formula is as follows:
[0098] F a =CFE1(F s ), F b =CFE2(F a ), F c =CFE3(F b )
[0099] in, C a is the number of feature channels in layer a, C b is the number of feature channels in layer b, a, b∈[0, N-1], CFE i (·) represents the i-th (i=1, 2, 3) ordinary convolutional level feature extraction operation.
[0100] Step 2-4) F cThe top feature map F of the feature pyramid is obtained through the hierarchical feature extraction block based on the Transformer structure and fast spatial pyramid pooling. N-1 , the calculation formula is as follows:
[0101] F N-1 =TFPE(F c )
[0102] in, C N-1 is the number of feature channels in the N-1th layer, and TFPE(·) represents the hierarchical feature extraction operation based on the Transformer structure and fast spatial pyramid pooling.
[0103] So far, after passing through the backbone network, we have obtained a pyramid-shaped feature set F with four layers of resolution from large to small. a , F b , F c , F N-1 .
[0104] Figure 2 The schematic diagram of the feature pyramid network structure provided by the present invention is Figure 1 The "FPN" module in the figure. FPN includes a regular convolution block "Conv", two UCCC blocks (convolution fusion blocks), and a UCC-CBAM block with global attention (global attention fusion block). Among them, "UCCC" corresponds to upsampling "Upsample", concatenation "Concat", "C3" and convolution "Conv" layers respectively; the convolution kernel size in the "Conv" layer is 1 and the stride is 1, and "CBAM" represents the attention mechanism module of the convolution block, which is a global attention mechanism module that combines space and channels. Figure 2 As shown, step 3) outputs the pyramid feature F of the backbone network a , F b , F c , F N-1 , execute from top to bottom:
[0105] Step 3-1) First, N-1 After passing through the first regular “Conv” block, we get the feature F′ N-1 , then through the first UCCC block, that is, F′ N-1 After upsampling, the second layer feature F in the pyramid c Perform "Concat", and then perform feature fusion through the "C3" layer and the "Conv" layer to obtain F' c ;
[0106] Step 3-2) F′ c The second UCCC block fuses F bGet F′ b ;
[0107] Step 3-3) F′ b Fusion F by UCC-CBAM with global attention a Get F′ a ;
[0108] The calculation formula is as follows:
[0109] F′ N-1 =Conv(F N-1 )
[0110] F′ c =UCCC1(F′ N-1 )
[0111] F′ b =UCCC2(F c )
[0112] F′ a =UCC-CBAM(F′ b )
[0113] In the above process, the upsampling factor is 2. Except for the upsampling operation that changes the size of the feature map, the other operations only change the number of feature channels but not the size. Therefore, the feature group F′ N-1 The size is 20×20, F′ c The size is 40×40, F′ b The size is 80×80, and F′ a The size is 160×160, still forming a pyramid shape.
[0114] Figure 3 Schematic diagram of the path fusion network (PAN) structure provided by the present invention. PAN contains two CCC-CBAM blocks (global attention convolution blocks) and a CCTF-CBAM block (multiple attention block) based on the Transformer structure. Among them, "CCC" corresponds to "Conv", "Concat", and "C3" respectively; "CCTF" corresponds to "Conv", "Concat", and "C3TR" respectively. The convolution kernel size of "Conv" is 3, the step size is 2, and "C3TR" is "C3" with a Transformer structure. Figure 3 As shown, step 4) pyramid feature F′ N-1 , F′ c , F′ b , F′ a , executed from the bottom up:
[0115] Step 4-1) First, F′ aThrough the first CCC-CBAM block. That is, for F′ a Use "Conv" to downsample and then compare with F' b "Concat", then perform feature fusion through "C3" and "CBAM" to get F″ b ;
[0116] Step 4-2) F″ b Fusion of F″ via a second CCC-CBAM block c Get F″ c ;
[0117] Step 4-3) F″ c Fusion of F′ via CCTF-CBAM blocks based on Transformer structure N-1 Get F″ N-1 ;
[0118] The calculation formula is as follows:
[0119] F″ b = CCC-CBAM1(F′ a )
[0120] F″ c =CCC-CBAM2(F″ b )
[0121] F″ N-1 =CCTF-CBAM(F″ c )
[0122] So far, after passing through the neck layer of the network, a pyramid-shaped feature group F′ with four layers of resolution from large to small is obtained. a , F″ b , F″ c , F″ N-1 .
[0123] Figure 4 Schematic diagram of the feature cross fusion module provided by the present invention. The feature cross fusion module includes two feature cross fusion units UCC. Among them, "U" represents upsampling, and the upsampling factor is 4; the first "C" represents "Concat", and the second "C" represents convolution with a kernel size of 3 and a step size of 1, the purpose of which is to fuse the spliced features. Figure 4 As shown, step 5) includes:
[0124] Step 5-1) Set feature F c ′ passes through the first feature cross fusion unit UCC. That is, F c ′ after upsampling with F′ a "Concat", then use "Conv" to get the features F"ca ;
[0125] Step 5-2) Similarly, feature F″ N-1 Through another UCC Fusion F″ b Get F″ (N-1)b ;
[0126] The calculation formula is as follows:
[0127] F″ ca =UCC1(F″ c , F′ a )
[0128] F″ (N-1)b =UCC2(F″ N-1 , F″ b )
[0129] At this point, the output feature F′ is obtained a , F″ b , F″ c , F″ N-1 , F″ ca ,F″( N-1)b Among them, F″ N-1 The size is 20×20, F″ c The size is 40×40, F″ b and F″ (N-1)b The size is 80×80, F′ a and F″ ca The size is 160×160.
[0130] Figure 5 This is a schematic structural diagram of the detection head module provided by the present invention. Figure 5 The detection head in the picture shown is one of them. The number of detection heads in the detection head module corresponds to the number of output features. There are 6 detection heads in total. Each detection head contains a 1×1 "Conv" layer (Con,1, whose output size is H×W×128) to reduce the channel dimension, followed by two parallel branches, which are two 3×3 "Conv" layers (Con,3, whose output size is H×W×128). The two branches are used for classification tasks ("Cls.") and regression ("Reg.") tasks respectively. The target branch ("Obj.") is added to the regression branch, and the final Cls (whose output size is H×W×C) is obtained through a 1×1 two-dimensional convolution "Conv2d" (Conv2d,1). cls), Reg (whose output size is H×W×4) and Obj (whose output size is H×W×1). Among them, the number of channels of Cls is the number of target categories, the number of channels of Reg is 4, corresponding to the center coordinates (x, y) of the target and the height h and width w of the target, and the number of channels of Obj is 1. The value predicted by Obj represents the probability that the prediction is the target, that is, the confidence. H and W represent the size of the feature map, h and w are the sizes of the targets in the feature map, h<H, w<W.
[0131] Therefore, for the output feature F′ a , F″ b , F″ c , F″ N-1 , F″ ca , F″ (N-1)b ,like Figure 5 As shown, step 6) specifically includes:
[0132] Step 6-1) Feature F′ a After passing the corresponding detection head, three predictions Y a,Reg , Y a,Obj , Y a,cls , and then concatenate the three predictions in the channel dimension to get the prediction Y a :
[0133] Y a =Cat([Y a,Reg , Y a , O b j , Y a,Cls ],1)
[0134] Among them, "Cat" represents the concatenation operation, and "1" represents the channel dimension.
[0135] Step 6-2) Take the predicted Y in step 6-1) a The first 4 channels of , i.e. the predicted coordinates of the target, are projected onto the input image;
[0136] Step 6-3) Repeat the above steps for the remaining 5 features to get the predicted Y a , Y b , Y c , Y N-1 , Y ca , Y (N-1)b Among them, Y N-1 The size is 20×20, Y c The size is 40×40, Y b and Y (N-1)b The size is 80×80, Y a and Y ca The size is 160×160.
[0137] Based on the above embodiment, step 7 specifically includes:
[0138] According to the prediction Y a , Y b , Y c , Y N-1 , Y ca and Y (N-1)b The regression loss, target loss and classification loss are calculated respectively; the regression loss is calculated for each target in the image through the regression loss function, and the calculation formula is:
[0139] loss reg =loss iou
[0140] loss iou =-ln(iou)
[0141] Among them, loss reg is the regression loss, loss iou is a regression loss function, iou refers to the intersection-and-union ratio of the predicted box A and the true box B of each target; the predicted box A of the target is the predicted position of the target, and the true box B is the true position of the target;
[0142] The target loss is calculated for each grid of the predicted feature map; the classification loss is calculated for each target; both the target loss and the classification loss are obtained using the binary cross entropy loss function, and the calculation methods are as follows:
[0143] loss obj =loss(x obj ,y obj )
[0144] loss cls =loss(x cls ,y cls )
[0145] loss(x,y)=mean{l n , ..., l N-1}
[0146] l n =-ω n [y n logσ(x n )+(1-y n )·log(1-σ(x n ))]
[0147] Among them, loss obj is the target loss, loss clsis the classification loss, loss(x, y) is the binary cross entropy loss function, x obj is the confidence of each grid of the predicted feature map, y obj is the true confidence of each grid; x cls is the predicted category of the target, y cls is the true category of the target; N represents the number of samples, x n Indicates the score of predicting that the nth sample is a positive example, y n represents the label of the nth sample, σ represents the Sigmoid function, l n is the loss of the nth sample, ω n is the loss weight coefficient of the nth sample;
[0148] The loss between the output of the model and the true label is calculated based on the regression loss, target loss, and classification loss. The calculation formula is:
[0149] loss=loss reg +loss obj +loss cls
[0150] Update the model parameters according to the calculated loss.
[0151] Step 7-2) uses the model parameters obtained in step 7-1) as the weight value of this iteration; randomly select a group of pictures from the remaining pictures, and obtain a new parameter combination through steps 2), 3), 4), 5), 6) and 7-1); iterate repeatedly until all M groups of pictures are trained;
[0152] Step 7-3) Reshuffle the training images and go to step 1; repeat until the optimal parameter combination is trained.
[0153] On the basis of the above technical solution, the step 8) specifically includes:
[0154] Step 8-1) For the image to be tested, use bilinear interpolation to adjust the size of the image to the required size of the model input 1280×1280×3;
[0155] Step 8-2) Input the adjusted image into the optimal parameter model and obtain the prediction result after forward reasoning;
[0156] Step 8-3) The prediction result is normalized using the Sigmoid function, and then the predicted coordinate "Reg" is projected onto the input image;
[0157] Step 8-4) performs non-maximum suppression (NMS) on the prediction result in step 8-3) to obtain the final prediction result, including the location of the target in the image, the category and its confidence score.
[0158] Step 8-5) Repeat the above steps until all the images to be tested are tested.
[0159] If the image to be tested has a real label, a quantitative evaluation can be performed directly by comparing the predicted result with the real label; if the image to be tested does not have a real label, a qualitative evaluation can be performed by visualizing the predicted result on the image.
[0160] The present invention also provides a marine target detection system based on attention mechanism and feature cross-fusion, which is implemented by a marine target detection network model constructed according to any of the above methods. The system includes:
[0161] Backbone network, used for multi-level feature extraction of input images;
[0162] The neck layer is used to further fuse the multi-level features extracted by the backbone network, improve more representative context information, and obtain comprehensive semantic fusion features;
[0163] Feature pyramid network and path fusion network are used to convey strong semantic features from top to bottom and strong positioning features from bottom to top respectively;
[0164] Feature cross-fusion module, used to cross-fuse high-level features with low-level features to improve the correlation between features and information utilization;
[0165] The detection head is used to decode the final features and output the predicted category and location information.
[0166] From the above specific description of the present invention, it can be seen that the attention mechanism is introduced in the backbone network and the neck layer during the implementation of the present invention, which can comprehensively learn richer semantic information and detail information from the pixels, channels and spaces. In addition, a feature cross-fusion module is added before the detection head to cross-fuse high- and low-level features again, improve the information utilization rate between features, and further optimize the features, so that the deep learning model has stronger learning ability and robustness for maritime targets, and can more accurately identify and locate maritime targets.
[0167] It should be particularly pointed out that the purpose of the present invention is to detect marine targets, but the scope of application of the present invention is not limited to marine target detection, but is also applicable to other image / vision-based target detection. For example, when detecting targets on land, the method proposed in the present invention can also be selected for detection.
[0168] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention is described in detail with reference to the embodiments, it should be understood by those skilled in the art that any modification or equivalent replacement of the technical solutions of the present invention does not depart from the spirit and scope of the technical solutions of the present invention and should be included in the scope of the claims of the present invention.
Claims
1. A target detection method based on attention mechanism and feature cross-fusion, the method first extracts features from preprocessed training set images, and cross-refines the extracted features through feature pyramid network, path fusion network and feature cross-fusion module respectively, and introduces multiple attention mechanisms during the refining, thereby obtaining output features, sending the output features to the detection head to obtain prediction results, calculating the loss between the prediction results and the true labels, repeatedly training and adjusting model parameters according to the calculated loss, until the optimal model parameters are obtained, and then outputting the target detection network model, and then inputting the image to be detected into the network model to obtain the prediction results, and finally, decoding the prediction results to obtain the position, category and confidence of the target in the image to be detected. The method includes the following steps when establishing the target detection network model: Step 1) Data preprocessing: After scaling and enhancing the images required for training, the images are randomly divided into M groups with B images in each group; Step 2) Randomly read a group of pictures, and extract and compress the features of the input pictures layer by layer through the N-layer backbone network to obtain the feature map of each layer; Step 3) For the hierarchical features of the last layer in step 2), the low-level features are fused one by one from top to bottom through upsampling to obtain features containing more semantic information; Step 4) For the last layer of features in step 3), the feature map is downsampled through a convolution operation, and high-level features are fused layer by layer from bottom to top to obtain features containing more positioning information; Step 5) The two feature maps with lower resolution in step 4) are cross-fused by upsampling with the feature maps with the same resolution in the respective upper layers to obtain output features; Step 6) sending the output features in step 5) to the detection head for detection and decoding to obtain the predicted coordinates of the target on the original input image as well as the predicted category and confidence; Step 7) Calculate the loss function between the network prediction and the true value, and use the gradient descent method to update the parameters in the above model; iterate repeatedly until the optimal parameter combination is trained, and output the target detection network model.
2. The target detection method based on attention mechanism and feature cross fusion according to claim 1 is characterized in that: The backbone network in step 2) includes a shallow feature extraction block, three common convolutional hierarchical feature extraction blocks, and a hierarchical feature extraction block based on a Transformer structure and fast spatial pyramid pooling; wherein the shallow feature extraction operation includes 2 downsamplings, and each common convolutional hierarchical feature extraction operation and the hierarchical feature extraction operation based on a Transformer structure and fast spatial pyramid pooling each includes only 1 downsampling; and each downsampling multiple is 2; specifically, the following steps are included: Step 2-1) Randomly read a set of images X in , through the shallow feature extraction block, the shallow feature F is obtained s ; Step 2-2) The shallow feature F s Through the first ordinary convolutional level feature extraction block, the first layer feature map F of the feature pyramid is obtained. a ; Step 2-3) F a Through the second ordinary convolutional level feature extraction block, the second layer feature map F of the feature pyramid is obtained. b , and then F b Through the third ordinary convolutional level feature extraction block, the third layer feature map F of the feature pyramid is obtained c ; Step 2-4) F c The top feature map F of the feature pyramid is obtained through the hierarchical feature extraction block based on the Transformer structure and fast spatial pyramid pooling. N-1 .
3. The target detection method based on attention mechanism and feature cross fusion according to claim 1 is characterized in that: The feature pyramid network in step 3) includes a regular convolution block, two convolution fusion blocks, and a global attention fusion block; The convolution fusion block includes: an upsampling layer, a splicing layer, a C3 layer and a Conv layer; the global attention fusion block includes an upsampling layer, a splicing layer, a C3 layer and a global attention layer; the upsampling factor in the upsampling layer is 2; the convolution kernel size in the Conv layer is 1 and the step size is 1; specifically, for the feature map F a 、F b 、F c and F N-1 , perform the following steps from top to bottom: Step 3-1) First, N-1 After passing the first regular convolution block, we get the feature map F N ' -1 , and then through the first convolution fusion block, F N ' -1 After upsampling, c The concatenation is then performed, and then the features are fused through the C3 layer and the Conv layer to obtain the feature map F c ′; Step 3-2) F c ′Fuse F through the second convolutional fusion block b Get the feature map F b ′; Step 3-3) F b ′ is fused through the global attention fusion block F a Get the feature map F a ′.
4. The target detection method based on attention mechanism and feature cross fusion according to claim 1 is characterized in that: The path fusion network in step 4) includes two global attention convolution blocks and one multi-attention block; The global attention convolution block includes: Conv layer, splicing layer, C3 layer and global attention layer; the multiple attention block includes: Conv layer, splicing layer, C3 layer based on Transformer structure and global attention layer; the convolution kernel size of Conv layer is 3 and the step size is 2; specifically, for the feature map F N ' -1 、F c ′、F b ′ and F a ', perform the following steps from bottom to top: Step 4-1) First, F a ′ passes through the first global attention convolution block, that is, F a ′ is downsampled by Conv layer and F b ′, and then perform feature fusion through the C3 layer and the global attention layer to obtain the feature map F b ″; Step 4-2) F b ″Fused through the second global attention convolutional block c ′Get the feature map F c ″; Step 4-3) F c ″Fusing F through multiple attention blocks N ' -1 Get the feature map F N ″ -1 .
5. The target detection method based on attention mechanism and feature cross fusion according to claim 1, characterized in that: The step 5) comprises two feature cross fusion units; The feature cross-fusion unit includes: an upsampling layer, a concatenation layer, and a Conv layer; wherein the upsampling factor of the upsampling layer is 4; the convolution kernel size of the Conv layer is 3, and the step size is 1; specifically, for the feature map F a ′、F b ″、F c ″ and F N ″ -1 , perform the following steps: Step 5-1) Set feature F c ″Through the first feature cross-fusion unit, F c ″After upsampling, a ′ concatenated, and then the feature fusion is performed through the Conv layer to obtain the feature map F c ″ a ; Step 5-2) Set feature F N ″ -1 The feature map F is obtained by another feature cross fusion unit ( ″ N-1)b .
6. The target detection method based on attention mechanism and feature cross fusion according to claim 1, characterized in that: In step 6), the number of detection heads corresponds to the number of output features; each detection head includes a 1×1 Conv layer and two parallel branches, and the parallel branches are two 3×3 Conv layers; the two branches are used for classification tasks and regression tasks respectively; the target branch is added to the regression task branch; The final classification prediction, regression prediction and target prediction are obtained through a 1×1 two-dimensional convolution operation; the classification prediction determines which category the detected target belongs to, and the number of channels is the number of target categories; the regression prediction determines the relative position of the detected target in the image and is represented in the form of a rectangular box, with 4 channels, which correspond to the center coordinates (x, y) of the target and the height h and width w of the target respectively; the number of channels for target prediction is 1, and the predicted value is the confidence, wherein the confidence indicates the probability that the prediction is the target; specifically, the output feature map F a ′、F b ″、F c ″、F N ″ -1 、F c ' a ′ and F ( ″ N-1)b , perform the following steps: Step 6-1) Set feature F a ′After passing the corresponding detection head, three predictions Y are obtained a,Reg , Y a,Obj , Y a,Cls , and then concatenate the three predictions in the channel dimension to get the prediction Y a ; Step 6-2) Take the predicted Y in step 6-1) a The first 4 channels of are projected onto the input image; Step 6-3) For the remaining 5 features F b ″、F c ″、F N ″ -1 、F c ' a ′ and F ( ″ N-1)b Carry out steps 6-1) and 6-2) for feature F in sequence a ′, and get the predicted Y b , Y c , Y N-1 , Y ca and Y (N-1)b .
7. The target detection method based on attention mechanism and feature cross fusion according to claim 1, characterized in that: The step 7) specifically includes: Step 7-1) Based on the prediction Y a , Y b , Y c , Y N-1 , Y ca and Y (N-1)b The regression loss, target loss and classification loss are calculated respectively; the regression loss is calculated for each target in the image through the regression loss function, and the calculation formula is: loss reg =loss iou loss iou =-ln(iou) Among them, loss reg is the regression loss, loss iou is a regression loss function, iou refers to the intersection-and-union ratio of the predicted box A and the true box B of each target; the predicted box A of the target is the predicted position of the target, and the true box B is the true position of the target; The target loss is calculated for each grid of the predicted feature map; the classification loss is calculated for each target; both the target loss and the classification loss are obtained using the binary cross entropy loss function, and the calculation methods are as follows: loss obj =loss(x obj ,y obj ) loss cls =loss(x cls ,y cls ) loss(x,y)=mean{l n ,...,l N-1 } l n =-ω n [y n logσ(x n )+(1-y n )·log(1-σ(x n ))] Among them, loss obj is the target loss, loss cls is the classification loss, loss(x,y) is the binary cross entropy loss function, x obj is the confidence of each grid of the predicted feature map, y obj is the true confidence of each grid; x cls is the predicted category of the target, y cls is the true category of the target; N represents the number of samples, x n Indicates the score of predicting that the nth sample is a positive example, y n represents the label of the nth sample, σ represents the Sigmoid function, l n is the loss of the nth sample, ω n is the loss weight coefficient of the nth sample; The loss between the output of the model and the true label is calculated based on the regression loss, target loss, and classification loss. The calculation formula is: loss=loss reg +loss obj +loss cls Update model parameters according to the calculated loss; Step 7-2) uses the model parameters obtained in step 7-1) as the weight value of this iteration; randomly select a group of pictures from the remaining pictures, and obtain a new parameter combination through steps 2), 3), 4), 5), 6) and 7-1); iterate repeatedly until all M groups of pictures are trained; Step 7-3) reshuffles the training images and goes to step 1); repeatedly execute steps 1) to 7-2) until the optimal parameter combination is trained.
8. The target detection method based on attention mechanism and feature cross fusion according to claim 1, characterized in that: When the image to be detected is input into the target detection network model for detection, the following steps are specifically included: Step 8-1) For the image to be tested, use bilinear interpolation to adjust the size of the image to the size required by the model input; Step 8-2) Input the adjusted image into the optimal parameter model and obtain the prediction result after forward reasoning; Step 8-3) The prediction results are normalized using the Sigmoid function, and then the coordinates of the regression prediction are projected onto the input image; Step 8-4) performing non-maximum suppression on the prediction result in step 8-3) to obtain a final prediction result, wherein the final prediction result includes the location of the target in the image, the category and its confidence score; Step 8-5) Change another image to be tested, and repeat steps 8-1)-8-4) until all images to be tested are tested; For the final prediction results of all images, if they are test images with real labels, quantitative evaluation is performed directly by comparing the prediction results with the real labels; if they are test images without real labels, qualitative evaluation is performed by visualizing the prediction results on the images.
9. A target detection system based on attention mechanism and feature cross-fusion, implemented by a target detection network model constructed according to any one of the methods described in claims 1-8, characterized in that: The system comprises: Backbone network, used for multi-level feature extraction of input images; The neck layer is used to further fuse the multi-level features extracted by the backbone network, improve more representative context information, and obtain comprehensive semantic fusion features; Feature pyramid network, used to convey strong semantic features from top to bottom; Path fusion network, used to convey strong localization features from bottom to top; A feature cross-fusion module is used to cross-fuse high-level features with low-level features to improve the relevance and information utilization between features; and The detection head is used to decode the final features and output the predicted category and location information.
