Underwater image detection system and method based on YOLOv8s model
By improving the YOLOv8s model, combining denoising and dynamic receptive field mechanisms, and using a dual attention mechanism for feature enhancement, the problem of noise interference in underwater image detection and detection accuracy reduction in complex backgrounds is solved, and more efficient feature extraction is achieved and detection accuracy.
Patent Information
- Application Number
- CN202411487919.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-02-14
AI Technical Summary
When existing underwater image detection algorithms deal with noise interference caused by light refraction and scattering and complex scenes where the target is highly fused with the background, the detection accuracy is reduced, making it difficult to effectively extract the complex and diverse characteristics of underwater targets.
The improved YOLOv8s model is adopted, combining the denoising mechanism and dynamic adjustment of the receptive field mechanism, and removing noise through the generation of an adversarial network, and using the dual attention mechanism for feature enhancement, and finally obtaining the target detection results through feature fusion and detection.
It significantly improves the depth and accuracy of feature extraction, enhances the adaptability to complex backgrounds, significantly improves the underwater image detection performance, improves detection accuracy and reduces model storage requirements.
Smart Images

Figure CN119445351A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image detection, and in particular to an underwater image detection system and method based on a YOLOv8s model. Background Art
[0002] Underwater image detection is a vital component of underwater exploration, aiming to accurately locate and identify objects in underwater optical images, such as fish, corals, and submarine pipelines. This not only helps underwater robots complete navigation, obstacle avoidance, and sampling tasks, but also provides important support for marine scientists in biodiversity, ecosystem, and fishery research. The application of underwater image detection technology has greatly promoted the development of marine scientific research, resource exploration, environmental protection, and underwater archaeology. For example, in marine biological research, scientists can use this technology to monitor and analyze the behavior, population distribution, and habitat of marine organisms; in environmental protection, it can detect marine pollutants and their impact on the ecosystem, and take timely protection and restoration measures; in fishery management, the technology can efficiently assess fishery resources and guide sustainable fishing; in underwater archaeology, the application of technology can help archaeologists discover and record cultural relics in complex underwater environments. However, underwater image detection faces many challenges. Due to the absorption and scattering of light in water, underwater images are usually blurred and have heterogeneous noise. These degradation problems will seriously affect the edge, texture, and color characteristics of the target, thereby reducing the accuracy and robustness of detection. Especially in deep water environments, light attenuation is more significant, resulting in a significant decrease in image quality, making target resolution more difficult. In addition, underwater targets are usually small, and often overlap and occlude, making target segmentation and positioning more complex and challenging. Furthermore, the shape, posture and lighting conditions of underwater targets change over time and environment, further increasing the diversity and complexity of targets. These factors put higher demands on the design and optimization of target detection algorithms, and it is necessary to develop detection algorithms that adapt to underwater environments to improve detection performance.
[0003] Most of the traditional underwater image detection algorithms are based on traditional feature extraction methods, such as shape, color and texture, to determine the candidate area of the object through sliding windows of different scales, and input the object features into the classifier for classification. However, these traditional methods have obvious limitations. Their feature extraction is highly dependent on manual design, which makes it difficult to effectively capture the complex and diverse changes of the target, resulting in insufficient invariance and robustness of the features, and it is difficult to cope with complex background and noise interference. For example, in the extraction of shape features, due to the refraction and scattering effects of light in water, the edges and contours of the object may be distorted and deformed, making it difficult for the detection method based on shape features to stably identify the target. In addition, the noise and background complexity in the underwater environment also make the extraction of texture features more difficult and unreliable. Therefore, the traditional target detection algorithm is only applicable to images with significant features and simple background, and has obvious limitations in practical applications. With the development of computer and deep learning technology, complex deep learning models have gradually become the research focus of underwater image detection. Compared with traditional methods, deep learning detection methods have significant advantages such as high accuracy, strong generalization ability and feature self-extraction. For example, algorithms such as YOLO, SSD, RetinaNet, R-CNN, and Fast R-CNN use convolutional neural networks (CNN) to automatically learn high-level semantic features of images without manually designing or selecting features, effectively improving feature expression and generalization capabilities. These deep learning models can simultaneously learn feature extraction and target classification tasks through end-to-end training, thus avoiding the complex feature engineering and multi-stage detection process in traditional methods, reducing computational overhead and implementation difficulty.
[0004] Although deep learning technology has shown great potential in underwater image detection, existing mainstream algorithms, such as YOLOv8s, still have some limitations when dealing with the unique challenges of underwater environments. Specifically, YOLOv8s performs poorly in dealing with noise interference caused by light refraction and scattering, and its feature extraction capability is limited in complex scenes where the target and background are highly integrated, resulting in reduced detection accuracy. Summary of the invention
[0005] The purpose of the present invention is to provide an underwater image detection system and method based on the YOLOv8s model that effectively improves the depth and accuracy of feature extraction to improve detection performance.
[0006] The purpose of the present invention can be achieved by the following technical solutions:
[0007] An underwater image detection system based on the YOLOv8s model, comprising:
[0008] Underwater image acquisition and preprocessing subsystem: used to collect underwater image data and perform preprocessing;
[0009] Target detection subsystem: used to perform target detection on preprocessed underwater image data using an improved YOLOv8s model, wherein the improved YOLOv8s model is used to obtain a feature map based on the preprocessed underwater image data by combining a denoising mechanism with a dynamic adjustment of the receptive field mechanism, and to perform feature enhancement based on the feature map using a dual attention mechanism, and then perform feature fusion and detection to obtain a target detection result;
[0010] Performance monitoring and evaluation subsystem: used to monitor and evaluate the target detection results;
[0011] Detection result display and output subsystem: used to output and display the target detection results.
[0012] Furthermore, the target detection subsystem includes:
[0013] Image input processing module: used to process the pre-processed underwater image data, including image size uniform adjustment, image normalization and random transformation;
[0014] Underwater feature denoising and enhancement module: used to remove noise based on the processed underwater image data by using Fourier analysis method and generative adversarial network to obtain a denoised underwater image, and based on the denoised underwater image, perform initial feature enhancement by using position weight calculation mechanism and dynamic receptive field convolution operation to obtain an initial feature map, wherein the generative adversarial network includes a generator and a discriminator;
[0015] A dual attention enhanced feature extraction module is used to perform feature enhancement again based on the initial feature map by combining the global spatial attention mechanism with the separation channel attention mechanism to obtain the final feature map;
[0016] Feature fusion module: used to perform feature fusion based on the final feature map to obtain fusion features;
[0017] Prediction head module: used to obtain target detection results based on the fusion features using the prediction head and calculate the loss function, where the expression for detection by the prediction head is:
[0018]
[0019] In the formula, P(class i |p) represents the calculation result of the i-th element of vector p, the probability of the current input data in category i, p = [p 1 ,…,p K ], K is the number of categories;
[0020] Calculate loss and update network module: used to update network weights using the loss function through the back propagation algorithm, and use the SGD optimization algorithm for parameter optimization.
[0021] Furthermore, the step of obtaining the denoised underwater image includes:
[0022] The processed underwater image data is converted into the frequency domain by using a two-dimensional discrete Fourier transform to obtain a Fourier transform result, including a signal part and a noise part, wherein the expression of the Fourier transform result is:
[0023]
[0024] f c (x,y)=f signal (x,y)+n scat (x,y)
[0025] In the formula, f c (x, y) is the input image of channel c, f signal (x, y) is the image signal part, n scat (x,y) is the underwater noise part of the image, is the conversion result of the noisy frequency domain, u and v are the frequency coordinates in the horizontal and vertical directions in the frequency domain, H and W are the height and width of the image, and j is an imaginary unit, which is equivalent to is the noise-free frequency domain image, i.e. the signal part, is the noise frequency image, i.e. the noise part;
[0026] The generator is used to transform the Fourier transform result Convert to near ideal frequency components Denoised frequency domain image And through the inverse Fourier transform Convert back to the spatial domain to obtain the denoised underwater image, where the expression of the denoised underwater image is:
[0027]
[0028] In the formula, f denoised (x,y) is the denoised underwater image.
[0029] Furthermore, the loss function adopted by the generative adversarial network includes a generator loss function and a discriminator loss function, and the generator loss function is:
[0030]
[0031] The discriminator loss function is:
[0032]
[0033] In the formula, is the generator loss function, is the discriminator loss function, is the adversarial loss of GAN, G and D are the generator and discriminator respectively, is the noisy frequency domain of the image, u and v are the frequency coordinates in the horizontal and vertical directions in the frequency domain, respectively. represents the expectation of the distribution of noisy signals. In other words, this expectation is to sum and average the frequency domain of all noisy images. is the L2 loss, λ is a weight coefficient, is the noise-free frequency domain, To express the expectation of the true noise-free signal distribution, For the generator Convert to near ideal frequency components The output, f denoised (x,y) is the image of channel c after denoising.
[0034] Furthermore, the step of obtaining the initial feature map includes:
[0035] Based on the denoised underwater image, global average pooling is performed, and the expression of the global average pooling is:
[0036]
[0037] Based on the denoised underwater image, global maximum pooling is performed, and the expression of the global maximum pooling is:
[0038]
[0039] The global average pooling result and the global maximum pooling result are combined to calculate the importance weight of the pixel position, where the calculation expression of the position importance weight is:
[0040] A c,h,w =σ(W gap ·GAP c,h,w +W gmp ·GMP c,h,w +b)
[0041] The importance weight is applied to the denoised underwater image to obtain an underwater image containing the weight, wherein the underwater image containing the weight is expressed as:
[0042] X′ c,h,w =A c,h,w ·X c,h,w
[0043] The underwater image containing the weight is input into the dynamic receptive field convolution to perform enhanced feature extraction, and an initial feature map is obtained, wherein the enhanced feature extraction process is expressed as:
[0044]
[0045] In the formula, GAP c,h,w is a global average pooling operation, H and W represent height and width respectively, X c,h,w For input images, GMP c,h,w To globally maximize the computational operation, A c,h,w is the weight, σ is the sigmoid activation function, W gap and W gmp is the weight matrix, b is the bias term, X′ c,h,w is the image after feature enhancement, Y′ c′,h,w is the value of the output feature map at channel c′, height h, and width w, X′ c,h+i-1,w+j-1 is the value of the input image after feature enhancement at channel c, height h+i-1, and width w+j-1, W c′,c,i,j is the weight of the convolution kernel, b c′ is the bias term.
[0046] Furthermore, the execution steps of the dual attention enhanced feature extraction module include:
[0047] Based on the initial feature map, a convolution operation is performed and a global spatial attention mechanism is used for processing to obtain a global spatial attention feature map;
[0048] Based on the initial feature map, a convolution operation is performed and a separate channel attention mechanism is used for processing to obtain a separate channel attention feature map;
[0049] The global spatial attention feature map and the separation channel attention feature map are added and convolved to obtain a final feature map.
[0050] Furthermore, the step of obtaining a global spatial attention feature map includes:
[0051] The initial feature map A after convolution is transformed to obtain a first initial feature map B, a second initial feature map C and a third initial feature map D;
[0052] The first initial feature map B and the second initial feature map C are reshaped, and then the transpose of the reshaped C and the reshaped B is matrix multiplied, and softmax is used to calculate the spatial attention map S, where the calculation expression of the spatial attention map S is:
[0053]
[0054] The third initial feature map D is reshaped, and a global spatial attention feature map is obtained based on the reshaped D and the spatial attention map S, wherein the global spatial attention feature map is expressed as:
[0055]
[0056] In the formula, S ij To measure the impact of the i-th position on the j-th position, A j , B i , C j , D i are the feature vector of the original input position j, the feature vector of the position i after the first feature map B is reshaped, the feature vector of the position j after the second feature map C is reshaped, and the feature vector of the position i of the third feature map D, respectively. ij (N) is the noise suppression factor for each specific position i, j, N is the number of pixels represented by H×W, E j is the final output feature vector of position j, combined with the feature information after the attention mechanism, s ji is the spatial attention weight, α is a parameter, and C, H, and W are channel, height, and width, respectively.
[0057] Furthermore, the step of obtaining the separation channel attention feature map includes:
[0058] The initial feature map A after convolution is reshaped, the reshaped A and the transpose of the reshaped A are matrix multiplied, and softmax is used to calculate the channel attention map X, where the calculation expression of the channel attention map X is:
[0059]
[0060] Based on the channel attention map X and the reshaped A, a separation channel attention feature map is obtained, where the separation channel attention feature map is expressed as:
[0061]
[0062] Where N is H×W, which represents the number of pixels, and E j is the feature vector of the jth channel in the output feature map, α is the parameter, x ji is the separated channel attention feature map, C, H, W are channel, height, and width respectively, A i , A j are the i-th channel of the input feature map and the j-th channel of the input feature map respectively, and β is the scaling parameter.
[0063] Furthermore, the loss function calculated in the prediction head module includes a classification loss function, a bounding box loss function and a target confidence loss function. The classification loss function is used to calculate the difference between the target category detection result and the true category. The expression of the classification loss function is:
[0064]
[0065] In the formula, Class Loss is the classification loss, N is the total number of samples, C is the total number of categories, and y i,c Indicates that the i-th sample belongs to the true label of category c. The value is 1 if the category exists, otherwise it is 0. represents the probability that the model predicts that the i-th sample belongs to category c, ∈ is additive white Gaussian noise, which is used to introduce a random factor of noise generated by the simulated underwater environment between the model prediction and the true label;
[0066] The bounding box loss function is used to calculate the deviation between the predicted target box and the real target box of the target. The expression of the bounding box loss function is:
[0067]
[0068] In the formula, Box Loss is the bounding box loss, λ coord is the weight coefficient, S 2 is the number of grid cells output by the network, B represents the number of bounding boxes predicted by each grid cell, and x i ,y i 、w i 、h i are the position parameters of the real target frame, Then is the corresponding parameter of the prediction, ∈ is the introduced noise term;
[0069] The target confidence loss function is used to calculate the gap between the target detection accuracy and the actual situation. The expression of the target confidence loss function is:
[0070]
[0071] In the formula, Objectness Loss is the target confidence loss, y i is the target confidence label of the i-th sample, is the model's confidence prediction value of whether sample i contains the target, and ∈ is the introduced noise term.
[0072] The present invention also provides an underwater image detection method based on the YOLOv8s model, comprising the following steps:
[0073] Collect underwater image data and perform preprocessing;
[0074] An improved YOLOv8s model is used to perform target detection on the preprocessed underwater image data, wherein the improved YOLOv8s model is used to obtain a feature map based on the preprocessed underwater image data by combining a denoising mechanism and a dynamic adjustment of the receptive field mechanism, and a dual attention mechanism is used to perform feature enhancement based on the feature map, and then feature fusion and detection are performed to obtain a target detection result;
[0075] Monitoring and evaluating the target detection results;
[0076] The target detection result is output and displayed.
[0077] Compared with the prior art, the present invention has the following beneficial effects:
[0078] (1) The target detection subsystem of the present invention adopts a denoising mechanism and a dynamic adjustment of the receptive field mechanism to filter out noise and dynamically adjust the receptive field to focus on the target features, thereby solving the noise problem caused by refraction and scattering in underwater optical images and improving the ability to extract underwater target features. The dual attention mechanism is then used to enhance features to enhance adaptability to complex backgrounds, thereby effectively improving the depth and accuracy of feature extraction and significantly improving underwater image detection performance.
[0079] (2) The underwater feature denoising enhancement module of the present invention uses a generative adversarial network to obtain a highly adaptable underwater noise filter for denoising, and combines adaptive receptive field weighted convolution to dynamically adjust the weight of the receptive field through the dimensional information of the input image, so that the convolution can adaptively focus on the features of specific areas when processing different scales and positions, which can effectively improve the ability to extract key features, thereby better improving the detection accuracy. The introduction of this module avoids the interference of noise in the feature extraction process while achieving efficient extraction of underwater target features.
[0080] (3) The dual attention enhanced feature extraction module of the present invention adopts the global spatial attention mechanism and the separated channel attention mechanism for feature enhancement, aiming to solve the problem of difficulty in feature extraction caused by the high fusion of underwater targets and backgrounds. In the global spatial attention mechanism, a noise suppression factor for the underwater environment is adopted, so that the module can effectively filter the interference of underwater noise while distinguishing different spatial positions, so as to focus on the target area more accurately. At the same time, the separated channel attention mechanism further strengthens the importance of target features and suppresses background noise and interference features by dynamically adjusting the weight of each channel. Compared with the traditional attention mechanism, this module can not only reduce the detection difficulties caused by the fusion of targets and backgrounds in underwater environments through improvements, but also significantly improve the target detection accuracy in complex underwater scenes.
[0081] (4) The feature fusion module of the present invention combines the improved underwater feature denoising enhancement module and the dual attention enhanced feature extraction module to add a large-size feature map output, and optimizes the downsampling, feature splicing and convolution operations that are not suitable for low-resolution underwater images. This method reduces the weight of the model while optimizing the computational efficiency of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] Figure 1 It is a schematic diagram of the system structure of the present invention;
[0083] Figure 2 It is a schematic diagram of the structure of the underwater feature noise reduction enhancement module of the present invention;
[0084] Figure 3 It is a schematic diagram of the structure of the dual attention enhancement feature extraction module of the present invention;
[0085] Figure 4 It is a schematic diagram of the global spatial attention principle of the present invention;
[0086] Figure 5 It is the principle diagram of separation channel attention of the present invention;
[0087] Figure 6 It is a detection effect diagram of the present invention. DETAILED DESCRIPTION
[0088] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.
[0089] This embodiment provides an underwater image detection system based on the YOLOv8s model. Figure 1 As shown, the system includes an underwater image acquisition and preprocessing subsystem 1, a target detection subsystem 2, a performance monitoring and evaluation subsystem 3, and a detection result display and output subsystem 4. The underwater image acquisition and preprocessing subsystem 1 is responsible for acquiring underwater images and performing preprocessing operations such as denoising, color correction and enhancement to ensure the quality and consistency of the input data. At the same time, data enhancement technology is used to generate diverse training samples to improve the robustness and generalization ability of the model. The target detection subsystem 2 performs real-time target detection on the preprocessed underwater images, identifies and locates underwater target objects, and ensures rapid response in the underwater environment. The performance monitoring and evaluation subsystem 3 is responsible for real-time monitoring and evaluation of the performance of the detection model, calculating key indicators including accuracy, recall rate and F1 score, and helping to discover and optimize the deficiencies of the model. The detection result display and output subsystem 4 intuitively displays the detected results, such as marking the target position on the image, generating a detection report, or outputting the results in other forms for users to view and analyze.
[0090] The specific implementation steps of the underwater image acquisition and preprocessing subsystem 1 are as follows:
[0091] Acquire image data from underwater environments, perform preprocessing, and then enhance to form a dataset: This case uses the underwater optical target detection intelligent algorithm dataset URPC 2020 as the main dataset, which consists of 5543 images, all of which were taken in a real underwater environment. The entire dataset includes four target detection categories: sea cucumbers, sea urchins, scallops, and starfish. The data enhancement subsystem divides the dataset training set, test set, and validation set in a ratio of 8:1:1.
[0092] The specific implementation steps of the target detection subsystem 2 are as follows:
[0093] First, the YOLOv8s model is improved, a network structure based on the YOLOv8s model is established, and it is initialized: the target detection subsystem 2 is responsible for building the network. First, a new underwater feature denoising and enhancement module 12 is designed. By combining the underwater image denoising mechanism and the mechanism of dynamically adjusting the receptive field, the model's ability to extract underwater target features is improved. Then, a dual attention enhancement feature extraction module 13 is added to enhance the model's adaptability to complex backgrounds. Through these improvements, the target detection subsystem 2 builds a detection model that can better adapt to underwater environmental targets, and then initializes the network.
[0094] The subsystem mainly includes an image input processing module 11, an underwater feature denoising and enhancement module 12, a dual attention enhancement feature extraction module 13, a feature fusion module 14, a prediction head module 15, and a loss calculation and updating network module 16.
[0095] 1) After the data is input into the target detection subsystem 2, the system passes the data to the input image for processing through the image input processing module 11. The input image usually has different resolutions and sizes, while the detection model requires the input image to have a fixed size. Therefore, the image input processing module 11 adjusts the input image to a model input size of 640×640 pixels, and then performs image normalization to scale the image pixel values to a uniform range [0,1] to increase the model training speed and accelerate convergence. Subsequently, the image is randomly transformed through data enhancement to increase the diversity of the data set and thus enhance the generalization ability of the model. Commonly used data enhancement methods include rotation, flipping, cropping, scaling, and color jittering. After completion, the data set is input into the feature extraction module.
[0096] 2) In the feature map extraction module, the underwater feature denoising and enhancement module 12 is first used to process the data set to enhance the feature extraction of targets in the underwater environment. This module is divided into two steps. The purpose of the first step is to address the noise problem that is prevalent in the underwater environment by suppressing specific noise frequency components in the frequency domain, and then applying the inverse Fourier transform to convert the image back to the spatial domain, thereby obtaining a clearer feature map. The specific steps for processing to filter out these noises are as follows:
[0097] For the input underwater image, assuming the dimension is (C, H, W), the image f of its channel c c (x, y) is composed of the signal part and the underwater noise part, respectively signal (x,y) and n scat (x,y) is:
[0098] f c (x,y)=f signal (x,y)+n scat (x,y)
[0099] Next, the image is converted to the frequency domain using a two-dimensional discrete Fourier transform. The formula for the two-dimensional Fourier transform is as follows:
[0100]
[0101] Next, the result of the Fourier transform can be divided into the signal part and the noise part:
[0102]
[0103] in, Corresponding to the performance of scattered noise in the frequency domain, due to n scat (x, y) itself has a certain degree of randomness and complex structure. It is difficult to effectively filter out these noises simply by using filters. Therefore, the advantage of introducing the generative adversarial network (GAN) is that it can use deep learning methods to distinguish between signals and noises better when learning this distribution according to the different frequency distributions of noise and signals in the frequency domain, thereby generating more accurate denoising results and generating frequencies close to the original signals to achieve the purpose of eliminating noise. The following are the details of the generative adversarial network:
[0104] The network consists of a generator G and a discriminator D. The generator uses a convolutional neural network (CNN) structure to transform the input noisy frequency domain Mapping to the frequency domain for denoising The discriminator uses the frequency domain output by the generator to determine whether the frequency domain comes from the noise-free frequency domain. Or the denoised frequency domain generated by the generator During the calculation process, the goal of the generator is to minimize the following loss function:
[0105]
[0106] Among them, the first term is the adversarial loss of GAN, which is used to train the generator to deceive the discriminator, and the second term is the L2 loss, which ensures that the image generated by the generator is as close as possible to the frequency domain of the noise-free image in the frequency domain. At the same time, the goal of the discriminator is to maximize the following loss function:
[0107]
[0108] After the calculation is completed, the generator will input Convert to near ideal frequency components Output Then the denoised frequency domain image is converted back to the spatial domain by inverse Fourier transform to obtain the denoised channel c image:
[0109]
[0110] After obtaining the noise-eliminating dataset, the data is input into the dynamic receptive field convolution. This convolution is designed to solve the problem that underwater targets and backgrounds are highly similar, which makes feature extraction difficult. Figure 2 As shown. The module introduces a calculation mechanism for position importance weights before the convolution operation to effectively improve the ability to extract key features, thereby better improving the detection accuracy. The specific details of this module are as follows: Assume that the dimension of the input image of the current input module is (C, H, W), where C is the number of channels, H is the height, and W is the width. This module needs to calculate the importance weight of each position before the convolution operation to enhance the feature extraction effect. It is divided into three steps: calculating global average pooling and global maximum pooling, combining pooling results and calculating weights, and applying the calculated weights. First, the specific calculation process of the first step, global average pooling, is introduced:
[0111]
[0112] Global maximization calculation process:
[0113]
[0114] This step means finding the maximum value among all positions of channel c.
[0115] Then combine the pooling results and calculate the weights. The formula is as follows:
[0116] A c,h,w =σ(W gap ·GAP c,h,w +W gmp ·GMPc,h,w +b)
[0117] σ is the sigmoid activation function, W gap and W gmp is the weight matrix and b is the bias term.
[0118] Finally, the obtained weights are applied to the input feature map, thus completing the feature enhancement effect:
[0119] X′ c,h,w =A c,h,w ·X c,h,w
[0120] Then, the enhanced feature extraction process is completed by combining with standard convolution. The specific details are shown in the formula:
[0121]
[0122] where Y′ c′,h,w is the value of the output feature map at channel c′, height h, and width w, X′ c,h+i-1,w+j-1 is the value of the input image after feature enhancement at channel c, height h+i-1, and width w+j-1, W c′,c,i,j is the weight of the convolution kernel, b c′ is the bias term.
[0123] Then, the output feature map of the underwater feature denoising and enhancement module 12 is input to the dual attention enhancement feature extraction module 13, which is shown in the attached figure. Figure 3 As shown in the figure, the input feature map is convolved twice to generate feature maps with one eighth of the original number of channels, recorded as (C / 8, H, W), and then the two feature maps enter an attention channel respectively. The first attention channel is the global spatial attention, as shown in Figure 4 As shown in the figure, this channel updates specific features by weighting and weighted sum of all position features. The weight is determined by the feature similarity between two positions, so as to effectively extract meaningful spatial features. In this channel, a convolution layer is first used to transform the input feature map A into three new feature maps B, C and D, whose sizes are (C / 8, H, W). Then, B and C are reshaped into (C / 8×N), where N is H×W, which represents the number of pixels. Then, the transposed matrix multiplication of C and B is performed, and the spatial attention map S is calculated using the softmax layer. The details are as follows:
[0124]
[0125] Among them, γ ij (N) is the noise suppression factor for each specific location i, j. This allows the feature weights to be dynamically adjusted based on the different noise levels at the location, reducing the impact of noise on the specific location.ji Measure the influence of the i-th position on the j-th position. For the third feature map D, it is also reshaped to (C / 8×N), multiplied by the transpose of D and S, and the result is reshaped back to (C / 8, H, W), and finally multiplied by the parameter α, and the initial feature map A of the input channel is summed to obtain the final output E:
[0126]
[0127] The parameter α is initialized to 0 and gradually increases through the learning process. Another attention channel is the separation channel attention, such as Figure 5 As shown, unlike the global spatial attention, the features are directly reshaped from (C / 8,H,W) to (C / 8×N), and then the matrix multiplication between the reshaped feature map A and its transpose is performed, and a softmax layer is used to obtain the channel attention map X:
[0128]
[0129] Among them, x ji It measures the influence of the i-th channel on the j-th channel. Finally, perform matrix multiplication between the transpose of X and A, reshape the result back to (C / 8, H, W), multiply the result by a scaling parameter β and perform element-wise summation with A to obtain the final feature map E, where each output channel E j for:
[0130]
[0131] β is a parameter learned during the training process. Similar to α, β is also learned through training, and the final output feature is the weighted sum of all channels and original features. In the next step, after performing a convolution operation on the two channels, the feature maps of the two channels are added together, and then a convolution operation is performed to restore the number of feature map channels to (C, H, W), and the final output of the dual attention enhancement feature extraction module 13 is obtained. At the same time, the data is input into the feature fusion module 14 for feature fusion.
[0132] 3) Then the prediction head module 15 performs category prediction and position regression on the input respectively, and outputs losses, including classification loss (Class Loss), bounding box loss (Box Loss) and target confidence loss (Objectness Loss). These independent loss functions are weighted and aggregated to form the total loss of the loss function. The choice of weights depends on the specific task requirements and training strategies:
[0133] 31) The input feature map is passed through a series of convolutional layers and activation functions to extract higher-level features. The feature map is then further processed by the convolutional layer to generate an output feature map. The output feature map is then mapped to the dimension of the number of categories, that is, the number of categories for each candidate box. Finally, softmax is used to convert the input features into a probability distribution. Assume that the input of softmax is a vector p=[p 1 ,…,p K ], then the formula of the softmax function is:
[0134]
[0135] Where P(class i |p) represents the calculation result of the i-th element of vector p, the probability of the current input data in category i, and K represents the number of categories.
[0136] 32) This step calculates the classification loss (Class Loss) function based on the obtained prediction information. The cross entropy loss between the true category label and the model's predicted probability is calculated to measure the difference between the model's classification output and the true category. During the training process, the classification performance of the model is optimized by minimizing the classification loss. The formula is as follows:
[0137]
[0138] Among them, N represents the total number of samples, C represents the total number of categories, and y i,c Indicates that the i-th sample belongs to the true label of category c. The value is 1 if the category exists, otherwise it is 0. Represents the probability that the model predicts that the i-th sample belongs to category c. ∈ is additive white Gaussian noise, which is used to introduce random factors of noise generated by simulating underwater environment between model prediction and true label, which can help the model better adapt to the uncertainty and complexity of underwater environment, improve training effect, and thus improve the accuracy of detection results.
[0139] 33) At the same time, the bounding box loss (Box Loss) is used to measure the deviation between the predicted target box position and the actual target box. By minimizing this loss, the target positioning accuracy of the target detection model can be optimized. The loss function is presented in the form of squared error, and the specific formula is:
[0140]
[0141] In the formula, λ coord is the weight coefficient used to balance the target box position error and other loss terms; S 2 is the number of grid cells output by the network, and B represents the number of bounding boxes predicted by each grid cell. i,y i , w i ,h i are the position parameters of the real target box, and is the corresponding parameter predicted by the model. The introduction of the noise term ∈ is intended to enhance the robustness of the model in target positioning in complex underwater environments.
[0142] 34) Finally, the objectness loss is calculated to evaluate the gap between the model's accuracy in determining whether the target exists and the actual situation. By optimizing this loss, the model's ability to distinguish in target detection tasks is improved. This loss function is usually expressed using the cross entropy loss function, and the formula is as follows:
[0143]
[0144] Where N is the total number of samples, y i is the target confidence label of the i-th sample, is the model's confidence prediction value of whether sample i contains the target. The introduction of the noise term ∈ helps to deal with unpredictable changes in complex underwater environments, thereby improving the adaptability and robustness of the model.
[0145] 4) Calculate the loss update network module 16 to use the loss function to update the network weights through the back propagation algorithm, and apply the SGD optimization algorithm to optimize the parameters:
[0146] 41) Initialization parameters: set the initial weight w t is a model parameter, and the learning rate α is used as the step size of gradient descent to control the magnitude of each update.
[0147] 42) Calculate the gradient: Calculate the loss function f(w t ) For the weight w t gradient in It is the partial derivative of the loss function with respect to the weight, reflecting the impact of the current weight on the loss.
[0148] 43) Update weights: Use the gradient information to update the weights according to the following formula:
[0149] w t+12 =w t -α·g t
[0150] Here α is the learning rate. By adjusting the learning rate, the size of each weight update can be controlled to ensure that the model gradually converges.
[0151] 44) Iterative update: Repeat the above steps in each iteration, and gradually adjust the weights to gradually reduce the loss function of the model until the optimal solution is reached.
[0152] During the calculation process, the performance monitoring and evaluation subsystem 3 will continuously use the validation set to evaluate the model until the model achieves the expected effect. The output subsystem will output the final result to obtain the predicted underwater target prediction result.
[0153] The specific execution steps of the performance monitoring and evaluation subsystem 3 include:
[0154] 1) In the performance monitoring and evaluation subsystem 3, a validation set independent of the training set is used for intermittent validation. After each training period, the model is evaluated on the validation set to calculate key performance indicators (such as validation loss, accuracy, recall, and F1 score). These indicators can help determine the current generalization ability and actual performance of the model.
[0155] 2) If the verification result does not meet the expected goal, the system will make corresponding adjustments based on the performance evaluation results. Specific adjustment measures may include optimizing hyperparameters (such as learning rate, batch size, etc.), adjusting the network structure, modifying the data enhancement strategy, etc. These adjustments will be applied to the model, and then the system will continue to repeat the training and evaluation process from target detection subsystem 2 to performance monitoring and evaluation subsystem 3. If the verification results meet the goal for several consecutive times, or the training reaches the preset maximum number of iterations (epochs), the system will automatically perform the last verification and display the final verification results.
[0156] After passing the performance monitoring and evaluation subsystem 3, the test result display and output subsystem 4 will use the test set to conduct a final test on the robustness and generalization of the model and output the results.
[0157] In actual detection applications, the performance monitoring and evaluation subsystem 3 monitors the actual detection results in real time and evaluates the actual evaluation performance.
[0158] The specific implementation steps of the test result display and output subsystem 4 are as follows:
[0159] During the testing process, an independent test set is used to fully evaluate the final model. The test set contains unseen data and is designed to test the performance of the model in a real environment. Various key indicators (such as accuracy, recall, F1 score, average precision, etc.) are calculated during the evaluation process, which can fully reflect the performance of the model. The test results are visualized, including drawing detection boxes and labels on the image, and generating detailed detection reports for users to view and analyze. The result display and output subsystem can also save the detection results to a specified location for subsequent use and research.
[0160] As shown in Table 1, the present invention has achieved good improvements in all indicators. From the considerable improvement in the average detection accuracy, it can be concluded that the present invention solves the difficulties of underwater image detection, effectively overcomes underwater noise, and improves the detection accuracy of underwater targets. At the same time, the model size is reduced by 27.0%, which effectively reduces the model storage requirements and is more suitable for underwater detection scenarios.
[0161] In the present invention, the experimental performance index results are shown in Table 1:
[0162] Table 1 Comparison of detection performance between YOLOv8s and the present invention
[0163] Comparison Items YOLOv8s The present invention Accuracy 0.840 0.843 Recall 0.783 0.794 Average precision (learning rate 0.1) 0.852 0.865 Average precision (learning rate 0.01) 0.813 0.846 Average precision (learning rate 0.001) 57.1 73.6 Model storage space 11.1M 8.0M
[0164] This embodiment proposes an underwater image detection system based on the YOLOv8s model, which can detect targets in low-resolution and high-noise underwater images and has smaller model storage requirements. The detection effect is shown in the attached figure. Figure 6 As shown, the system successfully detects and classifies a variety of targets in a high-noise environment of underwater images. The classification results are marked with rectangular boxes, showing the effectiveness of the system in detecting targets in underwater environments, which proves the advantages of the present invention in the field of underwater image detection.
[0165] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0166] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. An underwater image detection system based on the YOLOv8s model, characterized in that: include: Underwater image acquisition and preprocessing subsystem (1): used to acquire underwater image data and perform preprocessing; Target detection subsystem (2): used for performing target detection on the preprocessed underwater image data using an improved YOLOv8s model, wherein the improved YOLOv8s model is used for obtaining a feature map based on the preprocessed underwater image data by combining a denoising mechanism with a dynamic adjustment of the receptive field mechanism, performing feature enhancement based on the feature map using a dual attention mechanism, and then performing feature fusion and detection to obtain a target detection result; Performance monitoring and evaluation subsystem (3): used to monitor and evaluate the target detection results; Detection result display and output subsystem (4): used to output and display the target detection result.
2. According to claim 1, an underwater image detection system based on the YOLOv8s model is characterized in that: The target detection subsystem (2) comprises: Image input processing module (21): used for processing the pre-processed underwater image data, including uniform image size adjustment, image normalization and random transformation; An underwater feature denoising and enhancement module (22) is used to remove noise based on the processed underwater image data by using a Fourier analysis method and a generative adversarial network to obtain a denoised underwater image, and to perform initial feature enhancement based on the denoised underwater image by using a position weight calculation mechanism and a dynamic receptive field convolution operation to obtain an initial feature map, wherein the generative adversarial network includes a generator and a discriminator; A dual attention enhancement feature extraction module (23) is used to perform feature enhancement again based on the initial feature map by combining a global spatial attention mechanism with a separate channel attention mechanism to obtain a final feature map; A feature fusion module (24): used for performing feature fusion based on the final feature map to obtain fusion features; Prediction head module (25): used to obtain target detection results based on the fusion features using the prediction head, and calculate the loss function, wherein the expression for the prediction head to perform detection is: In the formula, P(class i |p) represents the calculation result of the i-th element of vector p, the probability of the current input data in category i, p = [p1,…,p K ], K is the number of categories; Calculate loss and update network module (26): used to update network weights using the loss function through a back propagation algorithm, and use an SGD optimization algorithm to perform parameter optimization.
3. An underwater image detection system based on the YOLOv8s model according to claim 2, characterized in that: The step of obtaining the denoised underwater image comprises: The processed underwater image data is converted into the frequency domain by using a two-dimensional discrete Fourier transform to obtain a Fourier transform result, including a signal part and a noise part, wherein the expression of the Fourier transform result is: f c (x,y)=f signal (x,y)+n scat (x,y) In the formula, f c (x, y) is the input image of channel c, f signal (x, y) is the image signal part, n scat (x, y) is the underwater noise part of the image, is the conversion result of the noisy frequency domain, u and v are the frequency coordinates in the horizontal and vertical directions in the frequency domain, H and W are the height and width of the image, and j is an imaginary unit, which is equivalent to is the noise-free frequency domain image, i.e. the signal part, is the noise frequency image, i.e. the noise part; The generator is used to transform the Fourier transform result Convert to near ideal frequency components Denoised frequency domain image And through the inverse Fourier transform Convert back to the spatial domain to obtain the denoised underwater image, where the expression of the denoised underwater image is: In the formula, f denoised (x, y) is the denoised underwater image.
4. The underwater image detection system based on the YOLOv8s model according to claim 2, characterized in that: The loss function used by the generative adversarial network includes a generator loss function and a discriminator loss function, and the generator loss function is: The discriminator loss function is: In the formula, is the generator loss function, is the discriminator loss function, is the adversarial loss of GAN, G and D are the generator and discriminator respectively, is the noisy frequency domain of the image, u and v are the frequency coordinates in the horizontal and vertical directions in the frequency domain, is the expectation of the noisy signal distribution, which is the sum and average of all noisy images in the frequency domain. is the L2 loss, λ is the weight coefficient, is the noise-free frequency domain, is the expectation of the noise-free true signal distribution, For the generator Convert to near ideal frequency components The output of f denoised (x, y) is the image of channel c after denoising.
5. The underwater image detection system based on the YOLOv8s model according to claim 2, characterized in that: The step of obtaining the initial feature map comprises: Based on the denoised underwater image, global average pooling is performed, and the expression of the global average pooling is: Based on the denoised underwater image, global maximum pooling is performed, and the expression of the global maximum pooling is: The global average pooling result and the global maximum pooling result are combined to calculate the importance weight of the pixel position, where the calculation expression of the position importance weight is: AM c,h,w σ(W gap ·GAP c,h,w +W gmp ·GMP c,h,w +b) The importance weight is applied to the denoised underwater image to obtain an underwater image containing the weight, wherein the underwater image containing the weight is expressed as: X′ c,h,w =A c,h,w ·X c,h,w The underwater image containing the weight is input into the dynamic receptive field convolution to perform enhanced feature extraction, and an initial feature map is obtained, wherein the enhanced feature extraction process is expressed as: In the formula, GAP c,h,w is a global average pooling operation, H and W represent height and width respectively, X c,h,w For input images, GMP c,h,w To globally maximize the computational operation, A c,h,w is the weight, σ is the sigmoid activation function, W gap and W gmp is the weight matrix, b is the bias term, X′ c,h,w is the image after feature enhancement, Y′ c′,h,w is the value of the output feature map at channel c′, height h, and width w, X′ c,h+i-1,w+j-1 is the value of the input image after feature enhancement at channel c, height h+i-1, and width w+j-1, W c′,c,i,j is the weight of the convolution kernel, b c′ is the bias term.
6. The underwater image detection system based on the YOLOv8s model according to claim 2, characterized in that: The execution steps of the dual attention enhancement feature extraction module (23) include: Based on the initial feature map, a convolution operation is performed and a global spatial attention mechanism is used for processing to obtain a global spatial attention feature map; Based on the initial feature map, a convolution operation is performed and a separate channel attention mechanism is used for processing to obtain a separate channel attention feature map; The global spatial attention feature map and the separation channel attention feature map are added and convolved to obtain a final feature map.
7. The underwater image detection system based on the YOLOv8s model according to claim 6, characterized in that: The step of obtaining a global spatial attention feature map comprises: The initial feature map A after convolution is transformed to obtain a first initial feature map B, a second initial feature map C and a third initial feature map D; The first initial feature map B and the second initial feature map C are reshaped, and then the reshaped C and the transposed reshaped B are matrix multiplied, and softmax is used to calculate the spatial attention map S, where the calculation expression of the spatial attention map S is: The third initial feature map D is reshaped, and a global spatial attention feature map is obtained based on the reshaped D and the spatial attention map S, wherein the global spatial attention feature map is expressed as: In the formula, S ij To measure the impact of the i-th position on the j-th position, A j , B i , C j , D i are the feature vector of the original input position, the feature vector of position i after the first feature map B is reshaped, the feature vector of position j after the second feature map C is reshaped, and the feature vector of position i of the third feature map D, γ ij (N) is the noise suppression factor for each specific position i, j, N is the number of pixels represented by H×W, E j is the final output feature vector of position (j), combined with the feature information after the attention mechanism, s ji is the spatial attention weight, α is a parameter, and C, H, and W are channel, height, and width, respectively.
8. The underwater image detection system based on the YOLOv8s model according to claim 6, characterized in that: The step of obtaining the separation channel attention feature map comprises: The initial feature map A after convolution is reshaped, the reshaped A and the transpose of the reshaped A are matrix multiplied, and softmax is used to calculate the channel attention map X, where the calculation expression of the channel attention map X is: Based on the channel attention map X and the reshaped A, a separation channel attention feature map is obtained, where the separation channel attention feature map is expressed as: Where N is H×W, which represents the number of pixels, and E j is the feature vector of the jth channel in the output feature map, α is the parameter, x ji is the separated channel attention feature map, C, H, W are channel, height, and width respectively, A i , A j are the i-th channel of the input feature map and the,-th channel of the input feature map respectively, and β is the scaling parameter.
9. The underwater image detection system based on the YOLOv8s model according to claim 2, characterized in that: The loss function calculated in the prediction head module (25) includes a classification loss function, a bounding box loss function and a target confidence loss function. The classification loss function is used to calculate the difference between the target category detection result and the true category. The expression of the classification loss function is: In the formula, Class Loss is the classification loss, N is the total number of samples, C is the total number of categories, and y i,c Indicates that the i-th sample belongs to the true label of category c. The value is 1 if the category exists, otherwise it is 0. represents the probability that the model predicts that the i-th sample belongs to category c, ∈ is additive white Gaussian noise, which is used to introduce a random factor of noise generated by the simulated underwater environment between the model prediction and the true label; The bounding box loss function is used to calculate the deviation between the predicted target box and the real target box of the target. The expression of the bounding box loss function is: In the formula, Box Loss is the bounding box loss, λ coord is the weight coefficient, S 2 is the number of grid cells output by the network, B represents the number of bounding boxes predicted by each grid cell, and x i ,y i 、w i 、h i are the position parameters of the real target frame, Then is the corresponding parameter of the prediction, ∈ is the introduced noise term; The target confidence loss function is used to calculate the gap between the target detection accuracy and the actual situation. The expression of the target confidence loss function is: In the formula, Objectness Loss is the target confidence loss, y i is the target confidence label of the i-th sample, is the model's confidence prediction value of whether sample i contains the target, and ∈ is the introduced noise term.
10. An underwater image detection method based on the YOLOv8s model, characterized in that: The following steps are involved: Collect underwater image data and perform preprocessing; An improved YOLOv8s model is used to perform target detection on the preprocessed underwater image data, wherein the improved YOLOv8s model is used to obtain a feature map based on the preprocessed underwater image data by combining a denoising mechanism and a dynamic adjustment of the receptive field mechanism, and a dual attention mechanism is used to perform feature enhancement based on the feature map, and then feature fusion and detection are performed to obtain a target detection result; Monitoring and evaluating the target detection results; The target detection result is output and displayed.
Citation Information
Cited By
Intelligent detection and evaluation method and system for underground pipeline defects
CN119848675A
Data analysis system based on mass spectrum detection platform
CN119936168A
Picture detection method and device, storage medium and computer program product
CN121366296A
Multi-degree-of-freedom dredging and obstacle removing operation track planning and control method
CN122024030A