An underwater complex background small target detection method and system based on unsupervised domain adaptation
By collaboratively designing the backbone network through feature alignment and target-level contrastive learning in complex underwater backgrounds, the problem of background noise interference in underwater small target detection is solved, thereby improving detection accuracy and stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TSINGHUA SHENZHEN INTERNATIONAL GRADUATE SCHOOL
- Filing Date
- 2026-04-28
- Publication Date
- 2026-07-14
AI Technical Summary
Existing unsupervised domain adaptation detection methods struggle to effectively distinguish small target features from background noise in complex underwater environments, leading to negative migration and the accumulation of false label errors, resulting in decreased detection performance.
By performing transferable weighted alignment on the multi-level feature maps of the backbone network, combined with the global prototype of momentum smooth update and similarity gating mechanism, the background-level feature alignment loss and target-level contrastive learning loss are calculated to optimize the detection model to adapt to complex underwater backgrounds.
It significantly improves the accuracy and stability of underwater small target detection, effectively avoids the risk of negative migration caused by background texture differences, suppresses false label errors, and enhances intra-class compactness and inter-class separability.
Smart Images

Figure CN122391837A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of target detection technology, and in particular to a method and system for detecting small underwater targets in complex backgrounds based on unsupervised domain adaptation. Background Technology
[0002] Underwater target detection is a key technology in marine ecological monitoring, resource development, and underwater facility inspection, especially for the automatic identification and localization of small underwater targets such as plankton, fish fry, shellfish, or minute defects in pipelines. With the development of underwater in-situ imaging technology, deep learning-based target detection models have become the mainstream tool in this field. However, the underwater environment has typical complex background characteristics. Turbidity and lighting conditions vary significantly across different sea areas, depths, and seasons, and are accompanied by a large amount of dynamic background noise, such as high-density suspended particles, marine debris, and bubbles. This makes it difficult to directly apply detection models trained in specific scenarios to new, unseen scenarios; that is, there is a significant data distribution difference between the source and target domains.
[0003] Existing unsupervised domain adaptation detection methods typically employ adversarial training to perform equal-weighted or fixed-weight domain alignment of multi-layer features. However, in complex underwater environments, indiscriminate alignment forces the model to align background noise features in the source and target domains, disrupting the focus on scarce small target features and resulting in negative transfer. At the same time, existing methods lack effective noise suppression mechanisms when updating category prototypes using target domain pseudo-labels, leading to the continuous accumulation of false positives and false negatives in small target pseudo-labels during training, ultimately causing a decline in detection performance. Summary of the Invention
[0004] This invention provides a method and system for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation, in order to overcome the shortcomings of existing technologies.
[0005] This invention provides a method for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation, comprising: S1: Preprocess the source domain labeled image data and the target domain unlabeled image data to obtain the source domain dataset and the target domain dataset; S2: Input the source domain dataset into the basic object detection model for supervised training to obtain the source domain pre-trained model; S3: Based on the source domain dataset and the target domain dataset, the multi-level feature maps output by multiple layers of the backbone network are weighted and aligned according to the transferability weights to obtain the background-level feature alignment loss; S4: Based on the source domain pre-trained model, construct global prototypes for multiple categories of target-level features output by the detection head, perform momentum smoothing updates on the global prototypes according to the similarity gating mechanism, and calculate the target-level contrastive learning loss by combining the attraction of similar categories and the repulsion of dissimilar categories. S5: The background-level feature alignment loss, the target-level contrastive learning loss, and the standard detection loss are weighted and summed to obtain the overall loss, which is then used to jointly optimize the basic target detection model until convergence, thus obtaining the domain-adaptive detection model. S6: Apply the domain adaptation detection model to the target domain image to output the category and location information of small underwater targets.
[0006] According to the present invention, a method for detecting small underwater targets in complex backgrounds based on unsupervised domain adaptation is provided. In step S1, the source domain labeled image data is an underwater image with target category and bounding box position labels collected in a preset water area, and the target domain unlabeled image data is an unlabeled underwater image collected in a water area with a background distribution difference from the source domain.
[0007] According to the present invention, a method for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation is provided. In step S2, the basic target detection model is a two-stage detection model based on a region proposal network.
[0008] According to the present invention, a method for detecting small underwater targets in complex backgrounds based on unsupervised domain adaptation is provided, wherein step S3 further includes: S31: Perform forward propagation on the source domain dataset and the target domain dataset respectively to extract feature maps of multiple layers in the backbone network; S32: Independent domain classifiers are deployed in parallel. Multiple domain classifiers are connected to the backbone network through a gradient inversion layer. Adversarial losses are calculated for feature maps at multiple levels, and the adversarial losses are used as the transferability index of features at the corresponding levels. S33: Input the transferability metrics of multiple levels into the Softmax function to obtain the feature alignment weights corresponding to multiple levels; S34: The adversarial losses of multiple levels are weighted and summed according to the feature alignment weights to obtain the background-level feature alignment loss.
[0009] According to the present invention, a method for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation is provided. In step S32, the adversarial loss is a binary cross-entropy loss; in step S33, the loss used to generate the feature alignment weights adopts a gradient-separating version; in step S34, the expression for the background-level feature alignment loss is:
[0010] in, Background-level feature alignment loss, For hierarchical indexes in the backbone network, For the first Layer feature alignment weights, For the first Adversarial loss of layer classifiers.
[0011] According to the present invention, a method for detecting small underwater targets in complex backgrounds based on unsupervised domain adaptation is provided, wherein step S4 further includes: S41: Use the source domain pre-trained model to perform forward propagation on the source domain dataset, extract instance features with real labels, calculate the average vector of instance features of multiple categories by category, and use the average vector as the initial value of the source domain global prototype and the target domain global prototype. S42: In each training batch, the source domain real label instance features and the target domain pseudo label instance features in the current batch are averaged by category to obtain the source domain local prototype and the target domain local prototype. S43: Calculate the cosine similarity between the local prototype of the target domain and the global prototype of the historical target domain, determine the update weight based on the cosine similarity, and perform a smooth update on the global prototype of the target domain to obtain the updated global prototype of the target domain. S44: Based on the source domain global prototype and the updated target domain global prototype, calculate the target-level contrastive learning loss.
[0012] According to the present invention, a method for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation is provided. In step S43, the expression for the cosine similarity is:
[0013] in, To detect the target category index in the task. For category cosine similarity, For category The historical global prototype vector of the target domain maintained at the end of the previous training batch. For category The local prototype vector of the target domain obtained by average pooling of the effective pseudo-label instance features of the target domain in the current training batch; The expression for updating the weights is:
[0014] in, For category Dynamically updated weights The preset basic momentum coefficient; The expression for smoothly updating the global prototype of the target domain is:
[0015] in, For category The target domain global prototype updated in the current batch.
[0016] According to the present invention, a method for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation is provided. In step S44, the target-level contrastive learning loss is composed of a weighted sum of similar-class attraction loss and dissimilar-class repulsion loss, expressed as:
[0017] in, For target-level contrastive learning loss, Loss due to attraction to similar things To balance hyperparameters, Loss due to rejection of other species; The expression for the similar attraction loss is:
[0018] in, To detect the target category index in the task. The total number of target categories for the detection task. For category The source domain global prototype vector, For category The global prototype vector of the target domain; The expression for the heterogeneity rejection loss is:
[0019] in, The total number of all out-of-type prototype pairs. This is the preset interval hyperparameter. The first category prototype index in the heterogeneous prototype pair. For the second category prototype index in the heterogeneous prototype pair, For the first One prototype vector, For the first One prototype vector.
[0020] According to the present invention, a method for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation is provided. The expression for the overall loss in step S5 is as follows:
[0021] in For the overall loss, For standard detection loss, Background-level feature alignment loss, For target-level contrastive learning loss, The first weighted hyperparameter, This is the second weighted hyperparameter.
[0022] This invention also provides an underwater complex background small target detection system based on unsupervised domain adaptation, for performing an underwater complex background small target detection method based on unsupervised domain adaptation as described in any of the above claims, including: Preprocessing module: Used to preprocess the source domain labeled image data and the target domain unlabeled image data to obtain the source domain dataset and the target domain dataset; Basic object detection model: used to receive the source domain dataset for supervised training to obtain a source domain pre-trained model; The background-level feature alignment module is connected to the backbone network in the basic target detection model. It is used to perform weighted alignment of the multi-level feature maps output by multiple layers of the backbone network based on the source domain dataset and the target domain dataset, according to the transferability weights, to obtain the background-level feature alignment loss. Target-level contrastive learning module: Based on the source domain pre-trained model, it constructs global prototypes of multiple categories from the target-level features output by the detection head, performs momentum smoothing updates on the global prototypes according to the similarity gating mechanism, and calculates the target-level contrastive learning loss by combining the attraction of similar categories and the repulsion of dissimilar categories. Joint optimization module: used to perform weighted summation of the background-level feature alignment loss, the target-level contrastive learning loss, and the standard detection loss to obtain the overall loss, and then jointly optimize the basic target detection model until convergence, to obtain the domain-adaptive detection model; The output module is configured as the domain-adaptive detection model trained by the joint optimization module, which is used to detect the target domain image and output the category and location information of small underwater targets.
[0023] This invention achieves significant overall performance improvement in cross-domain small target detection tasks through a collaborative design of background-level feature alignment and target-level contrastive learning. Regarding background-level feature alignment, this invention introduces an adversarial training mechanism based on a gradient inversion layer and calculates a transferability index based on the adversarial loss of each domain classifier. After Softmax normalization, adaptive feature alignment weights are generated. This allows layers with high transferability in the backbone network to receive higher weights during alignment, while the alignment contribution of low-transferability layers dominated by background noise is correspondingly reduced. This effectively avoids the negative transfer risk caused by complex underwater background textures in cross-domain alignment, enabling the model to maintain stable feature representation capabilities even when facing target domain scenes with significant differences in turbidity, illumination, and suspended particles. In terms of target-level contrastive learning, this invention maintains global prototypes of each category across batches in the model memory and dynamically adjusts the update weights using the cosine similarity between the target domain local prototype and the historical global prototype. This results in a larger update amplitude when the pseudo-label quality is high and an automatically narrowed update amplitude when the pseudo-label quality is low. Combined with the momentum smoothing mechanism, this effectively suppresses the damage to category prototypes caused by false positives and false negatives, avoiding the continuous accumulation of errors during self-training. At the same time, the same-category attraction loss drives the same-category features of the source and target domains to move towards a common center by minimizing the square Euclidean distance between cross-domain same-category prototypes. Meanwhile, the interval-based Hinge-form heterogeneous repulsion loss applies interval constraints to various heterogeneous prototype pairs, such as cross-domain heterogeneous, target domain heterogeneous, and source domain heterogeneous, ensuring that heterogeneous prototypes maintain sufficient distance margin in the feature space. The two work together to reshape the discriminative structure of the feature space, significantly enhancing the intra-class compactness and inter-class separability of small underwater targets under complex background interference. Ultimately, this significantly improves the detection accuracy and stability of the domain adaptation detection model in the target domain. Attached Figure Description
[0024] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0025] Figure 1 This is a schematic diagram of a method for detecting small underwater targets in complex backgrounds based on unsupervised domain adaptation, provided in an embodiment of the present invention. Figure 2 A schematic diagram of the underwater complex background small target detection system based on unsupervised domain adaptation is provided by the present invention. Figure 3 This is a schematic diagram of the overall framework of an in-situ plankton detection method based on unsupervised domain adaptation provided in an embodiment of the present invention; Figure 4 This is a schematic diagram illustrating the working principle architecture of the background-level feature alignment module provided in an embodiment of the present invention. Figure 5 This is a schematic diagram illustrating the working principle architecture of the target-level contrastive learning module provided in an embodiment of the present invention. Figure 6 This is a schematic diagram showing the comparison of the detection experimental results of the underwater complex background small target detection method based on the present invention in the target domain, as provided in the embodiments of the present invention. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, embodiments of this invention, and should not be construed as limiting the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention. In the description of this invention, it should be understood that the terminology used is for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0027] The embodiments of the present invention are described below with reference to the figures.
[0028] like Figure 1 As shown, this invention provides a method for detecting small underwater targets in complex backgrounds based on unsupervised domain adaptation, comprising: S1: Preprocess the labeled image data in the source domain and the unlabeled image data in the target domain to obtain the source domain dataset and the target domain dataset.
[0029] In step S1, the source domain labeled image data is an underwater image collected in a preset water area that includes target category and bounding box location labels, and the target domain unlabeled image data is an unlabeled underwater image collected in a water area with a background distribution difference from the source domain.
[0030] Furthermore, the source domain labeled image data consists of underwater images collected in a preset water area, containing annotations of target category and bounding box location. The annotation information includes the target category and its bounding box coordinates in the image. The target domain unlabeled image data consists of unlabeled underwater images collected in water areas with background distribution differences from the source domain, containing no category or location annotation information. In step S1, the present invention performs standardization processing such as size unification and pixel normalization on the above two parts of image data, ultimately obtaining source domain datasets and target domain datasets that can be directly input into the model.
[0031] S2: Input the source domain dataset into the basic object detection model for supervised training to obtain the source domain pre-trained model; the basic object detection model is a two-stage detection model based on the region proposal network.
[0032] In step S2, the basic target detection model is a two-stage detection model based on a region proposal network, consisting of a backbone network, a region proposal network, and a detection head. The backbone network performs layer-by-layer convolution on the input image to extract feature maps with different semantic levels. The region proposal network receives the feature maps output by the backbone network and generates candidate target regions and their foreground and background confidence scores on the feature maps. The detection head classifies and regresses bounding boxes on the features of the candidate regions after RoIAlign alignment, outputting the target category and precise location coordinates of each candidate region. In step S2, the source domain dataset is input into the above model, and supervised training is performed using the sum of classification cross-entropy loss and bounding box regression loss as the standard detection loss. After the model parameters converge, the source domain pre-trained model is obtained.
[0033] S3: Based on the source domain dataset and the target domain dataset, the multi-level feature maps output by multiple layers of the backbone network are weighted and aligned according to the transferability weights to obtain the background-level feature alignment loss.
[0034] Step S3 further includes: S31: Perform forward propagation on the source domain dataset and the target domain dataset respectively to extract feature maps of multiple layers in the backbone network.
[0035] In step S31, the present invention first loads the weights of the pre-trained model in the source domain. Then, the images from both the source and target domain datasets are simultaneously fed into the backbone network for forward propagation, extracting output feature maps from multiple layers of the backbone network. The shallow feature maps have high spatial resolution, preserving more local texture and edge details; the mid-level feature maps balance local features and semantic information; and the deep feature maps have the lowest spatial resolution and the highest level of semantic abstraction, containing target-level semantic representations. Finally, the source and target domain images undergo forward propagation in the same backbone network, each obtaining feature maps from multiple layers, which are then processed further.
[0036] S32: Independent domain classifiers are deployed in parallel. Multiple domain classifiers are connected to the backbone network through a gradient inversion layer. Adversarial losses are calculated for feature maps at multiple levels, and the adversarial losses are used as the transferability index of features at the corresponding levels. The adversarial loss is a binary cross-entropy loss.
[0037] Furthermore, this invention deploys structurally independent domain classifiers for each level of feature map. Each domain classifier consists of multiple convolutional layers and one fully connected layer. Each domain classifier is connected to the output of the corresponding level's backbone network through a gradient inversion layer. The gradient inversion layer directly transmits features during forward propagation and multiplies the gradient by a negative coefficient before transmitting it back to the backbone network during backward propagation, driving the backbone network to extract domain-invariant features. Each domain classifier receives the source domain feature map and the target domain feature map of the corresponding level, outputs the predicted probability that each position belongs to the source domain or the target domain, and then calculates the adversarial loss for that level using binary cross-entropy loss. This adversarial loss value is used as an indicator of the transferability of the features at that level. That is, the larger the adversarial loss, the more difficult it is for the domain classifier to distinguish between source domain and target domain features, and the stronger the cross-domain transferability of the features at that level.
[0038] S33: Input the transferability metrics of multiple levels into the Softmax function to obtain the feature alignment weights corresponding to multiple levels; wherein, the loss used to generate the feature alignment weights adopts the gradient separation version.
[0039] In step S33, the present invention constructs a vector from the transferability indices of each layer, inputs it into the Softmax function for normalization, and obtains the feature alignment weights corresponding to each layer. The sum of all layer weights is strictly equal to 1. Furthermore, the transferability indices used to generate the feature alignment weights employ a gradient-separated version, meaning that gradient backpropagation along this path is cut off when calculating the weights. The weight generation process does not cause additional interference to the feature learning of the backbone network; the weights only participate as weighting coefficients in the subsequent loss calculation.
[0040] S34: The adversarial losses of multiple levels are weighted and summed according to the feature alignment weights to obtain the background-level feature alignment loss.
[0041] In step S34, the expression for the background-level feature alignment loss is:
[0042] in, Background-level feature alignment loss, For hierarchical indexes in the backbone network, For the first Layer feature alignment weights, For the first Adversarial loss of layer classifiers.
[0043] In step S34, the present invention uses the feature alignment weights obtained in step S33 to weight the original adversarial loss of the corresponding layer, and sums the weighted results of all layers to obtain the background-level feature alignment loss, as shown in the expression above. For the obtained background-level feature alignment loss, layers with strong transferability have larger weights and contribute more to the weighted summation; layers with weak transferability and dominated by background noise have smaller weights, and their alignment constraints are correspondingly reduced, thereby avoiding over-alignment of features at low transferability layers.
[0044] S4: Based on the source domain pre-trained model, construct global prototypes for multiple categories of target-level features output by the detection head, perform momentum smoothing updates on the global prototypes according to the similarity gating mechanism, and calculate the target-level contrastive learning loss by combining the attraction of similar categories and the repulsion of dissimilar categories constraints.
[0045] Step S4 further includes: S41: Use the source domain pre-trained model to perform forward propagation on the source domain dataset, extract instance features with real labels, calculate the average vector of instance features of multiple categories by category, and use the average vector as the initial value of the source domain global prototype and the target domain global prototype.
[0046] In step S41, the present invention utilizes the source domain pre-trained model obtained in step S2 to perform a complete forward propagation on all images in the source domain dataset. The RoI Align layer of the detection head aligns the features of each candidate region, outputting the instance-level feature vector corresponding to each candidate region. Since the source domain dataset carries the true labels, each instance feature vector has a clear category affiliation. Subsequently, the present invention averages the above instance feature vectors according to their categories to obtain the average feature vector for each category. This average feature vector is used as the initial value for both the source domain global prototype and the target domain global prototype, stored in the model memory, and continuously maintained across batches.
[0047] S42: In each training batch, the source domain real label instance features and target domain pseudo label instance features in the current batch are averaged by category to obtain the source domain local prototype and the target domain local prototype.
[0048] Furthermore, in step S42 of this invention, in each training batch, the detection head outputs instance-level feature vectors for the source domain image and the target domain image within the current batch. For the source domain instance feature vector, the category is directly assigned based on the true label; for the target domain instance feature vector, the category is assigned based on the pseudo-labels obtained by filtering the prediction results of the target domain image in this invention, and only the instance features corresponding to the prediction boxes with a prediction confidence exceeding a preset threshold of 0.8 are retained for subsequent calculations. Subsequently, this invention performs average pooling on the source domain instance feature vectors belonging to the same category within the current batch to obtain the source domain local prototype; and performs average pooling on the filtered target domain instance feature vectors by category, that is, it calculates the average of all instance feature vectors under the same category element by dimension, and outputs the category center vector with the same dimension as a single instance feature vector to obtain the target domain local prototype.
[0049] S43: Calculate the cosine similarity between the local prototype of the target domain and the global prototype of the historical target domain, determine the update weight based on the cosine similarity, and perform a smooth update on the global prototype of the target domain to obtain the updated global prototype of the target domain.
[0050] In step S43, the expression for the cosine similarity is:
[0051] in, To detect the target category index in the task. For category cosine similarity, For category The historical global prototype vector of the target domain maintained at the end of the previous training batch. For category The target domain local prototype vector is obtained by average pooling of the effective pseudo-label instance features in the target domain in the current training batch.
[0052] The expression for updating the weights is:
[0053] in, For category Dynamically updated weights The preset basic momentum coefficient is set to 0.9.
[0054] The expression for the smooth update of the target domain global prototype is as follows:
[0055] in, For category The target domain global prototype updated in the current batch.
[0056] In step S43, after obtaining the local prototype of the target domain, the present invention calculates the cosine similarity between the local prototype of the target domain and the historical global prototype of the target domain stored in the model memory. The cosine similarity is calculated by dividing the inner product of the two vectors by the product of their respective L2 norms, as shown in the expression above. The output value is a scalar in the range of [-1, 1], which reflects the degree of consistency between the two vectors in direction. The closer the value is to 1, the more consistent the directions are.
[0057] Subsequently, the present invention multiplies the cosine similarity with a preset basic momentum coefficient to obtain the dynamic update weight of the current batch. The update weight controls the update magnitude of the target domain local prototype to the historical global prototype. The larger the update weight, the greater the magnitude of the historical global prototype moving closer to the current local prototype; the smaller the update weight, the higher the retention rate of the historical global prototype.
[0058] Ultimately, this invention uses a weighted fusion of the historical global prototype and the local prototype of the target domain according to the update weight. That is, it updates the target domain global prototype according to the expression for smooth update of the target domain global prototype, and obtains the updated target domain global prototype, which overwrites the historical value in memory for use in the next batch.
[0059] S44: Based on the source domain global prototype and the updated target domain global prototype, calculate the target-level contrastive learning loss.
[0060] In step S44, the target-level contrastive learning loss is composed of a weighted sum of similar-class attraction loss and dissimilar-class repulsion loss, expressed as:
[0061] in, For target-level contrastive learning loss, Loss due to attraction to similar things To balance hyperparameters, Loss due to rejection of other species.
[0062] The expression for the similar attraction loss is:
[0063] in, To detect the target category index in the task. The total number of target categories for the detection task. For category The source domain global prototype vector, For category The target domain global prototype vector.
[0064] The expression for the heterogeneity rejection loss is:
[0065] in, The total number of all out-of-type prototype pairs. This is a preset interval hyperparameter with a value of 0.5. The first category prototype index in the heterogeneous prototype pair. For the second category prototype index in the heterogeneous prototype pair, For the first One prototype vector, For the first One prototype vector.
[0066] In step S44, the present invention takes the source domain global prototype maintained in step S41 and the updated target domain global prototype obtained in step S43 as inputs, calculates the same-class attraction loss and the different-class repulsion loss respectively, and then sums them by weight to obtain the target-level contrastive learning loss.
[0067] The calculation method for the same-class attraction loss is as follows: for all categories, calculate the squared L2 norm of the difference between the global prototype vector of the source domain and the global prototype vector of the target domain for that category, and then calculate the mean for all categories to obtain a scalar loss value. The smaller this value, the closer the cross-domain same-class prototypes are in the feature space. The calculation method for the different-class repulsion loss is as follows: traverse all different-class prototype pairs, including cross-domain different-class, target domain-internal different-class, and source domain-internal different-class cases. For each different-class prototype pair, calculate the L2 norm of the difference between the two prototype vectors. If this distance is less than a preset interval hyperparameter, the loss is considered. This results in a positive penalty term, i.e., with Subtract that distance as the loss contribution for the pair; if the distance exceeds... If the loss contribution of this pair is 0, then the average of the penalty terms for all out-of-class prototype pairs is obtained as the out-of-class repulsion loss scalar.
[0068] Ultimately, this invention combines similar attraction losses with equilibrium hyperparameters. The weighted outlier rejection losses are summed to obtain the target-level contrastive learning loss, as shown in the expression above.
[0069] S5: The background-level feature alignment loss, the target-level contrastive learning loss, and the standard detection loss are weighted and summed to obtain the overall loss, which is then used to jointly optimize the basic target detection model until convergence, thus obtaining the domain-adaptive detection model.
[0070] The expression for the overall loss in step S5 is as follows:
[0071] in For the overall loss, For standard detection loss, Background-level feature alignment loss, For target-level contrastive learning loss, The first weighted hyperparameter, This is the second weighted hyperparameter.
[0072] In step S5, the present invention performs a weighted summation of the background-level feature alignment loss obtained in step S34, the target-level contrastive learning loss obtained in step S44, and the standard detection loss of the basic target detection model itself to obtain the overall loss. The standard detection loss is composed of the classification cross-entropy loss output by the detection head and the bounding box SmoothL1 regression loss. The background-level feature alignment loss and the target-level contrastive learning loss are weighted by the first weight hyperparameter λ1 and the second weight hyperparameter λ2, respectively; in this embodiment, both are set to 0.1. After the overall loss is calculated, the present invention uses the stochastic gradient descent method with momentum to backpropagate and update all parameters of the basic target detection model, continuously optimizing until the model converges, thus obtaining the domain-adaptive detection model.
[0073] S6: Apply the domain adaptation detection model to the target domain image to output the category and location information of small underwater targets.
[0074] In step S6, the present invention switches the converged domain adaptation detection model to inference mode, disables the loss calculation of the domain classifier and contrastive learning module, and retains only the forward propagation path of the backbone network, region proposal network, and detection head. The target domain image, after preprocessing, is input into the domain adaptation detection model. The backbone network extracts feature maps, the region proposal network generates candidate regions, and the detection head classifies and regresses bounding boxes on the candidate regions, ultimately outputting the category information and bounding box coordinates of the underwater small target.
[0075] like Figure 2 As shown, the present invention also provides an underwater small target detection system based on unsupervised domain adaptation against complex backgrounds, comprising: Preprocessing module 100: used to preprocess the source domain labeled image data and the target domain unlabeled image data to obtain the source domain dataset and the target domain dataset; Basic object detection model 200: used to receive the source domain dataset for supervised training to obtain a source domain pre-trained model; Background-level feature alignment module 300 is connected to the backbone network in the basic target detection model 200. It is used to perform weighted alignment of multi-level feature maps output by multiple layers of the backbone network based on the source domain dataset and the target domain dataset, according to the transferability weight, to obtain background-level feature alignment loss. Target-level contrastive learning module 400: Based on the source domain pre-trained model, it constructs global prototypes of multiple categories from the target-level features output by the detection head, performs momentum smoothing updates on the global prototypes according to the similarity gating mechanism, and calculates the target-level contrastive learning loss by combining the attraction of similar categories and the repulsion of dissimilar categories. Joint optimization module 500: used to perform weighted summation of the background-level feature alignment loss, the target-level contrastive learning loss, and the standard detection loss to obtain the overall loss for joint optimization of the basic target detection model 200 until convergence, thus obtaining the domain-adaptive detection model; The output module 600 is configured as the domain adaptation detection model trained by the joint optimization module 500, which is used to detect the target domain image and output the category information and location information of the underwater small target.
[0076] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0077] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the underwater complex background small target detection method based on unsupervised domain adaptation described in the various embodiments or some parts of the embodiments.
[0078] To better understand this invention, the following description, in conjunction with illustrations, explains the proposed model structure of an underwater complex background small target detection method and system based on unsupervised domain adaptation.
[0079] Figure 1 This is a flowchart illustrating the overall framework of the method of the present invention, showing the complete data flow from input to domain adaptation training of the source domain labeled image and the target domain unlabeled image. Figure 1In the algorithm, the input on the left is divided into two paths: one is a labeled image from the source domain, and the other is an unlabeled image from the target domain. Both images undergo preprocessing to unify their size and normalize their pixels before being fed into a base object detection model with ResNet as the backbone network. The backbone network performs convolutional operations on the input image layer by layer, outputting feature maps at three levels: C3, C4, and C5. C3 is a shallow feature map, C4 is a mid-level feature map, and C5 is a deep feature map.
[0080] for Figure 1 The data flow of the Background Feature Alignment (BFA) module is as follows: feature maps at layers C3, C4, and C5 are connected to three independent Gradient Reversal Layers (GRLs), and each GRL is followed by an independent Domain Classifier. Source and target domain feature maps flow simultaneously through the GRLs and domain classifiers at each layer. The domain classifiers output the adversarial loss for each layer. The adversarial losses at the three layers are normalized using Softmax to obtain feature alignment weights. These weighted sums of the adversarial losses from the three layers then output the background feature alignment loss, which is fed into... Figure 1 The weighted alignment module marked as Weighted Alignment completes the loss aggregation.
[0081] for Figure 1 The data flow between the detection head and the target-level contrastive learning module (TCL) is as follows: the feature map output by the backbone network is used by the Region Proposal Network (RPN) to generate candidate regions, which are then fed into the detection head. The detection head consists of RoI Align, a classification branch (cls.), and a regression branch (reg.). RoI Align spatially aligns the candidate region features and outputs fixed-size instance-level feature vectors, which are fed into the classification branch to output class predictions and the regression branch to output bounding box coordinates. The instance features output by the detection head from the source domain image are aggregated into a source domain prototype based on the ground truth labels, and the instance features output by the detection head from the target domain image are aggregated into a target domain prototype based on pseudo-labels. Both are used in the calculation of the target-level contrastive learning loss. Figure 1 On the right, the target domain image is processed by the classification branch of the detection head, and the predicted result is used as a pseudo-label to feed back into the construction of the target domain category prototype, forming a self-training closed loop.
[0082] Figure 2 This is a diagram illustrating the working principle of the Background Feature Alignment (BFA) module of the present invention, showing the complete data processing flow of weighted alignment of the three-level feature maps (C3, C4, and C5) with the domain classifier through the gradient inversion layer.
[0083] Figure 2In the diagram, the top layer shows the three hierarchical feature maps output by the backbone network, numbered C3, C4, and C5 from left to right. The spatial resolution of these feature maps decreases sequentially, while their semantic abstraction increases. Below each feature map is a Gradient Reversal Layer (GRL). During forward propagation, the GRL directly passes the feature map to the domain classifier below. During backpropagation, it multiplies the gradient from the domain classifier by a negative coefficient and returns it to the backbone network, driving the backbone network to extract domain-invariant features between the source and target domains.
[0084] In addition, each gradient inversion layer is connected to an independent domain classifier. The three domain classifiers have the same structure but independent parameters and do not share parameters. Each domain classifier receives the feature map passed from the corresponding layer through the gradient inversion layer, outputs the binary classification prediction probability of whether the location in the feature map belongs to the source domain or the target domain for each spatial location, and then calculates the adversarial loss of that layer using binary cross-entropy loss. This adversarial loss also serves as a metric for the transferability of the features at that layer.
[0085] Figure 2 In the middle, below is the weighted alignment module. The adversarial loss values output by the three domain classifiers are fed down into the weighted alignment module. The weighted alignment module forms a vector from the adversarial loss values of the three levels and inputs it into the Softmax function for normalization to obtain the feature alignment weights of the three levels. The sum of the weights is 1. Then, the adversarial loss of the corresponding level is weighted and summed with the weights of each level to output the background level feature alignment loss. Figure 2 The purple arrows represent gradient reversal paths, and the green arrows represent forward feature propagation paths. The two colors of arrows together indicate the bidirectional data flow of forward and backward propagation within the BFA module.
[0086] Figure 3 The working principle architecture diagram of the target-level contrastive learning module (TCL) provided by this invention shows the complete data processing flow from instance features to category prototype construction, prototype update and contrastive learning loss calculation.
[0087] Figure 3 In the image, the upper part represents the local prototype calculation stage. The left side shows the source domain category prototype calculation area, and the right side shows the target domain category prototype calculation area. Each side displays instance feature image patches for three categories (represented by triangles, pentagons, and squares, respectively). Source domain instance features are averaged by category based on the ground truth labels, while target domain instance features are averaged by category after filtering based on pseudo-labels, yielding local prototypes for each category in the source and target domains. Figure 3 The corresponding shapes are used to represent the prototypes of each category. Figure 3The Update arrow in the middle indicates the update operation from the local prototype to the global prototype. That is, the dynamic update weight is calculated based on the cosine similarity, and the local prototype of the target domain is integrated into the historical global prototype of the target domain in a weighted fusion manner to complete the smooth update.
[0088] Figure 3 In the middle, below is the contrastive learning loss calculation stage, divided into two rows of prototypes: the top row is the source domain global prototype, and the bottom row is the target domain global prototype. Figure 3 In the diagram, the horizontal bidirectional arrows between the global prototypes of the source and target domains represent similarity attraction constraints, i.e., applying a constraint to minimize the squared Euclidean distance between similar prototypes across domains, driving similar prototypes in the source and target domains to move closer to each other in the feature space. Cross-arrows with an × symbol represent dissimilarity repulsion constraints between different categories of prototypes within the global prototype of the source domain, between different categories of prototypes within the global prototype of the target domain, and between dissimilar prototypes across the source and target domains. This applies a Hinge loss based on the margin to all dissimilar prototype pairs, ensuring that the Euclidean distance between dissimilar prototypes is not less than a preset margin hyperparameter m, covering three types of dissimilar prototype pairs: cross-domain dissimilar, target domain intra-domain dissimilar, and source domain intra-domain dissimilar.
[0089] The following describes the underwater complex background small target detection method of the present invention based on unsupervised domain adaptation with reference to specific embodiments.
[0090] S101: Data Acquisition and Preparation. Acquire labeled underwater images of the source domain and unlabeled underwater images of the target domain. All images are acquired using underwater imaging equipment (such as PlanktonScope).
[0091] Source domain data: Collected from the coast of area A, totaling 2792 images, labeled using annotation tools such as LabelImg software, including three types of targets: cauda, copepods, and Noctiluca scintillans, with corresponding labeled instances of 3764, 5912, and 3364, respectively.
[0092] Target domain data: Collected from location B, totaling 1754 images, unlabeled.
[0093] S102: Model Training Phase. The target detection model is trained using source and target domain data to achieve domain adaptation, enabling it to recognize small underwater targets across domains. Detailed processing steps are as follows: S1021: Source Domain Pre-training. The basic object detection model is trained under supervision using a source domain labeled dataset to obtain the parameters of the source domain pre-trained model; the preferred basic object detection model is Faster R-CNN.
[0094] S1022: Perform background-level feature alignment. Load the weights of the source domain pre-trained model; obtain the source domain dataset. and unlabeled target domain dataset This serves as the input for domain adaptation training. Background-level feature alignment is performed on the multi-level feature maps output by the backbone network of the basic detection model, and the loss is calculated according to the aforementioned formula. .
[0095] Specifically, after the feature maps output from layers C3, C4, and C5 of the backbone network, three independent domain classifiers are deployed in parallel. These domain classifiers are connected to the backbone network through gradient inversion layers (GRL). Each domain classifier consists of three convolutional layers with a kernel size of 3x3 and a stride of 2, and one fully connected layer.
[0096] Subsequently, the classifier for each domain is calculated. The losses of the confrontation The adversarial loss is a standard binary cross-entropy loss. Then, the adversarial losses for each layer are... Input the Softmax function to generate normalized feature alignment weights. .
[0097] S1023: Perform target-level contrastive learning (TCL). Specifically, perform contrastive learning on the target-level features output by the detection head (RoIHead) of the base detection model and calculate the loss. .
[0098] Furthermore, initialization is performed first. This involves creating a class for each category in both the source and target domains. Maintain a global prototype in the model's memory. and At the beginning of the step, a complete forward propagation is performed on the source domain dataset using a pre-trained model to extract features from all instances with true labels. For each category... Calculate the average vector of features of all its instances, and use this average vector as... and The initial value.
[0099] Next, the local prototype (LP) is calculated. This is done by considering all elements belonging to the category within the current batch. The instance features (source domain from real labels, target domain from pseudo-labels exceeding a preset confidence threshold of 0.8) are obtained by average pooling. and .
[0100] Then, the dynamically updated weights are calculated according to the aforementioned formula. In progress The preset momentum coefficient is set to 0.9. After calculating the update weights, a smooth update is performed, i.e., using the formula... Perform a smooth update on the global prototype and calculate the total TCL loss during the update. .
[0101] S1024: Overall Optimization. Specifically, this involves calculating the overall loss function. Train the model until it converges, and then calculate the overall loss function using the following formula: In the formula: The standard losses for Faster R-CNN include the classification cross-entropy loss from RoIHead and the SmoothL1 regression loss for bounding boxes. For background-level alignment loss, For target-level contrastive learning loss, and The weight hyperparameter is 0.1. In this embodiment, the optimizer is a momentum-based SGD.
[0102] S103: Inference Application Stage. The trained object detection model is applied to the target domain image to be detected, outputting the final underwater small target detection category and location. For example... Figure 6 As shown, after applying the method of the present invention, the detection effect of the model in location B is significantly improved.
[0103] It should be noted that the above embodiments use the detection of small underwater planktonic targets as an example to describe the present invention in detail. However, the technical concept of the present invention does not rely on the physical properties unique to underwater imaging. Its core lies in addressing the cross-domain detection problem of small targets under complex background conditions by suppressing background domain drift through background-level feature alignment and mitigating the accumulation of false label noise for small targets through target-level contrastive learning. Therefore, the method of the present invention has good versatility and can be extended to various visual detection tasks with similar technical characteristics. For example, in drone aerial photography scenarios, due to differences in flight altitude, viewing angle, and lighting conditions, there are often significant inter-domain distribution differences between different aerial photography data. At the same time, pedestrians, vehicles, or facilities on the ground are usually presented as small-scale targets in the images and are easily affected by complex surface textures and shadows. In this scenario, drone aerial images can be used as input data for the source and target domains. The background-level feature alignment mechanism described in the present invention can be used to suppress background differences under different aerial photography conditions, and the discriminative power of small target features can be enhanced through target-level contrastive learning, thereby improving cross-scene detection performance.
[0104] For example, in remote sensing image detection tasks, different sensor types, resolutions, and imaging conditions can lead to significant data distribution shifts. Targets such as ships and vehicles typically occupy fewer pixels in large-scale remote sensing images, exhibiting typical small-target characteristics. The method of this invention is also applicable to such scenarios. By weighted alignment of multi-layer features based on their transferability, it reduces the interference of complex terrain backgrounds on the domain adaptation process and utilizes target-level contrastive learning to suppress the adverse effects of false-label noise on model training.
[0105] In the above extended applications, only the input data format and basic detection network structure need to be adapted according to the specific imaging equipment and task requirements. The background-level feature alignment and target-level contrast learning mechanism proposed in this invention can be directly reused, or reused after adaptability adjustments in terms of threshold, network structure parameters, etc., according to the specific task.
[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for detecting small targets in complex underwater backgrounds based on unsupervised domain adaptation, characterized in that, include: S1: Preprocess the source domain labeled image data and the target domain unlabeled image data to obtain the source domain dataset and the target domain dataset; S2: Input the source domain dataset into the basic object detection model for supervised training to obtain the source domain pre-trained model; S3: Based on the source domain dataset and the target domain dataset, the multi-level feature maps output by multiple layers of the backbone network are weighted and aligned according to the transferability weights to obtain the background-level feature alignment loss; S4: Based on the source domain pre-trained model, construct global prototypes for multiple categories of target-level features output by the detection head, perform momentum smoothing updates on the global prototypes according to the similarity gating mechanism, and calculate the target-level contrastive learning loss by combining the attraction of similar categories and the repulsion of dissimilar categories. S5: The background-level feature alignment loss, the target-level contrastive learning loss, and the standard detection loss are weighted and summed to obtain the overall loss, which is then used to jointly optimize the basic target detection model until convergence, thus obtaining the domain-adaptive detection model. S6: Apply the domain adaptation detection model to the target domain image to output the category and location information of small underwater targets.
2. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 1, characterized in that, In step S1, the source domain labeled image data is an underwater image collected in a preset water area that includes target category and bounding box location labels, and the target domain unlabeled image data is an unlabeled underwater image collected in a water area with a background distribution difference from the source domain.
3. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 1, characterized in that, In step S2, the basic target detection model is a two-stage detection model based on a region proposal network.
4. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 1, characterized in that, Step S3 further includes: S31: Perform forward propagation on the source domain dataset and the target domain dataset respectively to extract feature maps of multiple layers in the backbone network; S32: Independent domain classifiers are deployed in parallel. Multiple domain classifiers are connected to the backbone network through a gradient inversion layer. Adversarial losses are calculated for feature maps at multiple levels, and the adversarial losses are used as the transferability index of features at the corresponding levels. S33: Input the transferability metrics of multiple levels into the Softmax function to obtain the feature alignment weights corresponding to multiple levels; S34: The adversarial losses of multiple levels are weighted and summed according to the feature alignment weights to obtain the background-level feature alignment loss.
5. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 4, characterized in that, In step S32, the adversarial loss is a binary cross-entropy loss; in step S33, the loss used to generate the feature alignment weights adopts the gradient-separating version; in step S34, the expression for the background-level feature alignment loss is: in, Background-level feature alignment loss, For hierarchical indexes in the backbone network, For the first Layer feature alignment weights, For the first Adversarial loss of layer classifiers.
6. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 1, characterized in that, Step S4 further includes: S41: Use the source domain pre-trained model to perform forward propagation on the source domain dataset, extract instance features with real labels, calculate the average vector of instance features of multiple categories by category, and use the average vector as the initial value of the source domain global prototype and the target domain global prototype. S42: In each training batch, the source domain real label instance features and the target domain pseudo label instance features in the current batch are averaged by category to obtain the source domain local prototype and the target domain local prototype. S43: Calculate the cosine similarity between the local prototype of the target domain and the global prototype of the historical target domain, determine the update weight based on the cosine similarity, and perform a smooth update on the global prototype of the target domain to obtain the updated global prototype of the target domain. S44: Based on the source domain global prototype and the updated target domain global prototype, calculate the target-level contrastive learning loss.
7. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 6, characterized in that, In step S43, the expression for the cosine similarity is: in, To detect the target category index in the task. For category cosine similarity, For category The historical global prototype vector of the target domain maintained at the end of the previous training batch. For category The local prototype vector of the target domain obtained by average pooling of the effective pseudo-label instance features of the target domain in the current training batch; The expression for updating the weights is: in, For category Dynamically updated weights The preset basic momentum coefficient; The expression for smoothly updating the global prototype of the target domain is: in, For category The target domain global prototype updated in the current batch.
8. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 6, characterized in that, In step S44, the target-level contrastive learning loss is composed of a weighted sum of the same-class attraction loss and the different-class repulsion loss, expressed as: in, For target-level contrastive learning loss, Loss due to attraction to similar things To balance hyperparameters, Loss due to rejection of other species; The expression for the similar attraction loss is: in, To detect the target category index in the task. The total number of target categories for the detection task. For category The source domain global prototype vector, For category The global prototype vector of the target domain; The expression for the heterogeneity rejection loss is: in, The total number of all out-of-type prototype pairs. This is the preset interval hyperparameter. The first category prototype index in the heterogeneous prototype pair. For the second category prototype index in the heterogeneous prototype pair, For the first One prototype vector, For the first One prototype vector.
9. The underwater complex background small target detection method based on unsupervised domain adaptation according to claim 1, characterized in that, The expression for the overall loss in step S5 is: in For the overall loss, For standard detection loss, Background-level feature alignment loss, For target-level contrastive learning loss, The first weighted hyperparameter, This is the second weighted hyperparameter.
10. An underwater complex background small target detection system based on unsupervised domain adaptation, used to execute the underwater complex background small target detection method based on unsupervised domain adaptation as described in any one of claims 1 to 9, characterized in that, include: Preprocessing module: Used to preprocess the source domain labeled image data and the target domain unlabeled image data to obtain the source domain dataset and the target domain dataset; Basic object detection model: used to receive the source domain dataset for supervised training to obtain a source domain pre-trained model; The background-level feature alignment module is connected to the backbone network in the basic target detection model. It is used to perform weighted alignment of the multi-level feature maps output by multiple layers of the backbone network based on the source domain dataset and the target domain dataset, according to the transferability weights, to obtain the background-level feature alignment loss. Target-level contrastive learning module: Based on the source domain pre-trained model, it constructs global prototypes of multiple categories from the target-level features output by the detection head, performs momentum smoothing updates on the global prototypes according to the similarity gating mechanism, and calculates the target-level contrastive learning loss by combining the attraction of similar categories and the repulsion of dissimilar categories. Joint optimization module: used to perform weighted summation of the background-level feature alignment loss, the target-level contrastive learning loss, and the standard detection loss to obtain the overall loss, and to jointly optimize the basic target detection model until convergence, thus obtaining the domain-adaptive detection model; The output module is configured as the domain-adaptive detection model trained by the joint optimization module, which is used to detect the target domain image and output the category and location information of small underwater targets.