Water body color anomaly identification method and system based on contrast learning, medium and device

CN123033115APending Publication Date: 2026-11-03CRSC COMM & INFORMATION GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611202466.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-10
Publication Date
2026-11-03

AI Technical Summary

Technical Problem

现有的水体颜色异常识别方法依赖人工巡检或基于阈值的传统图像处理,效率低且鲁棒性差,难以区分水草底部裸露和藻类暴发等外观相似场景。

Method used

We employ a contrastive learning-based approach, extracting deep features through a shared encoder to construct positive and negative sample pairs. We then utilize ECA and a cross-attention module to generate channel-enhanced and attention-enhanced features, and combine contrastive loss and classification loss for joint optimization to enhance feature discriminativeness.

Benefits of technology

It improves the ability to distinguish between exposed aquatic plants and algal blooms, reduces the false positive rate, and enhances the model's adaptability to changes in lighting and complex environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123033115A_ABST
    Figure CN123033115A_ABST
Patent Text Reader

Abstract

The present application relates to the field of computer vision and artificial intelligence, and discloses a water body color anomaly recognition method and system based on contrast learning, a medium and equipment, which comprises: obtaining water body monitoring image data and preprocessing, extracting the deep features of each image through a shared encoder, and constructing training image pairs including positive sample pairs and negative sample pairs based on feature similarity; inputting the deep features of each image in the training image pairs into an ECA module, generating corresponding channel attention weights, and performing channel-by-channel weighting on the corresponding deep features to obtain channel enhanced features; through a cross-attention module, the channel enhanced features of the two images in the image pair are subjected to cross-sample information interaction to generate attention enhanced features that fuse the context information of the image pair; the attention enhanced features are input into a recognition network, and a classification loss function and a contrast loss function are combined for joint optimization, so that the model simultaneously obtains class discrimination ability and feature measurement ability, thereby training a water body color anomaly recognition model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of computer vision and artificial intelligence, and in particular to a method, system, medium, and device for identifying water color anomalies based on contrastive learning. Background Technology

[0002] With the increasing demand for water environment monitoring, water color, as one of the important external characteristics reflecting changes in water quality, is widely used in environmental monitoring of rivers, lakes, reservoirs, and nearshore waters. When water bodies are affected by pollutant discharge, abnormal algal growth, or changes in the external environment, water color often changes abnormally. Therefore, the identification of abnormal water color is of great significance for water environment safety supervision.

[0003] Existing methods for identifying water color anomalies mostly rely on manual inspection or traditional image processing methods based on thresholds and rules. Manual inspection is inefficient and heavily influenced by subjective experience; image processing methods based on fixed thresholds or manual features are poorly adaptable to complex environments such as changes in lighting, shooting angle, and water surface reflection, and have limited robustness.

[0004] Convolutional Neural Networks (CNNs) are capable of extracting high-level representative features and have achieved significant results in classification. However, they still face many challenges in practical applications. For example, in water monitoring tasks, due to factors such as exposed aquatic plants at the bottom, water images often exhibit a greenish or yellowish visual characteristic, which is highly similar to the appearance of algal blooms. Because the differences between the two in low-level visual features such as color and texture are small, traditional classification methods based on single-image feature learning are prone to confusion, thus reducing overall classification performance. Summary of the Invention

[0005] To address the aforementioned problems, the present invention aims to provide a method, system, medium, and device for identifying water color anomalies based on contrastive learning. This method can improve the ability to distinguish easily confused categories, enhance feature discrimination, and reduce misjudgments between scenarios such as exposed bottoms of aquatic plants and algal blooms.

