An image retrieval method based on image patch and attribute alignment

By dividing the image into window images and performing attribute alignment, combined with the Transformer Block module and the global average pooling layer, the shortcomings of the deep hashing method in invisible category image retrieval are solved, efficient and compact hash codes are generated, and the image quality is significantly improved. Search accuracy.

CN118332153BActive Publication Date: 2024-10-01NINGBO UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410758668.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-10-01
Estimated Expiration
2044-06-13

AI Technical Summary

Technical Problem

It is difficult for existing deep hashing methods to effectively handle image retrieval of invisible categories without retraining the model, and the zero-th hashing method ignores the local attribute characteristics of the image, resulting in reduced retrieval accuracy.

Method used

By segmenting the image into non-overlapping window images, using attribute vectors for semantic alignment, and combining the Transformer Block module and the global average pooling layer, the hash retrieval model is trained to generate efficient and compact hash codes and improve image retrieval accuracy.

Benefits of technology

It achieves the generation of appropriate hash codes for invisible categories without retraining the model, improves the precision and accuracy of image retrieval, and significantly improves the performance of image retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure SMS_54
    Figure SMS_54
  • Figure SMS_55
    Figure SMS_55
Patent Text Reader

Abstract

The invention discloses an image retrieval method based on image block and attribute alignment, which is characterized in that firstly, a part of a window image of a sample is replaced by a corresponding attribute vector to form a fused image with the remaining window image, then the remaining window image and the fused image are sent to an encoder to obtain fused image encoder features and original image encoder features, then the corresponding fused image decoder features and original image decoder features are obtained through a decoder, and then a trained feature extraction model and a hash retrieval model are obtained through training, and finally a query sample is searched in a retrieval set hash code retrieval library for a hash code with a Hamming distance closest to the hash code of the query sample, and a retrieval sample corresponding to the hash code is used as a retrieval result; the advantage is that the retrieval performance of samples of invisible classes is significantly improved, rich feature information can be extracted, the obtained hash code is efficient and compact, and the image retrieval efficiency is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to an image retrieval method, in particular to an image retrieval method based on image block and attribute alignment. Background Art

[0002] In recent years, the combination of deep learning and hash learning has made breakthrough progress in hash-based image retrieval methods; however, the retrieval performance of deep hashing methods is highly dependent on training data. Generally, the categories that appear in the training data are defined as visible classes, while the categories that do not appear in the training data are defined as unseen classes. Existing deep hashing methods are difficult to guarantee the retrieval effect of unseen data. In the context of data explosion, unseen classes will inevitably appear in the retrieval process, and the cost of retraining the model is very high. Therefore, it is crucial to learn a hash model that can be transferred to unseen classes. Inspired by zero-shot learning, some zero-shot hashing methods have been proposed to solve this problem. These methods use the shared attributes between visible and unseen classes to transfer supervision information, and can generate suitable hash codes for unseen data without retraining the network. Although zero-shot hashing methods have received widespread attention, they also have some shortcomings. These methods usually use CNN convolutional neural networks to extract features from the entire image and then map them to attribute embedding and attribute alignment of the image, but they ignore that attributes only correspond to specific parts of the image. These methods ignore attribute features aligned with local alignment and introduce significant noise, resulting in reduced accuracy. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide an image retrieval method based on image block and attribute alignment with efficient and compact hash codes and high image retrieval accuracy.

[0004] The technical solution adopted by the present invention to solve the above technical problem is: an image retrieval method based on image block and attribute alignment, comprising the following steps:

[0005] Step 1): Divide the categories of samples in the image dataset into visible classes and invisible classes, and select N samples as the training set, and then use the N The similarity matrix is ​​constructed based on the category labels of samples; the attributes of the image dataset are converted into attribute vectors through the word vector method, and then the attribute vectors are encoded through the fully connected layer, and all the encoded attribute vectors are defined to form an attribute space;

