Ship target detection method, device and readable storage medium
By introducing local sliding window branches and global sliding window branches into the YOLOv8 backbone network, combined with data enhancement processing and attention blocks, the accuracy and adaptability of surface ship detection are improved, and the problem of low detection accuracy in complex environments is solved.
Patent Information
- Application Number
- CN202410808322.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-21
AI Technical Summary
The detection accuracy of surface ship detection in complex environments is low, affected by low image resolution and brightness, and the similarity of ship shapes at different angles is high, resulting in reduced detection accuracy.
The MobileViTv2 module is used to build the initial ship detection model under the YOLOv8 backbone network architecture. It combines the local sliding window branch and the global sliding window branch, and improves the detection accuracy through data enhancement processing and attention block optimization model.
It improves the accuracy and adaptability of surface ship detection, balances detection speed and accuracy, and enhances the ability to identify ship targets with specific aspect ratios.
Smart Images

Figure CN118379696B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of target detection technology, and in particular to a ship target detection method, device and readable storage medium. Background Art
[0002] Object detection is a technology that determines the location and type of target objects based on algorithms such as image processing, computer vision, and deep learning. Compared with traditional object detection tasks, surface ship detection faces more complex detection environments and requirements.
[0003] On the one hand, affected by the image acquisition equipment and environment, the sample images collected on the water surface have problems of low resolution and low brightness, resulting in poor detection effect; on the other hand, the shapes of the same ship photographed at different angles vary greatly, and the similarity of different ships at specific angles is high, both of which will lead to reduced detection accuracy of surface ships. Summary of the invention
[0004] The problem solved by the present invention is how to improve the detection accuracy of ship targets.
[0005] In order to solve the above problems, the present invention provides a ship target detection method, device and readable storage medium.
[0006] In a first aspect, the present invention provides a ship target detection method, comprising:
[0007] Collecting ship data, performing data enhancement processing on the ship data and obtaining a ship data set;
[0008] An initial ship detection model is built based on the MobileViTv2 module under the YOLOv8 backbone network architecture, wherein the MobileViTv2 module includes a local sliding window branch and a global sliding window branch;
[0009] The initial ship detection model is trained by using the ship data set to obtain a ship target detection model, and ship target detection is performed based on the ship target detection model;
[0010] The local sliding window branch is used to extract local features of the ship data set, the global sliding window branch is used to extract global features of the ship data set, the local sliding window branch is an adaptive learning window branch, the local sliding window branch includes an attention block, and the parameters of the attention block are designed based on a preset ship aspect ratio;
[0011] The loss function of the initial ship detection model includes the classification loss function, the regression loss function and the dynamic feature learning loss function, the classification loss function is a binary cross entropy loss function, and the regression loss function is an overlap loss function;
[0012] The calculation formula of the classification loss function is:
[0013] ;
[0014] in, BCE represents the binary cross entropy loss function, N It indicates the total number of positive and negative samples after sampling of the ship prediction frame. represents the predicted classification label of the ship prediction box i, Indicates the probability that the predicted classification label of the ship prediction box i is the true classification label;
[0015] The calculation formula of the regression loss function is:
[0016] ;
[0017] ;
[0018] ;
[0019] ;
[0020] in, represents the overlap loss function, d Indicates the distance between the center point of the predicted box and the real box. c represents the minimum enclosing rectangle, represents the scale of the prediction box, Indicates the similarity between the predicted box and the true box. v represents the correction factor, A Represents the intersection area of the predicted box and the true box, B represents the union area of the predicted box and the true box, Indicates the width of the target box. Indicates the height of the target box. Indicates the width of the prediction box, Indicates the height of the prediction box;
[0021] The calculation formula of the dynamic feature learning loss function is:
[0022] ;
[0023] in, The dynamic feature learning loss function representing the probability distribution of adjacent prediction boxes, yrepresents the true value of the ship sample, Indicates the prediction value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the prediction value of the prediction box corresponding to the adjacent integer coordinates on the right side of the ship prediction box, It represents the probability corresponding to the predicted value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the probability corresponding to the predicted value of the prediction box corresponding to the adjacent integer position on the right side of the ship prediction box y.
[0024] Optionally, the collecting ship data, performing data enhancement processing on the ship data and obtaining a ship data set includes:
[0025] Collecting the ship data and manually calibrating the ship data, wherein the ship data includes pictures of ship targets in several complex environment scenes;
[0026] Performing data enhancement processing on the manually calibrated ship data to obtain target ship data;
[0027] Acquiring a public ship dataset and performing correction processing on the public ship dataset;
[0028] The corrected ship public data set is merged with the target ship data to obtain a ship data set.
[0029] Optionally, the data enhancement processing method includes at least one of mosaic processing, random perspective transformation, geometric transformation processing, and random HSV transformation.
[0030] Optionally, the YOLOv8 backbone network architecture includes a backbone network, a neck network and a head network;
[0031] The backbone network includes a MobileViTv2 module, and the MobileViTv2 module is used to extract features from an input ship sample image to obtain a first feature extraction image;
[0032] The neck network is used to perform multi-scale feature map fusion on the first feature extraction image to obtain a multi-scale detection fusion image;
[0033] The head network is used to perform feature extraction on the multi-scale detection fusion image to obtain a second feature extraction image, compare the second feature extraction image with the validation set image in the ship data set, determine a regression loss function and a classification loss function respectively, and use the regression loss function and the classification loss function to adjust the model parameters of the initial ship detection model.
[0034] Optionally, the MobileViTv2 module includes a convolution submodule, a MV2 submodule, a DMViT submodule and a SPPF submodule;
[0035] The convolution submodule is used to perform feature extraction and downsampling processing on the training set image in the ship data set to obtain a first sub-feature image;
[0036] The MV2 submodule is used to perform downsampling processing on the first sub-feature image based on the main branch path and the shortcut branch path respectively, and fuse the results of the downsampling processing to obtain a second sub-feature image;
[0037] The DMViT submodule includes the local sliding window branch, the global sliding window branch and a splicing unit, the local sliding window branch is used to extract the local features of the second sub-feature image, the global sliding window branch is used to extract the global features of the second sub-feature image, and the splicing unit is used to splice the local features and the global features to obtain a third sub-feature image;
[0038] The SPPF submodule is used to perform multi-scale feature fusion processing on the third sub-feature image to obtain the first feature extraction image.
[0039] Optionally, performing multi-scale feature map fusion on the first feature extraction image to obtain a multi-scale detection fusion image includes:
[0040] Performing feature scaling processing on the first feature extraction image by upsampling;
[0041] Performing multi-size target fusion processing on the first feature extraction image after feature scaling processing;
[0042] The first feature extraction image after the multi-scale target fusion processing is down-sampled to obtain the multi-scale detection fusion image.
[0043] In a second aspect, the present invention provides a ship target detection device, comprising:
[0044] A data acquisition module is used to collect ship data, perform data enhancement processing on the ship data and obtain a ship data set;
[0045] A ship detection model building module is used to build an initial ship detection model under the YOLOv8 backbone network architecture based on the MobileViTv2 module, wherein the MobileViTv2 module includes a local sliding window branch and a global sliding window branch;
[0046] A detection module, configured to train the initial ship detection model using the ship data set to obtain a ship target detection model, and perform ship target detection based on the ship target detection model;
[0047] The local sliding window branch is used to extract local features of the ship data set, the global sliding window branch is used to extract global features of the ship data set, the local sliding window branch is an adaptive learning window branch, the local sliding window branch includes an attention block, and the parameters of the attention block are designed based on a preset ship aspect ratio;
[0048] The loss function of the initial ship detection model includes the classification loss function, the regression loss function and the dynamic feature learning loss function, the classification loss function is a binary cross entropy loss function, and the regression loss function is an overlap loss function;
[0049] The calculation formula of the classification loss function is:
[0050] ;
[0051] in, BCE represents the binary cross entropy loss function, N It indicates the total number of positive and negative samples after sampling of the ship prediction frame. represents the predicted classification label of the ship prediction box i, Indicates the probability that the predicted classification label of the ship prediction box i is the true classification label;
[0052] The calculation formula of the regression loss function is:
[0053] ;
[0054] ;
[0055] ;
[0056] ;
[0057] in, represents the overlap loss function, d Indicates the distance between the center point of the predicted box and the real box. c represents the minimum enclosing rectangle, represents the scale of the prediction box, Indicates the similarity between the predicted box and the true box. v represents the correction factor, A Represents the intersection area of the predicted box and the true box, B represents the union area of the predicted box and the true box, Indicates the width of the target box. Indicates the height of the target box. Indicates the width of the prediction box, Indicates the height of the prediction box;
[0058] The calculation formula of the dynamic feature learning loss function is:
[0059] ;
[0060] in, The dynamic feature learning loss function representing the probability distribution of adjacent prediction boxes, y represents the true value of the ship sample, Indicates the prediction value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the prediction value of the prediction box corresponding to the adjacent integer coordinates on the right side of the ship prediction box, It represents the probability corresponding to the predicted value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the probability corresponding to the predicted value of the prediction box corresponding to the adjacent integer position on the right side of the ship prediction box y.
[0061] Optionally, the data acquisition module includes:
[0062] A calibration submodule, used to collect the ship data and manually calibrate the ship data, wherein the ship data includes pictures of ship targets in several complex environment scenes;
[0063] The target ship data submodule is used to perform data enhancement processing on the ship data after manual calibration to obtain the target ship data;
[0064] A correction submodule, used for acquiring a ship public data set and performing correction processing on the ship public data set;
[0065] The ship data set submodule is used to merge the corrected ship public data set with the target ship data to obtain a ship data set.
[0066] In a third aspect, the present invention provides an electronic device, including a memory and a processor;
[0067] The memory is used to store computer programs;
[0068] The processor is used to implement any of the ship target detection methods described above when executing the computer program.
[0069] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the ship target detection method as described in any one of the above items is implemented.
[0070] Compared with the prior art, the beneficial effects of the present invention are as follows: after collecting ship data, data enhancement processing is performed on the ship data, which can improve the quality of the collected ship data and avoid the reduction of ship detection accuracy caused by poor ship data quality; the initial ship detection model built on the lightweight YOLOv8 backbone network architecture can achieve a balance between speed and accuracy, and the MobileViTv2 module is replaced by the YOLOv8 backbone network, which can introduce a local sliding window branch on the basis of the global sliding window branch of the MobileViTv2 module, and focus on the preset ship aspect ratio parameter design. The adaptive learning window branch can automatically adjust the ship aspect ratio parameters, thereby enhancing the local feature extraction capability of the ship target detection model image while improving the adaptability to ship targets with specific aspect ratios, thereby improving the detection accuracy of surface ships. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] Figure 1 A schematic diagram of a process of detecting a ship target according to an embodiment of the present invention;
[0072] Figure 2 Schematic diagram of the process of S11 in a ship target detection method according to an embodiment of the present invention;
[0073] Figure 3 The present invention is a schematic structural diagram of a ship target detection device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0074] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0075] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein.
[0076] Reference Figure 1 The embodiment of the present invention provides a ship target detection method, comprising:
[0077] S11. Collect ship data, perform data enhancement processing on the ship data and obtain a ship data set.
[0078] It needs to be explained that the ship data here refers to the image data related to surface ships, which provides a data basis for the subsequent training of the ship target detection model. Among them, since the collection of ship data is limited by the complex environment of the water surface, data enhancement data can effectively improve the quality of ship data, thereby improving the detection accuracy of the ship target detection model. The ship target detection model refers to a model that can obtain the ship classification and ship position in the ship data by inputting ship data into the ship detection model. That is, manual calibration of ship classification and ship position is required in the ship data set, and the ship data here can be understood as ship data after manual calibration.
[0079] Usually, in order to realize the training of the ship target detection model, it is often necessary to divide the obtained ship data set into a training set, a validation set and a test set. The division here can be random division. The training set is used for training the ship target detection model, the validation set is used to adjust the hyperparameters of the ship target detection model and evaluate the performance of the ship target detection model, and the test set is used to evaluate the generalization ability and performance of the ship target detection model.
[0080] S12. Build an initial ship detection model based on the MobileViTv2 module under the YOLOv8 backbone network architecture, wherein the MobileViTv2 module includes a local sliding window branch and a global sliding window branch.
[0081] The YOLOv8 backbone network architecture has good image processing performance and flexibility, and has excellent performance in image classification and segmentation tasks. The present invention adopts the YOLOv8 network structure to build an initial ship detection model, which can effectively improve the detection accuracy of the ship target detection model, but the YOLOv8 network structure also has the problem of large consumption of computing resources. The MobileViTv2 module is a lightweight module for image processing tasks, which consumes less computing resources. The MobileViTv2 module is used as the backbone network of the YOLOv8 network structure to take into account the precise measurement accuracy and computing cost of the ship target detection model, thereby achieving the optimization of the accuracy and performance of the ship target detection model. Since the MobileViTv2 module usually only includes a global sliding window branch, it focuses on the extraction of global features of the image. In the face of images with a small proportion of ship areas, it is impossible to perform high detection. The present invention adds a local sliding window in the MobileViTv2 module to be suitable for ship detection of images with a small proportion of ship areas, thereby comprehensively improving the detection capability of the ship target detection model.
[0082] S13. Training the initial ship detection model using the ship data set to obtain a ship target detection model, and performing ship target detection based on the ship target detection model.
[0083] Specifically, the ship data set is divided into training set images, validation set images, and test set images; then the training set is used to train the initial ship detection model. During the training process, the ship target detection model continuously adjusts parameters through the back propagation algorithm to minimize the loss function, so that the ship target detection model can detect ship targets more accurately. During the training process, the ship target detection model can also be evaluated and tuned through the validation set to avoid overfitting and improve the generalization ability of the ship target detection model. After the ship target detection model is trained, the ship image to be detected is input into the trained ship target detection model, and the ship target detection model will output the location and category information of the ship target detected in the image, thereby realizing automatic detection and recognition of ship targets.
[0084] Furthermore, the ratio of the number of training set images, validation set images, and test set images is 6: 3: 1. By reasonably dividing the number ratio of training set images, validation set images, and test set images, the detection accuracy of the ship target detection model can be improved.
[0085] Among them, the local sliding window branch is used to extract local features of the ship data set, the global sliding window branch is used to extract global features of the ship data set, the local sliding window branch is an adaptive learning window branch, and the local sliding window branch includes an attention block, and the parameters of the attention block are designed based on a preset ship aspect ratio.
[0086] Furthermore, the local sliding window branch is used to extract local features of the image data in the ship dataset to improve the recognition of ship targets by the ship target detection model, while the global sliding window branch is used to extract global features of the image data in the ship dataset to improve the ship target detection model's understanding of the environment and position of the ship. An attention block is arranged in the local sliding window, and the parameters of the attention block are designed based on the preset ship aspect ratio so that the ship target detection model can automatically learn the size and shape of the window according to the aspect ratio of the ship in the ship dataset, and effectively identify ships with specific aspect ratios, thereby improving the detection accuracy of the ship target detection model.
[0087] The loss function of the initial ship detection model includes the classification loss function, the regression loss function and the dynamic feature learning loss function, the classification loss function is a binary cross entropy loss function, and the regression loss function is an overlap loss function;
[0088] The calculation formula of the classification loss function is:
[0089] ;
[0090] in, BCE represents the binary cross entropy loss function,N It indicates the total number of positive and negative samples after sampling of the ship prediction frame. represents the predicted classification label of the ship prediction box i, It represents the probability that the predicted classification label of the ship prediction box i is the true classification label. The binary cross entropy loss function is used to measure the difference between the probability distribution predicted by the ship target detection model and the actual label, thereby improving the classification ability of the ship target model for ships.
[0091] The calculation formula of the regression loss function is:
[0092] ;
[0093] ;
[0094] ;
[0095] ;
[0096] in, represents the overlap loss function, d Represents the distance between the center point of the predicted box and the real box, c represents the minimum enclosing rectangle, represents the scale of the prediction box, Indicates the similarity between the predicted box and the true box. v represents the correction factor, A Represents the intersection area of the predicted box and the true box, B represents the union area of the predicted box and the true box, Indicates the width of the target box. Indicates the height of the target box. Indicates the width of the prediction box, Represents the height of the prediction box. The overlap loss function can comprehensively evaluate the accuracy of the ship target detection model in predicting the ship location, and the correction factor can prevent the error type of the feature from being biased during the optimization of the ship target detection model, thereby more comprehensively improving the accuracy of ship target detection.
[0097] The calculation formula of the dynamic feature learning loss function is:
[0098] ;
[0099] in, The dynamic feature learning loss function representing the probability distribution of adjacent prediction boxes, y represents the true value of the ship sample, Indicates the prediction value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the prediction value of the prediction box corresponding to the adjacent integer coordinates on the right side of the ship prediction box, It represents the probability corresponding to the predicted value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the probability corresponding to the predicted value of the prediction box corresponding to the adjacent integer position on the right side of the ship prediction box y. The dynamic feature learning loss function enables the ship target detection model to focus on the distribution of the target position and the adjacent area more quickly, and realizes dynamic feature learning by minimizing the difference in the distribution probability of adjacent prediction boxes, so that the ship target detection model can better capture the subtle features around the target position, thereby improving the accuracy of the ship target detection model.
[0100] The classification loss function, the regression loss function and the dynamic feature learning loss function together constitute the loss function of the ship target detection model. By minimizing the loss function, the model parameters of the ship target detection model are continuously optimized during the training process, thereby improving the precision of the ship target detection model.
[0101] Compared with the prior art, the beneficial effects of the present invention are as follows: after collecting ship data, data enhancement processing is performed on the ship data, which can improve the quality of the collected ship data and avoid the reduction of ship detection accuracy caused by poor ship data quality; the initial ship detection model built on the lightweight YOLOv8 backbone network architecture can achieve a balance between speed and accuracy, and the MobileViTv2 module is replaced by the YOLOv8 backbone network, which can introduce a local sliding window branch on the basis of the global sliding window branch of the MobileViTv2 module, and focus on the preset ship aspect ratio parameter design. The adaptive learning window branch can automatically adjust the ship aspect ratio parameters, thereby enhancing the local feature extraction capability of the ship target detection model image while improving the adaptability to ship targets with specific aspect ratios, thereby improving the detection accuracy of surface ships.
[0102] Reference Figure 2 , step S11 comprises:
[0103] S111, collecting the ship data and manually calibrating the ship data, wherein the ship data includes pictures of ship targets in several complex environment scenes.
[0104] It needs to be explained that we first need to collect image data containing ship targets. These images can be taken in various complex environments, such as: the shooting locations are ports, seas, waterways, etc.; the shooting environments are rainy days, foggy days and nights, and the ship types can be bulk carriers, cargo ships, yachts, passenger ships and fishing boats, so as to ensure the robustness and generalization ability of the ship target detection model in various scenarios.
[0105] S112: Perform data enhancement processing on the manually calibrated ship data to obtain target ship data.
[0106] After obtaining the ship data, manual calibration is required. Manual calibration refers to manually annotating the ship targets in the image with bounding boxes or pixel-level standards to indicate the ship target areas that the ship target detection model needs to focus on during training.
[0107] The ship data after manual calibration may have problems such as insufficient sample quantity, limited angle and illumination changes, etc. By performing data enhancement processing on the ship data, the robustness and generalization ability of the ship target detection model can be effectively improved.
[0108] S113: Acquire a ship public data set, and perform correction processing on the ship public data set.
[0109] Since the ship data obtained by shooting may have insufficient samples, obtaining a public ship data set can effectively increase the richness of the ship data set, thereby improving the accuracy of the ship target detection model; and correcting the public ship data set can ensure the quality and consistency of the data. Correction processing includes but is not limited to data cleaning, annotation correction, image correction, data balancing and data format conversion.
[0110] S114: Merge the corrected ship public data set with the target ship data to obtain a ship data set.
[0111] By merging the corrected ship public dataset and target ship data, the sample data and data diversity of the ship target detection model can be increased, and the ship target categories are increased, which can improve the adaptability and robustness of the ship target detection model.
[0112] In one embodiment, the data enhancement processing method includes at least one of mosaic processing, random perspective transformation, geometric transformation processing, and random HSV transformation.
[0113] It should be explained that mosaic processing is a data enhancement method for image splicing, which randomly selects four different images and splices them into a large image, and then randomly crops and scales the large image to generate new training samples. Mosaic processing can increase the diversity of data and improve the adaptability of the target detection model to different scenes and environments.
[0114] Random perspective transformation is an extension of affine transformation. It simulates the perspective effect in real scenes by performing random perspective transformation on the image. Perspective transformation includes translation, rotation, scaling, and shearing operations. Random perspective transformation can make the ship target detection model better adapt to targets under different viewing angles and angles, and enhance the robustness of the ship target detection model.
[0115] Geometric transformation processing includes rotation, translation, scaling, mirror flipping, etc. Through geometric transformation processing, various forms of image enhancement processing can be easily performed to generate more diverse training samples. Random HSV transformation refers to HSV (Hue, Saturation, Value), which is a commonly used color space representation method. Random HSV transformation randomly adjusts the hue, saturation, and brightness of the image to increase the color diversity of the image. This method can make the model more adaptable to different lighting conditions and color changes.
[0116] The above data enhancement processing methods can be used alone or in combination. They can be flexibly selected according to task requirements and data characteristics to improve the accuracy of the ship target detection model.
[0117] In one embodiment, the YOLOv8 backbone network architecture includes a backbone network, a neck network, and a head network.
[0118] The backbone network includes a MobileViTv2 module, and the MobileViTv2 module is used to extract features from the ship data in the input ship data set to obtain a first feature extraction image.
[0119] The backbone network uses the MobileViTv2 module to extract features from the ship data in the input ship data set to obtain the first feature extraction image.
[0120] The neck network is used to perform multi-scale feature map fusion on the first feature extraction image to obtain a multi-scale detection fusion image.
[0121] The neck network is used to fuse multi-scale feature maps of the first feature extraction images from different levels and scales to obtain a multi-scale detection fusion image, thereby improving the detection capability of the ship target detection model for targets of different scales.
[0122] The head network is used to perform feature extraction on the multi-scale detection fusion image to obtain a second feature extraction image, compare the second feature extraction image with the validation set image in the ship data set, calculate a classification loss function and a regression loss function respectively, and use the classification loss function and the regression loss function to adjust the model parameters of the initial ship detection model.
[0123] The head network receives the multi-scale detection fusion image as input and is responsible for further feature extraction and processing, so as to extract more abstract and advanced feature information from the multi-scale detection fusion image to obtain the second feature extraction image. The second feature extraction image extracted by the head network is then compared with the training set image in the ship dataset to determine the classification loss function and the regression loss function. The classification loss function is used to evaluate the classification performance of the initial ship target detection model, and the regression loss function is used to evaluate the position prediction accuracy of the initial ship target detection model. The model parameters of the initial ship target detection model are adjusted by using the classification loss function and the regression loss function, thereby optimizing the performance and accuracy of the ship target detection model.
[0124] In one embodiment, the MobileViTv2 module includes a convolution submodule, a MV2 submodule, a DMViT submodule and a SPPF submodule.
[0125] The convolution submodule is used to perform feature extraction and down-sampling processing on the training set images in the ship data set to obtain a first sub-feature image, so as to achieve a smaller training set image size and retain effective information.
[0126] The MV2 submodule is used to downsample the first sub-feature image based on the main branch path and the shortcut branch path, and fuse the results of the downsampling process to obtain the second sub-feature image. Among them, the main branch path is responsible for feature extraction of the input first sub-feature image, while the shortcut branch provides a direct channel, which can bypass the main branch path and directly pass the original information to the subsequent level or module, and fuse the output of the main branch path and the shortcut branch path through the jump connection to obtain the second sub-feature image. The jump connection allows the gradient to propagate more freely in the network, avoiding the problem of gradient disappearance or explosion, so that the output can maintain a high information richness. The MV2 submodule can not only effectively reduce the amount of calculation by downsampling and jump connection, but also maintain the information richness and gradient stability of the ship target detection model, thereby improving the detection performance and efficiency of the ship target detection model.
[0127] The DMViT submodule includes the local sliding window branch, the global sliding window branch and a splicing unit, wherein the local sliding window branch is used to extract the local features of the second sub-feature image, the global sliding window branch is used to extract the global features of the second sub-feature image, and the splicing unit is used to splice the local features and the global features to obtain a third sub-feature image. The local sliding window branch helps the ship target detection model to better understand the details and local structures in the image; while the global sliding window branch helps the ship target detection model to better identify the overall structure and relationship in the second sub-feature image; the fusion of global features and local features enables the ship target detection model to better understand the image, thereby improving the detection accuracy and effect of the ship target detection model.
[0128] The SPPF submodule is used to perform multi-scale feature fusion processing on the third sub-feature image to obtain the first feature extraction image.
[0129] Specifically, the SPPF submodule can perform pooling operations at multiple scales on the third sub-feature image. These scales can be pooling windows of different sizes, such as 1x1, 2x2, 3x3, etc., which are used to capture feature information at different scales. After multi-scale pooling, a series of feature representations of different scales are obtained, and these features are fused together to achieve the fusion of multiple feature scales, which can reduce the computational complexity of the ship target detection model while improving the detection performance and robustness of multi-scale targets.
[0130] In one embodiment, performing multi-scale feature map fusion on the first feature extraction image to obtain a multi-scale detection fusion image includes:
[0131] The first feature extraction image is subjected to feature scaling processing by upsampling; upsampling can increase the size of the first feature extraction image, so that the first feature map can contain more image detail information and semantic information, so that the ship target detection model can better detect small-sized targets.
[0132] Performing multi-size target fusion processing on the first feature extraction image after feature scaling processing;
[0133] The first feature extraction image after the multi-scale target fusion processing is downsampled to obtain the multi-scale detection fusion image. Downsampling can reduce the size of the first image, reduce the calculation amount and memory consumption of the ship target detection model, retain important semantic information, and obtain a multi-scale detection fusion image with multi-scale information.
[0134] Reference Figure 3The present invention also provides a ship target detection device, comprising:
[0135] A data acquisition module is used to collect ship data, perform data enhancement processing on the ship data and obtain a ship data set;
[0136] A ship detection model building module is used to build an initial ship detection model under the YOLOv8 backbone network architecture based on the MobileViTv2 module, wherein the MobileViTv2 module includes a local sliding window branch and a global sliding window branch;
[0137] A detection module, configured to train the initial ship detection model using the ship data set to obtain a ship target detection model, and perform ship target detection based on the ship target detection model;
[0138] Among them, the local sliding window branch is used to extract local features of the ship data set, the global sliding window branch is used to extract global features of the ship data set, the local sliding window branch is an adaptive learning window branch, and the local sliding window branch includes an attention block, and the parameters of the attention block are designed based on a preset ship aspect ratio.
[0139] The loss function of the initial ship detection model includes the classification loss function, the regression loss function and the dynamic feature learning loss function, the classification loss function is a binary cross entropy loss function, and the regression loss function is an overlap loss function;
[0140] The calculation formula of the classification loss function is:
[0141] ;
[0142] in, BCE represents the binary cross entropy loss function, N It indicates the total number of positive and negative samples after sampling of the ship prediction frame. represents the predicted classification label of the ship prediction box i, Indicates the probability that the predicted classification label of the ship prediction box i is the true classification label;
[0143] The calculation formula of the regression loss function is:
[0144] ;
[0145] ;
[0146] ;
[0147] ;
[0148] in, represents the overlap loss function, d Represents the distance between the center point of the predicted box and the real box, c represents the minimum enclosing rectangle, represents the scale of the prediction box, Indicates the similarity between the predicted box and the true box. v represents the correction factor, A Represents the intersection area of the predicted box and the true box, B represents the union area of the predicted box and the true box, Indicates the width of the target box. Indicates the height of the target box. Indicates the width of the prediction box, Indicates the height of the prediction box;
[0149] The calculation formula of the dynamic feature learning loss function is:
[0150] ;
[0151] in, The dynamic feature learning loss function representing the probability distribution of adjacent prediction boxes, y represents the true value of the ship sample, Indicates the prediction value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the prediction value of the prediction box corresponding to the adjacent integer coordinates on the right side of the ship prediction box, It represents the probability corresponding to the predicted value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the probability corresponding to the predicted value of the prediction box corresponding to the adjacent integer position on the right side of the ship prediction box y.
[0152] In one embodiment, the data acquisition module includes:
[0153] A calibration submodule, used to collect the ship data and manually calibrate the ship data, wherein the ship data includes pictures of ship targets in several complex environment scenes;
[0154] The target ship data submodule is used to perform data enhancement processing on the ship data after manual calibration to obtain the target ship data;
[0155] A correction submodule, used for acquiring a ship public data set and performing correction processing on the ship public data set;
[0156] The ship data set submodule is used to merge the corrected ship public data set with the target ship data to obtain a ship data set.
[0157] An embodiment of the present invention further provides an electronic device including a memory and a processor; the memory is used to store a computer program; the processor is used to implement the above-mentioned ship target detection method when executing the computer program. The electronic device may be a computer or a server, etc.
[0158] Still another embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the ship target detection method as described above is implemented.
[0159] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc. In the present application, the unit described as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present invention. In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
[0160] Although the present invention is disclosed as above, the protection scope of the present invention is not limited thereto. Those skilled in the art may make various changes and modifications without departing from the spirit and scope of the present invention, and these changes and modifications will fall within the protection scope of the present invention.
Claims
1. A ship target detection method, characterized in that: include: Collecting ship data, performing data enhancement processing on the ship data and obtaining a ship data set; An initial ship detection model is built based on the MobileViTv2 module under the YOLOv8 backbone network architecture, wherein the MobileViTv2 module includes a local sliding window branch and a global sliding window branch; The initial ship detection model is trained by using the ship data set to obtain a ship target detection model, and ship target detection is performed based on the ship target detection model; The local sliding window branch is used to extract local features of the ship data set, the global sliding window branch is used to extract global features of the ship data set, the local sliding window branch is an adaptive learning window branch, the local sliding window branch includes an attention block, and the parameters of the attention block are designed based on a preset ship aspect ratio; The loss function of the initial ship detection model includes a classification loss function, a regression loss function and a dynamic feature learning loss function, the classification loss function is a binary cross entropy loss function, and the regression loss function is an overlap loss function; The calculation formula of the classification loss function is: ; in, BCE represents the binary cross entropy loss function, N It indicates the total number of positive and negative samples after sampling of the ship prediction frame. represents the predicted classification label of the ship prediction box i, Indicates the probability that the predicted classification label of the ship prediction box i is the true classification label; The calculation formula of the regression loss function is: ; ; ; ; in, represents the overlap loss function, d Indicates the distance between the center point of the predicted box and the real box. c represents the minimum enclosing rectangle, represents the scale of the prediction box, Indicates the similarity between the predicted box and the true box. v represents the correction factor, A Represents the intersection area of the predicted box and the true box, B represents the union area of the predicted box and the true box, Indicates the width of the target box. Indicates the height of the target box. Indicates the width of the prediction box, Indicates the height of the prediction box; The calculation formula of the dynamic feature learning loss function is: ; in, The dynamic feature learning loss function representing the probability distribution of adjacent prediction boxes, y represents the true value of the ship sample, Indicates the prediction value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the prediction value of the prediction box corresponding to the adjacent integer coordinates on the right side of the ship prediction box, It represents the probability corresponding to the predicted value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the probability corresponding to the predicted value of the prediction box corresponding to the adjacent integer position on the right side of the ship prediction box y.
2. The ship target detection method according to claim 1, characterized in that: The collecting of ship data, performing data enhancement processing on the ship data and obtaining a ship data set comprises: Collecting the ship data and manually calibrating the ship data, wherein the ship data includes pictures of ship targets in several complex environment scenes; Performing data enhancement processing on the manually calibrated ship data to obtain target ship data; Acquiring a public ship dataset and performing correction processing on the public ship dataset; The corrected ship public data set is merged with the target ship data to obtain a ship data set.
3. The ship target detection method according to claim 1, characterized in that: The data enhancement processing method includes at least one of mosaic processing, random perspective transformation, geometric transformation processing, and random HSV transformation.
4. The ship target detection method according to claim 1, characterized in that: The YOLOv8 backbone network architecture includes a backbone network, a neck network and a head network; The backbone network includes a MobileViTv2 module, and the MobileViTv2 module is used to extract features from an input ship sample image to obtain a first feature extraction image; The neck network is used to perform multi-scale feature map fusion on the first feature extraction image to obtain a multi-scale detection fusion image; The head network is used to perform feature extraction on the multi-scale detection fusion image to obtain a second feature extraction image, compare the second feature extraction image with the validation set image in the ship data set, determine a classification loss function and a regression loss function respectively, and use the classification loss function and the regression loss function to adjust the model parameters of the initial ship detection model.
5. The ship target detection method according to claim 4, characterized in that: The MobileViTv2 module includes a convolution submodule, an MV2 submodule, a DMViT submodule and an SPPF submodule; The convolution submodule is used to perform feature extraction and downsampling processing on the training set image in the ship data set to obtain a first sub-feature image; The MV2 submodule is used to perform downsampling processing on the first sub-feature image based on the main branch path and the shortcut branch path respectively, and fuse the results of the downsampling processing to obtain a second sub-feature image; The DMViT submodule includes the local sliding window branch, the global sliding window branch and a splicing unit, the local sliding window branch is used to extract the local features of the second sub-feature image, the global sliding window branch is used to extract the global features of the second sub-feature image, and the splicing unit is used to splice the local features and the global features to obtain a third sub-feature image; The SPPF submodule is used to perform multi-scale feature fusion processing on the third sub-feature image to obtain the first feature extraction image.
6. The ship target detection method according to claim 4, characterized in that: The performing multi-scale feature map fusion on the first feature extraction image to obtain a multi-scale detection fusion image comprises: Performing feature scaling processing on the first feature extraction image by upsampling; Performing multi-size target fusion processing on the first feature extraction image after feature scaling processing; The first feature extraction image after the multi-scale target fusion processing is down-sampled to obtain the multi-scale detection fusion image.
7. A ship target detection device, characterized in that: include: A data acquisition module is used to collect ship data, perform data enhancement processing on the ship data and obtain a ship data set; A ship detection model building module is used to build an initial ship detection model under the YOLOv8 backbone network architecture based on the MobileViTv2 module, wherein the MobileViTv2 module includes a local sliding window branch and a global sliding window branch; A detection module, configured to train the initial ship detection model using the ship data set to obtain a ship target detection model, and perform ship target detection based on the ship target detection model; The local sliding window branch is used to extract local features of the ship data set, the global sliding window branch is used to extract global features of the ship data set, the local sliding window branch is an adaptive learning window branch, the local sliding window branch includes an attention block, and the parameters of the attention block are designed based on a preset ship aspect ratio; The loss function of the initial ship detection model includes a classification loss function, a regression loss function and a dynamic feature learning loss function, the classification loss function is a binary cross entropy loss function, and the regression loss function is an overlap loss function; The calculation formula of the classification loss function is: ; in, BCE represents the binary cross entropy loss function, N It indicates the total number of positive and negative samples after sampling of the ship prediction frame. represents the predicted classification label of the ship prediction box i, Indicates the probability that the predicted classification label of the ship prediction box i is the true classification label; The calculation formula of the regression loss function is: ; ; ; ; in, represents the overlap loss function, d Indicates the distance between the center point of the predicted box and the real box. c represents the minimum enclosing rectangle, represents the scale of the prediction box, Indicates the similarity between the predicted box and the true box. v represents the correction factor, A Represents the intersection area of the predicted box and the true box, B represents the union area of the predicted box and the true box, Indicates the width of the target box. Indicates the height of the target box. Indicates the width of the prediction box, Indicates the height of the prediction box; The calculation formula of the dynamic feature learning loss function is: ; in, The dynamic feature learning loss function representing the probability distribution of adjacent prediction boxes, y represents the true value of the ship sample, Indicates the prediction value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the prediction value of the prediction box corresponding to the adjacent integer coordinates on the right side of the ship prediction box, It represents the probability corresponding to the predicted value of the prediction box corresponding to the integer coordinate on the left side of the ship prediction box y. Indicates the probability corresponding to the predicted value of the prediction box corresponding to the adjacent integer position on the right side of the ship prediction box y.
8. The ship target detection device according to claim 7, characterized in that: The data acquisition module comprises: A calibration submodule, used to collect the ship data and manually calibrate the ship data, wherein the ship data includes pictures of ship targets in several complex environment scenes; The target ship data submodule is used to perform data enhancement processing on the ship data after manual calibration to obtain the target ship data; A correction submodule, used for acquiring a ship public data set and performing correction processing on the ship public data set; The ship data set submodule is used to merge the corrected ship public data set with the target ship data to obtain a ship data set.
9. An electronic device, characterized in that: including memory and processor; The memory is used to store computer programs; The processor is used to implement the ship target detection method according to any one of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the ship target detection method according to any one of claims 1 to 6 is implemented.
