A background-ignoring contrastive learning method for underwater fish image classification

By constructing an adaptive subject and background extraction module and a contrast loss function, the contrast-ignoring background learning method (CLIB) solves the problem of background noise interference and achieves higher classification accuracy in the underwater fish image classification task. .

CN117788885BActive Publication Date: 2025-01-24QINGHAI NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311689648.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-11
Publication Date
2025-01-24
Estimated Expiration
2043-12-11

AI Technical Summary

Technical Problem

In the underwater fish image classification task, the high activity of fish schools and background noise interference lead to a slight positive effect of background on model training, while background noise brings great interference to model training.

Method used

A contrast-ignoring learning method (CLIB) is proposed. By constructing an adaptive subject and background extraction module, three views of the original image, subject and background are constructed, and the CLIB contrast loss function is used to bring the positive samples closer and the negative samples farther away, reducing the Interference from background noise.

Benefits of technology

Effectively reduce the interference of background noise, improve the accuracy of underwater fish image classification, and is suitable for the mission of underwater fish image classification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117788885B_ABST
    Figure CN117788885B_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of underwater fish image classification, and provides a background-ignoring contrast learning method for underwater fish image classification, referred to as CLIB, comprising the following steps: S1, constructing an adaptive subject and background extraction module of an underwater fish image to extract the subject and background of the underwater fish image; S2, constructing the subject, the background and the original image into three views, respectively sending them to an encoder after random data enhancement, and then mapping them to a feature space through a projection head; S3, defining samples in the three views as different positive and negative samples according to a positive and negative sample definition rule of a CLIB contrast loss function, and then using the CLIB contrast loss function to close the mapping of positive sample pairs and distance the mapping of negative sample pairs in the feature space; the invention pays more attention to the subject of the fish image and ignores the background, can greatly reduce the interference of background noise, and is more suitable for underwater fish image classification tasks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of underwater fish image classification, and in particular to a background-ignoring contrast learning method for underwater fish image classification. Background Art

[0002] The ocean is one of the most important ecosystems on earth and an important area for human survival and development. However, the marine ecological environment has been continuously damaged in recent years, and humans are the first to bear the responsibility of protecting the ocean. To protect the ocean, we first need to understand the health of the ocean. The distribution and number of fish of different species in a specific water area can well reflect the health of the ecological environment in the water area. Therefore, studying the types and numbers of fish through the collected underwater fish images has important scientific research significance for further understanding the health of the ocean and protecting endangered species. However, underwater optical images are quite different from terrestrial optical images: due to the special optical environment in the water body, different wavelengths of light have different propagation characteristics in the water medium, resulting in color distortion, visual blur and low contrast in the images collected by underwater sensors. In addition, due to the high activity of fish schools, the same type of fish may appear in different backgrounds, and different types of fish may appear in the same background. As a result, the background has little positive effect on training a high-precision underwater fish image classification model. On the contrary, the extreme background noise attached to the background will greatly interfere with the model training. These extreme noise problems make underwater fish image recognition a challenging task.

[0003] Early research on underwater fish image classification tasks was mostly based on traditional machine learning models combined with image processing technology. The main steps are: 1) Use image processing technology to denoise and enhance underwater fish images; 2) Extract pre-designed features from underwater fish images; 3) Train traditional machine learning models based on these extracted features to further achieve classification results. The classification effect of traditional machine learning models is closely related to the effectiveness of manually designed feature extraction methods, and researchers mostly rely on experience to design features. The disadvantage of this is that there is a certain degree of subjectivity and blindness. Although the methods based on traditional machine learning models have achieved certain classification effects, most of the features designed by researchers are only designed for specific data sets. When faced with a new data set or applied in practice, there is often a large error between the actual effect of the model and the ideal effect.