[0006] Step 2): Construct the feature extraction model to be trained. NThe training samples are randomly shuffled to obtain shuffled training samples, and the shuffled training samples are input into the feature extraction model to be trained. First, each training sample is divided into non-overlapping window images through an image segmentation module, and the set of all window images is defined as an image space. In the image space, m% of the window images are randomly selected and mapped to the attribute space to obtain the mapped window image, 25≤m≤75, and the cosine similarity between the mapped window image and the attribute vector in the attribute space is obtained. For each mapped window image, the attribute vector with the highest cosine similarity is selected and mapped back to the image space, and the attribute vector mapped back to the image space replaces the m% of the window image at the original position, and then is fused with the remaining 1-m% of the window image to form a fused image; an encoder and a decoder are constructed, and the remaining 1-m% of the window image and the fused image are respectively input into the encoder to obtain the original image encoder features corresponding to the remaining 1-m% of the window image and the fused image encoder features corresponding to the fused image; the original image encoder features and the fused image encoder features are respectively input into the decoder to obtain the original image decoder features corresponding to the original image encoder features and the fused image decoder features corresponding to the fused image encoder features;

[0007] Step 3): Construct a hash retrieval model to be trained, input the original image encoder features of the training sample into the hash retrieval model to be trained to obtain the hash code of the training sample and the classification result of the training sample;

[0008] Step 4): Define the common loss function of the feature extraction model to be trained and the hash retrieval model to be trained, use the original image encoder features, fused image encoder features, original image decoder features, fused image decoder features, hash codes of the training samples and classification results of the training samples to obtain the value of the loss function, update the feature extraction model to be trained and the hash retrieval model to be trained respectively through the back propagation algorithm, and obtain the trained feature extraction model and the trained hash retrieval model after the training is completed;

[0009] Step 5): Select samples from the invisible classes in the image dataset M samples as the query set, and the remaining samples in the image dataset as the retrieval set. The query samples in the query set are subjected to feature extraction by the trained feature extraction model to obtain the original image encoder features of the query samples, and the trained hash retrieval model is used to extract the original image encoder features of the query samples to obtain the hash codes of the query samples; the retrieval samples in the retrieval set are subjected to feature extraction by the trained feature extraction model to obtain the original image encoder features of the retrieval samples, and the trained hash retrieval model is used to extract the original image encoder features of the retrieval samples to obtain the hash codes of the retrieval samples, and the set consisting of the hash codes of all the retrieval samples is defined as the retrieval set hash code retrieval library;

[0010] Step 6): Use the query sample in the query set to search, find the hash code with the closest Hamming distance to the hash code of the query sample in the retrieval set hash code retrieval library, and display the retrieval sample corresponding to the hash code as the retrieval result to complete the retrieval process of the query sample.

[0011] Compared with the prior art, the advantages of the present invention are that the image is first segmented into a number of non-overlapping window images through an image segmentation module, part of the window images are randomly selected and mapped to the attribute space, the cosine similarity is compared with the attribute vector, and the attribute vector most similar to the window image is selected and mapped back to the image space; this method can automatically find the attribute most similar to the window image under the constraint of the loss function, and realize the semantic alignment of the window image and the attribute; then the fused image and the remaining window image are sent to the encoder to obtain the fused image encoder features and the original image encoder features, and then the fused image encoder features and the original image encoder features are sent to the decoder to obtain the fused image decoder features and the original image decoder features, and the fused image decoder features and the original image decoder features are compared with the original image features, which can be used to use Transformer The powerful modeling ability of the Block module uses the reconstruction ability to obtain more discriminative features in the image; then a global average pooling layer is added after the encoder, and additional hash layers and classification layers are added, and the network training is performed under the joint optimization of hash loss, classification loss and contrast loss. By jointly optimizing hash loss, classification loss and contrast loss, feature representation and hash function can be learned from the input image at the same time. The obtained hash code is efficient and compact, thereby effectively improving the accuracy of image retrieval.

[0012] Preferably, in step 1), the training set is used N The specific process of constructing the similarity matrix based on the category labels of samples is as follows:

[0013] The samples in the image dataset are divided into visible and invisible classes, and the samples in the visible class are selected N samples as training set X , , x i express X For any sample in i ≤ N , and record the corresponding category label matrix as Y , ,in, y i express Y Any category label in C is the total number of categories, using N The similarity matrix is ​​constructed based on the category labels of samplesS , ,in, express X Any two samples x i and x j Similarity, 1≤ i ≤ j ≤ N ,when x i and x j Belong to more than one category, , and define x i and x j is a similar sample pair; otherwise , and define x i and x j The attributes of the image dataset are converted into attribute vectors through the word vector method. These attribute vectors are semantically similar, and the attribute vectors with the same semantics have a high cosine similarity.

