Zero-shot sketch retrieval model training and image retrieval method
By employing preprocessing, block embedding, and multi-head cross-attention mechanisms in a zero-shot sketch retrieval model, a visual correspondence between sketches and images to be retrieved is established. This addresses the problem of low retrieval efficiency for new categories of data in existing technologies and achieves highly efficient sketch retrieval results.
Patent Information
- Application Number
- CN202311717079.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-13
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-12-13
AI Technical Summary
Existing technologies struggle to effectively handle new categories of data in sketch retrieval tasks, resulting in low retrieval efficiency and failing to meet users' needs for efficient retrieval.
A zero-shot sketch retrieval model is adopted. Through preprocessing, block embedding, multi-head cross-attention mechanism and alignment module, visual correspondence between sketch image and image to be retrieved is established. The model is trained using triple loss and cross-entropy loss values to achieve effective retrieval of new category data.
Without increasing the training data, the sketch retrieval model improves its retrieval performance for new categories of data, enabling users to perform efficient sketch retrieval on test data.
Smart Images

Figure CN117708361B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and more specifically, to a method for training a zero-shot sketch retrieval model and image retrieval. Background Technology
[0002] With the rapid development of internet technology in recent years, image data on the internet has also exploded, creating a demand for users to efficiently retrieve relevant images. Sketches, as images depicting the approximate outline of an object, are composed of sparse lines, allowing users to easily draw sketches to visually convey the images they want to search for. For image retrieval, when users find it difficult to visually describe the images they want to search for, using sketches—a method that users can directly draw and visually represent—has unparalleled advantages, thus giving rise to the sketch retrieval task.
[0003] Traditional sketch retrieval methods assume that the test and training data belong to the same category and attempt to learn a common feature subspace that preserves the inherent cross-domain correlations between different data domains (sketches and images to be retrieved) for retrieval. However, in real-world retrieval scenarios, the database continuously expands due to the addition of data from new categories, and recent studies have shown that these methods perform poorly for new categories that are not visible during training.
[0004] If traditional sketch retrieval algorithms are to achieve better results with new categories of data, these categories need to be added to the training data and retrained. However, this is undoubtedly extremely inefficient in real-world scenarios and cannot meet users' needs for efficient retrieval. Summary of the Invention
[0005] The purpose of this application is to provide a zero-sample sketch retrieval model training and image retrieval method to address the shortcomings of the prior art, thereby solving the problem of inefficiency in the prior art and its inability to meet users' needs for efficient retrieval.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows:
[0007] In a first aspect, one embodiment of this application provides a training method for a zero-shot sketch retrieval model. The zero-shot sketch retrieval model includes: a preprocessing module, a block embedding module, a first cue module, a second cue module, an image encoder, an alignment module, a cross-attention module of a first multi-head cross-attention mechanism, and a cross-attention module of a second multi-head cross-attention mechanism. The image encoder is an image encoder based on a pre-trained model of contrastive text-image pairs. The method includes:
[0008] The preprocessing module is used to preprocess the sketch image and the image to be retrieved within the sample pair, respectively; wherein, the sketch image includes a depicted object, and the image to be retrieved includes the instance object corresponding to the depicted object;
[0009] The preprocessed sketch image and the image to be retrieved are respectively input into the block embedding module to obtain the sketch visual features corresponding to the sketch image and the instance visual features corresponding to the image to be retrieved;
[0010] The image encoder acquires the output of the first prompting module and the visual features of the sketch;
[0011] The image encoder acquires the output of the second prompting module and the visual features of the instance;
[0012] The image encoder outputs sample sketch encoding features and sample instance encoding features to the cross-attention module of the first multi-head cross-attention mechanism and the cross-attention module of the second multi-head cross-attention mechanism, respectively, to establish a visual correspondence between the sketch image and the image to be retrieved;
[0013] The sample sketch coding features and sample instance coding features output by the image encoder are processed by the alignment module to obtain aligned sample sketch coding features and aligned sample instance coding features.
[0014] Based on the visual correspondence between the sketch image and the image to be retrieved, the triplet loss value is determined;
[0015] Based on the aligned sample sketch encoding features and the aligned sample instance encoding features, the cross-entropy loss value is determined;
[0016] The zero-shot sketch retrieval model is trained based on the triplet loss value and the cross-entropy loss value to obtain the trained zero-shot sketch retrieval model.
[0017] Optionally, the preprocessing module is used to preprocess the sketch image and the image to be retrieved within the sample pair, respectively, including:
[0018] The dimensions of the sketch image and the image to be retrieved are adjusted to preset sizes, and the resized sketch image is converted into a tensor.
[0019] The values in the three color channels of the sketch image after conversion to tensors are normalized according to the preset average (0.5, 0.5, 0.5) and preset standard deviation (0.5, 0.5, 0.5).
[0020] Optionally, before adjusting the sizes of the sketch image and the image to be retrieved to preset sizes, and converting the resized sketch image into a tensor, the method further includes:
[0021] The blank areas around the depicted object are removed based on the differences in their pixel values.
[0022] Optionally, the block embedding module includes: a first block embedding module and a second block embedding module, wherein the second block embedding module is a learnable image block embedding module composed of five convolutional layers; the step of inputting the preprocessed sketch image and the image to be retrieved into the block embedding module respectively to obtain the sketch visual features corresponding to the sketch image and the instance visual features corresponding to the image to be retrieved includes:
[0023] The first block embedding module performs data conversion on the preprocessed sketch image to obtain the first sketch visual features;
[0024] The second block embedding module performs data conversion on the preprocessed sketch image to obtain a second sketch visual feature; wherein, the sketch visual feature includes: the first sketch visual feature and the second sketch visual feature;
[0025] The first block embedding module performs data transformation on the preprocessed image to be retrieved to obtain the first instance visual features;
[0026] The second block embedding module performs data conversion on the preprocessed image to be retrieved to obtain a second instance visual feature; wherein, the instance visual feature includes: the first instance visual feature and the second instance visual feature.
[0027] Optionally, the first prompt module is The second prompt module is N in the first prompt module and the second prompt module e All are the number of prompt vectors, and d is the dimension of the vector. The dimension of the vector is consistent with the visual features extracted by the block embedding module.
[0028] Optionally, the image encoder further includes a first linear mapping layer, which maps category features having the overall information of all features of the sample sketch or the image to be retrieved, so as to classify according to the category features, the aligned sample sketch encoding features, and the aligned sample instance encoding features.
[0029] Optionally, the alignment module includes a first alignment module, a second alignment module, and a third alignment module, wherein the first alignment module is used to align the sketch image, the second alignment module is used to align the image to be retrieved, and the third alignment module is used to align the sketch image and the image to be retrieved.
[0030] Optionally, training the zero-shot sketch retrieval model based on the triplet loss value and the cross-entropy loss value to obtain the trained zero-shot sketch retrieval model includes:
[0031] The zero-shot sketch retrieval model is trained based on the triplet loss value, the cross-entropy loss value pair, and the preset scaling factor to obtain the trained zero-shot sketch retrieval model.
[0032] Secondly, another embodiment of this application provides an image retrieval method, the method comprising:
[0033] Obtain the input sketch image;
[0034] According to a preset sketch retrieval model, the sketch image is processed to obtain the sketch encoding features of the sketch image; wherein, the image retrieval model is a sketch retrieval model trained by the training method of the sketch retrieval model of any of the above-mentioned first aspects;
[0035] Based on the sketch encoding features and the instance encoding features of multiple instance images in the preset image library, at least one target instance image is determined from the preset image library.
[0036] Optionally, determining at least one target instance image from the preset image library based on the sketch coding features and the instance coding features of multiple instance images in the preset image library includes:
[0037] Based on the sketch coding features and the instance coding features of multiple instance images in the preset image library, the cosine similarity between the sketch coding features and the instance coding features of each instance image is determined.
[0038] Based on the cosine similarity values, at least one target instance image is determined from the preset image library.
[0039] Thirdly, another embodiment of this application provides a training apparatus for a zero-shot sketch retrieval model, the apparatus comprising: a processing module, an acquisition module, a determination module, and a training module, wherein:
[0040] The processing module is used to preprocess the sketch image and the image to be retrieved within the sample pair using the preprocessing module; wherein, the sketch image includes a depicted object, and the image to be retrieved includes an instance object corresponding to the depicted object;
[0041] The acquisition module is used to input the preprocessed sketch image and the image to be retrieved into the block embedding module to obtain the sketch visual features corresponding to the sketch image and the instance visual features corresponding to the image to be retrieved; the image encoder obtains the output of the first prompting module and the sketch visual features; the image encoder obtains the output of the second prompting module and the instance visual features; the image encoder outputs sample sketch encoding features and sample instance encoding features to the cross-attention module of the first multi-head cross-attention mechanism and the cross-attention module of the second multi-head cross-attention mechanism respectively to establish a visual correspondence between the sketch image and the image to be retrieved, wherein the image encoder is an image encoder based on a pre-trained model of contrasting text-image pairs; the sample sketch encoding features and sample instance encoding features output by the image encoder are processed by the alignment module to obtain aligned sample sketch encoding features and aligned sample instance encoding features;
[0042] The determining module is used to determine the triplet loss value based on the visual correspondence between the sketch image and the image to be retrieved; and to determine the cross-entropy loss value based on the aligned sample sketch encoding features and the aligned sample instance encoding features.
[0043] The training module is used to train the zero-shot sketch retrieval model based on the triplet loss value and the cross-entropy loss value to obtain the trained zero-shot sketch retrieval model.
[0044] Optionally, the processing module is specifically used to adjust the size of the sketch image and the image to be retrieved to a preset size, and convert the resized sketch image into a tensor; and normalize the values in the three color channels of the converted sketch image according to a preset average value (0.5, 0.5, 0.5) and a preset standard deviation (0.5, 0.5, 0.5).
[0045] Optionally, the processing module is specifically configured to remove the blank areas around the depicted object based on the differences in its pixel values.
[0046] Optionally, the processing module is specifically configured to: 1) perform data conversion on the preprocessed sketch image by the first block embedding module to obtain a first sketch visual feature; 2) perform data conversion on the preprocessed sketch image by the second block embedding module to obtain a second sketch visual feature; wherein the sketch visual feature includes: the first sketch visual feature and the second sketch visual feature; 3) perform data conversion on the preprocessed image to be retrieved by the first block embedding module to obtain a first instance visual feature; 4) perform data conversion on the preprocessed image to be retrieved by the second block embedding module to obtain a second instance visual feature; wherein the instance visual feature includes: the first instance visual feature and the second instance visual feature.
[0047] Optionally, the first prompt module is The second prompt module is N in the first prompt module and the second prompt module e All are the number of prompt vectors, and d is the dimension of the vector. The dimension of the vector is consistent with the visual features extracted by the block embedding module.
[0048] Optionally, the image encoder further includes a first linear mapping layer, which maps category features having the overall information of all features of the sample sketch or the image to be retrieved, so as to classify according to the category features, the aligned sample sketch encoding features, and the aligned sample instance encoding features.
[0049] Optionally, the alignment module includes a first alignment module, a second alignment module, and a third alignment module, wherein the first alignment module is used to align the sketch image, the second alignment module is used to align the image to be retrieved, and the third alignment module is used to align the sketch image and the image to be retrieved.
[0050] Optionally, the training module is specifically used to train the zero-shot sketch retrieval model based on the triplet loss value, the cross-entropy loss value pair, and a preset scaling factor, so as to obtain the trained zero-shot sketch retrieval model.
[0051] Fourthly, another embodiment of this application provides an image retrieval device, the device comprising: an acquisition module and a determination module, wherein:
[0052] The acquisition module is used to acquire the input sketch image;
[0053] The determining module is used to process the sketch image according to a preset sketch retrieval model to obtain the sketch encoding features of the sketch image; wherein, the image retrieval model is a sketch retrieval model trained by the training method of the sketch retrieval model of any of the first aspects mentioned above; and to determine at least one target instance image from the preset image library according to the sketch encoding features and the instance encoding features of multiple instance images in the preset image library.
[0054] Optionally, the determining module is specifically configured to determine the cosine similarity between the sketch coding features and the instance coding features of each instance image based on the sketch coding features and the instance coding features of multiple instance images in a preset image library; and to determine at least one target instance image from the preset image library based on the cosine similarity.
[0055] Fifthly, another embodiment of this application provides an electronic device, including: a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the method as described in either the first or second aspect above.
[0056] In a sixth aspect, another embodiment of this application provides a storage medium storing a computer program, which, when executed by a processor, performs the steps of the method as described in either the first or second aspect above.
[0057] The beneficial effects of this application are as follows: Using the training method of the zero-shot sketch retrieval model provided in this application, after acquiring the sketch image and the image to be retrieved, the model preprocesses both images. Then, the preprocessed sketch image and the image to be retrieved are input into the block embedding module to obtain sketch visual features and instance visual features. After obtaining the output of the first cue module and the sketch visual features, the image encoder outputs the sample sketch encoding features to the cross-attention module of the first multi-head cross-attention mechanism. Furthermore, after obtaining the output of the second cue module and the instance visual features, the image encoder also outputs the sample instance. Encoding features are incorporated into the cross-attention module of the second multi-head cross-attention mechanism to establish a visual correspondence between the sketch image and the image to be retrieved. After the alignment module processes the aligned sample sketch encoding features and sample instance encodings, the triplet loss value and cross-entropy loss value are determined. The zero-shot sketch retrieval model is then trained based on the triplet loss value and the cross-entropy loss value to obtain the trained zero-shot sketch retrieval model. This training method yields a zero-shot sketch retrieval model with high retrieval performance, and it still supports sketch retrieval even when there are data categories in the test data that are different from those in the training data. Attached Figure Description
[0058] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0059] Figure 1 This is a schematic diagram of the structure of a zero-sample sketch retrieval model provided in an embodiment of this application;
[0060] Figure 2 A flowchart illustrating a training method for a zero-shot sketch retrieval model provided in another embodiment of this application;
[0061] Figure 3 A schematic flowchart of an image retrieval method provided in an embodiment of this application;
[0062] Figure 4 A schematic diagram of the structure of a training device for a zero-sample sketch retrieval model provided in an embodiment of this application;
[0063] Figure 5 This is a schematic diagram of the structure of an image retrieval device provided in an embodiment of this application;
[0064] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of this application, but not all embodiments.
[0066] The components of the embodiments of this application described and illustrated in the accompanying drawings can be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of this application provided in the drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0067] The following explanation, using several specific application examples, illustrates the training method for a zero-shot sketch retrieval model provided in this application. Figure 1 This is a schematic diagram of the structure of a zero-sample sketch retrieval model provided in an embodiment of this application, as shown below. Figure 1 As shown, the zero-shot sketch retrieval model includes: a preprocessing module, a block embedding module, a first cue module, a second cue module, an image encoder, an alignment module, a cross-attention module with a first multi-head cross-attention mechanism, and a cross-attention module with a second multi-head cross-attention mechanism. The image encoder is a Contrastive Language-Image Pre-training (CLIP) model based on a pre-trained model of contrastive text-image pairs. Figure 2 A flowchart illustrating a training method for a zero-shot sketch retrieval model provided in an embodiment of this application is shown below. Figure 1 As shown, the method includes:
[0068] S101: The preprocessing module is used to preprocess the sketch image and the image to be retrieved within the sample pair respectively.
[0069] The sketch image includes a depicted object, and the image to be retrieved includes instance objects corresponding to the depicted object. The sketch image can include any type of depicted object, such as depicting people, animals, plants, cartoon characters, etc. It should be understood that the types of depicted objects included in the sketch image can be flexibly adjusted according to user needs and are not limited to those given in the above embodiments.
[0070] In the embodiments of this application, the preprocessing method may be as follows: adjust the size of the sketch image and the image to be retrieved to a preset size, and convert the resized sketch image into a tensor; normalize the values in the three color channels of the sketch image after conversion into a tensor according to a preset average value (0.5, 0.5, 0.5) and a preset standard deviation (0.5, 0.5, 0.5).
[0071] For sketch images, before adjusting the size to the preset size, it is also necessary to remove the blank parts around the depicted object based on the difference in its pixel values.
[0072] In other words, the preprocessing steps for the sketch image in this application differ from those for the image to be retrieved. The preprocessing for the sketch image includes four steps: First, the blank areas around the objects depicted in the sketch image are removed based on the differences in their pixel values. Then, the size of the sketch image after removing the blank areas is adjusted to 224×224. After that, it is converted into a tensor. Finally, the values of the three channels in the sketch image after being converted into a tensor are normalized according to the mean (0.5, 0.5, 0.5) and standard deviation (0.5, 0.5, 0.5).
[0073] The preprocessing of the image to be retrieved includes three steps: first, the size of the image to be retrieved is adjusted to 224×224, then it is converted into a tensor, and finally the values of the three channels in the image to be retrieved after being converted into a tensor are normalized according to the mean (0.5, 0.5, 0.5) and standard deviation (0.5, 0.5, 0.5).
[0074] S102: Input the preprocessed sketch image and the image to be retrieved into the block embedding module to obtain the sketch visual features corresponding to the sketch image and the instance visual features corresponding to the image to be retrieved.
[0075] In embodiments of this application, the block embedding module includes: a first block embedding module and a second block embedding module, wherein the second block embedding module is a learnable image block embedding module composed of five convolutional layers; the steps of obtaining sketch visual features and instance visual features may include: the first block embedding module performing data conversion on the preprocessed sketch image to obtain a first sketch visual feature; the second block embedding module performing data conversion on the preprocessed sketch image to obtain a second sketch visual feature; wherein the sketch visual features include: the first sketch visual feature and the second sketch visual feature; the first block embedding module performing data conversion on the preprocessed image to be retrieved to obtain a first instance visual feature; the second block embedding module performing data conversion on the preprocessed image to be retrieved to obtain a second instance visual feature; wherein the instance visual feature includes: the first instance visual feature and the second instance visual feature.
[0076] In the embodiments of this application, the first block embedding module can be, for example, a traditional image embedding module, and the second block embedding module can be, for example, a learnable image block embedding module consisting of five convolutional layers, denoted as T. This second block embedding module also transforms the input preprocessed sketch image / preprocessed image to be retrieved into second sketch visual features / second instance visual features (second visual features), denoted as Y = {y i |i=1,…,N}, and y i ∈R d The first sketch visual feature / first instance visual feature (first visual feature) obtained by the first block embedding module is denoted as Z = {z i |i=1,…,N}, and z i ∈R d They are all N in number and have a feature dimension of d. However, the newly added second block embedding module has a larger receptive field than the first block embedding module when extracting the second visual features, and the extracted y i It has a wider range of visual information and utilizes y i This is beneficial for establishing visual relationships between sparse sketch images and the images to be retrieved. The visual features of the input module are denoted as V = {v}. i |i=1,…,N}, and v i ∈R d The result is obtained by adding the two previously acquired tokens: V = Y + Z; that is, let s represent the sketch image and p represent the image to be retrieved. For the sketch image's visual features: V s =Y s +Z s For instance visual features of the image to be retrieved: V p =Y p +Z p .
[0077] S103: The image encoder acquires the output of the first prompting module and the visual features of the sketch.
[0078] S104: The image encoder obtains the output of the second prompting module and the instance visual features.
[0079] In the embodiments of this application, the image encoder is a CLIP image encoder, and the first prompting module is... The second prompt module is N in the first prompt module and the second prompt module e All are the number of cue vectors, and d is the dimension of the vector. The dimension of the vector is consistent with the visual features extracted by the block embedding module.
[0080] The first prompt module will be used as an example for explanation (the operation of the second prompt module is the same). For an input sketch image, including the category that integrates all feature information, denoted as v0, and the V corresponding to the sketch image extracted earlier. s , forming X s =(v0,V s E s The module that follows the input. The newly added first and second prompt modules will be used for prompt learning. During training, the parameters in the first and second prompt modules will be continuously updated to maintain the generalization ability of the model backbone.
[0081] S105: The image encoder outputs the sample sketch encoding features and sample instance encoding features to the cross-attention module of the first multi-head cross-attention mechanism and the cross-attention module of the second multi-head cross-attention mechanism, respectively, to establish a visual correspondence between the sketch image and the image to be retrieved.
[0082] In the embodiments of this application, the image encoder is a CLIP image encoder, which further includes a first linear mapping layer. The first linear layer maps category features that have overall information of all features of the sample sketch or the image to be retrieved, so as to classify according to the category features, the aligned sample sketch encoding features and the aligned sample instance encoding features.
[0083] In this embodiment, the first linear layer is denoted as H. s This first linear layer can be used to map the category features v0, which contain the overall information of all features of a sketch image or the image to be retrieved. Since the relevant visual and text features in the embedding space of the image encoder are highly aligned, the 512-dimensional features obtained after mapping can be combined with the text features encoded by the image encoder for classification. Here, the features corresponding to the sketch image are denoted as f. S The features corresponding to the image to be retrieved are denoted as f. p .
[0084] This invention designs two cross-attention modules based on a multi-head cross-attention mechanism after the model backbone, denoted as the first multi-head cross-attention mechanism cross-attention module C. s Cross-attention module C of the second multi-head cross-attention mechanism pTo establish a visual correspondence between the sketch image and the image to be retrieved, both use the output of the last layer of the model backbone, which consists of a multi-head self-attention module (MSA) and a feed-forward network (FFN), as input. Both also have only one layer of structure based on a multi-head cross-attention mechanism and a feed-forward network. C s The output features correspond to the sketch image, C p The output features correspond to the image to be retrieved. The cross-attention module C uses the first multi-head cross-attention mechanism. s For example, in this application, the Queries obtained by feature mapping of the sketch image are denoted as Q. s Replace with Q obtained by mapping the image to be retrieved p If CA refers to the multi-head cross-attention mechanism, then the multi-head cross-attention mechanism performed on the multi-head cross-attention mechanism module can be represented by the following formula:
[0085]
[0086] Similarly, the cross-attention module C of the second multi-head cross-attention mechanism p In the cross-attention mechanism, the Queries obtained from the feature mapping of the image to be retrieved are denoted as Q. p Q is obtained by converting it to a sketch image mapping. s The features acquired through the cross-attention module, regardless of whether they belong to the sketch image or the image to be retrieved, all incorporate visual information from the image to be retrieved / sketching image.
[0087] Therefore, the model constructed in this application can establish visual correspondences between different types of images. Based on these visual correspondences, the model can determine whether different types of images match. Without requiring the relevant categories of the test data to participate in training, knowledge transfer from training data to test data is achieved.
[0088] S106: The sample sketch coding features and sample instance coding features output by the image encoder are processed by the alignment module to obtain aligned sample sketch coding features and aligned sample instance coding features.
[0089] The alignment module includes a first alignment module, a second alignment module, and a third alignment module. The first alignment module is used to align the sketch image, the second alignment module is used to align the image to be retrieved, and the third alignment module is used to align the sketch image and the image to be retrieved.
[0090] Furthermore, this invention employs a multimodal pre-trained large-scale image encoder as the model backbone, specifically the image encoder of the multimodal pre-trained large-scale model CLIP, to leverage the rich multimodal knowledge (including both visual and textual modalities) possessed by the CLIP image encoder. This image encoder structure belongs to the Vision Transformer (ViT) architecture, with an input image size of (224, 224), each patch size of (32, 32), and a feature dimension d of 768 for all features. After the patch embedding module, the backbone has a 12-layer structure composed of multi-head self-attention (MSA) modules and a feed-forward network (FFN). For each multi-head self-attention module, there is a (W... q W k W v These three linear mapping layers map the same feature to queries (Q), keys (K), and values (V). Assume the input to the i-th layer of the model backbone is X. i-1 That is, the output of the previous layer. The mapping process is as follows:
[0091] Q = X i-1 W q K = X i-1 W k V = X i-1 W v
[0092] If SA represents the multi-head cross-attention mechanism, and ψ represents the soft maximum function (softmax) activation function, then the multi-head cross-attention mechanism performed on the multi-head cross-attention module can be expressed by the following formula:
[0093]
[0094] If LN refers to Layer Normalization, the entire process of the i-th layer of the model backbone is as follows:
[0095] X i =MSA(LN(X) i-1 ))+X i-1
[0096] X i =FFN(LN(X) i ))+X i
[0097] This application designs three alignment modules, referred to as the first alignment module. Second alignment module and the third alignment module These are used respectively for aligning the sketch image, aligning the image to be retrieved, and simultaneously aligning the sketch image and the image to be retrieved, where N c d represents the number of data categories used in the training data. t The feature dimension of the text features extracted by the text encoder representing the image encoder used in this application, for example, can be 512, and is related to the feature f extracted by the model backbone. S f p Consistent.
[0098] In the embodiments of this application, three alignment modules are designed because the CLIP image encoder used lacks sketch knowledge, while the image to be retrieved is closer to the image data used for training the CLIP image encoder. Therefore, applying the CLIP image encoder to the sketch and applying it to the image to be retrieved require different degrees of fine-tuning. Hence, this application designs a first alignment module A. s (Second Alignment Module A) p Alignment can be achieved by using a sketch image (the image to be retrieved), but this method retains some information specific to the sketch and the image to be retrieved, hindering alignment between different types of images. Therefore, this application also designs a third alignment module A. c This allows for the simultaneous alignment of both sketch images and images to be retrieved, reducing the retention of proprietary information within the same type of image by the model.
[0099] S107: Determine the triplet loss value based on the visual correspondence between the sketch image and the image to be retrieved.
[0100] S108: Determine the cross-entropy loss value based on the aligned sample sketch encoding features and the aligned sample instance encoding features.
[0101] This application includes a linear mapping layer, denoted as H, following the cross-attention module. c This application maps v0 after passing through the cross-attention module to obtain features with different types of image visual information. The features of the sketch image are denoted as... The features of the image to be retrieved are denoted as... To perform preliminary alignment between different types of images and assist in establishing their visual correspondence, a loss function based on triplet loss is used, where the distance parameter is calculated based on the cosine similarity between features extracted from the selected samples. It is applied in this application.
[0102] For example, let's take a set of instances, where... Features extracted from sketch instances Features extracted from instances that are consistent with (or inconsistent with) the sketch instance category are used to... Close to the positive example Stay away from negative examples The loss function is expressed by the following formula:
[0103]
[0104] Where μ is the distance separating positive and negative examples, and d(a,b) represents the distance parameter, which is calculated as follows:
[0105] d(a,b) = 1 - cos(a,b)
[0106] Where cos(a,b) represents the cosine similarity between feature a and feature b.
[0107] S109: The zero-sample sketch retrieval model is trained based on the triplet loss value and the cross-entropy loss value to obtain the trained zero-sample sketch retrieval model.
[0108] In the embodiments of this application, the trained zero-shot sketch retrieval model can be obtained, for example, by training the zero-shot sketch retrieval model based on triplet loss values, cross-entropy loss value pairs, and a preset scaling factor.
[0109] This application constructs a set of artificial prompts similar to "a photo of a [category]", where [category] is replaced by the English words representing the categories in the training data. For a given category, this application combines the English words of that category with the artificial prompt set to obtain a set of English sentences containing those words. The text encoder of the image encoder model used in this application extracts the text features of all sentences in this set, and after normalization, averages them to obtain a text feature that represents the category information. Performing the same operation on all categories of the training data yields a feature set. Because the visual and textual features in the embedding space of the image encoder are highly aligned, all features in this set can represent the class centers of the corresponding categories. For any image, the image features extracted by the image encoder and C... t By comparing the cosine similarity of all features, the image can be classified more accurately. Therefore, this application uses C. t The parameters of the three alignment modules are initialized, and then the alignment modules are combined with the alignment loss proposed in this application. This allows for the alignment of different types of image data. For sketches, the output of the model backbone utilizes a linear layer H. s The acquired features f S , Formula for calculating data in the sketch image portion As shown below:
[0110]
[0111] Where CE stands for Cross Entropy, and y represents the label of the sketch image training data. Similarly, The formula for calculating the data of the image portion to be retrieved As shown below:
[0112]
[0113] After that, alignment loss The calculation formula is as follows:
[0114]
[0115] Furthermore, based on the above explanation, the overall training objective adopted during model training in this application is as follows:
[0116]
[0117] Where λ t and λ a The hyperparameters used to balance the influence of the various loss functions are set before training, and these two hyperparameters are not updated during training. During training, the model updates the newly added learnable block embedding module (T) and two learnable cue modules (E). s E p Two cross-attention modules (C) s C p ), the linear mapping layer after the cross-attention module (H) c ) and the parameters of the three alignment modules (A s A p and A c For the model backbone, only the parameters of the Layer Normalization layer, Positional Encoding, and ClassToken (which integrates information from other tokens) participate in the training process, while the parameters of the remaining parts are fixed.
[0118] The training method of the zero-shot sketch retrieval model provided in this application involves preprocessing the sketch image and the image to be retrieved after acquiring them. The preprocessed sketch image and the image to be retrieved are then input into a block embedding module to obtain sketch visual features and instance visual features, respectively. After acquiring the output of the first cueing module and the sketch visual features, the image encoder outputs sample sketch encoding features to the cross-attention module of the first multi-head cross-attention mechanism. Furthermore, after acquiring the output of the second cueing module and the instance visual features, the image encoder also outputs sample instance encoding features. The cross-attention module of the second multi-head cross-attention mechanism is used to establish a visual correspondence between the sketch image and the image to be retrieved. After the alignment module processes the sketch encoding features and sample instance encoding of the aligned samples, the triplet loss value and cross-entropy loss value are determined. The zero-shot sketch retrieval model is trained based on the triplet loss value and cross-entropy loss value to obtain the trained zero-shot sketch retrieval model. The zero-shot sketch retrieval model obtained by this training method has high retrieval performance and still supports users to perform sketch retrieval when there are data categories in the test data that are different from the categories in the training data.
[0119] This application conducts experiments on three benchmark datasets widely used for zero-shot sketch retrieval: Sketchy, TUBerlin, and QuickDraw. Sketchy has 125 categories, including 75,471 sketches and 12,500 images to be retrieved. To alleviate the data imbalance between sketches and images to be retrieved, an additional 60,502 images were added. Sketchy commonly uses two training and testing category partitions, denoted as Sketchy and Sketchy-NO. The former selects 25 categories for testing only, while the latter selects 21 categories. The difference is that the testing categories in Sketchy-NO do not overlap with those in ImageNet, thus eliminating the influence of ImageNet-related knowledge from the pre-trained model during model testing, making retrieval more difficult with this partition. TUBerlin has 250 categories, including 20,000 sketches and 204,489 images to be retrieved. TuBerlin commonly uses a training and testing class split, selecting 30 classes for testing only. QuickDraw has 110 classes, including 330,000 sketches and 204,000 images to be retrieved. QuickDraw also uses a training and testing class split, selecting 30 classes for testing only. Of the three datasets, Sketchy is easier to handle; TuBerlin is more challenging due to imbalanced data (an imbalance between sketches and images to be retrieved) and its abstract sketches; QuickDraw is the most challenging due to its multi-object images.
[0120] The model trained in this application can successfully perform zero-shot sketch retrieval. For data in the test category that was not used in the training, it can retrieve images of the same category. Furthermore, by comparing the sketch used for retrieval with the retrieved image, it can be seen that the retrieved image has a similar shape to the sketch used for retrieval. This further demonstrates that the model trained in this application can effectively compare sketches and images with semantic gaps and select matching images based on visual similarity.
[0121] This application uses commonly used retrieval performance metrics, mAP (mean average precision) and Prec (precision), for evaluation. The models trained in this application consistently outperform previous baseline methods. This demonstrates the superiority of this approach compared to other baseline methods. It selects CLIP, a model with rich multimodal knowledge, as the model backbone, employs a multi-head cross-attention module, and facilitates knowledge transfer between training and testing data by establishing visual correspondences between sketches and the images to be retrieved. Furthermore, with the help of a prompting module, it maintains the model's generalization ability by keeping the backbone parameters relatively fixed, thus aiding in the knowledge transfer process from training to testing data. Moreover, this application achieves even more significant improvements on the more challenging Sketchy-NO, TUBberlin, and QuickDraw algorithms, further illustrating the superiority of this method.
[0122] Optionally, based on the above embodiments, this application embodiment may also provide an image retrieval method, the implementation process of which will be illustrated below with reference to the accompanying drawings. Figure 3 This is a flowchart illustrating an image retrieval method according to an embodiment of this application, as shown below. Figure 3 As shown, image retrieval methods may include:
[0123] S201: Obtain the input sketch image.
[0124] In the embodiments of this application, the sketch image needs to include a depicted object, such as any object depicting a person, an animal, or a cartoon character. The sketch image can be drawn directly by the user, uploaded by the user through an upload operation, or directly photographed by the user. The specific image type and the method of obtaining the sketch image can be flexibly adjusted according to the user's needs and are not limited to those given in the above embodiments.
[0125] S202: Based on the preset sketch retrieval model, process the sketch image to obtain the sketch coding features of the sketch image.
[0126] The image retrieval model is as described above. Figure 2 The sketch retrieval model is trained using the described training method.
[0127] S203: Based on the sketch coding features and the instance coding features of multiple instance images in the preset image library, determine at least one target instance image from the preset image library.
[0128] In embodiments of this application, the method for determining a target instance image may be, for example, as follows: based on the sketch coding features and the instance coding features of multiple instance images in a preset image library, determine the cosine similarity between the sketch coding features and the instance coding features of each instance image; and based on each cosine similarity, determine at least one target instance image from the preset image library.
[0129] Based on the above, the sketch retrieval model proposed in this application is constructed. Combined with the overall training objective outlined above, it is trained using training data. After training, a zero-shot sketch retrieval model is obtained, which can retrieve images from sketches with good results even on data categories not included in the training. Specifically, this application uses the output of the trained sketch retrieval model's backbone through a linear layer H... s Obtain the features f of all sketches participating in the test. S and features f of all images to be retrieved p The retrieval is based on the sketch feature f S With the features f of the image to be retrieved p The cosine similarity between two sketches measures the degree of similarity; a higher cosine similarity value indicates a better match. Furthermore, the order of search results for a sketch is based on its feature f. S With all the features f of the image to be retrieved p The cosine similarity values are obtained by sorting them from largest to smallest.
[0130] To facilitate understanding of this application, the following complete embodiment will be used to explain and illustrate this application: This application first provides a training method for a sketch retrieval model, which includes: a block embedding module, a first prompting module, a second prompting module, and an image encoder. The method includes:
[0131] A pre-defined block embedding module is used to extract features from the sample sketch image and the corresponding sample instance image to obtain the visual features of the sample sketch and the visual features of the sample instance.
[0132] The first preset prompt module is used to process the prompt text corresponding to the sample sketch image to obtain the prompt text features of the sample sketch;
[0133] A preset second prompt module is used to process the prompt text corresponding to the sample instance image to obtain the prompt text features of the sample instance;
[0134] Using a preset CLIP image encoder, the sample image feature sequence and the sample instance feature sequence are encoded respectively to obtain sample sketch encoded features and sample instance encoded features. The sample sketch feature sequence includes: sample sketch visual features, sample sketch prompt text features and preset category features. The sample instance feature sequence includes: sample instance visual features, sample instance prompt text features and preset category features.
[0135] The target sketch retrieval model is obtained by training based on the sample sketch encoding features and sample instance encoding features.
[0136] Optionally, the sketch retrieval model further includes: a first cross-attention module, a second cross-attention module, and a first linear layer, trained based on the sample sketch encoding features and sample instance encoding features to obtain the target sketch retrieval model, including:
[0137] The sample sketch encoding features are processed using a preset first cross-attention module to obtain sample sketch attention features;
[0138] The sample instance encoding features are processed using a pre-defined second cross-attention module to obtain sample instance attention features;
[0139] A preset first linear layer is used to map the sample sketch attention features and sample instance attention features to obtain sample sketch mapping features and sample instance mapping features;
[0140] The target sketch retrieval model is obtained by training with sample sketch mapping features and sample instance mapping features.
[0141] Optionally, the sketch retrieval model further includes: a second linear layer, a first alignment module, and a second alignment. Before processing the sample sketch encoding features using a preset first cross-attention module to obtain the sample sketch attention features, the method further includes:
[0142] A pre-defined second linear layer is used to perform category mapping on the sample sketch encoding features and the sample instance encoding features;
[0143] A preset first alignment module is used to align the encoded features of the sample sketches after category mapping to obtain the sample sketch alignment features.
[0144] A preset second alignment module is used to align the encoded features of sample instances after category mapping to obtain sample instance aligned features.
[0145] The sample sketch encoding features are processed using a pre-defined first cross-attention module to obtain sample sketch attention features, including:
[0146] The sample sketch alignment features are processed using a preset first cross-attention module to obtain sample sketch attention features;
[0147] The sample instance encoding features are processed using a pre-defined second cross-attention module to obtain sample instance attention features, including:
[0148] The sample instance alignment features are processed using a pre-defined second cross-attention module to obtain sample instance attention features.
[0149] Optionally, the sketch retrieval model further includes: a third alignment module; the method further includes:
[0150] A preset third alignment module is used to align the sample sketch encoding features and the sample instance encoding features after category mapping to obtain fused alignment features.
[0151] The sample sketch alignment features are processed using a pre-defined first cross-attention module to obtain sample sketch attention features, including:
[0152] A preset first cross-attention module is used to process the sample sketch alignment features and fused alignment features to obtain the sample sketch attention features;
[0153] The sample instance alignment features are processed using a pre-defined second cross-attention module to obtain sample instance attention features, including:
[0154] A pre-defined second cross-attention module is used to process the sample instance alignment features and fusion alignment features to obtain sample instance attention features.
[0155] Optionally, before using a pre-defined block embedding module to extract features from the sample sketch image and the corresponding sample instance image to obtain the visual features of the sample sketch and the visual features of the sample instance, the method further includes:
[0156] Adjust the dimensions of both the sample sketch image and the corresponding sample instance image to the preset size;
[0157] Pixel normalization is performed on the resized sample sketch image and sample instance image.
[0158] Optionally, before adjusting the dimensions of both the sample sketch image and the corresponding sample instance image to a preset size, the method further includes:
[0159] Based on the pixel values in the sample sketch image, the blank areas in the sample sketch image are removed to obtain the processed sample sketch image.
[0160] Secondly, this application also provides an image retrieval method, the method comprising:
[0161] Obtain the input sketch image;
[0162] Based on the preset sketch retrieval model, the sketch image is processed to obtain the sketch encoding features of the sketch image; wherein, the image retrieval model is the sketch retrieval model trained by the training method of the sketch retrieval model in the above embodiment;
[0163] Based on the sketch coding features and the instance coding features of multiple instance images in the preset image library, at least one target instance image is determined from the preset image library.
[0164] The training apparatus for the zero-shot sketch retrieval model provided in this application will be explained below with reference to the accompanying drawings. This training apparatus for the zero-shot sketch retrieval model can perform the above-described... Figures 1-2 The training method for any zero-sample sketch retrieval model, its specific implementation, and its beneficial effects are described above and will not be repeated below.
[0165] Figure 4 This is a schematic diagram of the structure of a training device for a zero-shot sketch retrieval model provided in an embodiment of this application, as shown below. Figure 4 As shown, the device includes: a processing module 301, an acquisition module 302, a determination module 303, and a training module 304, wherein:
[0166] The processing module 301 is used to preprocess the sketch image and the image to be retrieved in the sample pair using the preprocessing module; wherein the sketch image includes the depicted object, and the image to be retrieved includes the instance object corresponding to the depicted object.
[0167] The acquisition module 302 is used to input the preprocessed sketch image and the image to be retrieved into the block embedding module to obtain the sketch visual features corresponding to the sketch image and the instance visual features corresponding to the image to be retrieved. The image encoder obtains the output of the first prompting module and the sketch visual features. The image encoder is an image encoder based on a pre-trained model of contrasting text-image pairs. The image encoder obtains the output of the second prompting module and the instance visual features. The image encoder outputs the sample sketch encoding features and sample instance encoding features to the cross-attention module of the first multi-head cross-attention mechanism and the cross-attention module of the second multi-head cross-attention mechanism to establish a visual correspondence between the sketch image and the image to be retrieved. The sample sketch encoding features and sample instance encoding features output by the image encoder are processed by the alignment module to obtain the aligned sample sketch encoding features and aligned sample instance encoding features.
[0168] The determination module 303 is used to determine the triplet loss value based on the visual correspondence between the sketch image and the image to be retrieved; and to determine the cross-entropy loss value based on the aligned sample sketch encoding features and the aligned sample instance encoding features.
[0169] Training module 304 is used to train the zero-sample sketch retrieval model based on triplet loss and cross-entropy loss to obtain the trained zero-sample sketch retrieval model.
[0170] Optionally, the processing module 301 is specifically used to adjust the size of the sketch image and the image to be retrieved to a preset size, and convert the adjusted sketch image into a tensor; and normalize the values in the three color channels of the sketch image after conversion into a tensor according to a preset average value (0.5, 0.5, 0.5) and a preset standard deviation (0.5, 0.5, 0.5).
[0171] Optionally, the processing module 301 is specifically used to remove the blank areas around the depicted object based on the differences in its pixel values.
[0172] Optionally, the processing module 301 is specifically configured to: 1) perform data conversion on the preprocessed sketch image by the first block embedding module to obtain a first sketch visual feature; 2) perform data conversion on the preprocessed sketch image by the second block embedding module to obtain a second sketch visual feature; wherein the sketch visual feature includes: a first sketch visual feature and a second sketch visual feature; 3) perform data conversion on the preprocessed image to be retrieved by the first block embedding module to obtain a first instance visual feature; 4) perform data conversion on the preprocessed image to be retrieved by the second block embedding module to obtain a second instance visual feature; wherein the instance visual feature includes: a first instance visual feature and a second instance visual feature.
[0173] Optionally, the first prompt module is The second prompt module is N in the first prompt module and the second prompt module e All are the number of cue vectors, and d is the dimension of the vector. The dimension of the vector is consistent with the visual features extracted by the block embedding module.
[0174] Optionally, the image encoder also includes a first linear mapping layer, which maps category features that have overall information on all features of the sample sketch or the image to be retrieved, in order to classify based on the category features, the aligned sample sketch encoding features, and the aligned sample instance encoding features.
[0175] Optionally, the alignment module includes a first alignment module, a second alignment module, and a third alignment module, wherein the first alignment module is used to align the sketch image, the second alignment module is used to align the image to be retrieved, and the third alignment module is used to align the sketch image and the image to be retrieved.
[0176] Optionally, the training module 304 is specifically used to train the zero-sample sketch retrieval model based on the triplet loss value, the cross-entropy loss value pair, and the preset scaling factor, so as to obtain the trained zero-sample sketch retrieval model.
[0177] The above-described device is used to execute the method provided in the foregoing embodiments, and its implementation principle and technical effect are similar, so they will not be described again here.
[0178] The image retrieval device provided in this application will be explained and described below with reference to the accompanying drawings. This image retrieval device can perform the above-described... Figure 3 The specific implementation and beneficial effects of image retrieval methods are described above and will not be repeated below.
[0179] Figure 5 This is a schematic diagram of the structure of an image retrieval device provided in an embodiment of this application, as shown below. Figure 5 As shown, the device includes: an acquisition module 401 and a determination module 402, wherein:
[0180] The acquisition module 401 is used to acquire the input sketch image;
[0181] The determining module 402 is used to process the sketch image according to the preset sketch retrieval model to obtain the sketch encoding features of the sketch image; wherein, the image retrieval model is a sketch retrieval model trained by the training method of the sketch retrieval model of any of the first aspects mentioned above; based on the sketch encoding features and the instance encoding features of multiple instance images in the preset image library, at least one target instance image is determined from the preset image library.
[0182] Optionally, the determining module 402 is specifically used to determine the cosine similarity between the sketch coding features and the instance coding features of each instance image based on the sketch coding features and the instance coding features of multiple instance images in the preset image library; and to determine at least one target instance image from the preset image library based on each cosine similarity.
[0183] These modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more microprocessors, or one or more Field Programmable Gate Arrays (FPGAs). Alternatively, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a system-on-a-chip (SOC).
[0184] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device can be integrated into a terminal device or a chip of a terminal device.
[0185] like Figure 6 As shown, the electronic device includes: a processor 501, a bus 502, and a storage medium 503.
[0186] Processor 501 is used to store programs, and processor 501 calls the programs stored in storage medium 503 to execute the above-mentioned programs. Figures 1-3 Corresponding method implementation examples.
[0187] Optionally, this application also provides a program product, such as a storage medium storing a computer program, including a program that executes the embodiments corresponding to the above-described methods when run by a processor.
[0188] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0189] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0190] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in a combination of hardware and software functional units.
[0191] The integrated units implemented as software functional units described above can be stored in a computer-readable storage medium. These software functional units, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A training method for a zero-shot sketch retrieval model, characterized in that, The zero-shot sketch retrieval model includes: a preprocessing module, a block embedding module, a first cue module, a second cue module, an image encoder, an alignment module, a cross-attention module of a first multi-head cross-attention mechanism, and a cross-attention module of a second multi-head cross-attention mechanism. The image encoder is a pre-trained image encoder based on a contrastive text-image pair model. The block embedding module includes: a first block embedding module and a second block embedding module. The second block embedding module is a learnable image block embedding module composed of five convolutional layers. The method includes: The preprocessing module is used to preprocess the sketch image and the image to be retrieved within the sample pair, respectively; wherein, the sketch image includes a depicted object, and the image to be retrieved includes the instance object corresponding to the depicted object; The first block embedding module performs data conversion on the preprocessed sketch image to obtain the first sketch visual features; The second block embedding module performs data conversion on the preprocessed sketch image to obtain a second sketch visual feature; wherein, the sketch visual feature includes: the first sketch visual feature and the second sketch visual feature; The first block embedding module performs data transformation on the preprocessed image to be retrieved to obtain the first instance visual features; The second block embedding module performs data transformation on the preprocessed image to be retrieved to obtain a second instance visual feature; wherein, the instance visual feature includes: the first instance visual feature and the second instance visual feature; The image encoder acquires the output of the first prompting module and the visual features of the sketch; The image encoder acquires the output of the second prompting module and the visual features of the instance; The image encoder outputs sample sketch encoding features and sample instance encoding features to the cross-attention module of the first multi-head cross-attention mechanism and the cross-attention module of the second multi-head cross-attention mechanism, respectively, to establish a visual correspondence between the sketch image and the image to be retrieved; The sample sketch encoding features and sample instance encodings output by the image encoder are processed by the alignment module to obtain aligned sample sketch encoding features and aligned sample instance encoding features. The alignment module includes a first alignment module, a second alignment module, and a third alignment module. The first alignment module is used to align the sketch image, the second alignment module is used to align the image to be retrieved, and the third alignment module is used to align the sketch image and the image to be retrieved. Based on the visual correspondence between the sketch image and the image to be retrieved, the triplet loss value is determined; Based on the aligned sample sketch encoding features and the aligned sample instance encoding features, the cross-entropy loss value is determined; The zero-shot sketch retrieval model is trained based on the triplet loss value and the cross-entropy loss value to obtain the trained zero-shot sketch retrieval model.
2. The method according to claim 1, characterized in that, The preprocessing module is used to preprocess the sketch image and the image to be retrieved within the sample pair, including: The dimensions of the sketch image and the image to be retrieved are adjusted to preset sizes, and the resized sketch image is converted into a tensor. The values in the three color channels of the sketch image after conversion to tensors are normalized according to the preset average (0.5, 0.5, 0.5) and preset standard deviation (0.5, 0.5, 0.5).
3. The method as described in claim 2, characterized in that, Before adjusting the sizes of the sketch image and the image to be retrieved to preset sizes, and converting the resized sketch image into a tensor, the method further includes: The blank areas around the depicted object are removed based on the differences in their pixel values.
4. The method according to claim 1, characterized in that, The first prompt module is ; The second prompt module is The first prompt module and the second prompt module d represents the dimension of the vector, and the dimension of the vector is consistent with the visual features extracted by the block embedding module.
5. The method according to claim 1, characterized in that, The image encoder further includes a first linear mapping layer, which maps category features that have the overall information of all features of the sample sketch or the image to be retrieved, so as to classify according to the category features, the aligned sample sketch encoding features and the aligned sample instance encoding features.
6. The method according to claim 1, characterized in that, The step of training the zero-shot sketch retrieval model based on the triplet loss value and the cross-entropy loss value to obtain the trained zero-shot sketch retrieval model includes: The zero-shot sketch retrieval model is trained based on the triplet loss value, the cross-entropy loss value pair, and the preset scaling factor to obtain the trained zero-shot sketch retrieval model.
7. An image retrieval method, characterized in that, The method includes: Obtain the input sketch image; According to a preset sketch retrieval model, the sketch image is processed to obtain the sketch encoding features of the sketch image; wherein, the image retrieval model is a sketch retrieval model trained by the training method of the sketch retrieval model of any one of claims 1-6 above; Based on the sketch encoding features and the instance encoding features of multiple instance images in the preset image library, at least one target instance image is determined from the preset image library.
8. The method according to claim 7, characterized in that, The step of determining at least one target instance image from the preset image library based on the sketch encoding features and the instance encoding features of multiple instance images in the preset image library includes: Based on the sketch coding features and the instance coding features of multiple instance images in the preset image library, the cosine similarity between the sketch coding features and the instance coding features of each instance image is determined. Based on the cosine similarity values, at least one target instance image is determined from the preset image library.