[0004] In 2015, the accuracy of image recognition by artificial intelligence algorithms based on deep learning surpassed that of human eyes for the first time, and artificial intelligence achieved a leap forward. In recent years, with the improvement of computer computing power, deep learning has further ushered in a big explosion. Strictly speaking, deep learning is a new field in machine learning research. A great advantage of deep learning is that it does not rely on artificially designed feature extraction methods. It further interprets data by simulating the neuronal mechanism of the human brain. Compared with traditional machine learning models, it saves a lot of tedious manual design steps. As one of the most representative algorithms of deep learning, convolutional neural networks have been widely used in various fields. From LeNet, AlexNet to later ResNet, ShuffleNet, etc., convolutional neural networks have become one of the indispensable methods in the field of computer vision after continuous improvement by researchers. Although the original convolutional neural network can extract good features of data, it still needs to use the labels that people have marked in advance in the process of feature learning. The labeling of data often requires experts to spend a lot of energy and time, and there may be labeling errors. Such wrong labels will bring great misleading in the process of model learning.

[0005] However, many current works have overlooked a very critical issue: due to the high mobility of fish schools, the same type of fish may appear in different backgrounds, and different types of fish may appear in the same background, resulting in the background part having little positive effect on training a high-precision underwater fish image classification model. On the contrary, the background noise attached to the background part will greatly interfere with model training. In addition, it is extremely difficult to obtain underwater fish images, and the image annotation work requires a lot of energy and time from experts. Summary of the invention

[0006] The present invention provides a background-ignoring contrast learning method for underwater fish image classification, referred to as CLIB, which can greatly reduce the interference of background noise and is more suitable for underwater fish image classification tasks.

[0007] A background-ignoring contrast learning method for underwater fish image classification according to the present invention is characterized in that it comprises the following steps:

[0008] S1, constructing an adaptive subject and background extraction module for underwater fish images to extract the subject and background of underwater fish images;

[0009] S2, construct the subject, background, and original image into three views, which are respectively sent to the encoder after random data enhancement, and then mapped to the feature space through the projection head;

[0010] S3. Define the samples in the three views as different positive and negative samples according to the positive and negative sample definition rules of the CLIB contrast loss function, and then use the CLIB contrast loss function to bring the positive sample pairs closer and the negative sample pairs farther in the feature space.

[0011] Preferably, in S1, an adaptive subject and background extraction module is constructed, denoted as E, to extract the subject and background of the image, and the rule for extracting the subject is: extract the central area, that is, the length and width of the central area are 1 / 2W×1 / 2H; the rule for extracting the background is: extract the four corners of the image and then splice them into a whole background image, that is, each corner is 1 / 4W×1 / 4H, and the background image part is 4×1 / 4W×1 / 4H; wherein H represents the height of the image, and W represents the width of the image.

[0012] Preferably, in S2, firstly, N sample images are randomly sampled, where N represents the number of sample images obtained by the random sampling, and the N images are input into the adaptive subject and background extraction module to obtain 3N samples, i.e., three views of the original image, the subject, and the background, and then random data enhancement is performed respectively to obtain 3N expanded samples;

[0013] Preferably, in S3, the CLIB contrast loss function defines positive and negative samples for samples in the three views according to the following rules: positive sample definition: the original image and the main sample from the same image are positive samples of each other, and the positive sample only appears in the original image and the main view; negative sample definition: 2 (N-1) samples excluding the positive samples in the original image and the main view and all samples of the background view are combined as the negative samples of the random sampling, and the background view only exists as a negative sample;

[0014] Preferably, in S3, for a positive sample pair (i, j), the CLIB contrast loss function l i,j Defined as:

[0015]

[0016] In the formula, 1 [k≠i] is the indicator function. When k≤2N, that is, k belongs to the original image and the main view, k further determines whether k is equal to i. When k is not equal to i, the value is 1. If k>2N, the indicator function value is directly set to 1. τ is the temperature coefficient, exp is the exponential function; sim is the cosine similarity function, which is used to calculate the similarity between feature vectors; z i 、z j 、z k Represent the i, j, and k-th feature vectors respectively; the total loss Γ is the cross calculation formula for all positive sample pairs (i, j) and (j, i) in the batch as follows:

[0017]

[0018] In the formula, 3k-1 and 3k-2 are used to represent all positive sample pairs in the batch, indicating that the positive samples only exist in the original image and the main view, and the background view only exists as a negative sample.