[0014] Preferably, the specific process of step 2) is as follows:

[0015] Step 2-1: Convert the original sample with a dimension of 224×224×3 x i The image segmentation module is used to segment the images into non-overlapping window images, each of which has a window size of 16×16. The non-overlapping window images are expanded in the channel direction to obtain a window image with a dimension of 14×14×768.

[0016] Step 2-2: Reorganize the window image with a dimension of 14×14×768 into a window image with a dimension of 196×768, define the window image with a dimension of 196×768 as the image space, randomly select m% of the window images from the 196 768-dimensional window images in the image space and map them to the attribute space to obtain the mapped window image, obtain the cosine similarity between the mapped window image and the attribute vector in the attribute space, select the attribute vector with the highest cosine similarity for each mapped window image and map it back to the image space; replace the m% of the window images with the attribute vector mapped back to the image space at the original position, and then fuse them with the remaining 1-m% of the window images in the image space to form a fused image;

[0017] Step 2-3: Construct an encoder, which consists of 12 layers of Transformer Block modules. First, the remaining 1-m% window image and fused image in the image space are sent to the first LN layer as input features for normalization to obtain the first normalized features, and then the first normalized features are input into the multi-head self-attention module. Subsequently, the feature map output by the multi-head self-attention module and the input features are residually connected, and the obtained results are normalized through the second LN layer to obtain the second normalized features. Finally, the second normalized features are input into the multi-layer perceptron to obtain the original image encoder features corresponding to the remaining 1-m% window image in the image space and the fused image encoder features corresponding to the fused image.

[0018] Step 2-4: Construct a decoder, which consists of 8 layers of Transformer Block modules. The original image encoder features and the fused image encoder features are input into the decoder to obtain the original image decoder features corresponding to the original image encoder features and the fused image decoder features corresponding to the fused image encoder features. The TransformerBlock module can effectively model the long-distance dependencies in the image, and the attention mechanism enables the Transformer Block module to dynamically adjust the area of ​​interest according to the input.

[0019] Preferably, the specific process of step 3) is as follows:

[0020] Step 3-1: Construct the hash retrieval model to be trained, including the pooling layer, the hashing layer and the classification layer. Pass the original image encoder features of the training sample through the pooling layer, and apply global average pooling in the pooling layer to obtain a feature vector with a dimension of 768×1. ;

[0021] Step 3-2: lose Enter the hash layer for processing and get the feature vector output by the hash layer h i , ,Will h i Binarization to get hash code b i , ,in, W represents the weight matrix of the hash layer, express W The transpose of o represents the bias of the hash layer, tanh(·) is the hyperbolic tangent function, sgn(·) is the sign function, and then h i After the classification layer, the classification result is obtained , , Softmax(·) represents the normalized exponential function, represents the weight matrix of the classification layer, express The transpose of Represents the bias of the classification layer.

[0022] Preferably, the specific process of step 4) is as follows:

[0023] Step 4-1: Define the common loss function of the feature extraction model to be trained and the hash retrieval model to be trained as L, ,in, α , β is a hyperparameter, L c is the classification loss, , L r is the contrast loss, ,in p i For the i The window image of the image space corresponding to the training samples, For the i The original image decoder features corresponding to the training samples, q i For the i The fused image decoder features corresponding to samples, L h is the hash loss, , , S 1 is with x i A collection of related similar sample pairs, express S The number of elements of 1, S 0 is the same as x i A collection of related dissimilar sample pairs, express S The number of elements that are 0, for h i The transpose of h j Indicates that x j The feature vector output by the hash layer after inputting the hash retrieval model to be trained;

[0024] Step 4-2: Set the maximum number of iterations, and use the AdamW optimization algorithm to iteratively optimize the feature extraction model to be trained and the hash retrieval model to be trained according to the loss function. When the maximum number of iterations is reached, stop the iteration process and obtain the trained feature extraction model and the trained hash retrieval model.