[0006] To achieve the above objectives, the present invention adopts the following technical solution: a water color anomaly recognition method based on contrastive learning, comprising: acquiring water monitoring image data, preprocessing the image data, extracting depth features of each image through a shared encoder, constructing training image pairs including positive sample pairs and negative sample pairs based on the depth features; inputting the two images in the training image pairs into an ECA module respectively, generating corresponding channel attention weights based on their depth features, and weighting the channel attention weights with the corresponding depth features channel by channel to obtain channel enhancement features of the two images; wherein, the ECA module is an efficient channel attention module; inputting the channel enhancement features of the two images in the sample pair into a cross-attention module to perform cross-sample feature interaction and generate attention enhancement features fused with contextual information; inputting the attention enhancement features into a classification network, and jointly optimizing them through a contrastive loss function and a classification loss function; wherein, by minimizing the contrastive loss function, the distance between positive sample pairs in the feature space is reduced, and the distance between negative sample pairs in the feature space is greater than a preset interval threshold, while the classification loss function is used to provide category supervision to train a water color anomaly recognition model.

[0007] Furthermore, training image pairs, including positive and negative sample pairs, are constructed based on deep features, including: Two images with an Euclidean distance less than or equal to a preset first distance threshold are selected as positive sample pairs, and two images with an Euclidean distance greater than or equal to a preset second distance threshold are selected as negative sample pairs, wherein the second distance threshold is greater than the first distance threshold.

[0008] Furthermore, the acquisition of channel enhancement features from the two images includes: The image depth features of positive and negative sample pairs are input into the ECA module, and a one-dimensional vector is obtained by global average pooling. Channel interactions are modeled using fast one-dimensional convolution with a kernel size of k, generating channel attention weights for each channel. By weighting the channel attention weights with the corresponding image depth features channel by channel, the channel enhancement features of the two images in the image pair are obtained.

[0009] Furthermore, the channel enhancement features of the two images in the sample pair are input into the cross-attention module to perform cross-sample feature interaction, generating attention enhancement features that fuse contextual information, including: The query matrix Q, key matrix K, and value matrix V are generated from the channel enhancement features of image 1 and image 2, respectively. The similarity between the query matrix Q of image 1 and the key matrix K of image 2 is calculated and then normalized to obtain the cross-attention weights. Multiply the cross-attention weights by the value matrix V of image 2 to obtain the contextual features of the image pair; Contextual features are fused with corresponding channel enhancement features to generate attention-enhanced features, which learn the difference features and common features between image pairs.

[0010] Furthermore, the comparison loss function is as follows: , in, The Euclidean distance between the two images is... For category labels, , It is a constant. The preset interval threshold for the feature distance between negative sample pairs; These are positive sample pairs. These are negative sample pairs.

[0011] Furthermore, the classification loss function is: , in, Category labels; This represents the probability that the model predicts the same category, where y=1 indicates the same category and y=0 indicates different categories.

[0012] Furthermore, the total loss function for joint optimization is: , in, , The weighting constant is used to balance the two types of losses.

[0013] A water color anomaly recognition system based on contrastive learning includes: a data acquisition and processing module, which acquires water monitoring image data, preprocesses the image data, extracts depth features of each image through a shared encoder, and constructs training image pairs including positive and negative sample pairs based on the depth features; a feature enhancement module, which inputs the two images from the training image pair into an ECA module, generates corresponding channel attention weights based on their depth features, and performs channel-wise weighting of the channel attention weights with the corresponding depth features to obtain channel enhancement features for the two images; an interaction enhancement module, which inputs the channel enhancement features of the two images from the sample pair into a cross-attention module to perform cross-sample feature interaction and generate attention enhancement features that fuse contextual information; and a recognition module, which inputs the attention enhancement features into a classification network and performs joint optimization through a contrastive loss function and a classification loss function; wherein, by minimizing the contrastive loss function, the distance between positive sample pairs in the feature space is reduced, and the distance between negative sample pairs in the feature space is made greater than a preset interval threshold, while the classification loss function is used to provide category supervision to train a water color anomaly recognition model.

[0014] A computer-readable storage medium storing one or more programs, the one or more programs including instructions that, when executed by a computing device, cause the computing device to perform any of the methods described above.

[0015] A computing device includes: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include instructions for performing any of the methods described above.

[0016] The present invention has the following advantages due to the adoption of the above technical solutions: 1. This invention can improve the ability to distinguish easily confused categories. By using the difference constraints between samples through comparative learning, it enhances the discriminative power of features and reduces misjudgments between scenarios such as exposed bottoms of aquatic plants and algal blooms.