[0019] The present invention proposes a background-ignoring contrast learning method for underwater fish image classification based on the fact that background noise in underwater fish images has a large negative impact on classification tasks. The method uses a large amount of unlabeled data to perform self-supervised training on the model, reducing the model's dependence on labels. By reconstructing contrast learning views, three views of the original image, the main body, and the background are obtained for contrast learning. The contrast loss function is further improved to obtain the CLIB contrast loss function, so that the background view only exists as a negative sample, expanding the negative samples of the contrast process, so that the model pays more attention to the main body of the fish image and ignores the background. Through comparative experiments, ablation experiments, and feature visualization experiments on two data sets, Fish4Knowledge and Fish-gres, it is proved that the present invention can greatly reduce the interference of background noise and is more suitable for underwater fish image classification tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A flowchart of a background-ignoring contrast learning method for underwater fish image classification in an embodiment;

[0021] Figure 2 An example diagram for defining positive and negative samples in the embodiment;

[0022] Figure 3 This is a visualization analysis diagram of the Grad-Cam features in the embodiment. DETAILED DESCRIPTION

[0023] In order to further understand the content of the present invention, the present invention is described in detail in conjunction with the accompanying drawings and embodiments. It should be understood that the embodiments are only for explaining the present invention and are not intended to limit it.

[0024] Example

[0025] like Figure 1 As shown, this embodiment provides a background-ignoring contrastive learning method (CLIB) for underwater fish image classification, which includes the following steps:

[0026] S1, constructing an adaptive subject and background extraction module for underwater fish images to extract the subject and background of underwater fish images;

[0027] In S1, an adaptive subject and background extraction module is constructed, denoted as E, to extract the subject and background of the image. The rule for extracting the subject is: extract the central area, that is, the length and width of the central area are 1 / 2W×1 / 2H; the rule for extracting the background is: extract the four corners of the image and then splice them into a whole background image, that is, each corner is 1 / 4W×1 / 4H, and the background image part is 4×1 / 4W×1 / 4H; where H represents the height of the image and W represents the width of the image. The sizes of the image input encoder of different views are shown in Table 1. The image size of the input encoder on the Fish4Knowledge dataset is 64×64, and the image size of the input encoder on the Fish-gres dataset is 224×224.

[0028] Table 1 Size table of different views

[0029] view Fish4Knowledge Fish-gres Original image 64×64 224×224 main body 64×64 224×224 background 64×64 224×224

[0030] S2, construct the subject, background, and original image into three views, which are respectively sent to the encoder after random data enhancement, and then mapped to the feature space through the projection head;

[0031] In S2, N sample images are first randomly sampled, where N represents the number of sample images obtained by random sampling. These N images are input into the adaptive subject and background extraction module to obtain 3N samples, namely, the original image, subject, and background views. Then, random data enhancement is performed on each of them to obtain 3N expanded samples.

[0032] S3, Ignoring the background contrast learning method

[0033] The samples in the three views are defined as different positive and negative samples according to the positive and negative sample definition rules of the CLIB contrast loss function, and then the CLIB contrast loss function is used to bring the positive sample pairs closer and the negative sample pairs farther apart in the feature space.

[0034] View construction: positive and negative sample definition examples are as follows Figure 2 As shown in FIG. 1 , the positive sample definition is: the original image and the main sample from the same image are each other's positive samples; the negative sample definition is: the original image, 2 (N-1) samples excluding the positive samples in the main view and all samples in the background view are combined as the negative samples of the random sampling.

[0035] Loss function: The number of negative samples in CLIB is greatly increased because the N samples of the entire background view are considered as negative samples. After the view is constructed, each sample feature corresponds to a similar sample (positive sample) and 3N-2 dissimilar samples (negative samples). After all images of the three views are passed through the encoder and projection network, 3N feature vectors are obtained. The cosine similarity is used to calculate the similarity between sample i and the remaining 3N-1 feature vectors:

[0036]

[0037] In the formula, z i and z j represents two feature vectors after the encoder and projection network, T represents the transpose of the vector, ∥z i ∥ indicates the length of the vector;