[0025] Through the constraints of classification loss, the feature extraction model and hash retrieval model can generate more discriminative features and hash codes for samples of different categories; through the constraints of contrast loss, the original image decoder features and the fused image decoder features are close to the window image in the image space, and the attributes and image block encodings with the same semantics are as similar as possible; hash loss can make the hash codes generated by similar sample pairs close and the hash codes of dissimilar sample pairs far apart, and at the same time, weights are added to the hash loss to balance similar and dissimilar samples. DETAILED DESCRIPTION

[0026] The present invention is described in further detail below.

[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention is clearly and completely described below. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] An image retrieval method based on image block and attribute alignment comprises the following steps:

[0029] Step 1): Divide the categories of samples in the image dataset into visible classes and invisible classes, and select N samples as training set X , , x i express X For any sample in i ≤ N , and record the corresponding category label matrix as Y , ,in, y i express Y Any category label in C is the total number of categories, using N The similarity matrix is ​​constructed based on the category labels of samples S , ,in, express X Any two samples x i and x j Similarity, 1≤ i ≤ j ≤ N ,when x i andx j Belong to more than one category, , and define x i and x j is a similar sample pair; otherwise , and define x i and x j are dissimilar sample pairs; the attributes of the image dataset are converted into attribute vectors through the word embedding method. These attribute vectors are semantically similar, and the attribute vectors representing the same semantics have a high cosine similarity; then the attribute vectors are encoded through a fully connected layer, and all the encoded attribute vectors are defined to form an attribute space.

[0030] The specific process of step 2) is as follows:

[0031] Step 2-1: Convert the original sample with a dimension of 224×224×3 x i The image segmentation module is used to segment the images into non-overlapping window images, each of which has a window size of 16×16. The non-overlapping window images are expanded in the channel direction to obtain a window image with a dimension of 14×14×768.

[0032] Step 2-2: Reorganize the window image with a dimension of 14×14×768 into a window image with a dimension of 196×768, define the window image with a dimension of 196×768 as the image space, randomly select m% of the window images from the 196 768-dimensional window images in the image space and map them to the attribute space to obtain the mapped window image, obtain the cosine similarity between the mapped window image and the attribute vector in the attribute space, select the attribute vector with the highest cosine similarity for each mapped window image and map it back to the image space; replace the m% of the window images with the attribute vector mapped back to the image space at the original position, and then fuse them with the remaining 1-m% of the window images in the image space to form a fused image;

[0033] Step 2-3: Construct an encoder, which consists of 12 layers of Transformer Block modules. First, the remaining 1-m% window image and fused image in the image space are sent to the first LN layer as input features for normalization to obtain the first normalized features, and then the first normalized features are input into the multi-head self-attention module. Subsequently, the feature map output by the multi-head self-attention module and the input features are residually connected, and the obtained results are normalized through the second LN layer to obtain the second normalized features. Finally, the second normalized features are input into the multi-layer perceptron to obtain the original image encoder features corresponding to the remaining 1-m% window image in the image space and the fused image encoder features corresponding to the fused image.

[0034] Step 2-4: Construct a decoder. The decoder consists of 8 layers of Transformer Block modules. The original image encoder features and the fused image encoder features are respectively input into the decoder to obtain the original image decoder features corresponding to the original image encoder features and the fused image decoder features corresponding to the fused image encoder features.

[0035] Step 3): Construct a hash retrieval model to be trained, input the original image encoder features of the training sample into the hash retrieval model to be trained to obtain the hash code of the training sample and the classification result of the training sample. The specific process is as follows:

[0036] Step 3-1: Construct the hash retrieval model to be trained, including the pooling layer, the hashing layer and the classification layer. Pass the original image encoder features of the training sample through the pooling layer, and apply global average pooling in the pooling layer to obtain a feature vector with a dimension of 768×1. ;

[0037] Step 3-2: Input the hash layer to process and get the feature vector output by the hash layer h i , ,Will h i Binarization to get hash code b i , ,in, W represents the weight matrix of the hash layer, express W The transpose of o represents the bias of the hash layer, tanh(·) is the hyperbolic tangent function, sgn(·) is the sign function, and then h i After the classification layer, the classification result is obtained , , Softmax(·) represents the normalized exponential function, represents the weight matrix of the classification layer, express The transpose of Represents the bias of the classification layer.