[0017] 2. This invention can highlight key local differences and introduce ECA to make the model pay more attention to the effective features of key regions and suppress background interference.

[0018] 3. This invention improves the model's adaptability and stability under complex factors such as changes in illumination, sediment disturbance, and water surface reflection by using cross-sample feature interaction and attention guidance mechanisms.

[0019] 4. This invention can achieve effective representation learning under a shared backbone network structure, which is convenient for application in different waters and under different shooting conditions. Attached Figure Description

[0020] Figure 1 This is a flowchart of the water color anomaly identification method based on contrastive learning in an embodiment of the present invention; Figure 2 This is a schematic diagram of the ECA module in an embodiment of the present invention; Figure 3 This is a schematic diagram of the cross-attention module in an embodiment of the present invention. Detailed Implementation

[0021] To address the issues of existing water color anomaly identification algorithms being prone to category confusion in water bodies with similar appearances, leading to insufficient accuracy and robustness, this invention proposes a water color anomaly identification method, system, medium, and device based on contrastive learning. This invention introduces contrastive learning, enhancing the discriminative power of feature representations through comparative constraints between samples. This invention constructs positive and negative sample pairs, enabling the model to bring similar samples closer together and distance dissimilar samples from each other in the feature space. Specifically, contrastive learning maximizes the consistency of positive sample pairs and minimizes the similarity of negative sample pairs, thereby learning more discriminative feature representations.

[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the described embodiments of the present invention are within the scope of protection of the present invention.

[0023] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of exemplary embodiments according to the invention. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0024] In one embodiment of the present invention, a water color anomaly identification method based on contrastive learning is provided. This method highlights key discrimination areas and utilizes contrastive learning to improve the accuracy and robustness of water color anomaly identification. In this embodiment, as shown... Figures 1 to 3 As shown, the method includes the following steps: 1) Acquire water body monitoring image data, preprocess the image data, and extract the depth features of each image through a shared encoder. Based on the depth features, construct training image pairs including positive and negative sample pairs.

[0025] 2) Input the two images from the training image pair into the ECA module respectively, generate corresponding channel attention weights based on their depth features, and then weight the channel attention weights with the corresponding depth features channel by channel to obtain the channel enhancement features of the two images, so as to enhance the discriminative feature response related to the identification of water color anomalies; wherein, the ECA module is an efficient channel attention module.

[0026] 3) The channel enhancement features of the two images in the sample pair are input into the cross-attention module to perform cross-sample feature interaction and generate attention enhancement features that fuse contextual information.

[0027] 4) Input attention-enhancing features into the classification network and jointly optimize them using the contrastive loss function and the classification loss function to enable the model to simultaneously obtain class discrimination ability and feature measurement ability. Specifically, by minimizing the contrastive loss function, the distance between positive sample pairs in the feature space is reduced, and the distance between negative sample pairs in the feature space is made greater than the preset interval threshold. At the same time, the classification loss function is used to provide class supervision in order to train a water color anomaly recognition model.

[0028] In step 1) above, training image pairs including positive and negative sample pairs are constructed based on deep features. The specific implementation process is as follows: two images with an Euclidean distance less than or equal to a preset first distance threshold are selected as positive sample pairs, and two images with an Euclidean distance greater than or equal to a preset second distance threshold are selected as negative sample pairs, and the second distance threshold is greater than the first distance threshold.

[0029] In this embodiment, image depth features are extracted using ResNet18 (Residual Network-18), and similarity is calculated using Euclidean distance. For each image, positive sample pairs with high intra-class similarity and negative sample pairs with high inter-class similarity are selected to form the image pairs used for training.

[0030] In this embodiment, image data preprocessing includes: image cropping, normalization, etc.

[0031] In step 2) above, if Figure 2 As shown, by introducing the Channel Attention (ECA) module, the acquisition of channel enhancement features from two images specifically includes the following steps: 2.1) Input the image depth features of the positive and negative sample pairs into the ECA module respectively, and obtain a one-dimensional vector through global average pooling (GAP). For example, obtain a one-dimensional channel description vector with a size of 1×1×C, where C represents the number of feature channels.