[0038] For a positive sample pair (i, j), CLIB contrast loss function l i,j Defined as:

[0039]

[0040] In the formula, 1 [k≠i] is the indicator function. When k≤2N, that is, k belongs to the original image and the main view, k further determines whether k is equal to i. When k is not equal to i, the value is 1. If k>2N, the indicator function value is directly set to 1; τ is the temperature coefficient, exp is the exponential function; z i 、z j 、z k Represent the i, j, and k-th feature vectors respectively; the total loss Γ is the cross calculation formula for all positive sample pairs (i, j) and (j, i) in the batch as follows:

[0041]

[0042] In the formula, 3k-1 and 3k-2 are used to represent all positive sample pairs in the batch, indicating that the positive samples only exist in the original image and the main view, and the background view only exists as a negative sample.

[0043] In S3, training is performed, specifically:

[0044] In the backbone network stage, the training goal is to make the representations z1 and z2 of data x after two random data augmentations and then passing through the feature extraction network and projection network in sequence as similar as possible, and as dissimilar as possible to the rest of the feature vectors;

[0045] In the classifier training stage, the parameters of the encoder f(·) are frozen and the projection network g(·) is removed, and the classifier L is connected after the encoder f(·). In the training process, a small number of labels are used to train the classifier, and the labels are defined as y∈Y={1, 2, 3, …, K}, where K is the number of categories in the data set. The training goal is: the value of the data x after passing through the feature extraction network f(·) and then through the classifier L is equal to y, that is, L(f(x))=y, where y represents the true category of the data x.

[0046] The whole process of a background-ignoring contrastive learning method (CLIB) for underwater fish image classification is shown in the following algorithm:

[0047]

[0048] Experiment and analysis

[0049] This example first introduces the experimental settings and evaluation indicators, and then compares CLIB with a benchmark model (SimCLR) and six current mainstream self-supervised visual representation learning methods. It further conducts ablation experiments and feature visualization analysis experiments on the CLIB method.

[0050] Experimental settings and evaluation metrics

[0051] Experimental data set: This embodiment uses two fish image data sets: Fish4Knowledge and Fish-gres, where Fish4Knowledge is a fish image taken underwater, and Fish-gres is a fish image taken on land. The specific information of the data set is shown in Table 2. In the backbone network training stage, all images are put into the network for training and the model with the lowest loss value is saved as the result of the backbone network training stage; in the classifier training stage, the data set is divided into 1:1:8, where 10% is used as the training set, 10% is used as the validation set, and the remaining 80% is used as the test set. The model with the highest accuracy on the validation set is saved as the result of the classifier training stage, and then the model is used to test the test set to obtain the final accuracy.

[0052] Table 2 Dataset types and quantities

[0053] Dataset Number of types Number of images Fish4Knowledge 23 27370 Fish-gres 8 3248

[0054] Experimental environment: All experiments were run in the same hardware and software environment. Specifically, the CPU used Intel(R) Xeon(R) Platinum 8358P, the GPU used A40 (48GB), the running memory size was 80GB, the Python version was 3.8, the Pytoch version was 2.0, and all program codes were compiled under PyCharm.

[0055] Training parameter settings: SGD optimizer is used in the training phase, momentum is set to 0.9, initial learning rate is 0.01, final learning rate is 0.0001, and cosine annealing method is used to dynamically adjust the learning rate according to the current training round; the temperature coefficient of the loss function is set to 0.07; in the backbone network training phase, the training rounds are set to 500 rounds, and the batch size is set to 1024 for the model trained on the Fish4Knowledge dataset and 128 for the model trained on the Fish-gres dataset; in the classifier training phase, it is 100 rounds, and the batch size is set to 128 for the models trained on the two datasets.

[0056] Evaluation criteria: In order to more objectively test the CLIB method proposed in this embodiment, accuracy, precision, recall and F1 value are used as evaluation criteria. The calculation method is as follows:

[0057]

[0058]

[0059]

[0060]