[0038] Step 4): Define the common loss function of the feature extraction model to be trained and the hash retrieval model to be trained, use the original image encoder features, fused image encoder features, original image decoder features, fused image decoder features, hash codes of training samples and classification results of training samples to obtain the value of the loss function, and update the feature extraction model to be trained and the hash retrieval model to be trained respectively through the back propagation algorithm. After the training is completed, the trained feature extraction model and the trained hash retrieval model are obtained. The specific process is as follows:

[0039] Step 4-1: Define the common loss function of the feature extraction model to be trained and the hash retrieval model to be trained as L, ,in, α , β is a hyperparameter, L c is the classification loss, , L r is the contrast loss, ,in p i For the i The window image of the image space corresponding to the training samples, For the i The original image decoder features corresponding to the training samples, q i For the i The fused image decoder features corresponding to samples, L h is the hash loss, , , S 1 is with x i A collection of related similar sample pairs, express S The number of elements of 1, S 0 is the same as x i A collection of related dissimilar sample pairs, express S The number of elements that are 0, for h i The transpose of h j Indicates that x jThe feature vector output by the hash layer after inputting the hash retrieval model to be trained; wherein, through the constraint of classification loss, the feature extraction model and the hash retrieval model can generate more discriminative features and hash codes for samples of different categories; through the constraint of contrast loss, the original image decoder features and the fused image decoder features are both close to the window image in the image space, and the attributes and image block encodings with the same semantics are as similar as possible; the hash loss can make the hash codes generated by similar sample pairs close, and make the hash codes of dissimilar sample pairs far apart, and at the same time, the weights for balancing similar and dissimilar samples are added to the hash loss;

[0040] Step 4-2: Set the maximum number of iterations, and use the AdamW optimization algorithm to iteratively optimize the feature extraction model to be trained and the hash retrieval model to be trained according to the loss function. When the maximum number of iterations is reached, stop the iteration process to obtain the trained feature extraction model and the trained hash retrieval model. When the AWA2 dataset is used, the maximum number of iterations is set to 100, and when the CUB dataset is used, the maximum number of iterations is set to 300.

[0041] Step 5): Select from the samples of the invisible class M samples as the query set, and the remaining samples in the image dataset as the retrieval set. The query samples in the query set are subjected to feature extraction by the trained feature extraction model to obtain the original image encoder features of the query samples, and the trained hash retrieval model is used to extract the original image encoder features of the query samples to obtain the hash codes of the query samples; the retrieval samples in the retrieval set are subjected to feature extraction by the trained feature extraction model to obtain the original image encoder features of the retrieval samples, and the trained hash retrieval model is used to extract the original image encoder features of the retrieval samples to obtain the hash codes of the retrieval samples, and the set consisting of the hash codes of all the retrieval samples is defined as the retrieval set hash code retrieval library;

[0042] Step 6): Use the query sample in the query set to search, find the hash code with the closest Hamming distance to the hash code of the query sample in the retrieval set hash code retrieval library, and display the retrieval sample corresponding to the hash code as the retrieval result to complete the retrieval process of the query sample.

[0043] The retrieval performance of the image retrieval method of this embodiment is compared through specific comparative examples below, wherein the image retrieval method of this embodiment is abbreviated as this method, and the ablation experiment performed after replacing the attribute labels in the image retrieval method of this embodiment with category labels is abbreviated as this method (ablation).

[0044] Table 1:

[0045]

[0046] Table 1 shows the MAP@5000 results of the image retrieval method of this embodiment and other traditional linear hashing methods on three datasets CIFAR10, CUB and AWA2 when the hash code length is 24 bits to 128 bits.

[0047] It can be seen from Table 1 that, compared with the linear hashing method ASZH method, the image retrieval method of this embodiment improves the average mAP values ​​of the image retrieval method of this embodiment on the three data sets by 30.49%, 2.83% and 6.00% respectively.

[0048] Table 2:

[0049]

