Underwater target detection method and device based on improved YOLOv7, and medium

By improving the YOLOv7 model and combining Efficient Decoupled Head, anchorless, and FFSM attention mechanisms, the problem of balancing model accuracy and real-time performance in underwater target detection is solved, achieving more efficient underwater target detection.

CN121544870APending Publication Date: 2026-02-17BEIJING INSTITUTE OF TECHNOLOGY (ZHUHAI)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610036428.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-13
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

Existing underwater target detection algorithms struggle to balance model accuracy, real-time performance, and lightweight design, resulting in low detection efficiency and poor real-time performance in complex underwater scenarios, making it difficult to meet practical application needs.

Method used

We employ an improved YOLOv7 model, combining Efficient Decoupled Head, Anchor-free, and FFSM attention mechanisms. By designing an FFSM attention module, introducing the SimOTA algorithm, and data augmentation methods, we optimize feature extraction and detection performance.

Benefits of technology

It improves the accuracy and speed of underwater target detection, reduces the number of model parameters, achieves faster detection speed and smaller model parameter count, is suitable for complex underwater scenarios, and meets practical application needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121544870A_ABST
    Figure CN121544870A_ABST
Patent Text Reader

Abstract

The invention discloses an underwater target detection method and device based on improved YOLOv7 and a medium, and belongs to the technical field of underwater target detection, and the method comprises the steps: S100, constructing an improved YOLOv7 network; s200, acquiring an underwater image data set for training; inputting the image into an improved YOLOv7 network, and performing positive sample distribution through a SimOTA algorithm; calculating CIoU bounding box regression loss and performing back propagation optimization; acquiring an underwater image to be detected; and inputting the improved YOLOv7 network to obtain a target detection result. The improved YOLOv7 algorithm shows excellent feature extraction capability, is excellent in performance in a complex underwater scene, and has higher detection speed and smaller model parameter quantity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of underwater target detection technology, and in particular to an underwater target detection method, device and medium based on an improved YOLOv7. Background Technology

[0002] In recent years, underwater target detection has attracted much attention due to its wide application in underwater robotics, marine biology, and resource exploration. Challenges such as low visibility, light scattering, light attenuation, and device memory limitations in underwater environments have prompted researchers to propose various solutions. Traditional methods, such as template matching, edge detection, and morphological algorithms, while simple and easy to use, still have limitations in complex underwater scenarios. For example, Mathias A proposed an algorithm based on two-dimensional empirical mode decomposition (BEMD) to extract features from underwater scenes and generate spots, which has been successfully applied to fish detection.

[0003] To overcome the challenges of underwater target detection, an increasing number of researchers have explored deep learning-based underwater target detection algorithms. Currently, mainstream target detection algorithms are divided into two-stage and single-stage algorithms. Two-stage algorithms first generate candidate boxes and perform coarse localization using an RPN network, then classify and precisely localize the candidate boxes. This type of algorithm is represented by the R-CNN series, such as Fast-RCNN and Faster-RCNN. Single-stage algorithms treat the target detection task as a single regression problem, dividing the feature map extracted by the network into multiple grids and simultaneously predicting the classification and localization of objects in each grid. Representative algorithms include SSD and the YOLO series, including YOLO, YOLO9000, YOLOv3, YOLOv4, YOLOv5, YOLOX, and YOLOv6. Many researchers have achieved significant results in deep learning-based underwater target detection algorithms. For example, Zeng et al. proposed the Faster R-CNN-AON network, successfully addressing the problem of limited sample images in underwater environments. Song et al. improved the accuracy and robustness of detection by combining Boosting R-CNN with uncertainty modeling.

[0004] Zhang et al. proposed a lightweight underwater target detection method based on YOLOv4 and multi-scale attention feature fusion, which improves detection accuracy while maintaining small scale and low computational complexity. Lei et al. proposed an improved underwater target detection algorithm based on YOLOv5, using the Swin Transformer as the backbone network. By improving the multi-scale feature fusion method of the path aggregation network and the confidence loss function, they enhanced the target detection capability.

[0005] Although two-stage optimization methods have made some progress in underwater target detection, they still suffer from low efficiency, poor real-time performance, and high computational complexity. Most existing methods struggle to balance model accuracy, real-time performance, and lightweight design in underwater target detection, resulting in less than ideal real-time performance in practical applications. Therefore, when researching underwater target detection algorithms, in addition to improving detection accuracy, it is also necessary to consider the model's real-time performance and computational complexity to achieve better performance and application results. Summary of the Invention

[0006] This invention aims to address at least one of the technical problems existing in the prior art. To this end, this invention proposes an underwater target detection method, apparatus, and medium based on an improved YOLOv7 model. By designing an FFSM, introducing an EfficientDecoupled Head, and employing Strong Data Augmentation, the detection accuracy of the YOLOv7 model is significantly improved, inference speed is increased, the number of parameters is reduced, and overall performance is significantly enhanced. In the field of underwater target detection, the improved YOLOv7 algorithm demonstrates excellent feature extraction capabilities, performs exceptionally well in complex underwater scenarios, and features faster detection speed and a smaller number of model parameters.

[0007] One embodiment of the present invention provides an underwater target detection method based on an improved YOLOv7, comprising the following steps: S100, constructing an improved YOLOv7 network; the improved YOLOv7 network includes a backbone network, a neck network, and a detection head; the backbone network includes four initial convolutional modules, and multiple ELAN modules and MP modules connected sequentially, wherein the MP modules include max pooling layers and CBS modules, and the backbone network outputs feature maps at three scales; the feature maps at the three scales include shallow feature maps, mid-level feature maps, and deep feature maps; the neck network adopts a PAFPN structure, including an FFSM attention module and a CSPSPPF module, wherein the FFSM attention module includes a frequency domain feature modulation branch and a spatial domain feature modulation branch, and the CSPSPPF module includes a cross-stage partial connection node. The detection head is constructed using a fast spatial pyramid pooling structure. It is an efficient decoupled head structure containing a classification branch and a regression branch. The classification branch contains two parallel 3×3 convolutional layers, and the regression branch contains a REP module. The detection head employs an anchor-free detection mechanism. S200: Acquire the underwater image dataset for training. Input the images into the improved YOLOv7 network and perform positive sample allocation using the SimOTA algorithm. Calculate the CIoU bounding box regression loss and perform backpropagation optimization. S300: Acquire the underwater image to be detected. Input it into the improved YOLOv7 network. Extract multi-scale features from the input image through the backbone network, outputting feature maps at three scales. Input the feature maps output by the backbone network into the neck network to obtain a fused feature map. Input the fused feature map into the detection head to obtain the target detection result.