[0061] In the formula, TP represents the number of true positives, that is, the number of cases predicted by the network to be positive and actually positive; TN represents the number of true negatives, that is, the number of cases predicted by the network to be negative and actually negative; FP represents the number of false positives, that is, the number of cases predicted by the network to be positive and actually negative; FN represents the number of false negatives, that is, the number of cases predicted by the network to be negative and actually positive.

[0062] Comparative experimental analysis

[0063] In order to verify the effectiveness and superiority of the CLIB method proposed in this example, the current classic self-supervised visual representation learning methods were selected for comparative experiments, including SimCLR (A Simple Framework for Contrastive Learning of Visual Representations), MOCO (Momentum Contrast for Unsupervised Visual Representation Learning), SimSiam (Exploring Simple Siamese Representation Learning) ], BYOL (Bootstrap Your Own Latent), TiCo (Transformation Invariance and Covariance Contrast for Self-Supervised Visual Representation Learning), NNCLR (Nearest-Neighbor Contrastive Learning of Visual Representations), Dcl (Decoupled Contrastive Learning), seven methods with superior performance.

[0064] Table 3 shows the experimental results of the method proposed in this embodiment and the comparison method on two data sets. It can be seen intuitively that the accuracy, precision, recall and F1 value of CLIB on Fish4Knowledge are 96.01%, 91.48%, 75.94% and 80.16% respectively. The four evaluation indicators are greatly improved compared with other comparison methods. The accuracy is 9.65% higher than the TiCo method, and the precision, recall and F1 value are 50.16%, 41.37% and 44.83% higher than SimSiam respectively.

[0065] Since Fish4Knowledge is a dataset of fish taken underwater, its background is relatively simple. In order to reflect the main idea of ​​CLIB: focusing on the main body of the image and ignoring the background of the image, experimental verification is specially carried out on Fish-gres. Because Fish-gres is a fish image taken on land and the background difference between the same type of fish images is larger, according to the idea of ​​contrastive learning, the feature mapping of positive samples is brought closer and the feature mapping of negative samples is pulled farther away. For a dataset like Fish-gres with a large background difference between the same type, it should be more difficult for ordinary contrastive learning methods to achieve the purpose of feature learning by bringing the feature mapping of positive samples closer. The main idea of ​​CLIB proposed in this embodiment is to focus on the main part of the image and ignore the background part of the image. From the analysis, it is found that CLIB should have a better performance on the Fish-gres dataset. The experimental results verified the analysis. The accuracy, precision, recall and F1 value of CLIB on the Fish-gres dataset reached 87.59%, 88.38%, 86.35% and 87.17% respectively. The accuracy index exceeded SimCLR (8.72%), Moco (8.61%), SimSiam (20.94%), BYOL (19.56%), TiCo (19.63%), NNCLR (7.42%), and Dcl (9.84%). In addition, there are different improvements in the other three indicators (precision, recall and F1 value), which just verifies the effectiveness of CLIB's idea of ​​ignoring the background and focusing on the subject.

[0066] In summary, the experimental results and analysis on the Fish4Knowledge dataset show that CLIB can achieve excellent performance in the underwater fish image classification task. The experimental results and analysis on the Fish-gres dataset further verify the working mechanism and advantages of CLIB. The effectiveness of CLIB in the underwater fish image classification task full of extreme background noise is verified from both analytical and experimental aspects.

[0067] Table 3 Comparative experimental results

[0068]

[0069] Ablation experiment analysis