[0050] Table 2 shows the MAP@5000 results of the image retrieval method of this embodiment and other deep hashing methods on three benchmark datasets CIFAR10, CUB and AWA2 when the hash code length is 24 bits to 128 bits.

[0051] It can be seen from Table 2 that, compared with the deep hashing method DRMH method, the average mAP of the image retrieval method of this embodiment is improved by 22.38% and 11.13% on the CIFAR10 dataset and the AWA2 dataset; on the CUB dataset, the image retrieval method of this embodiment is improved by 4.48% compared with the deep hashing method SitNet; it can be seen that the image retrieval method of this embodiment performs significantly better than other methods on these three datasets.

[0052] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention 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 make equivalent replacements for some of the technical features therein. 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 invention.

Claims

1. An image retrieval method based on image block and attribute alignment, characterized in that The following steps are involved: Step 1): Divide the categories of samples in the image dataset into visible classes and invisible classes, and select N samples as the training set, and then use the N The similarity matrix is ​​constructed based on the category labels of the training samples; the attributes of the image dataset are converted into attribute vectors through the word vector method, and then the attribute vectors are encoded through the fully connected layer, and all the encoded attribute vectors are defined to form an attribute space; Step 2): Construct the feature extraction model to be trained. N The training samples are randomly shuffled to obtain shuffled training samples, and the shuffled training samples are input into the feature extraction model to be trained. First, each training sample is divided into non-overlapping window images through an image segmentation module, and the set of all window images is defined as an image space. In the image space, m% of the window images are randomly selected and mapped to the attribute space to obtain the mapped window image, 25≤m≤75, and the cosine similarity between the mapped window image and the attribute vector in the attribute space is obtained. For each mapped window image, the attribute vector with the highest cosine similarity is selected and mapped back to the image space, and the attribute vector mapped back to the image space replaces the m% of the window image at the original position, and then is fused with the remaining 1-m% of the window image to form a fused image; an encoder and a decoder are constructed, and the remaining 1-m% of the window image and the fused image are respectively input into the encoder to obtain the original image encoder features corresponding to the remaining 1-m% of the window image and the fused image encoder features corresponding to the fused image; the original image encoder features and the fused image encoder features are respectively input into the decoder to obtain the original image decoder features corresponding to the original image encoder features and the fused image decoder features corresponding to the fused image encoder features; Step 3): Construct a hash retrieval model to be trained, input the original image encoder features of the training sample into the hash retrieval model to be trained to obtain the hash code of the training sample and the classification result of the training sample; Step 4): Define the common loss function of the feature extraction model to be trained and the hash retrieval model to be trained, use the original image encoder features, fused image encoder features, original image decoder features, fused image decoder features, hash codes of the training samples and classification results of the training samples to obtain the value of the loss function, update the feature extraction model to be trained and the hash retrieval model to be trained respectively through the back propagation algorithm, and obtain the trained feature extraction model and the trained hash retrieval model after the training is completed; Step 5): Select samples from the invisible classes in the image dataset M samples as the query set, and the remaining samples in the image dataset as the retrieval set. The query samples in the query set are subjected to feature extraction by the trained feature extraction model to obtain the original image encoder features of the query samples, and the trained hash retrieval model is used to extract the original image encoder features of the query samples to obtain the hash codes of the query samples; the retrieval samples in the retrieval set are subjected to feature extraction by the trained feature extraction model to obtain the original image encoder features of the retrieval samples, and the trained hash retrieval model is used to extract the original image encoder features of the retrieval samples to obtain the hash codes of the retrieval samples, and the set consisting of the hash codes of all the retrieval samples is defined as the retrieval set hash code retrieval library; Step 6): Use the query sample in the query set to perform retrieval, find the hash code with the closest Hamming distance to the hash code of the query sample in the retrieval set hash code retrieval library, and use the retrieval sample corresponding to the hash code as the retrieval result to complete the retrieval process for the query sample.