[0008] According to some embodiments of the present invention, step S100 includes: S110, adjusting the output structure of the backbone network to output feature maps at three scales; S120, improving the neck network by using a PAFPN structure for feature fusion; designing an FFSM attention mechanism to model the input feature map in the frequency domain and spatial domain respectively, and generating an enhanced feature map through feature fusion; replacing the original YOLOv7 SPPCSPC module with a CSPSPPF module; S130, improving the detection head by using an efficient decoupling head to decouple the classification task and the regression task; predicting the target center point and width and height based on the Anchor-free method; introducing a REP module in the regression branch; step S200 includes: S210, during training optimization, using the CIoU loss function to optimize bounding box regression; combining SimOTA for dynamic allocation of positive samples; using Mosaic and Mixup data augmentation methods to improve the model's generalization ability and robustness.

[0009] According to some embodiments of the present invention, the FFSM attention module includes: a frequency domain feature modulation branch, used to perform a fast Fourier transform on the input feature map, map the spatial domain features to the frequency domain, and model the amplitude information and phase information respectively; and a spatial domain feature modulation branch, used to model the local context features in the spatial domain through convolution operations.

[0010] According to some embodiments of the present invention, the core overall equation of the FFSM attention module is as follows:

[0011] ;

[0012] in Indicates input features, This represents the convolution operation. It is a computational process of feature fusion. This indicates residual operations. This is the output of the frequency domain characteristic modulation branch. This is the output of the spatial domain feature modulation branch.

[0013] According to some embodiments of the present invention, the relevant equations for the frequency domain characteristic modulation branch are as follows:

[0014] ;

[0015] ;

[0016] ;

[0017] in Representing input features Features after a 1×1 convolution operation This indicates that a Fourier transform is to be performed. This indicates that an inverse Fourier transform is being performed. This indicates the calculation of the amplitude spectrum. Indicates the calculation of the spectrum. This represents convolution modeling. This represents the convolution operation. This indicates residual operations.

[0018] The relevant equations for the spatial domain feature modulation branch are as follows:

[0019] ;

[0020] ;

[0021] ;

[0022] This represents the input features.

[0023] According to some embodiments of the present invention, the cross-stage partial connection structure reduces computation and enhances gradient flow by dividing the feature map into two parts for processing and then merging them; the fast spatial pyramid pooling structure achieves multi-scale feature extraction by cascading multiple max pooling layers, wherein all pooling layers share the same convolutional kernel.

[0024] According to some embodiments of the present invention, the calculation formula for the CIoU bounding box regression loss is as follows:

[0025] ;

[0026] ;

[0027] ;

[0028] in, Indicates the bounding box regression weights. CIoU represents the loss, which measures the overlap between the predicted bounding box and the ground truth bounding box; IOU represents the ratio of the intersection area of ​​the predicted box and the ground truth box to the union area of ​​the predicted box and the ground truth box. This represents the square of the distance between the center point of the predicted bounding box and the center point of the ground truth bounding box; It represents the square of the diagonal distance of the smallest bounding rectangle that simultaneously contains both the predicted and ground truth bounding boxes; The penalty term represents the aspect ratio, which makes the loss smaller as the aspect ratios of the predicted box and the ground truth box are closer. , These represent the width and height of the actual bounding box, respectively. , These represent the width and height of the prediction box, respectively.

[0029] According to some embodiments of the present invention, the SimOTA algorithm includes: calculating the Cost matrix, as shown in the following formula:

[0030] ;

[0031] in These are the weighting coefficients. Indicates the index of the candidate box. Indicates the index of the real bounding box. , These represent the classification loss and IoU loss between the predicted bounding box and the ground truth bounding box, respectively.

[0032] The target confidence loss function determines the feature points corresponding to each ground truth bounding box by calculating the Cost matrix. These feature points are treated as positive samples, and the rest as negative samples. A binary cross-entropy loss is calculated based on the prediction results of whether the feature points contain objects. The classification loss function extracts the class prediction result for each feature point after obtaining it. Then, based on the class of the ground truth bounding box and the class prediction results of the feature points, a binary cross-entropy loss is calculated.

[0033] ;

[0034] ;

[0035] in Indices representing feature points Indicates the true label (0 or 1). This represents the probability after taking the logarithm. This represents the probability complement after taking the logarithm; The binary cross-entropy loss between the predicted bounding box target presence probability and the true target presence label was calculated. The binary cross-entropy loss between the category score of the foreground target and the true category label was calculated.

[0036] Another embodiment of the present invention provides an underwater target detection device based on an improved YOLOv7, comprising: a network construction module for constructing an improved YOLOv7 network; the improved YOLOv7 network includes a backbone network, a neck network, and a detection head; the backbone network includes four initial convolutional modules, and multiple ELAN modules and MP modules connected in sequence, wherein the MP modules include max pooling layers and CBS modules, and the backbone network outputs feature maps at three scales; the feature maps at the three scales include shallow feature maps, mid-level feature maps, and deep feature maps; the neck network adopts a PAFPN structure, including an FFSM attention module and a CSPSPPF module, wherein the FFSM attention module includes a frequency domain feature modulation branch and a spatial domain feature modulation branch, and the CSPSPPF module includes a cross-stage partial connection structure and a fast... The system employs a spatial pyramid pooling structure. The detection head is a highly efficient decoupled head structure, comprising a classification branch and a regression branch. The classification branch contains two parallel 3×3 convolutional layers, and the regression branch contains a REP module. The detection head uses an anchor-free detection mechanism. A network training module is used to acquire a training underwater image dataset. Images are input into an improved YOLOv7 network, and positive samples are assigned using the SimOTA algorithm. The CIoU bounding box regression loss is calculated and optimized via backpropagation. A target detection module is used to acquire the underwater image to be detected. This image is input into the improved YOLOv7 network. The backbone network extracts multi-scale features from the input image, outputting feature maps at three scales. The feature maps output by the backbone network are input into the neck network to obtain a fused feature map. The fused feature map is then input into the detection head to obtain the target detection result.