[0070] In order to further verify the internal working mechanism of CLIB, this embodiment designs three groups of ablation experiments. The first group is the baseline model SimCLR, the second group is based on SimCLR with background views added (only as negative samples), and the third group is the CLIB proposed in this embodiment. Before conducting the experiment, we first analyze the first set of ablation experiments, i.e., the baseline model, which uses the contrast loss function to bring the mapping of positive samples closer in the feature space and to distance the mapping of negative samples in the feature space. The second set of ablation experiments designed adds background views on the basis of SimCLR to further expand the negative samples. According to the idea of ​​SimCLR, the mapping of the two original image views and the background view in the feature space will be distanced during the training process. However, the original image view is not like the main view, and the background part still exists in the original image view. This will cause a contradiction during the training process: on the one hand, the mapping of the two original image views in the feature space is brought closer to each other. Since the background part still exists in the original image view, that is, the background parts of the two views are also brought closer to each other, the model will learn and pay attention to the background part; on the other hand, according to the idea of ​​distance negative samples by the contrast loss function, in the feature space, the representation of the original image view and the background view in the feature space during the training process will be distanced, that is, the model will increasingly ignore the background part, which is inconsistent with the aforementioned model learning and paying attention to the background part. Therefore, from the analysis, it can be concluded that the results of the second set of ablation experiments should be similar to those of the baseline model. The experimental data in Table 4 verifies the analysis. The results of the second group of ablation experiments are higher or lower than the baseline model in four indicators. The accuracy and recall on the Fish4Knowledge dataset are 0.15% and 1.38% higher than the baseline model, while the precision and F1 value are 5.61% and 0.38% lower; the accuracy, recall and F1 value on the Fish-gres dataset are 0.53%, 1.23% and 0.85% higher than the baseline model, while the precision is 0.19% lower. Therefore, it can be concluded that simply adding background view partial expansion negative samples on SimCLR cannot substantially improve the model.

[0071] The third group of ablation experiments is the CLIB method proposed in this embodiment, that is, on the basis of the second group, an original image view is replaced with the subject view proposed in this embodiment. From the analysis, it can be obtained that according to the idea of ​​contrastive learning, during the training process, the CLIB method regards the original image view and the subject view of an image as a pair of positive samples, and regards the remaining 2 (N-1) samples and the background views of the images in the entire batch as negative samples. In the process of model learning, by bringing the mapping of positive samples in the feature space closer and the mapping of negative samples in the feature space farther, the model gradually shifts its attention to the subject and ignores the background. In this case, there is no contradictory relationship in the second group of ablation experiments. Therefore, from the analysis, it can be obtained that the experimental effect of CLIB should be substantially improved compared with the baseline model. From the experimental data in Table 4, the analysis is fully verified. CLIB has been greatly improved in the four evaluation indicators of the two datasets. The accuracy, precision, recall and F1 value on the Fish4Knowledge dataset are improved by 1.28%, 10.26%, 5.37% and 6.06% respectively compared with the second group of ablation experiments, and the accuracy, precision, recall and F1 value on the Fish-gres dataset are improved by 8.19%, 8.35%, 7.67% and 8.1% respectively compared with the second group of ablation experiments. Therefore, the ablation experiment proves that CLIB is effective in focusing on the subject and ignoring the background.

[0072] Table 4 Ablation experiment results

[0073]

[0074] Feature visualization analysis

[0075] In order to intuitively express the focus of the CLIB method, that is, focusing on the subject and ignoring the background, the class activation map (Grad-Cam) is used to visualize the features. The results are shown in the figure. Figure 3 As shown in the figure, the darker the red area, the more important the area is to the decision classification of the model. The baseline model for comparison in this visualization experiment is SimCLR.

[0076] For most general methods, it is very easy to treat the background as part of the fish for decision classification. However, in the training process of CLIB, the background views of the entire batch are used to expand the negative samples and the mapping of positive and negative samples in the feature space is pulled apart, so that the trained model has the ability to distinguish between the subject and the background, which further enables the model to locate the subject and focus on the subject and ignore the background. Figure 3It can be seen intuitively that both the baseline model and CLIB pay attention to the identification of the main area, but the difference is that the baseline model is easily affected by the background. For example, in the first row, although the model pays attention to the fish part in the image, it also pays attention to the plant part below the image. For example, in the second row, the main part of the image, that is, the fish part, is very similar to the background, and it is even difficult to observe the position of the fish with the naked eye. The baseline model also regards the area below the main body that is extremely similar to the fish as the main body of the fish. This type of fish will be affected by its background when the model makes decisions and classifications, while CLIB has the ability to implicitly distinguish between the main body and the background. During the training process of the model, the negative impact of the background on the model's decision classification will be greatly reduced. Similarly, the same is true for the Fish-gres dataset. For example, in the seventh row, the baseline model pays great attention to the wrist part in the image and ignores the fish in the hand, while CLIB can accurately focus on the main part of the fish.