2. The image retrieval method based on image block and attribute alignment according to claim 1, characterized in that In step 1), the training set N The specific process of constructing the similarity matrix based on the category labels of samples is as follows: The samples in the image dataset are divided into visible and invisible classes, and the samples in the visible class are selected N samples as training set X , , x i express X For any sample in i ≤ N , and record the corresponding category label matrix as Y , ,in, y i express Y Any category label in C is the total number of categories, using N The similarity matrix is ​​constructed based on the category labels of samples S , ,in, express X Any two samples x i and x j Similarity, 1≤ i ≤ j ≤ N ,when x i and x j Belong to more than one category, , and define x i and x j is a similar sample pair; otherwise , and define x i and x j are dissimilar sample pairs.

3. The image retrieval method based on image block and attribute alignment according to claim 2, characterized in that The specific process of step 2) is as follows: Step 2-1: Convert the original sample with a dimension of 224×224×3 x i The image segmentation module is used to segment the images into non-overlapping window images, each of which has a window size of 16×16. The non-overlapping window images are expanded in the channel direction to obtain a window image with a dimension of 14×14×768. Step 2-2: Reorganize the window image with a dimension of 14×14×768 into a window image with a dimension of 196×768, define the window image with a dimension of 196×768 as the image space, randomly select m% of the window images from the 196 768-dimensional window images in the image space and map them to the attribute space to obtain the mapped window image, obtain the cosine similarity between the mapped window image and the attribute vector in the attribute space, select the attribute vector with the highest cosine similarity for each mapped window image and map it back to the image space; The attribute vector mapped back to the image space replaces m% of the window image at the original position, and then merges it with the remaining 1-m% of the window image in the image space to form a fused image; Step 2-3: Construct an encoder, which consists of 12 layers of Transformer Block modules. First, the remaining 1-m% window image and fused image in the image space are sent to the first LN layer as input features for normalization to obtain the first normalized features, and then the first normalized features are input into the multi-head self-attention module. Subsequently, the feature map output by the multi-head self-attention module and the input features are residually connected, and the obtained results are normalized through the second LN layer to obtain the second normalized features. Finally, the second normalized features are input into the multi-layer perceptron to obtain the original image encoder features corresponding to the remaining 1-m% window image in the image space and the fused image encoder features corresponding to the fused image. Step 2-4: Construct a decoder. The decoder consists of 8 layers of Transformer Block modules. The original image encoder features and the fused image encoder features are respectively input into the decoder to obtain the original image decoder features corresponding to the original image encoder features and the fused image decoder features corresponding to the fused image encoder features.

4. The image retrieval method based on image block and attribute alignment according to claim 3, characterized in that The specific process of step 3) is as follows: Step 3-1: Construct the hash retrieval model to be trained, including the pooling layer, the hashing layer and the classification layer. Pass the original image encoder features of the training sample through the pooling layer, and apply global average pooling in the pooling layer to obtain a feature vector with a dimension of 768×1. ; Step 3-2: Input the hash layer to process and get the feature vector output by the hash layer h i , ,Will h i Binarization to get hash code b i , ,in, W represents the weight matrix of the hash layer, express W The transpose of o represents the bias of the hash layer, tanh(·) is the hyperbolic tangent function, sgn(·) is the sign function, and then h i After the classification layer, the classification result is obtained , , Softmax(·) represents the normalized exponential function, represents the weight matrix of the classification layer, express The transpose of Represents the bias of the classification layer.

5. The image retrieval method based on image block and attribute alignment according to claim 4, characterized in that The specific process of step 4) is as follows: Step 4-1: Define the common loss function of the feature extraction model to be trained and the hash retrieval model to be trained as L, ,in, α , β is a hyperparameter, L c is the classification loss, , L r is the contrast loss, ,in p i For the i The window image of the image space corresponding to the training samples, For the i The original image decoder features corresponding to the training samples, q i For the i The fused image decoder features corresponding to samples, L h is the hash loss, , , S 1 is with x i A collection of related similar sample pairs, express S The number of elements of 1, S 0 is the same as x i A collection of related dissimilar sample pairs, express S The number of elements that are 0, for h i The transpose of h j Indicates that x j The feature vector output by the hash layer after inputting the hash retrieval model to be trained; Step 4-2: Set the maximum number of iterations, and use the AdamW optimization algorithm to iteratively optimize the feature extraction model to be trained and the hash retrieval model to be trained according to the loss function until the maximum number of iterations is reached. Stop the iteration process and obtain the trained feature extraction model and the trained hash retrieval model.