[0032] 2.2) The interaction between channels is modeled by fast one-dimensional convolution with kernel size k, and the channel attention weights of each channel are generated.

[0033] 2.3) Apply channel weights to the corresponding image features, and perform channel attention weights and corresponding image depth features channel-wise weighting to obtain the channel enhancement features of the two images in the image pair, so as to enhance the discriminative feature response that the model focuses on.

[0034] In step 3) above, if Figure 3 As shown, the channel enhancement features of the two images in the sample pair are input into the cross-attention module to perform cross-sample feature interaction and generate attention enhancement features that fuse contextual information. The specific steps include: 3.1) Generate query matrix Q, key matrix K, and value matrix V from the channel enhancement features of image 1 and image 2, respectively.

[0035] 3.2) Calculate the similarity between the query matrix Q of image 1 and the key matrix K of image 2, and obtain the cross-attention weights after normalization.

[0036] 3.3) Multiply the cross-attention weights with the value matrix V of image 2 to obtain the contextual features of the image pair.

[0037] 3.4) Fuse contextual features with corresponding channel enhancement features to generate attention enhancement features, in order to learn the difference features and common features between image pairs.

[0038] In this embodiment, the context feature is utilized. It provides cross-sample association clues to learn the differential and common features between samples.

[0039] The two-way attention enhancement features output are as follows:

[0040]

[0041]

[0042] In the formula, This represents the output of cross-attention, and can also be denoted as contextual features. T represents transpose; This represents the feature dimension of the query matrix or key matrix; , This represents attention-enhanced features that incorporate contextual information; Representing images respectively and images Channel enhancement features.

[0043] In step 4) above, the contrastive loss function is: , In the formula, The Euclidean distance between the two images is... f is an embedded function. These are the weights learned at a certain layer of the network. For category labels, , It is a constant. The preset interval threshold for the feature distance between negative sample pairs; These are positive sample pairs. These are negative sample pairs.

[0044] Among them, the contrastive loss function can also use Triplet loss, ArcFace, etc. to measure the learning loss.

[0045] In this embodiment, the classification loss function is the cross-entropy loss function, which aims to minimize the distance between the predicted probability and the true label. The classification loss function is: , in, Category labels; This represents the probability that the model predicts the same category, where y=1 indicates the same category and y=0 indicates different categories.

[0046] In this embodiment, the total loss function of the joint optimization is: , in, , The weighting constant is used to balance the two types of losses.

[0047] In this embodiment, cross attention is introduced to achieve sample feature alignment and difference modeling, and contrast loss and classification loss are combined for training optimization, so that samples of the same type are closer in the feature space and samples of different types are more separated.

[0048] In summary, this invention utilizes a sample pairing mechanism to jointly constrain and optimize contrastive loss and cross-entropy loss. Contrastive loss brings positive samples closer and distances negative samples to enhance discriminative representation; cross-entropy loss provides category supervision and constrains the model to learn stable classification decision boundaries, thereby improving classification accuracy and generalization ability. Furthermore, a cross-attention module is introduced between the two feature paths to achieve cross-sample information interaction and difference modeling, resulting in attention-enhanced feature representations. This invention can also be applied to image retrieval and visual tasks such as forgery detection.

[0049] In one embodiment of the present invention, a water color anomaly recognition system based on contrastive learning is provided, comprising: The data acquisition and processing module acquires water body monitoring image data, preprocesses the image data, extracts the depth features of each image through a shared encoder, and constructs training image pairs including positive and negative sample pairs based on the depth features. The feature enhancement module inputs the two images from the training image pair into the ECA module, generates corresponding channel attention weights based on their depth features, and then weights the channel attention weights with the corresponding depth features channel by channel to obtain the channel enhancement features of the two images. The interaction enhancement module inputs the channel enhancement features of the two images in the sample pair into the cross-attention module to perform cross-sample feature interaction and generate attention enhancement features that fuse contextual information. The recognition module inputs attention-enhancing features into the classification network and performs joint optimization through a contrastive loss function and a classification loss function. Specifically, by minimizing the contrastive loss function, the distance between positive sample pairs in the feature space is reduced, and the distance between negative sample pairs in the feature space is made greater than a preset interval threshold. At the same time, the classification loss function is used to provide category supervision in order to train a water color anomaly recognition model.

