A method for marine remote sensing ship image retrieval based on self-attention hashing
Through the ocean remote sensing ship image retrieval algorithm based on self-attention hashing, using the image embedding module, regularized attention encoder and learnable hash module, the problem of low image similarity matching efficiency in large-scale data is solved and achieved Fast and efficient ocean remote sensing ship image retrieval improves retrieval accuracy and efficiency.
Patent Information
- Application Number
- CN202410725176.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-06-06
AI Technical Summary
With the development of remote sensing technology and the accumulation of ocean remote sensing ship image data, existing technology is difficult to quickly perform image similarity matching in large-scale data, affecting retrieval performance and efficiency.
A marine remote sensing ship image retrieval algorithm based on self-attention hashing is adopted. By constructing a model including an image embedding module, a regularized attention encoder and a learnable hash module, image feature extraction and hash mapping are performed, and the loss function is used for optimization. model to achieve fast retrieval.
It improves the performance of image feature extraction at different scales, improves model generalization and retrieval efficiency, reduces storage space and mapping losses, and improves retrieval accuracy and speed.
Smart Images

Figure CN118312636B
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of remote sensing image processing and retrieval, and in particular to a method for retrieval of marine remote sensing ship images based on self-attention hashing. Background Art
[0002] Marine remote sensing ship image retrieval is a remote sensing technology application method. Its main task is to retrieve marine remote sensing ship images similar to the query image from a given marine remote sensing ship image database given a query image. This task has a wide range of applications in the fields of maritime traffic management, maritime safety, and ship monitoring. For example, when it is necessary to track a specific ship or identify the owner of a ship, the marine remote sensing ship image retrieval technology can be used to quickly find relevant marine remote sensing ship images from a large-scale marine remote sensing ship image database. In addition, marine remote sensing ship image retrieval can also be used for maritime patrols and border security. By comparing the marine remote sensing ship images in the image database with the real-time monitoring images, abnormal ships or suspicious activities can be discovered in a timely manner. With the development of remote sensing technology and the continuous accumulation of marine remote sensing ship image data, the field of marine remote sensing ship image retrieval has also received more and more attention and research.
[0003] With the development of remote sensing technology, the increase in the size of image databases makes it difficult to quickly perform image similarity matching, affecting retrieval performance and efficiency. Therefore, how to effectively and quickly perform image similarity matching in a large amount of data has become a very important task in marine remote sensing ship image retrieval. Summary of the invention
[0004] Aiming at the problem of inefficient retrieval on large-scale remote sensing image databases, the present invention proposes a marine remote sensing ship image retrieval algorithm based on self-attention hashing.
[0005] To achieve the above object, the present invention provides the following technical solutions:
[0006] A method for retrieval of marine remote sensing ship images based on self-attention hashing, the method comprising the following steps:
[0007] , collect remote sensing ocean and remote sensing ship image data sets, divide them into training sets, validation sets and test sets according to the proportion, and use them for subsequent model training, validation and evaluation respectively;
[0008] , build a marine remote sensing ship image retrieval model based on self-attention hashing;
[0009] , step The images in the training set, input step The constructed model uses the loss function to train the model and the back propagation algorithm to update the model;
[0010] , based on the trained ocean remote sensing ship image retrieval model, input the image to be retrieved and output the ocean remote sensing ship image data related to it.
[0011] As a further technical solution of the present invention, the steps of collecting a remote sensing ocean and remote sensing ship image data set and dividing it into a training set, a validation set and a test set according to a proportional number for subsequent model training, validation and evaluation include: collecting , , , Four marine remote sensing ship image retrieval datasets, the different categories of images in these four datasets are divided according to the ratio of 6:2:2, and are respectively used for training, verification, and retrieval test evaluation.
[0012] As a further technical solution of the present invention, step The method also includes preprocessing the ship data set and enhancing the data so that the network can focus more on extracting the semantic features in the image; the steps of preprocessing the ship data set and enhancing the data so that the network can focus more on extracting the semantic features in the image include: scaling the images in the ship data set to a size of 224×224, and then The values of the three channels are normalized and standardized to 0-1. Standardization can reduce the instability caused by the difference value, that is, subtract the channel mean from each input channel and divide it by the channel standard deviation. The common method is generally to use natural images. The mean and standard deviation of the dataset are [0.485, 0.456, 0.406] and [0.229, 0.224, 0.225]. However, the mean and standard deviation of remote sensing images are quite different from those of natural images. For each image, we change the mean to [0.294, 0.323, 0.318] and the standard deviation to [0.207, 0.194, 0.191]. Finally, we introduce common image enhancements, i.e., random rotation, random flipping, and random padding blocks with a probability of 0.1.
[0013] As a further technical solution of the present invention, the marine remote sensing ship image retrieval model based on self-attention hashing is composed of an image embedding module, a regularized attention encoder, and a learnable hashing module.
[0014] As a further technical solution of the present invention, the image embedding module combines the ideas of non-overlapping blocks and overlapping blocks to model the local information of the ocean remote sensing ship image:
[0015] Among them, the input ocean remote sensing ship image Divided into N subgraphs of the same shape , the size of each subgraph is ,p is selected as the common block size 16, c is the number of channels of the image, The embedding vector of the image patch The calculation is as follows:
[0016] ;
[0017] In the formula, It means three overlapping convolutions with a stride of 2, a kernel size of 3, and a padding of 1. It is an adaptive pooling layer that makes the output of overlapping convolutional layers consistent with that of non-overlapping convolutional layers. Represents a non-overlapping convolution with kernel size and stride of p;
[0018] Then the embedding vector is expanded in one dimension, the classification token is embedded in CT in the first dimension, and the position embedding is added. , the final image embedding , calculated as follows:
[0019] .
[0020] As a further technical solution of the present invention, the regularized attention encoder is used to alleviate the overfitting problem in the encoder, and randomly loses some keys and final results in the encoder during the attention mechanism calculation process:
[0021] ;
[0022] In the formula, p represents the Bernoulli distribution of a certain probability, which is used to convert a certain probability The keys are discarded, where is a learnable parameter;
[0023] The values obtained from the self-attention module are concatenated and then calculated through a fully connected layer to obtain the multi-head attention value. , the calculation is expressed as follows:
[0024] ;
[0025] ;
[0026] Among them, h is the number of attention heads, For the Attention head;
[0027] Under multiple multi-head attention calculations, the j-th encoder block The output of is calculated based on the result of the previous encoder block, the result of the self-attention module, and the result of the multi-layer perceptron module. The self-attention module calculates the multi-head attention value through a linear layer, and the multi-layer perceptron module uses layer normalization and The activation function is then used, and finally a dropout layer with a ratio of 0.1 is used for calculation, as follows:
[0028] ;
[0029] in, are learnable parameters in the self-attention module, is the output of the multilayer perceptron module.
[0030] As a further technical solution of the present invention, the learnable hash module is used to reduce the storage occupancy of image descriptors and improve retrieval performance. A hash learning module is added after the encoder output. First, the output of the encoder passes through a Dropout layer, then passes through a fully connected layer to project the features to 4096, and finally passes through Activation function obtains preliminary features :
[0031] ;
[0032] In order to reduce the redundancy of hash codes, the preliminary features Divided into Group, group mapping learning, and finally use and symbol function Hash mapping is calculated as follows:
[0033] ;
[0034] ;
[0035] in, It is a group mapping function. For the convenience of implementation, the step size and convolution kernel size are directly used. One-dimensional convolution implementation of;
[0036] In order to solve the problem of symbolic function The learning strategy of is not effective. The derivative of the sign function is set to the derivative of the hyperbolic tangent function.
[0037] ;
[0038] ;
[0039] Where b is the hash code, is the continuous floating-point feature output by the network.
[0040] As a further technical solution of the present invention, step The total loss function value L of the model is calculated, including the pairwise loss function , classification loss function and the reranking loss function , the total loss function of the model It is expressed as:
[0041] = + + ;
[0042] in, represents the hyperparameter that controls the ratio of the pairwise loss function, represents the hyperparameter that controls the proportion of the classification loss function, Represents a hyperparameter that controls the scale of the reranking loss function.
[0043] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the above-mentioned method for ocean remote sensing ship image retrieval based on self-attention hashing.
[0044] Compared with the prior art, the present invention has the following beneficial effects:
[0045] 1. To improve the feature extraction performance of remote sensing images at different scales, the present invention improves the image embedding module.
[0046] 2. To improve the generalization of the model and reduce the amount of computation, the present invention proposes a regularized attention mechanism in the encoder.
[0047] 3. To speed up image retrieval, improve retrieval efficiency, reduce storage space, and reduce quantization loss mapped to hash codes, the present invention uses a learnable hash module to obtain the hash code of the image.
[0048] 4. To improve the accuracy of retrieval, the present invention introduces re-ranking loss and secondary sorting methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 This is a flowchart of a method for ocean remote sensing ship image retrieval based on self-attention hashing.
[0050] Figure 2 Schematic diagram of the structure of the learnable hash module in this embodiment. DETAILED DESCRIPTION
[0051] In order to more clearly understand the above-mentioned objects, features and advantages of the present invention, the advantages of the present invention will be further illustrated by comparing the embodiments in combination with the accompanying drawings and specific implementation methods.
[0052] like Figure 1 As shown, an embodiment of the present invention provides a method for retrieval of marine remote sensing ship images based on self-attention hashing, and the method comprises the following steps:
[0053] , collect remote sensing ocean and remote sensing ship image data sets, divide them into training sets, validation sets and test sets according to the proportion, and use them for subsequent model training, validation and evaluation respectively;
[0054] , build a marine remote sensing ship image retrieval model based on self-attention hashing;
[0055] , step The images in the training set, input step The constructed model uses the loss function to train the model and the back propagation algorithm to update the model;
[0056] , based on the trained ocean remote sensing ship image retrieval model, input the image to be retrieved and output the ocean remote sensing ship image data related to it.
[0057] In this embodiment, the steps of collecting a remote sensing ocean and remote sensing ship image dataset and dividing it into a training set, a validation set and a test set in proportion to each other for subsequent model training, validation and evaluation include: collecting , , , Four marine remote sensing ship image retrieval datasets, the different categories of images in these four datasets are divided according to the ratio of 6:2:2, and are respectively used for training, verification, and retrieval test evaluation.
[0058] In this embodiment, step The method also includes preprocessing the ship data set and enhancing the data so that the network can focus more on extracting the semantic features in the image; the steps of preprocessing the ship data set and enhancing the data so that the network can focus more on extracting the semantic features in the image include: scaling the images in the ship data set to a size of 224×224, and then The values of the three channels are normalized and standardized to 0-1. Standardization can reduce the instability caused by the difference value, that is, subtract the channel mean from each input channel and divide it by the channel standard deviation. The common method is generally to use natural images. The mean and standard deviation of the dataset are [0.485, 0.456, 0.406] and [0.229, 0.224, 0.225]. However, the mean and standard deviation of remote sensing images are quite different from those of natural images. For each image, we change the mean to [0.294, 0.323, 0.318] and the standard deviation to [0.207, 0.194, 0.191]. Finally, we introduce common image enhancements, i.e., random rotation, random flipping, and random padding blocks with a probability of 0.1.
[0059] Specifically, the input of the ocean remote sensing ship image retrieval model is the ocean remote sensing ship image First, the image is input into the image embedding module to convert the image into an embedding vector, and then the embedding vector is passed through the feature learning encoder and hash layer in sequence. Finally, the model weights are optimized by calculating the loss function on the labels of the dataset. The loss function used is composed of pairwise loss, classification loss, and retrieval re-ranking loss.
[0060] In this embodiment, the ocean remote sensing ship image retrieval model based on self-attention hashing is composed of an image embedding module, a regularized attention encoder, and a learnable hashing module.
[0061] In this embodiment, the image embedding module combines the ideas of non-overlapping blocks and overlapping blocks to model the local information of the ocean remote sensing ship image:
[0062] Among them, the input ocean remote sensing ship image Divided into N subgraphs of the same shape , the size of each subgraph is , p is selected as the common block size 16, c is the number of channels of the image, The embedding vector of the image patch The calculation is as follows:
[0063] ;
[0064] In the formula, It means three overlapping convolutions with a stride of 2, a kernel size of 3, and a padding of 1. It is an adaptive pooling layer that makes the output of overlapping convolutional layers consistent with that of non-overlapping convolutional layers. Represents a non-overlapping convolution with kernel size and stride of p;
[0065] Then the embedding vector is expanded in one dimension, the classification token is embedded in CT in the first dimension, and the position embedding is added. , the final image embedding , calculated as follows:
[0066] .
[0067] In this embodiment, the regularized attention encoder is used to alleviate the overfitting problem in the encoder. Some keys and final results in the encoder are randomly lost during the attention mechanism calculation process:
[0068] ;
[0069] In the formula, Represents a Bernoulli distribution with a certain probability, which is used to convert a certain probability The keys are discarded, where is a learnable parameter;
[0070] The values obtained from the self-attention module are concatenated and then calculated through a fully connected layer to obtain the multi-head attention value. , the calculation is expressed as follows:
[0071] ;
[0072] ;
[0073] Among them, h is the number of attention heads, For the Attention head;
[0074] Under multiple multi-head attention calculations, the j-th encoder block The output of is calculated based on the result of the previous encoder block, the result of the self-attention module, and the result of the multi-layer perceptron module. The self-attention module calculates the multi-head attention value through a linear layer, and the multi-layer perceptron module uses layer normalization and The activation function is then used, and finally a dropout layer with a ratio of 0.1 is used for calculation, as follows:
[0075] ;
[0076] in, are learnable parameters in the self-attention module, is the output of the multilayer perceptron module.
[0077] See also Figure 2 In this embodiment, the learnable hash module is used to reduce the storage occupancy of image descriptors and improve retrieval performance. A hash learning module is added after the encoder output. First, the output of the encoder passes through a Dropout layer, then a fully connected layer to project the features to 4096, and finally through Activation function obtains preliminary features :
[0078] ;
[0079] In order to reduce the redundancy of hash codes, the preliminary features Divided into Group, group mapping learning, and finally use and symbol function Hash mapping is calculated as follows:
[0080] ;
[0081] ;
[0082] in, It is a group mapping function. For the convenience of implementation, the step size and convolution kernel size are directly used. One-dimensional convolution implementation of;
[0083] In order to solve the problem of symbolic function The learning strategy of is not effective. The derivative of the sign function is set to the derivative of the hyperbolic tangent function.
[0084] ;
[0085] ;
[0086] Where b is the hash code, is the continuous floating-point feature output by the network.
[0087] In this embodiment, step Calculate the total loss function value of the model , including pairwise loss function , classification loss function and the reranking loss function , the total loss function of the model It is expressed as:
[0088] = + + ;
[0089] in, represents the hyperparameter that controls the ratio of the pairwise loss function, represents the hyperparameter that controls the proportion of the classification loss function, Represents a hyperparameter that controls the scale of the reranking loss function.
[0090] (1) Pairwise loss function, which is expressed as follows:
[0091] ;
[0092] ;
[0093] Among them, p indicates whether the ocean remote sensing ship images are similar. is the regularizer. is the hash code of the anchor ship, is the hash code of the positive sample ship, Non-anchor point. express Paradigm, is a hyperparameter, express Paradigm, is the edge parameter.
[0094] (2) Classification loss function, which is expressed as follows:
[0095] ;
[0096] in, is the number of ship categories, P is the predicted probability between categories, and T is the true value.
[0097] (3) Re-ranking loss function: In order to solve the impact of retrieval order on the final result during the retrieval process, this chapter designs a re-ranking loss. Specifically, for each batch of training, the first image in the batch is selected as the query image, and the query comparison is performed based on the hash code of the image and the corresponding category. Its expression is as follows:
[0098] .
[0099] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the above-mentioned method for ocean remote sensing ship image retrieval based on self-attention hashing.
[0100] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
Claims
1. A method for ocean remote sensing ship image retrieval based on self-attention hashing, characterized in that: The method comprises the following steps: S1. Collect remote sensing ocean and ship image datasets, divide them into training set, validation set and test set according to the proportion, and use them for subsequent model training, validation and evaluation respectively; S2. Construct a marine remote sensing ship image retrieval model based on self-attention hashing; S3, input the image of the training set in step S1 into the model constructed in step S2, train the model using the loss function, and update the model through the back propagation algorithm; S4, based on the trained ocean remote sensing ship image retrieval model, input the image to be retrieved, and output the ocean remote sensing ship image data related thereto; The marine remote sensing ship image retrieval model based on self-attention hashing is composed of an image embedding module, a regularized attention encoder, and a learnable hashing module; The image embedding module combines the ideas of non-overlapping blocks and overlapping blocks to model the local information of marine remote sensing ship images: The input ocean remote sensing ship image S is divided into N sub-images s of the same shape. i , the size of each sub-image is p×p×c, p is selected as the common block size 16, c is the number of channels of the image, and the embedding vector PE of the i-th image block is i The calculation is as follows: ON i =Avg(Conv0(S i ))+Conv n (S i ); In the formula, Conv o It represents the superposition of three overlapping convolutions with a stride of 2, a convolution kernel size of 3, and a padding of 1. Avg is an adaptive pooling layer, which makes the output of the overlapping convolution layer consistent with that of the non-overlapping convolution layer. Conv n Represents a non-overlapping convolution with kernel size and stride of p; The embedding vector is then expanded in one dimension, the classification tokens are embedded in CT and concatenated in the first dimension, and finally the position embedding PoE is added. The final image embedding E is calculated as follows: E = dropout([CT, PE] + PoE); The regularized attention encoder is used to alleviate the overfitting problem in the encoder by randomly losing some keys and the final result in the encoder during the attention mechanism calculation process: In the formula, p represents a Bernoulli distribution with a certain probability, which is used to discard keys with a certain probability r, where r is a learnable parameter; The values obtained from the self-attention module are concatenated and then calculated through a fully connected layer to obtain the multi-head attention value F att , the calculation is expressed as follows: F att =MultiHead(Q,K,V); F att =Concat([head1,head2,...,head n ])W o ; Among them, h is the number of attention heads, head i is the i-th attention head; Under the calculation of multiple multi-head attention, the j-th encoder block H j The output of is calculated based on the result of the previous encoder block, the result of the self-attention module, and the result of the multi-layer perceptron module. The self-attention module calculates the multi-head attention value through a linear layer. The multi-layer perceptron module uses layer normalization and GELU activation function, and finally uses a dropout layer with a ratio of 0.1 for calculation. The calculation is as follows: H j =H j-1 +F att ×W att +F mlp ; Among them, W att is the learnable parameter in the self-attention module, F mlp is the output of the multi-layer perceptron module; The learnable hash module is used to reduce the storage occupancy of image descriptors and improve retrieval performance. A hash learning module is added after the encoder output. First, the output of the encoder passes through a Dropout layer, then a fully connected layer to project the features to 4096 dimensions, and finally a ReLU activation function is used to obtain the preliminary features F. init : F init =ReLU(Linear(Dropout(H))); In order to reduce the redundancy of the hash code, the preliminary feature F init Divided into K b Group, group mapping learning, and finally use the sum symbol function Sgn for hash mapping, which is calculated as follows: K b =4096 / / L b ; Among them, L is the group mapping function. For the convenience of implementation, we directly use the step size and convolution kernel size K b One-dimensional convolution implementation of; In order to solve the problem that the SGD-based learning strategy cannot take effect due to the sign function, the derivative of the sign function is set to the derivative of the hyperbolic tangent function; Forward:b=Sgn(b c ); Where b is the hash code, b c is the continuous floating-point feature output by the network.
2. According to the method for ocean remote sensing ship image retrieval based on self-attention hashing in claim 1, it is characterized in that: The steps of collecting a remote sensing ocean remote sensing ship image data set, dividing a training set, a validation set and a test set according to a proportional number, and using them for subsequent model training, validation and evaluation respectively, include: collecting four ocean remote sensing ship image retrieval data sets, namely DSCR, FGSC-23, FGSCR-42 and CGWX, dividing different categories of images in the four data sets according to a ratio of 6:2:2, and performing training, validation, and retrieval test evaluation respectively.
3. The method for ocean remote sensing ship image retrieval based on self-attention hashing according to claim 2, characterized in that: Step S1 also includes preprocessing the ship data set and enhancing the data so that the network is more focused on extracting semantic features in the image. The steps of preprocessing the ship data set and enhancing the data so that the network is more focused on extracting semantic features in the image include: scaling the images in the ship data set to a size of 224×224, and then performing 0-1 normalization and standardization calculation on the values of the RGB three channels, that is, subtracting the channel mean from each input channel and dividing it by the channel standard deviation; finally, introducing common image enhancement, that is, randomly rotating, randomly flipping, and randomly filling blocks with a probability of 0.
1.
4. The method for ocean remote sensing ship image retrieval based on self-attention hashing according to claim 1, characterized in that: In step S3, the total loss function value L of the model is calculated, including the pairwise loss function L pair , classification loss function L cls and the re-ranking loss function L rerank , the total loss function of the model is L retrieval It is expressed as: L retrieval =λ pair L pair +λ cls L cls +λ rerank L rerank ; Among them, λ pair represents the hyperparameter that controls the ratio of the pairwise loss function, λ cls represents the hyperparameter that controls the proportion of the classification loss function, λ rerank Represents a hyperparameter that controls the scale of the reranking loss function.
5. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
