Comparative learning remote sensing image basic model construction method based on completely aligned samples
By pre-training the learning model of the remote sensing image data chunked and fully aligned sample comparison, the problem of false positive samples in remote sensing images affecting the interpretation results is solved, and the accuracy and generalization of the remote sensing image interpretation model is improved. .
Patent Information
- Application Number
- CN202411061920.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-11-15
AI Technical Summary
The randomly cropped samples in remote sensing images are prone to false positive samples, which affects the accuracy of the interpretation results of the interpretation model constructed by the contrast-based self-supervised learning method.
By chunking the remote sensing image data, the pre-trained data set and the downstream task data set are obtained, the comparative learning model is pre-trained based on fully aligned samples, the encoder parameters are optimized, and the prediction model is constructed in combination with the decoder for accuracy evaluation. and parameter adjustment to avoid false positive sample pairs and improve the accuracy of prediction results.
It effectively avoids false positive sample pairs, improves the prediction accuracy and generalization of the remote sensing image interpretation model, and provides an efficient and accurate interpretation method for remote sensing images.
Smart Images

Figure CN118968222A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of remote sensing technology, and more specifically, to a method for constructing a basic model of remote sensing images by contrastive learning based on fully aligned samples, a device for constructing a basic model of remote sensing images by contrastive learning based on fully aligned samples, an electronic device and a storage medium. Background Art
[0002] Using deep learning to interpret remote sensing images in a large range and with high efficiency has gradually become the main means of application in the fields of natural resource survey and monitoring, ecological environment protection, etc. The methods for constructing interpretation models can be simply divided into supervised methods and unsupervised methods. Among them, unsupervised methods include traditional dimensionality reduction methods, clustering methods, etc., which can discover the inherent structure and relationship in the data without human intervention. In recent years, self-supervised learning methods based on the idea of unsupervised learning have also been continuously proposed and have become the focus of current research. Self-supervised learning uses carefully designed proxy tasks (pretext tasks) to generate pseudo labels in unlabeled images, mine useful knowledge in massive data, and improve the representation ability of the model. Self-supervised learning methods mainly include two categories: generative and comparative.
[0003] Although the generative self-supervised learning method can learn potential features at the pixel level, this method is prone to learning a lot of noise in the data and has certain limitations; the contrastive self-supervised learning method uses a twin network-like architecture, treating the same picture through data augmentation as a positive sample pair that can be classified into the same category, and other pictures as negative sample pairs, and learning useful potential information in the data by narrowing the gap between similar samples in the feature space. However, since remote sensing images are taken from high altitudes, compared with natural images, the main features in remote sensing image slices are smaller and not in the center of the picture, which will cause the sample pairs constructed by random cropping to be prone to false positive samples. This seriously affects the accuracy of the interpretation results of the remote sensing image interpretation model constructed using the contrastive self-supervised learning method.
[0004] Therefore, a new technical solution is urgently needed to solve the above technical problems. Summary of the invention
[0005] A series of simplified concepts are introduced in the Summary of the Invention, which will be further described in detail in the Detailed Description of the Invention. The Summary of the Invention does not mean to attempt to define the key features and essential technical features of the claimed technical solution, nor does it mean to attempt to determine the scope of protection of the claimed technical solution.
[0006] In a first aspect, the present invention proposes a method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples, comprising:
[0007] The remote sensing image data is divided into blocks to obtain pre-training datasets and downstream task datasets;
[0008] Pre-training a contrastive learning model based on fully aligned samples based on a pre-training dataset to obtain an encoder;
[0009] Input the downstream task dataset into the prediction model to obtain the prediction result, where the prediction model is built based on the encoder and decoder;
[0010] The prediction results are evaluated for accuracy, so that after adjusting the parameters of the prediction model based on the accuracy evaluation results to obtain a new prediction model, a new prediction result is obtained using the new prediction model, wherein the accuracy evaluation results of the new prediction results meet the accuracy requirements.
[0011] In some implementations, pre-training a contrastive learning model based on fully aligned samples based on a pre-training dataset to obtain an encoder includes:
[0012] The original image in the pre-training dataset is cropped to obtain global slices and local slices;
[0013] Performing color transformation processing on the global slices and the local slices respectively, so as to obtain multiple pairs of global samples and multiple pairs of local samples, wherein each pair of samples includes a student sample and a teacher sample;
[0014] Based on multiple pairs of global samples and multiple pairs of local samples, global features and local features are obtained accordingly, where both global features and local features contain category tags, and student samples and teacher samples are semantically completely aligned;
[0015] The visual transformer is trained based on global features and local features to obtain the encoder.
[0016] In some implementations, the global features include global teacher features and global student features, the local features include local teacher features and local student features, and the visual transformer is trained based on the global features and the local features to obtain an encoder, including:
[0017] Input the global student feature and the local student feature into the student visual transformer to output the first feature;
[0018] Inputting the global teacher features and the local teacher features into the teacher visual transformer to output a second feature;
[0019] Based on the first feature and the second feature, a first loss is calculated to update relevant parameters of the student visual transformer based on the function value of the first loss;
[0020] Based on the parameter-updated student visual transformer, relevant parameters of the teacher visual transformer are updated to obtain the encoder.
[0021] In some embodiments, the global student feature includes a global student part feature and a learning part feature, the local student feature includes a local student part feature, the global teacher feature includes a global teacher part feature, and the local teacher feature includes a local teacher part feature;
[0022] The method also includes:
[0023] Inputting the global teacher features and the local teacher features into the teacher visual transformer to output a second feature;
[0024] The global student features and the local student features are input into the student visual transformer to output the first features, including:
[0025] Inputting the category labels of the first feature and the second feature to a category prediction head to output a first vector;
[0026] Based on the first feature and the second feature, obtaining a second vector;
[0027] Inputting the second vector into a picture block prediction head to output a third vector;
[0028] Inputting the learned partial features of the first feature into a pixel prediction head to output a fourth vector;
[0029] Based on the first feature and the second feature, a first loss is calculated to update relevant parameters of the student visual transformer based on the function value of the first loss, including:
[0030] Calculating losses based on the first vector, the third vector, and the fourth vector respectively to obtain a plurality of loss values correspondingly;
[0031] The multiple loss values are summed according to the preset weights to obtain the function value of the first loss.
[0032] In some implementations, based on multiple pairs of global samples and multiple pairs of local samples, correspondingly obtaining global features and local features includes:
[0033] Perform convolution operation on each sample to obtain multiple convolution result corresponding features;
[0034] The category labels are concatenated to the image block dimensions of the features corresponding to all the multiple convolution results to obtain the labeled features;
[0035] The marked features are divided into student-part features, teacher-part features and learning-part features according to a preset ratio;
[0036] Use learnable mask tags to replace the original features of the learned part of the features;
[0037] Based on the student partial features, the teacher partial features and the learning partial features, global features and local features are obtained.
[0038] In some embodiments, before evaluating the accuracy of the prediction result, the method further comprises:
[0039] Based on the prediction result, a second loss is calculated to adjust the parameters of the prediction model based on the function value of the second loss.
[0040] In some embodiments, the method further comprises:
[0041] Wrap the encoder with a visual self-attention model adapter.
[0042] Secondly, a device for constructing a basic model of remote sensing images based on contrastive learning of fully aligned samples is proposed, including:
[0043] The data segmentation unit is used to segment and cut the remote sensing image data into blocks to obtain pre-training data sets and downstream task data sets;
[0044] A training unit, for pre-training a contrastive learning model based on fully aligned samples based on a pre-training dataset to obtain an encoder;
[0045] A prediction unit is used to input the downstream task dataset into the prediction model to obtain a prediction result, wherein the prediction model is constructed based on an encoder and a decoder;
[0046] The evaluation and adjustment unit is used to evaluate the accuracy of the prediction results, so as to obtain a new prediction result using the new prediction model after adjusting the parameters of the prediction model based on the accuracy evaluation results, wherein the accuracy evaluation results of the new prediction results meet the accuracy requirements.
[0047] In a third aspect, an electronic device is proposed, including a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used by the processor to execute the method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples as described above when the processor is running.
[0048] In a fourth aspect, a storage medium is also proposed, on which program instructions are stored. The program instructions are used to execute the method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples as described above during runtime.
[0049] According to the above technical scheme, the remote sensing image data is divided into blocks and cut to obtain a pre-training data set and a downstream task data set respectively, and the pre-training data set is input into the contrastive learning model based on fully aligned samples for pre-training, and the model parameters are optimized to obtain an encoder with good feature extraction capabilities, and the encoder is combined with the decoder to obtain a prediction model, and the downstream task data set is input into the prediction model to obtain the prediction result, and the prediction result is accurately evaluated and the parameters of the prediction model are adjusted according to the accuracy evaluation result. Thus, the basic model of remote sensing image based on contrastive learning of fully aligned samples, i.e., the prediction model, is constructed using the unlabeled model construction method, wherein the use of fully aligned sample pairs for pre-training can effectively avoid the occurrence of false positive sample pairs after random cutting, and ensure the accuracy of the prediction results. At the same time, the accuracy evaluation operation can also effectively improve the prediction accuracy of the prediction model, improve the accuracy and generalization of the basic model, and provide an efficient and accurate interpretation method for remote sensing image interpretation.
[0050] The method for constructing a basic model of remote sensing images by contrastive learning based on fully aligned samples of the present invention, and other advantages, objectives and features of the present invention will be partially reflected through the following description, and will also be partially understood by technicians in this field through research and practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0052] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0053] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the exemplary embodiments below. The accompanying drawings are only for the purpose of illustrating exemplary embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0054] Figure 1 A schematic flow chart of a method for constructing a basic model of remote sensing images by contrastive learning based on fully aligned samples provided in an embodiment of the present application;
[0055] Figure 2 A schematic diagram of comparing a prediction result provided in an embodiment of the present application with reference data;
[0056] Figure 3 A schematic block diagram of a device for constructing a basic model of remote sensing images by contrastive learning based on fully aligned samples provided in an embodiment of the present application; and
[0057] Figure 4 A schematic block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0058] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0059] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices. The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0060] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.
[0061] In order to solve the above technical problems, according to the first aspect of the present application, a method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples is proposed. Figure 1 The following is a schematic flow chart of a method 100 for constructing a remote sensing image basic model based on a comparison learning of fully aligned samples provided in an embodiment of the present application. Figure 1 As shown, method 100 may include the following steps.
[0062] Step S110, cutting the remote sensing image data into blocks to obtain a pre-training data set and a downstream task data set.
[0063] Exemplarily, the remote sensing image data includes a large amount of first remote sensing image data loaded from a network cloud platform and second remote sensing image data of a location where a remote sensing image interpretation task is expected to be performed. The first remote sensing image data can be cut into 512*512 blocks according to a specified block size to generate a pre-training data set.
[0064] Similarly, the second remote sensing image data is cut into 512*512 blocks according to the same block size to generate a downstream task data set, wherein the pre-training data set and the downstream task data set both contain multiple 512*512 image blocks, and the number of image blocks in the pre-training data set is much larger than the number of image blocks in the downstream task data set. Exemplarily, pixel detection can be performed on the image blocks during the cutting process, and if it is found that the background pixels of a certain image block account for more than, for example, 10% of the entire image block, the image block can be removed. It should be noted that background pixels refer to foreground pixels, and pixels with abnormal values or black values can also be regarded as background pixels.
[0065] Step S120 , pre-training a contrastive learning model based on fully aligned samples based on a pre-training data set to obtain an encoder.
[0066] Exemplarily, based on the aforementioned step S110, a pre-processed pre-training data set can be obtained, and the pre-training data set is input into a contrastive learning model based on fully aligned samples for pre-training. The contrastive learning model based on fully aligned samples is optimized in parameters, and an encoder with feature extraction capability for remote sensing images can be obtained.
[0067] Step S130, inputting the downstream task data set into the prediction model to obtain a prediction result, wherein the prediction model is constructed based on the encoder and the decoder.
[0068] For example, after obtaining the encoder, it can be combined with a specific decoder to obtain a prediction model. The downstream task data set is input into the prediction model, and the prediction result can be output accordingly. Among them, the decoder can be a linear detection model, a UNet decoder, an RCNN decoder, etc.
[0069] Step S140, performing accuracy evaluation on the prediction result, so as to obtain a new prediction model by adjusting the parameters of the prediction model based on the accuracy evaluation result, and then using the new prediction model to obtain a new prediction result, wherein the accuracy evaluation result of the new prediction result meets the accuracy requirement.
[0070] Exemplarily, the prediction result can be compared with the reference data, and the overall accuracy (OA), intersection over union (IoU), and F1 score (F1-score) can be used as accuracy evaluation indicators to evaluate the accuracy of the prediction result to obtain an accuracy evaluation result. Figure 2A schematic diagram of comparing a prediction result with reference data (true label) provided in an embodiment of the present application. For example, Among them, the reference data is real data, including target class data and other class data. TP represents the number of prediction results and reference data that are both target class c; FP represents the number of prediction results that are target class but reference data that are other classes; FN represents the number of prediction results that are other classes but reference data that are target class; TN represents the number of prediction results and reference data that are both other classes. In this embodiment, the target class is c, and all classes except c are referred to as other classes. It should be noted that "class" here refers to the class of objects in the image, which can also be referred to as a label. According to actual needs, corresponding thresholds can be set for different accuracy evaluation indicators. When any accuracy evaluation indicator does not exceed the set threshold, it can be considered that the accuracy of the prediction model does not meet the requirements. At this time, the parameters of the prediction model can be adjusted until the accuracy evaluation result of the prediction result output by the adjusted new prediction model meets the accuracy requirements, and the parameter adjustment is stopped, and the prediction result at this time is used as the final prediction result.
[0071] According to the above technical scheme, the remote sensing image data is divided into blocks and cut to obtain a pre-training data set and a downstream task data set respectively, and the pre-training data set is input into the contrastive learning model based on fully aligned samples for pre-training, and the model parameters are optimized to obtain an encoder with good feature extraction capabilities, and the encoder is combined with the decoder to obtain a prediction model, and the downstream task data set is input into the prediction model to obtain the prediction result, and the prediction result is accurately evaluated and the parameters of the prediction model are adjusted according to the accuracy evaluation result. Thus, the basic model of remote sensing image based on contrastive learning of fully aligned samples, i.e., the prediction model, is constructed using the unlabeled model construction method, wherein the use of fully aligned sample pairs for pre-training can effectively avoid the occurrence of false positive sample pairs after random cutting, and ensure the accuracy of the prediction results. At the same time, the accuracy evaluation operation can also effectively improve the prediction accuracy of the prediction model, improve the accuracy and generalization of the basic model, and provide an efficient and accurate interpretation method for remote sensing image interpretation.
[0072] In some implementations, step S120 pre-trains a contrastive learning model based on fully aligned samples based on a pre-training dataset to obtain an encoder, which may include:
[0073] Step S121, cropping the original image in the pre-training data set to obtain global slices and local slices.
[0074] In combination with the above-mentioned embodiment, the pre-training data set includes multiple 512*512 image blocks, which are used as original images for cropping. Exemplarily, an original image of 512*512 size is input, and the original image is randomly flipped horizontally or vertically with a probability of 0.5. Then, a cropping ratio value is randomly selected from, for example, 0.4-1, and an aspect ratio value is selected from 0.75-1.33, and the original image is cropped. After cropping, all image blocks are uniformly resampled to 448*448 size. The above steps are repeated twice to obtain two 448*448 slices, which are called global slices. Similarly, the original image is randomly flipped horizontally or vertically with a probability of 0.5. Then, a cropping ratio value is randomly selected from, for example, 0.05-0.4, and an aspect ratio value is selected from 0.75-1.33 to crop the original image. After cropping, all image blocks are uniformly resampled to 96*96 size. The above steps are repeated four times to obtain 4 96*96 slices, which are called local slices.
[0075] Step S122, performing color transformation processing on the global slices and the local slices respectively, so as to obtain multiple pairs of global samples and multiple pairs of local samples correspondingly, wherein each pair of samples includes a student sample and a teacher sample.
[0076] For each of the two 448*448 global slices and the four 96*96 local slices obtained in step S121, two identical copies are generated and random color transformation is performed with probabilities of 0.8 and 0.1 respectively, wherein the parameters of the color transformation may be 0.4 brightness, 0.1 hue, 0.2 saturation and 0.4 contrast. The processed copies are converted into tensors and then standardized as samples. Standardization can be achieved using the following formula: Among them, x i is the i-th channel of the sample, mean(X) and std(X) represent the mean and standard deviation of all data in the entire pre-training dataset, respectively. Finally, we get 2 pairs of global samples and 4 pairs of local samples, a total of 12 samples. In each pair of samples, one is a student sample and the other is a teacher sample.
[0077] Step S123, based on the multiple pairs of global samples and the multiple pairs of local samples, correspondingly obtaining global features and local features, wherein both the global features and the local features contain category tags.
[0078] Exemplarily, after obtaining multiple pairs of global samples and multiple pairs of local samples, global features and local features can be correspondingly obtained by feature extraction, and a category tag is added to each feature, represented by cls, where the category tag is used to represent the label of each feature. The student samples (features) and teacher samples (features) obtained in this way are completely aligned. Among them, complete alignment means that the semantics of the sample pairs are completely aligned to prevent the occurrence of false positive sample pairs due to semantic inconsistency.
[0079] Step S124, training the visual transformer based on the global features and the local features to obtain an encoder.
[0080] Exemplarily, inputting global features and local features into a visual transformer can correspond to outputting different features, and performing loss function calculation based on these output features, thereby using the loss function value to adjust relevant parameters of the visual transformer, thereby realizing the training of the visual transformer, and the trained visual transformer is called an encoder.
[0081] In this way, an encoder with good feature extraction capability for remote sensing images can be obtained, providing a reliable guarantee for obtaining accurate prediction results in the subsequent process.
[0082] In some implementations, step S123 may include obtaining global features and local features based on multiple pairs of global samples and multiple pairs of local samples:
[0083] Step S123a, performing convolution operation on each sample respectively to obtain features corresponding to multiple convolution results.
[0084] Exemplarily, the above 12 samples can be convolved with 768 16*16 convolution kernels (with a step size of 16 and an expansion of 0) to generate global features of (768, 28, 28) and local features of (768, 6, 6). Then, the last two dimensions of these features are merged to obtain 2 pairs of global features of (784, 768) and 4 pairs of local features of (36, 768), where "784" is the product of "28×28" and "36" is the product of "6×6".
[0085] Step S123b, concatenate the category label to the image block dimensions of the features corresponding to all multiple convolution results to obtain the labeled features.
[0086] Exemplarily, the learnable category label cls is concatenated to the image block dimensions of 2 pairs of (784, 768) global features and 4 pairs of (36, 768) local features, and a learnable position encoding is added to finally obtain labeled features: 2 pairs of (785, 768) global features and 4 pairs of (37, 768) local features.
[0087] Step S123c, dividing the marked features into student part features, teacher part features and learning part features according to a preset ratio.
[0088] Exemplarily, masks are constructed in units of image blocks according to preset ratios of 0.3, 0.4, and 0.3, wherein the masks do not intersect each other and are combined into a complete sample. Each marked feature is divided into a student part feature, a teacher part feature, and a learning part feature.
[0089] Step S123d, using learnable mask marks to replace the original features of the learned part of the features.
[0090] Exemplarily, in the learning part, a learnable mask marker is used to replace the original feature.
[0091] Step S123e, obtaining global features and local features based on the student partial features, the teacher partial features and the learning partial features.
[0092] The global student partial features and local student partial features are extracted from the student partial features, and the global teacher partial features and local teacher partial features are extracted from the teacher partial features, thereby generating 2 global student features (550, 768) containing global student partial features, learning partial features and category tags, 4 local student features (12, 768) containing local student partial features and category tags, and correspondingly 2 global teacher features (236, 768) containing global teacher partial features and category tags, and 4 local teacher features (12, 768) containing local teacher partial features and category tags. Among them, "550" is the rounded-up value of the product of "785×(0.3+0.4)", "12" is the rounded-up value of the product of "36×0.3", "236" is the rounded-up value of the product of "785×0.3", and "0.3+0.4" represents the sum of the proportions of the student part and the learning part. In this way, semantically aligned student features and teacher features can be obtained.
[0093] The global features and local features obtained based on the above method can ensure the training effect of the visual transformer.
[0094] In some implementations, step S124 training the visual transformer based on the global features and the local features to obtain the encoder may include:
[0095] Step S124a, inputting the global student feature and the local student feature into the student visual transformer to output a first feature;
[0096] Exemplarily, the global student feature includes a global student partial feature and a learning partial feature, and the local student feature includes a local student partial feature. The global student feature and the local student feature are respectively input into the student visual transformer, and the first feature is output. The student visual transformer has 12 visual transformer blocks, a fully connected layer dimension of 3072, and 12 attention heads, and the size of the first feature finally output is the same as the input student feature.
[0097] Step S124b, input the global teacher feature and the local teacher feature into the teacher visual transformer to output the second feature.
[0098] Exemplarily, the global teacher feature includes a global teacher partial feature, and the local teacher partial feature includes a local teacher partial feature. The global teacher feature and the local teacher feature are input into the teacher visual transformer, and a second feature is output. Exemplarily, the teacher visual transformer and the student visual transformer have the same structure, and the size of the second feature finally output is the same as the input teacher feature.
[0099] There is no execution order for the above steps S124a and S124b. The first feature and the second feature can be output synchronously or in different time periods.
[0100] Step S124c, based on the first feature and the second feature, calculate the first loss, and update relevant parameters of the student visual transformer based on the function value of the first loss.
[0101] Exemplarily, the first loss can be calculated by comparing the first feature with the second feature, and then the function value of the first loss is used to update the relevant parameters of the student visual transformer.
[0102] Step S124d, based on the student visual transformer with updated parameters, update the relevant parameters of the teacher visual transformer to obtain an encoder.
[0103] For example, the student visual transformer can be updated with parameters through the loss function, while the parameters of the teacher visual transformer are frozen and can be updated with moving average through momentum m, expressed as:
[0104] θ t =mθ t +(1-m)θ s , where θ s is the student vision transformer parameter, θ t is the teacher visual transformer parameter. The momentum m can be set to a larger value to ensure that the teacher visual transformer parameters can be updated slowly.
[0105] Therefore, the parameters of the teacher visual transformer can be indirectly updated by training the student visual transformer, so as to obtain more accurate prediction results when the teacher visual transformer is used as an encoder as part of the prediction model.
[0106] In some embodiments, the global student feature includes a global student part feature and a learning part feature, the local student feature includes a local student part feature, the global teacher feature includes a global teacher part feature, and the local teacher feature includes a local teacher part feature;
[0107] Step S124a inputs the global student feature and the local student feature into the student visual transformer to output the first feature, which may include:
[0108] Step S124a1, inputting the category labels of the first feature and the second feature into the category prediction head to output a first vector.
[0109] Exemplarily, the category labels of the first feature and the second feature may be respectively input into the category prediction head, wherein the category prediction head may include four fully connected layers having 2048, 2048, 256 and 131072 neurons respectively, and finally output two first vectors of size 131072.
[0110] Step S124a2, obtaining a second vector based on the first feature and the second feature.
[0111] Exemplarily, the global student partial feature and the local student partial feature in the first feature and the global teacher partial feature and the local teacher partial feature in the second feature can be averaged according to the image block dimension. For each partial feature, a vector with the same size as the respective category label can be obtained. These vectors are called second vectors.
[0112] Step S124a3: input the second vector to the picture block prediction header to output a third vector.
[0113] The second vectors are respectively input into the picture block prediction heads which are set in the same way as the category prediction heads, and finally two third vectors of size 131072 are output.
[0114] Step S124a4, input the learned partial features in the first feature into the pixel prediction head to output a fourth vector.
[0115] For example, the size of the learned part feature in the first feature is (324, 768), which is input to the pixel prediction head, and finally outputs a fourth vector of size (314, 768). The pixel prediction head includes four fully connected layers with 2048, 2048, 256 and 16×16×3 neurons.
[0116] Step S124c calculates the first loss based on the first feature and the second feature, and updates the relevant parameters of the student visual transformer based on the function value of the first loss, which may include:
[0117] Step S124c1, calculating the loss based on the first vector, the third vector and the fourth vector respectively, to obtain a plurality of corresponding loss values.
[0118] Exemplarily, the category loss can be calculated based on the first vector and the image block loss can be calculated based on the second vector by the following formulas:
[0119] Among them, s and t are the category labels of the input student features and teacher features, K is the output vector size, and tpt is s and tpt t To control the temperature value of the sharpness of the output distribution of the student visual transformer and the teacher visual transformer, c is the average of all batches B of the teacher output t updated with a single momentum n, which can be expressed as follows:
[0120]
[0121] For example, the original image can be converted to a size of (784, 768), and the learned partial feature mask is applied to obtain the original image pixels of (314, 768). The original image pixels and the pixel prediction results are calculated according to the following formula to calculate the pixel loss: L MSE (p,p ′ )=(pp ′ ) 2 , where p is the original image pixel value and p' is the pixel prediction result feature, i.e. the fourth vector.
[0122] Step S124c2, summing up the multiple loss values according to the preset weights to obtain the function value of the first loss.
[0123] Exemplarily, after calculating multiple loss values, a weighted sum operation can be performed on them according to preset weights, wherein the preset weights can be reasonably set according to experience or specific requirements, and are not limited here. Thus, the function value of the first loss can be obtained. Based on the function value of the first loss, the parameters of the student visual transformer can be updated.
[0124] Therefore, the loss function value can be calculated from multiple aspects such as category labeling, image block level and pixel level to realize the parameter update of the student visual transformer and ensure the rationality and generalization of the parameter update.
[0125] In some embodiments, before evaluating the accuracy of the prediction result in step S140, the method may further include: calculating a second loss based on the prediction result, and adjusting parameters of the prediction model based on a function value of the second loss.
[0126] Exemplarily, the teacher visual transformer can be used as a pre-trained encoder, combined with a specific decoder network model, and the model can be migrated to the specified downstream task using transfer learning technology. Taking the semantic segmentation task as an example, the pre-trained visual transformer can first be packaged with a visual self-attention model adapter (ViT-Adapter) so that it can better interact with the spatial prior knowledge of the image to ensure the accuracy of the prediction results. Then, the encoder and decoder (such as the decoder of UPerNet) can be connected to obtain a prediction model, and the remote sensing image slices in the downstream task data set of 512×512 size are input into the prediction model to obtain the prediction results. The second loss, namely the cross entropy loss, can be calculated by comparing the prediction result with the true label according to the following formula: Where C is the total number of all categories, y c is the value of the true label, if the sample belongs to the cth class y c =1, otherwise y c =0, is the probability that the sample predicted by the prediction model belongs to the cth class. Therefore, the parameters of the prediction model are fine-tuned based on the function value of the second loss.
[0127] In this way, the normal connection between the encoder and the decoder can be achieved, ensuring the availability of the constructed prediction model. At the same time, the prediction accuracy of the prediction model can be improved, which is convenient for subsequent accuracy evaluation.
[0128] It should be noted that all the above numerical values are exemplary data for the convenience of explanation and do not mean any limitation on the actual numerical values. In practical applications, any of the above numerical values can be specifically set according to needs and are not listed here one by one.
[0129] According to the second aspect of the present application, a device for constructing a basic model of remote sensing images by contrastive learning based on fully aligned samples is also proposed. Figure 3 A schematic block diagram of a device 300 for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples provided in an embodiment of the present application. The device 300 may include:
[0130] A data segmentation unit 310 is used to segment and cut the remote sensing image data into blocks to obtain a pre-training data set and a downstream task data set;
[0131] A training unit 320, configured to pre-train a contrastive learning model based on fully aligned samples based on a pre-training dataset to obtain an encoder;
[0132] A prediction unit 330, configured to input a downstream task data set into a prediction model to obtain a prediction result, wherein the prediction model is constructed based on an encoder and a decoder;
[0133] The evaluation and adjustment unit 340 is used to evaluate the accuracy of the prediction result, so as to obtain a new prediction result using the new prediction model after adjusting the parameters of the prediction model based on the accuracy evaluation result, wherein the accuracy evaluation result of the new prediction result meets the accuracy requirement.
[0134] According to a third aspect of the present invention, an electronic device is also provided. Figure 4 Schematic block diagram of an electronic device 400 provided in an embodiment of the present application. Figure 4 As shown, the electronic device 400 may include a processor 410 and a memory 420. The memory 420 stores computer program instructions, which are used by the processor 410 to execute the method for constructing a remote sensing image basic model based on contrast learning of fully aligned samples as described above.
[0135] According to a fourth aspect of the present invention, a storage medium is also provided, on which program instructions are stored, and the program instructions are used to execute the method for building a basic model of remote sensing images based on contrast learning of fully aligned samples as described above when running. The storage medium may include, for example, a storage component of a tablet computer, a hard disk of a computer, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, or any combination of the above storage media. The computer-readable storage medium may be any combination of one or more computer-readable storage media.
[0136] A person skilled in the art can understand the specific details and beneficial effects of the device, electronic device and storage medium for constructing a basic model of remote sensing images based on contrastive learning of fully aligned samples by reading the above description of the method for constructing a basic model of remote sensing images based on contrastive learning of fully aligned samples. For the sake of brevity, they will not be repeated here.
[0137] In the several embodiments provided in the present application, it should be understood that the disclosed devices and / or equipment can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0138] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0139] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0140] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0141] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples, characterized in that: include: The remote sensing image data is divided into blocks to obtain pre-training datasets and downstream task datasets; Pre-training a contrastive learning model based on fully aligned samples based on the pre-training dataset to obtain an encoder; Inputting the downstream task data set into a prediction model to obtain a prediction result, wherein the prediction model is constructed based on the encoder and the decoder; The prediction result is evaluated for accuracy, so that after adjusting the parameters of the prediction model based on the accuracy evaluation result to obtain a new prediction model, a new prediction result is obtained using the new prediction model, wherein the accuracy evaluation result of the new prediction result meets the accuracy requirement.
2. The method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples according to claim 1, characterized in that: The pre-training of a contrastive learning model based on fully aligned samples based on the pre-training dataset to obtain an encoder includes: Crop the original image in the pre-training data set to obtain a global slice and a local slice; Performing color transformation processing on the global slice and the local slice respectively, so as to obtain multiple pairs of global samples and multiple pairs of local samples correspondingly, wherein each pair of samples includes a student sample and a teacher sample; Based on the multiple pairs of global samples and the multiple pairs of local samples, global features and local features are correspondingly obtained, wherein both the global features and the local features contain category tags, and the student samples and the teacher samples are semantically completely aligned; A visual transformer is trained based on the global features and the local features to obtain the encoder.
3. The method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples according to claim 2, characterized in that: The global features include global teacher features and global student features, the local features include local teacher features and local student features, and the visual transformer is trained based on the global features and the local features to obtain the encoder, including: Inputting the global student feature and the local student feature into a student visual transformer to output a first feature; Inputting the global teacher feature and the local teacher feature into a teacher visual transformer to output a second feature; Based on the first feature and the second feature, a first loss is calculated to update relevant parameters of the student visual transformer based on a function value of the first loss; Based on the student visual transformer with updated parameters, relevant parameters of the teacher visual transformer are updated to obtain the encoder.
4. The method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples according to claim 3, characterized in that: The global student features include global student partial features and learning partial features, the local student features include local student partial features, the global teacher features include global teacher partial features, and the local teacher features include local teacher partial features; The step of inputting the global student feature and the local student feature into a student visual transformer to output a first feature comprises: Inputting the category labels of the first feature and the second feature into a category prediction head to output a first vector; Based on the first feature and the second feature, obtaining a second vector; Inputting the second vector into a picture block prediction head to output a third vector; Inputting the learned partial features of the first features into a pixel prediction head to output a fourth vector; The first loss is calculated based on the first feature and the second feature, so as to update relevant parameters of the student visual transformer based on the function value of the first loss, including: Calculating losses based on the first vector, the third vector, and the fourth vector respectively, so as to obtain a plurality of loss values correspondingly; The multiple loss values are summed according to preset weights to obtain a function value of the first loss.
5. The method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples according to claim 2, characterized in that: The obtaining of global features and local features based on the multiple pairs of global samples and the multiple pairs of local samples includes: Perform convolution operation on each sample to obtain multiple convolution result corresponding features; splicing the category label to the image block dimensions of the features corresponding to all the multiple convolution results to obtain the labeled features; Dividing the marked features into student-part features, teacher-part features and learning-part features according to a preset ratio; Replacing original features of the learned partial features with learnable mask markers; Based on the student part features, the teacher part features and the learning part features, the global features and the local features are obtained.
6. The method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples according to claim 1, characterized in that: Before evaluating the accuracy of the prediction result, the method further includes: Based on the prediction result, a second loss is calculated to adjust parameters of the prediction model based on a function value of the second loss.
7. The method for constructing a basic model of remote sensing images based on contrastive learning of fully aligned samples according to claim 1, characterized in that: The method further comprises: The encoder is wrapped with a visual self-attention model adapter.
8. A device for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples, characterized in that: include: A data segmentation unit, used for segmenting the remote sensing image data into blocks to obtain a pre-training data set and a downstream task data set, wherein the pre-training data set includes fully aligned training sample pairs; A training unit, configured to pre-train a contrastive learning model based on fully aligned samples based on the pre-training dataset to obtain an encoder; A prediction unit, configured to input the downstream task data set into a prediction model to obtain a prediction result, wherein the prediction model is constructed based on the encoder and the decoder; An evaluation and adjustment unit is used to evaluate the accuracy of the prediction result, so as to obtain a new prediction result using the new prediction model after adjusting the parameters of the prediction model based on the accuracy evaluation result, wherein the accuracy evaluation result of the new prediction result meets the accuracy requirement.
9. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used by the processor to execute the method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples according to any one of claims 1 to 7 when the processor is running.
10. A storage medium having program instructions stored thereon, wherein the program instructions are used to execute the method for constructing a basic model of remote sensing images based on contrast learning of fully aligned samples according to any one of claims 1 to 7 when running.