[0077] In summary, the idea of ​​CLIB can be further verified by using class activation maps to visualize the features. Through the process of contrastive learning, we can further purposefully focus on the fish body of the image and ignore the background part with extreme noise.

[0078] This embodiment proposes a background-ignoring contrast learning method for underwater fish image classification based on the fact that background noise in underwater fish images has a large negative impact on classification tasks. This method uses a large amount of unlabeled data to perform self-supervised training on the model, reducing the model's dependence on labels. By reconstructing contrast learning views, three views of the original image, the main body, and the background are obtained for contrast learning. The contrast loss function is further improved to obtain the CLIB contrast loss function, so that the background view only exists as a negative sample, expanding the negative samples of the contrast process, so that the model pays more attention to the main body of the fish image and ignores the background. Through contrast experiments, ablation experiments, and feature visualization analysis experiments, it is verified that the method proposed in this paper effectively improves the problem of excessive negative impact of background noise on underwater fish image classification tasks, improves recognition accuracy, and further analyzes its improvement mechanism from two levels of analysis and experimental verification.

[0079] The present invention and its embodiments are described schematically above, and the description is not restrictive. The drawings show only one embodiment of the present invention, and the actual structure is not limited thereto. Therefore, if a person skilled in the art is inspired by it and designs a structural method and an embodiment similar to the technical solution without creativity without departing from the purpose of the invention, they shall all fall within the protection scope of the present invention.

Claims

1. A background-ignoring contrast learning method for underwater fish image classification, characterized by: The following steps are involved: S1, constructing an adaptive subject and background extraction module for underwater fish images to extract the subject and background of underwater fish images; S2, construct the subject, background, and original image into three views, which are respectively sent to the encoder after random data enhancement, and then mapped to the feature space through the projection head; In S2, N sample images are first randomly sampled, where N represents the number of sample images obtained by random sampling. These N images are input into the adaptive subject and background extraction module to obtain 3N samples, i.e., the original image, subject, and background views. Then, random data enhancement is performed on each of them to obtain 3N expanded samples. S3, defining the samples in the three views as different positive and negative samples according to the positive and negative sample definition rules of the CLIB contrast loss function, and then using the CLIB contrast loss function to bring the positive sample pairs closer and the negative sample pairs farther in the feature space; In S3, the CLIB contrast loss function defines positive and negative samples for samples in the three views according to the following rules: positive sample definition: the original image and the main sample from the same image are positive samples of each other, and the positive sample only appears in the original image and the main view; negative sample definition: the 2(N-1) samples excluding the positive samples in the original image and the main view and all the samples in the background view are combined as randomly sampled negative samples, and the background view only exists as a negative sample; For any positive sample pair (i, j), CLIB contrast loss function Defined as: In the formula, 1 [k≠i] is the indicator function. When k≤2N, that is, k belongs to the original image and the main view, k further determines whether k is equal to i. When k is not equal to i, the value is 1. If k>2N, the indicator function value is directly set to 1. τ is the temperature coefficient, exp is the exponential function; sim is the cosine similarity function, which is used to calculate the similarity between feature vectors; z i 、z j 、z k Represent the i, j, and k-th feature vectors respectively; the total loss Γ is the cross calculation formula for all positive sample pairs (i, j) and (j, i) in the batch as follows: In the formula, 3k-1 and 3k-2 are used to represent all positive sample pairs in the batch, indicating that the positive samples only exist in the original image and the main view, and the background view only exists as a negative sample.

2. The background-ignoring contrast learning method for underwater fish image classification according to claim 1, characterized in that: In S1, an adaptive subject and background extraction module is constructed, denoted as E, to extract the subject and background of the image. The rule for extracting the subject is: extract the central area, that is, the length and width of the central area are 1 / 2W×1 / 2H; the rule for extracting the background is: extract the four corners of the image and then splice them into a whole background image, that is, each corner is 1 / 4W×1 / 4H, and the background image part is 4×1 / 4W×1 / 4H; where H represents the height of the image and W represents the width of the image.