[0037] Another aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method of any of the preceding embodiments.

[0038] The embodiments of the present invention include at least the following beneficial effects:

[0039] 1. This invention proposes an improved target detection network model, YOLOv7-AD, suitable for underwater environments, based on the YOLOv7 framework. This model combines techniques such as Efficient Decoupled Head, Anchor-free, and FFSM attention mechanism modules, effectively improving the detection accuracy for clustered small targets and ambiguous targets while reducing model parameters and increasing inference speed.

[0040] 2. This invention introduces an Efficient Decoupled Head in YOLOv7-AD, separating classification and regression tasks to reduce mutual interference, improve feature extraction, and thus enhance overall detection performance and better adapt to the loss function. Furthermore, this invention employs an anchorless design, simplifying the decoding process, reducing computational costs, and achieving a balance between model accuracy, inference speed, and parameter count.

[0041] 3. In the experiments conducted using the URPC dataset, our YOLOv7-AD model achieved an mAP value of 86.84 and a detection speed of 60.11 FPS, with only 35.071M parameters. The experimental results show that the improved YOLO model exhibits excellent detection accuracy and inference speed in underwater target detection, and is faster and lighter than the classic underwater target detection model, meeting the needs of efficient and accurate target detection in practical applications.

[0042] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0043] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:

[0044] Figure 1 This is a flowchart illustrating the method according to an embodiment of the present invention;

[0045] Figure 2 This is a schematic block diagram of the device according to an embodiment of the present invention;

[0046] Figure 3 This is a model architecture diagram of the improved YOLOv7 according to an embodiment of the present invention;

[0047] Figure 4 This is a block structure diagram of the improved YOLOv7 model framework in an embodiment of the present invention;

[0048] Figure 5 These are structural diagrams of different decoupling detection heads of the improved YOLOv7 according to embodiments of the present invention;

[0049] Figure 6 This is a diagram showing the overall architecture of the FFSM module according to an embodiment of the present invention;

[0050] Figure 7 A comparison chart showing the detection performance of YOLOv7 and the improved YOLOv7;

[0051] Figure 8A comparison chart of detection results for Faster-RCNN-ResNet50, YOLOv4, YOLOv5-l, YOLOX-l, and YOLOv7.

[0052] Figure label:

[0053] Network construction module 100, network training module 200, and object detection module 300. Detailed Implementation

[0054] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0055] In the description of this invention, "several" means one or more, "multiple" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0056] Terminology Explanation:

[0057] 1. BEMD (Bidimensional Empirical Mode Decomposition): A nonlinear signal processing method based on two-dimensional empirical mode decomposition for processing two-dimensional signals (such as images).

[0058] 2. RPN (Region Proposal Network): A deep learning network used to generate candidate regions (region proposals or region candidate boxes) in object detection tasks, which may contain objects of interest.

[0059] 3. R-CNN (Region-based Convolutional Neural Networks): A deep learning model for object detection. It first generates a series of candidate regions (called region proposals) that may contain objects from the image, and then classifies each candidate region through a convolutional neural network (CNN) to determine whether it contains the object and performs precise localization.

[0060] 4. SSD (Single Shot MultiBox Detector): A single-shot multibox detector, an algorithm for object detection that can simultaneously classify and regress the location of an object in a single forward propagation, thus achieving high detection speed.

[0061] 5. YOLO series: Real-time object detection algorithms, whose core idea is to treat object detection as a single regression problem. Unlike traditional detection algorithms (such as R-CNN), YOLO makes predictions directly on the entire image, including object categories and bounding boxes, thus completing detection in one go, resulting in high detection speed and good real-time performance.

[0062] 6. Faster R-CNN-AON (Faster Region-based Convolutional Neural Networks with Attention-Optimization Network): A fast region-based convolutional neural network with attention optimization network, an extended version of Faster R-CNN that introduces attention optimization network (AON) to further improve the accuracy of feature extraction and object detection.

[0063] 7. Boosting R-CNN (Boosting Region-based Convolutional Neural Networks): This type of R-CNN improves the performance of the R-CNN model through boosting techniques. Boosting is an ensemble learning method that combines multiple weak classifiers to build a strong classifier.

[0064] 8. Swing Transformer (Shifted Window Transformer): A novel neural network architecture based on Transformer, designed specifically for computer vision tasks. Its key idea is to divide the image into fixed-size, non-overlapping windows and perform self-attention computation within these windows. In subsequent layers, the window positions are shifted, enabling the model to capture global information across windows, thereby improving the expressive power of image features.

[0065] 9. ELAN (Efficient Layer Aggregation Network): The core idea of ​​ELAN is to enhance feature fusion capabilities through efficient inter-layer aggregation strategies.

[0066] 10. MP (Max Pooling) module: The max pooling module consists of max pooling (MaxPool) and CBS modules, and is a downsampling operation commonly used in convolutional neural networks.

[0067] 11. CBS (Convolution-Batch Normalization-SiLU) module: Convolution-Batch Normalization-SiLU activation function, commonly used in modern convolutional neural network architectures, combining convolution operations and regularization techniques to improve the model's learning ability and stability.

[0068] 12. CSPSPPF (Cross Stage Partial Spatial Pyramid Pooling-Fast) module: Cross Stage Partial Spatial Pyramid Pooling - Fast version, commonly used in YOLO series models, combines the advantages of cross stage partial networks and spatial pyramid pooling, and has been optimized to improve processing speed.

[0069] 13. SPPF (Spatial Pyramid Pooling-Fast) module: Spatial pyramid pooling - fast version, usually used in object detection models such as YOLO to improve the efficiency of multi-scale feature extraction.

[0070] 14. CSPNet (Cross Stage Partial Network) module: Cross Stage Partial Network enhances the gradient flow of convolutional neural networks and reduces computational cost through cross stage partial connections.

[0071] 15. ELAN-L (Efficient Layer Aggregation Network-Large) module: A large variant of ELAN, this network has more layers, higher feature dimensions, or stronger feature extraction capabilities, and is used to handle more complex tasks or larger-scale data.

[0072] 16. FPN (Feature Pyramid Network): A structure for multi-scale object detection. By constructing a pyramid structure, the network can extract features at different resolutions to process multi-scale objects.

[0073] 17. PAPPN (Path Aggregation Feature Pyramid Network): This network combines the advantages of path aggregation and FPN, further enhancing the multi-scale performance of feature pyramid networks in object detection tasks.