[0050] In the above embodiments, constructing training image pairs including positive and negative sample pairs based on deep features includes: Two images with an Euclidean distance less than or equal to a preset first distance threshold are selected as positive sample pairs, and two images with an Euclidean distance greater than or equal to a preset second distance threshold are selected as negative sample pairs, wherein the second distance threshold is greater than the first distance threshold.

[0051] In the above embodiments, obtaining the channel enhancement features of the two images includes: The image depth features of positive and negative sample pairs are input into the ECA module, and a one-dimensional vector is obtained by global average pooling. Channel interactions are modeled using fast one-dimensional convolution with a kernel size of k, generating channel attention weights for each channel. By weighting the channel attention weights with the corresponding image depth features channel by channel, the channel enhancement features of the two images in the image pair are obtained.

[0052] In the above embodiments, the channel enhancement features of the two images in the sample pair are input into the cross-attention module to perform cross-sample feature interaction and generate attention enhancement features that fuse contextual information, including: The query matrix Q, key matrix K, and value matrix V are generated from the channel enhancement features of image 1 and image 2, respectively. The similarity between the query matrix Q of image 1 and the key matrix K of image 2 is calculated and then normalized to obtain the cross-attention weights. Multiply the cross-attention weights by the value matrix V of image 2 to obtain the contextual features of the image pair; Contextual features are fused with corresponding channel enhancement features to generate attention-enhanced features, which learn the difference features and common features between image pairs.

[0053] In the above embodiment, the contrast loss function is: , in, The Euclidean distance between the two images is... For category labels, , It is a constant. The preset interval threshold for the feature distance between negative sample pairs; These are positive sample pairs. These are negative sample pairs.

[0054] In the above embodiment, the classification loss function is: , in, Category labels; This represents the probability that the model predicts the same category, where y=1 indicates the same category and y=0 indicates different categories.

[0055] In the above embodiments, the total loss function for joint optimization is: , in, , The weighting constant is used to balance the two types of losses.

[0056] The system provided in this embodiment is used to execute the above-described method embodiments. For specific processes and details, please refer to the above embodiments, which will not be repeated here.

[0057] In one embodiment of the present invention, a computing device is provided, which may be a terminal and may include: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors, and the one or more programs include instructions for performing any of the methods in the above embodiments.

[0058] Furthermore, when the aforementioned instructions can be implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0059] In one embodiment of the present invention, a computer program product is provided, the computer program product including a computer program stored on a non-transitory computer-readable storage medium, the computer program including program instructions, and when the program instructions are executed by a computer, the computer is able to perform the methods provided in the above-described method embodiments.

[0060] In one embodiment of the present invention, a non-transitory computer-readable storage medium is provided, which stores server instructions that cause a computer to perform the methods provided in the above embodiments.

[0061] The computer-readable storage medium provided in the above embodiments has a similar implementation principle and technical effect to the above method embodiments, and will not be described again here.

[0062] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0063] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0064] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0065] 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 identifying water color anomalies based on contrastive learning, characterized in that, include: Acquire water body monitoring image data, preprocess the image data, and extract the depth features of each image through a shared encoder. Based on the depth features, construct training image pairs including positive sample pairs and negative sample pairs. The two images in the training image pair are input into the ECA module, which generates corresponding channel attention weights based on their depth features. The channel attention weights are then weighted channel by channel with the corresponding depth features to obtain the channel enhancement features of the two images. The ECA module is an efficient channel attention module. The channel enhancement features of the two images in the sample pair are input into the cross-attention module to perform cross-sample feature interaction and generate attention enhancement features that fuse contextual information. Attention-enhancing features are input into the classification network and jointly optimized using a contrastive loss function and a classification loss function. Specifically, by minimizing the contrastive loss function, the distance between positive sample pairs in the feature space is reduced, and the distance between negative sample pairs in the feature space is made greater than a preset interval threshold. At the same time, the classification loss function is used to provide category supervision in order to train a water color anomaly recognition model.