[0074] 18. Head Detect module: The detection head module generates the final detection results (such as the object's category and location) based on the preceding feature maps.

[0075] 19. Anchor-free method (Anchor-free Object Detection): Anchor-free object detection simplifies the detection process by avoiding the use of anchor boxes, which can generally improve efficiency and reduce the dependence on complex hyperparameter tuning.

[0076] 20. REP Module (Re-parameterization Module): This module uses a more complex model structure during the training phase to enhance the model's learning and expressive capabilities. Then, during the inference phase, it transforms this complex structure into a simpler, equivalent model to improve inference efficiency.

[0077] 21. sigmoid function: Compresses any input value to between 0 and 1, representing it as an S-shaped curve.

[0078] 22. MLP (Multilayer Perceptron): A multilayer perceptron learns complex patterns by non-linearly mapping input data through neurons in hidden layers.

[0079] 23. CIoU Loss (Complete Intersection over Union Loss): A bounding box regression loss function used in object detection tasks, designed to improve the accuracy of object bounding box prediction.

[0080] 24. SimOTA (Simplified Optimal Transport Assignment): A simplified optimal transport assignment, typically used to optimize the positive and negative sample assignment in object detection, enabling the model to learn the bounding boxes and category information of objects more effectively, while improving computational efficiency.

[0081] 25. Cost Matrix: A matrix used to quantify the "cost" or "loss" between different decisions or matches. It has applications in many scenarios, especially in tasks such as optimal allocation or object detection.

[0082] 26. Mosaic method: A data augmentation technique that generates new training samples by stitching four images together to create a single image, thereby enhancing the generalization ability and robustness of the model.

[0083] 27. Mixup method: A data augmentation technique that generates new training samples by mixing two images and their corresponding labels in a certain proportion, in order to improve the generalization ability of the model and enhance its robustness to noise and adversarial examples.

[0084] 28. Efficient Decoupled Head: This head enables the model to better handle classification and localization tasks in complex scenes, especially in scenarios with object occlusion and complex backgrounds, where it performs more robustly.

[0085] 29. URPC (Underwater Robotics Perception Challenge Dataset): An dataset specifically designed for tasks such as underwater target detection, classification, and segmentation.

[0086] Reference Figure 1 This invention proposes an underwater target detection method based on an improved YOLOv7, comprising the following steps:

[0087] S100. Construct an improved YOLOv7 network; the improved YOLOv7 network includes a backbone network, a neck network, and a detection head; the backbone network includes four initial convolutional modules, and multiple ELAN modules and MP modules connected in sequence, wherein the MP module includes a max pooling layer and a CBS module, and the backbone network outputs feature maps at three scales; the feature maps at the three scales include shallow feature maps, mid-level feature maps, and deep feature maps; the neck network adopts a PAFPN structure, including an FFSM attention module and a CSPSPPF module, wherein the FFSM attention module includes a frequency domain feature modulation branch and a spatial domain feature modulation branch, and the CSPSPPF module includes a cross-stage partial connection structure and a fast spatial pyramid pooling structure; the detection head is an efficient decoupled head structure, including a classification branch and a regression branch, wherein the classification branch includes two parallel 3×3 convolutional layers, the regression branch includes a REP module, and the detection head adopts an anchor-free detection mechanism.

[0088] S200. Obtain the underwater image dataset used for training; input the images into the improved YOLOv7 network and perform positive sample allocation using the SimOTA algorithm; calculate the CIoU bounding box regression loss and perform backpropagation optimization.

[0089] S300. Acquire the underwater image to be detected; input the improved YOLOv7 network; extract multi-scale features from the input image through the backbone network and output feature maps at three scales; input the feature maps output by the backbone network into the neck network to obtain the fused feature maps; input the fused feature maps into the detection head to obtain the target detection result.

[0090] Corresponding to the foregoing embodiments, the present invention also provides embodiments of the apparatus. Since the apparatus embodiments are essentially corresponding to the method embodiments, relevant details can be found in the description of the method embodiments.

[0091] Reference Figure 2 This invention proposes an underwater target detection device based on an improved YOLOv7, comprising:

[0092] The network construction module 100 is used to construct an improved YOLOv7 network. The improved YOLOv7 network includes a backbone network, a neck network, and a detection head. The backbone network contains four initial convolutional modules, and multiple ELAN and MP modules connected sequentially. The MP modules contain max-pooling layers and CBS modules. The backbone network outputs feature maps at three scales: shallow, mid-level, and deep feature maps. The neck network adopts a PAFPN structure, containing an FFSM attention module and a CSPSPPF module. The FFSM attention module contains a frequency domain feature modulation branch and a spatial domain feature modulation branch. The CSPSPPF module contains a cross-stage partial connection structure and a fast spatial pyramid pooling structure. The detection head is an efficient decoupled head structure, containing a classification branch and a regression branch. The classification branch contains two parallel 3×3 convolutional layers, and the regression branch contains a REP module. The detection head uses an anchor-free detection mechanism.

[0093] The network training module 200 is used to acquire the underwater image dataset for training; the images are input into the improved YOLOv7 network, and positive samples are assigned using the SimOTA algorithm; the CIoU bounding box regression loss is calculated and backpropagation optimization is performed.

[0094] The target detection module 300 is used to acquire underwater images to be detected; input the improved YOLOv7 network; extract multi-scale features from the input image through the backbone network and output feature maps at three scales; input the feature maps output by the backbone network into the neck network to obtain fused feature maps; input the fused feature maps into the detection head to obtain target detection results.

[0095] Reference Figure 3 and Figure 4 The overall network model framework of this invention mainly consists of three parts after fusion: Detection Head, Neck Network, and Backbone Network. Among them, (1) represents the backbone network for extracting main features, (2) represents the neck network for fusing features, and (3) represents the detection head network for obtaining model prediction results. Figure 4Here is a block diagram of the module structure in the model framework, where (1) represents the combination of different convolution modules, where k represents the size of the convolution kernel and s represents the convolution stride, (2) represents the upsampling module, and (3) represents the basic structure of the MP module.

[0096] (E) represents the basic structure of the ELAN module, and (E) represents the basic structure of the ELAN-L module.

[0097] I. Backbone Network:

[0098] First, features are extracted from the input image, outputting multi-scale feature maps for use by the neck network to preserve multi-level information. For example... Figure 3 As shown in (1), the backbone network consists of four convolutional modules, followed by multiple feature extractions through ELAN and MP modules. Finally, the output of the backbone network comprises the outputs of the last three ELAN modules. The MP module consists of max pooling and CBS modules, while the ELAN module consists of multiple convolutional layers, as detailed in [see section 1]. Figure 4 (3) and (4).

[0099] Figure 3 In (1), the MP1 and ELAN modules are mainly responsible for capturing local information such as edges and textures in the image and extracting feature maps of shallow fine-grained information.

[0100] II. Neck Network:

[0101] By fusing (CAT) feature maps containing both shallow, fine-grained information and deep semantic information, the lower-level network acquires more contextual information, enhancing the network model's representational capabilities. The neck network distributes multi-scale learning tasks to multiple detection heads of different sizes. This embodiment of the invention improves the SPPCSPC module into a CSPSPPF module. It integrates SPPF and CSPNet modules, improving model inference speed. Figure 3 As shown in (2), the neck network adopts a PAFPN structure. In this structure, this embodiment uses the ELAN-L module for feature extraction and the MP module for downsampling to extract feature maps of deep semantic information, thereby enhancing the model's representation ability. The feature maps undergo four fusions (CAT) of shallow fine-grained information and deep semantic information. In addition, this embodiment designs an FFSM attention mechanism in the neck network, which simultaneously utilizes the global structural information of features in the frequency domain and the local contextual information in the spatial domain to achieve adaptive enhancement of key features and suppress redundant and noisy features. After feature extraction in the backbone network and neck network, the feature maps are passed to the detection head for further extraction and fusion of information to generate the final prediction result. Figure 3As shown in (3), this embodiment uses a Head Detect module, which consists of a 1×1 convolutional layer and two parallel 3×3 convolutional layers forming a decoupled structure. See details below. Figure 3 .

[0102] III. Detection Head:

[0103] Balancing classification and regression tasks is a major challenge in object detection. To address this issue, FCOS proposes the concept of a decoupled detection head and applies it to object detection models, subsequently extending it to other anchorless object detectors such as YOLOX. The specific structure is as follows... Figure 5 As shown. Figure 5 The `ours` in this embodiment refers to a more efficient decoupled head structure designed using a Hybrid Channels strategy. This structure compresses the number of channels in the original feature map before inputting it to the detection head network, balancing the model's representational capability and hardware computational cost. While the branched structure of the decoupled detection head improves regression performance, it also increases inference cost. Therefore, this embodiment introduces a more efficient hybrid channel strategy to replace the YOLOv7 detection head, enabling the model to flexibly adjust the weights of classification and regression tasks, improving feature extraction performance while balancing representational capability and computational cost. Figure 5 As shown, the Efficient Decoupled Head comprises two parallel 3×3 convolutional layers and compresses the output channels in the REP module to reduce computational cost. Furthermore, by adjusting the width multiplier of the backbone and neck networks to α=0.5, the number of channels in each layer (i.e., the number of convolutional kernels) is scaled by a factor of 0.5, further reducing computation and resulting in faster model inference. We have improved performance while maintaining model structural stability.

[0104] In some embodiments, the present invention also employs an anchor-free method, eliminating the need for predefined anchor boxes in traditional algorithms. This saves post-processing time, improves inference speed, significantly reduces the number of design parameters, simplifies the decoding process, and lowers computational costs through a more efficient candidate box generation and filtering method. Furthermore, in some embodiments, data augmentation techniques are used to improve the model's generalization performance.

[0105] IV. FFSM:

[0106] The FFSM (Frequency-Spatial Feature Modulation) attention mechanism module is a dual-branch feature modulation structure that jointly models frequency and spatial features. It consists of two parts: a frequency branch and a spatial branch. Figure 6 As shown. Figure 6 The overall model architecture of FFSM is described. It is the input feature map. This is the output feature map. It adaptively enhances key features and suppresses redundant and noisy features by simultaneously utilizing the global structural information of features in the frequency domain and the local contextual information in the spatial domain. The FFSM module introduces a frequency domain analysis mechanism, enabling the network to explicitly model the contribution of different frequency components in the target detection task, thus better adapting to the blurring, scattering, and low contrast problems commonly found in underwater images. The spatial domain feature modulation branch focuses on capturing the spatial structural information and local texture features of the target. To fully utilize the complementarity of frequency and spatial domain features, the FFSM module fuses the two feature paths.

[0107] Its core working equation is shown in formula (6):

[0108]

[0109] in Indicates input features, This represents the convolution operation. This is a feature concatenation operation along the channel dimension. This indicates residual operations. This is the output of the frequency domain characteristic modulation branch. This is the output of the spatial domain feature modulation branch.

[0110] Reference Figure 6 The frequency domain feature modulation branch of this invention is shown in the figure: Input feature map After 1×1 convolution, the spectrum and amplitude spectrum features are generated by FFT (Fourier Transform). The amplitude features are then modeled by convolution. Subsequently, the modulated amplitude information is recombined with the original phase information and restored to the spatial domain by IFFT (Inverse Fourier Transform). This process enables the model to highlight the frequency components that are sensitive to the target structure, while suppressing invalid high-frequency or low-frequency information introduced by underwater scattering and noise. The frequency domain feature modulation branch correlation equations are shown in equations (7), (8), and (9).

[0111]

[0112]

[0113]

[0114] in Representing input features Features after a 1×1 convolution operation This indicates that a Fourier transform is to be performed. This indicates that an inverse Fourier transform is being performed. This indicates the calculation of the amplitude spectrum. Indicates the calculation of the spectrum. This represents convolution modeling. This represents the convolution operation. This indicates residual operations.

[0115] The relevant equations for the spatial domain feature modulation branch are as follows:

[0116] Reference Figure 6 The architecture of the spatial feature modulation branch is shown in the figure, and the relevant equations are shown in equations (10), (11), and (12). It directly models the input feature map in the spatial domain and extracts local context information through multi-layer convolution operations. This branch focuses on capturing the spatial structure information and local texture features of the target, which is beneficial to improving the perception ability of small-scale targets and edge regions.

[0117]

[0118]

[0119]

[0120] This represents the input features.

[0121] V. Loss Function:

[0122] The formula for calculating the overall loss in this embodiment of the experiment is shown in the following equation:

[0123]

[0124] in, This represents the bounding box regression weights; the values ​​used in the experiment were... CIoU loss ( This improved loss function measures the overlap between predicted and ground truth bounding boxes, aiming to improve the accuracy of bounding box regression. It better assesses the similarity and overlap between bounding boxes, thus enhancing the accuracy and stability of detection results.

[0125]

[0126]

[0127] Wherein, IOU represents the ratio of the area of ​​the intersection of the predicted bounding box and the ground truth bounding box to the area of ​​their union. This represents the square of the distance between the center point of the predicted bounding box and the center point of the ground truth bounding box. It represents the square of the diagonal distance of the smallest bounding rectangle that simultaneously contains both the predicted and ground truth bounding boxes. The aspect ratio penalty term is used to reduce the loss as the aspect ratios of the predicted and ground truth boxes become closer. , These represent the width and height of the actual bounding box, respectively. , These represent the width and height of the prediction box, respectively.

[0128] This embodiment uses the SimOTA method in YoloX for dynamic allocation of positive sample numbers, specifically the calculation of the Cost matrix:

[0129]

[0130] in These are the weighting coefficients. Indicates the index of the candidate box. Indicates the index of the real bounding box. , represents the classification loss and IoU loss between the predicted bounding box and the ground truth bounding box, respectively. For non-matching predicted bounding boxes, a larger penalty term is applied to filter out positive samples of the ground truth box.

[0131] The target confidence loss function determines the feature points corresponding to each ground truth bounding box by calculating the Cost matrix. These feature points are treated as positive samples, and the rest as negative samples. A binary cross-entropy loss is then calculated based on the prediction result of whether the feature point contains an object. The classification loss function extracts the class prediction result for each feature point after obtaining it. Then, based on the class of the ground truth bounding box and the class prediction result of the feature point, a binary cross-entropy loss is calculated.

[0132]

[0133]

[0134] in Indices representing feature points Indicates the true label (0 or 1). This represents the probability after taking the logarithm. This represents the complement probability after taking the logarithm. The binary cross-entropy loss between the predicted bounding box target presence probability and the true target presence label was calculated. The binary cross-entropy loss between the category score of the foreground target and the true category label was calculated.

[0135] VI. Experimental results show that:

[0136] In this embodiment of the invention, seven metrics are used to evaluate model performance: precision, recall, mean precision (AP), mean average precision (mAP), frames per second (FPS), billions of floating-point operations per second (GFLOPS), and number of parameters. Precision (P) represents the proportion of samples correctly predicted as positive out of all predicted positive samples. Recall (R) represents the proportion of samples correctly predicted as positive out of the actual number of positive samples. Mean precision (AP) is the area under the precision-recall curve at different thresholds; a higher AP value indicates higher model accuracy. Mean average precision (mAP) is the average AP value across all categories; a higher mAP value indicates better overall recognition performance. In this embodiment, the mAP threshold is set to 0.5. Frames per second (FPS) represents the number of frames processed per second by the model; a higher FPS value indicates faster inference speed and better performance. Billions of floating-point operations per second (GFLOPS) represent the computational cost required by the model and are used to measure model complexity. The number of parameters (params) is the total number of parameters in the model and is used to evaluate the size of the model.

[0137] 6(1) Ablation Experiment:

[0138] To verify the effectiveness of optimization methods such as Efficient Decoupled Head, Anchor-free, and StrongAugmentatio in target detection and their contribution to the model optimization process, this invention conducted multiple ablation experiments, gradually introducing these optimization methods and observing their impact on the detection performance of the YOLOv7-AD algorithm.

[0139] First, the embodiments of the present invention compare the performance of the improved YOLOv7 (YOLOv7-AD) and the original YOLOv7 algorithm, such as... Figure 7As shown in the figure, the first row (Original) represents the original images of the dataset, the second row (Detection) represents the images detected by YOLOv7-AD, and the third row represents the images detected by YOLOv7. Boxes in the figure mark targets with blurred appearance, low visibility, and poor recognition. The results show that YOLOv7-AD outperforms the original YOLOv7 algorithm in detecting and recognizing clustered small targets and blurred targets. This indicates that the combination of the Efficient Decoupled Head and anchor-free mapping significantly improves the model's representational ability.

[0140] Furthermore, the application of the FFSM attention mechanism enables the model to automatically learn and focus on the key features of the target, improving the target's recognizability and localization accuracy. Strong Data Augmentation, through a series of enhanced data augmentation techniques such as Mosaic and Mixup methods, increases the diversity of training samples and the robustness of the model, making it more adaptable to complex underwater environments and improving overall detection performance.

[0141] In the experiments, this embodiment of the invention used metrics such as mAP, FPS, and parameter count to evaluate the model. Four experiments were designed, progressively adding different optimization methods to the previous experimental model to demonstrate their contribution to model performance. Experiment 1 used the original YOLOv7 model. Experiment 2 added a detection head. Experiment 3 incorporated the FFSM attention mechanism. Experiment 4 introduced a data augmentation method (Strong Data Augmentation). The experimental results are shown in Table 1.

[0142] Table 1 shows the impact of fusing different modules in the model on the metrics. DH represents the detection head, which combines anchor-free and decoupled detection heads.

[0143]

[0144] By comparing the experimental data in Index1 and Index2, we found that applying the DH module improved the model's mAP by 0.72%. However, the number of parameters increased slightly, and the inference speed decreased slightly. This indicates that the efficient decoupled detection head improved the model's representation ability and the network's convergence speed, but increased the number of parameters and inference cost. In contrast, the anchorless approach improved the model's generalization ability and simplified post-processing time, so the model's inference speed (FPS) only decreased slightly.

[0145] Comparing the experimental data from Index2 and Index3, we observed that applying the FFSM attention mechanism improved the model's FPS by 1.57%, reduced the number of parameters by 13.06%, and increased mAP by 0.4%. This indicates that the FFSM attention mechanism improves the quality of feature mapping and passes it to the detection head, thereby increasing model accuracy and inference speed while reducing the number of parameters and computational cost.

[0146] Compared to Index3 and Index4, the introduction of data augmentation improved mAP by 0.11%, while the number of parameters and FPS remained largely unchanged. This indicates that increasing the amount of data improves the model's robustness and generalization ability without adding extra computational overhead.

[0147] Compared with Index1 and Index4, the improved model achieved a 1.23% increase in mAP, a 1.52% increase in FPS, and a 6.78% reduction in parameters. These results demonstrate that by designing FFSM, efficiently decoupling the detection head, and implementing data augmentation, the model significantly improves detection accuracy, increases inference speed, reduces parameters, and achieves a substantial overall performance improvement.

[0148] 6 (2) Comparative Experiment:

[0149] In this embodiment of the invention, a comparative experiment was conducted with mainstream object detection algorithms such as EfficientDet, Faster-RCNN, YOLOv4, YOLOv5, YOLOX, YOLOv7, and ACFP-YOLO. The same URPC dataset and consistent training method were used, and the performance of each model was evaluated through qualitative and quantitative analysis. The experimental results are shown in Table 2. Figure 8 The detection performance of Faster-RCNN-ResNet50, YOLOv4, YOLOv5-1, YOLOX-1, and YOLOv7 is shown. The results indicate that YOLOv5 and YOLOv7 outperform Faster-RCNN, YOLOv4, and YOLOX in detection, but false positives or false negatives still exist. YOLOv7-AD, however, demonstrates greater accuracy in object recognition, showing a significant advantage.

[0150] In the quantitative analysis, the embodiments of this invention compared the mAP, parameter count, GFLOPS, and FPS of each model. Experimental results show that YOLOv7-AD has an mAP of 86.95%, significantly outperforming other algorithms, and also showing significant improvements in detection speed and computational cost. For example, compared to Faster-RCNN (ResNet50), YOLOv7-AD improves accuracy by 13.78%, speed by 145.79%, and reduces the number of parameters by 101.679M. Compared to YOLOv5-1, YOLOv7-AD improves mAP by 0.77%, speed by 8.89%, and reduces the number of parameters by 11.577M. Compared to YOLOX-1, YOLOv7-AD improves accuracy by 1.79%, speed by 21.95%, and reduces the number of parameters by 19.079M. Compared to YOLOv7, YOLOv7-AD improves mAP by 1.23%, speed by 1.52%, and reduces the number of parameters by 2.549M. Compared to ACFP-YOLO, it improves mAP by 1.19%, speed by 5.9%, and reduces the number of parameters by 2.82M.

[0151] These results demonstrate that YOLOv7-AD, combining an efficient decoupled head, free anchors, FFSM attention mechanism, and data augmentation techniques, performs exceptionally well in real-time underwater tasks, exhibiting high detection accuracy, speed, and a low number of model parameters.

[0152] Table 2 Performance metrics for different object detection algorithms on the URPC dataset.

[0153]

[0154] VII. Implementation Method:

[0155] 7 (1), Dataset:

[0156] This invention uses the URPC2020ZJ version of the URPC2020 dataset for experiments. This dataset (5543 images) covers four target categories: scallops, sea cucumbers, starfish, and sea urchins. Due to the scarcity of aquatic plant samples, this category was ignored during training. The dataset was divided into training, validation, and test sets in an 8:1:1 ratio. Because the images in this dataset come from real marine environments, they suffer from color distortion, low contrast, blurred features, target occlusion, dense distribution, and uneven class distribution, posing significant challenges to target detection.

[0157] 7. (II) Experimental Setup and Hyperparameter Configuration:

[0158] This embodiment of the invention trained and tested all experimental data under the same hardware and system environment. The hardware environment included a 16-core vCPU Intel(R) Xeon(R) Platinum 8350C CPU@2.60GHz and an RTX 3090 (24GB) graphics card. The operating system was Ubuntu 18.04, Python 3.8, PyTorch 1.8.1, and CUDA 11.1. This embodiment of the invention used the Adam optimizer for gradient descent, with an optimizer momentum set to 0.937, a learning rate update method of cosine annealing (cos), and a maximum learning rate of 0.001. During frozen training, only the parts other than the backbone network were trained, with a batch size of 16 and a training duration of 40 epochs; during unfrozen training, the entire network model was trained, with a batch size of 10 and a training duration of 60 epochs. During training, the pre-trained weights of the backbone network were loaded, and the remaining parts were trained from scratch. The total training period was 100 epochs. All experimental parameters are shown in Table 3.

[0159] Table 3. Experimental hyperparameter settings.

[0160]

[0161] Although specific embodiments are described herein, those skilled in the art will recognize that many other modifications or alternative embodiments are also within the scope of this disclosure. For example, any of the functions and / or processing capabilities described in connection with a particular device or component can be performed by any other device or component. Furthermore, while various exemplary embodiments and architectures have been described according to embodiments of this disclosure, those skilled in the art will recognize that many other modifications to the exemplary embodiments and architectures described herein are also within the scope of this disclosure.

[0162] It will be understood by those skilled in the art that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0163] The above is a detailed description of the preferred embodiments of this application. However, this application is not limited to the above embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.

Claims

1. An underwater target detection method based on an improved YOLOv7, characterized in that, Includes the following steps: S100. Construct an improved YOLOv7 network; the improved YOLOv7 network includes a backbone network, a neck network, and a detection head; the backbone network includes four initial convolutional modules, and multiple ELAN modules and MP modules connected in sequence, wherein the MP module includes a max pooling layer and a CBS module, and the backbone network outputs feature maps at three scales; the feature maps at the three scales include shallow feature maps, mid-level feature maps, and deep feature maps; the neck network adopts a PAFPN structure, including an FFSM attention mechanism module and a CSPSPPF module, wherein the FFSM attention mechanism module includes a frequency domain feature modulation branch and a spatial domain feature modulation branch, used to jointly model the input feature map in the frequency domain and spatial domain, and the CSPSPPF module includes a cross-stage partial connection structure and a fast spatial pyramid pooling structure; the detection head is an efficient decoupled head structure, including a classification branch and a regression branch, wherein the classification branch includes two parallel 3×3 convolutional layers, the regression branch includes a REP module, and the detection head adopts an anchor-free detection mechanism; S200. Obtain the underwater image dataset used for training; input the images into the improved YOLOv7 network and perform positive sample allocation using the SimOTA algorithm; calculate the CIoU bounding box regression loss and perform backpropagation optimization. S300. Acquire the underwater image to be detected; input the improved YOLOv7 network; extract multi-scale features from the input image through the backbone network and output feature maps at three scales; input the feature maps output by the backbone network into the neck network to obtain the fused feature maps; input the fused feature maps into the detection head to obtain the target detection result.

2. The underwater target detection method based on the improved YOLOv7 according to claim 1, characterized in that, Step S100 includes: S110. Adjust the output structure of the backbone network to output feature maps at three scales. S120. Improvements to the neck network include using a PAFPN structure for feature fusion; designing an FFSM attention mechanism to model features in the frequency and spatial domains respectively, and generating enhanced feature maps through feature fusion; and replacing the original YOLOv7 SPPCSPC module with a CSPSPPF module. S130. Improvements to the detection head include adopting an efficient decoupling head to decouple the classification and regression tasks; predicting the target center point and dimensions based on the anchor-free method; and introducing a REP module into the regression branch. Step S200 includes: S210. During training and optimization, the CIoU loss function is used to optimize bounding box regression; SimOTA is combined for dynamic allocation of positive samples; and Mosaic and Mixup data augmentation methods are used to improve the model's generalization ability and robustness.

3. The underwater target detection method based on the improved YOLOv7 according to claim 1, characterized in that, The FFSM attention mechanism module includes: The frequency domain feature modulation branch is used to perform a fast Fourier transform on the input feature map, mapping the spatial domain features to the frequency domain, and modeling the amplitude and phase information respectively. The spatial feature modulation branch is used to model local context features in the spatial domain through convolution operations; The frequency domain feature modulation branch and the spatial domain feature modulation branch complement each other through feature interaction and fusion mechanisms to generate jointly enhanced feature representations.

4. The underwater target detection method based on the improved YOLOv7 according to claim 3, characterized in that, The core equation governing the FFSM attention mechanism module is as follows: ; in Indicates input features, Indicates output features, This represents the convolution operation. It is a computational process of feature fusion. This indicates residual operations. This is the output of the frequency domain characteristic modulation branch. This is the output of the spatial domain feature modulation branch.

5. The underwater target detection method based on the improved YOLOv7 according to claim 4, characterized in that, The relevant equations for the frequency domain characteristic modulation branch are as follows: ; ; ; in Representing input features Features after a 1×1 convolution operation This indicates that a Fourier transform is to be performed. This indicates that an inverse Fourier transform is being performed. This indicates the calculation of the amplitude spectrum. Indicates the calculation of the spectrum. This represents convolution modeling. This represents the convolution operation. Indicates residual operation; The relevant equations for the spatial domain feature modulation branch are as follows: ; ; 。 6. The underwater target detection method based on the improved YOLOv7 according to claim 1, characterized in that, The cross-stage partial connection structure reduces computation and enhances gradient flow by dividing the feature map into two parts for processing and then merging them; the fast spatial pyramid pooling structure achieves multi-scale feature extraction by cascading multiple max pooling layers, where all pooling layers share the same convolutional kernel.

7. The underwater target detection method based on the improved YOLOv7 according to claim 1, characterized in that, The formula for calculating the CIoU bounding box regression loss is as follows: ; ; ; in, Indicates the bounding box regression weights. CIoU represents the loss, which measures the overlap between the predicted bounding box and the ground truth bounding box; IOU represents the ratio of the intersection area of ​​the predicted box and the ground truth box to the union area of ​​the predicted box and the ground truth box. This represents the square of the distance between the center point of the predicted bounding box and the center point of the ground truth bounding box; It represents the square of the diagonal distance of the smallest bounding rectangle that simultaneously contains both the predicted and ground truth bounding boxes; The penalty term represents the aspect ratio, which makes the loss smaller as the aspect ratios of the predicted box and the ground truth box are closer. , These represent the width and height of the actual bounding box, respectively. , These represent the width and height of the prediction box, respectively.

8. The underwater target detection method based on the improved YOLOv7 according to claim 1, characterized in that, The SimOTA algorithm includes: calculating the Cost matrix, as shown in the following formula: ; in These are the weighting coefficients. Indicates the index of the candidate box. Indicates the index of the real bounding box. , These represent the classification loss and IoU loss between the predicted bounding box and the ground truth bounding box, respectively. The target confidence loss function determines the feature points corresponding to each ground truth bounding box by calculating the Cost matrix. These feature points are treated as positive samples, and the rest as negative samples. A binary cross-entropy loss is calculated based on the prediction results of whether the feature points contain objects. The classification loss function extracts the class prediction result for each feature point after obtaining it. Then, based on the class of the ground truth bounding box and the class prediction results of the feature points, a binary cross-entropy loss is calculated. ; ; in Indices representing feature points Indicates the true label (0 or 1). This represents the probability after taking the logarithm. This represents the probability complement after taking the logarithm; The binary cross-entropy loss between the predicted bounding box target presence probability and the true target presence label was calculated. The binary cross-entropy loss between the category score of the foreground target and the true category label was calculated.

9. An underwater target detection device based on an improved YOLOv7, used to implement the method as described in any one of claims 1 to 8, characterized in that, include: A network construction module is used to build an improved YOLOv7 network. The improved YOLOv7 network includes a backbone network, a neck network, and a detection head. The backbone network contains four initial convolutional modules, and multiple ELAN and MP modules connected sequentially. The MP modules include max-pooling layers and CBS modules. The backbone network outputs feature maps at three scales: shallow, mid-level, and deep feature maps. The neck network adopts a PAFPN structure, including an FFSM attention module and a CSPSPPF module. The FFSM attention module includes a frequency domain feature modulation branch and a spatial domain feature modulation branch. The CSPSPPF module includes a cross-stage partial connection structure and a fast spatial pyramid pooling structure. The detection head is an efficient decoupled head structure, including a classification branch and a regression branch. The classification branch includes two parallel 3×3 convolutional layers, and the regression branch includes a REP module. The detection head uses an anchor-free detection mechanism. The network training module is used to acquire the underwater image dataset for training; the images are input into the improved YOLOv7 network, and positive samples are assigned using the SimOTA algorithm; the CIoU bounding box regression loss is calculated and backpropagation optimization is performed. The target detection module is used to acquire underwater images to be detected; input the improved YOLOv7 network; extract multi-scale features from the input image through the backbone network and output feature maps at three scales; input the feature maps output by the backbone network into the neck network to obtain fused feature maps; input the fused feature maps into the detection head to obtain the target detection result.

10. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method of any one of claims 1 to 8.