2. The water color anomaly recognition method based on contrastive learning as described in claim 1, characterized in that, Training image pairs, including positive and negative sample pairs, are constructed based on deep features, including: Two images with an Euclidean distance less than or equal to a preset first distance threshold are selected as positive sample pairs, and two images with an Euclidean distance greater than or equal to a preset second distance threshold are selected as negative sample pairs, wherein the second distance threshold is greater than the first distance threshold.

3. The water color anomaly recognition method based on contrastive learning as described in claim 1, characterized in that, The acquisition of channel enhancement features from two images includes: The image depth features of positive and negative sample pairs are input into the ECA module, and a one-dimensional vector is obtained by global average pooling. Channel interactions are modeled using fast one-dimensional convolution with a kernel size of k, generating channel attention weights for each channel. By weighting the channel attention weights with the corresponding image depth features channel by channel, the channel enhancement features of the two images in the image pair are obtained.

4. The water color anomaly recognition method based on contrastive learning as described in claim 1, characterized in that, The channel enhancement features of the two images in the sample pair are input into the cross-attention module to perform cross-sample feature interaction, generating attention enhancement features that fuse contextual information, including: The query matrix Q, key matrix K, and value matrix V are generated from the channel enhancement features of image 1 and image 2, respectively. The similarity between the query matrix Q of image 1 and the key matrix K of image 2 is calculated and then normalized to obtain the cross-attention weights. Multiply the cross-attention weights by the value matrix V of image 2 to obtain the contextual features of the image pair; Contextual features are fused with corresponding channel enhancement features to generate attention-enhanced features, which learn the difference features and common features between image pairs.

5. The water color anomaly recognition method based on contrastive learning as described in claim 1, characterized in that, The contrastive loss function is: , in, Let Euclidean distance be the distance between the two images. For category labels, , It is a constant. The preset interval threshold for the feature distance between negative sample pairs; These are positive sample pairs. These are negative sample pairs.

6. The water color anomaly recognition method based on contrastive learning as described in claim 1, characterized in that, The classification loss function is: , in, Category labels; This represents the probability that the model predicts the same category, where y=1 indicates the same category and y=0 indicates different categories.

7. The water color anomaly recognition method based on contrastive learning as described in claim 1, characterized in that, The total loss function of the joint optimization is: , in, , The weighting constant is used to balance the two types of losses.

8. A water color anomaly recognition system based on contrastive learning, characterized in that, include: The data acquisition and processing module acquires water body monitoring image data, preprocesses the image data, extracts the depth features of each image through a shared encoder, and constructs training image pairs including positive and negative sample pairs based on the depth features. The feature enhancement module inputs the two images from the training image pair into the ECA module, generates corresponding channel attention weights based on their depth features, and then weights the channel attention weights with the corresponding depth features channel by channel to obtain the channel enhancement features of the two images. The interaction enhancement module inputs the channel enhancement features of the two images in the sample pair into the cross-attention module to perform cross-sample feature interaction and generate attention enhancement features that fuse contextual information. The recognition module inputs attention-enhancing features into the classification network and performs joint optimization through a contrastive loss function and a classification loss function. Specifically, by minimizing the contrastive loss function, the distance between positive sample pairs in the feature space is reduced, and the distance between negative sample pairs in the feature space is made greater than a preset interval threshold. At the same time, the classification loss function is used to provide category supervision in order to train a water color anomaly recognition model.

9. A computer-readable storage medium for storing one or more programs, characterized in that, The one or more programs include instructions that, when executed by a computing device, cause the computing device to perform any of the methods described in claims 1 to 7.

10. A computing device, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including instructions for performing any of the methods described in claims 1 to 7.