A hash retrieval method based on adversarial training and related devices

By generating a central code as supervisory information and employing a minimax strategy to conduct adversarial training on the deep hashing model, the problem of insufficient robustness of the deep hashing method under adversarial sample attacks is solved, and the security of hash retrieval is improved.

CN116992090BActive Publication Date: 2025-12-05HARBIN INSTITUTE OF TECHNOLOGY (SHENZHEN) (INSTITUTE OF SCIENCE AND TECHNOLOGY INNOVATION HARBIN INSTITUTE OF TECHNOLOGY SHENZHEN)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310789952.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2025-12-05
Estimated Expiration
2043-06-28

AI Technical Summary

Technical Problem

Existing deep hashing methods lack globally discriminative semantic representation when facing adversarial attacks, resulting in insufficient robustness and affecting the security of hash retrieval.

Method used

By generating a central code as supervisory information, a minimax strategy is used to conduct adversarial training on the deep hash model, thereby enhancing the model's adversarial robustness.

Benefits of technology

This improves the robustness of deep hashing models against adversarial attacks and enhances the security of hash retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116992090B_ABST
    Figure CN116992090B_ABST
Patent Text Reader

Abstract

The application discloses a hash retrieval method based on adversarial training and a related device. The method comprises generating a pivot code based on all positive samples and all negative samples of training samples, performing adversarial training on a deep hash model by using the pivot code as supervision information and a minimax strategy, and then performing hash retrieval on a to-be-queried sample based on the deep hash model subjected to the adversarial training, so as to obtain a preset number of data samples corresponding to the to-be-queried sample. The application uses the pivot code with global semantic representation as supervision information. The similarity to all positive samples and the dissimilarity to negative samples carried by the pivot code can effectively guide the adversarial learning of the deep hash model. Meanwhile, the deep hash model is trained by using the minimax strategy, which can further enhance the adversarial robustness of the deep hash model, thereby improving the security of hash retrieval based on the deep hash model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information science and technology, and in particular to a hash retrieval method and related apparatus based on adversarial training. Background Technology

[0002] With the continuous growth of large-scale multimedia data, Approximate Nearest Neighbor (ANN) retrieval has attracted much attention due to its excellent efficiency and effectiveness. Among all ANN retrieval methods, hashing offers the significant advantage of mapping high-dimensional data to compact binary code, and has low cost in terms of both time and space complexity, making it a focus of attention, especially deep hashing methods based on deep neural networks. However, deep hashing methods are vulnerable to adversarial attacks, posing serious security risks.

[0003] Therefore, some studies have shown that adversarial training of deep hashing models can improve their ability to defend against adversarial examples. Adversarial training involves creating adversarial examples by adding imperceptible perturbations to the original samples, which can significantly confuse the deep hashing model and lead to incorrect results. However, existing deep hashing adversarial training methods generally lack globally discriminative semantic representations, making it impossible for deep hashing models to obtain effective supervision information. This affects the adversarial robustness of the trained deep hashing models, thus leaving deep hashing methods with security vulnerabilities.

[0004] Therefore, existing technologies still need to be improved and enhanced. Summary of the Invention

[0005] The technical problem to be solved by this application is to provide a hash retrieval method and related apparatus based on adversarial training, addressing the shortcomings of existing technologies.

[0006] To address the aforementioned technical problems, the first aspect of this application provides a hash retrieval method based on adversarial training, applied to an electronic device, the method comprising:

[0007] The query hash code of the sample to be queried is determined by a trained deep hash model, and the similarity between the query hash code and the sample hash code of each data sample in the retrieved dataset is calculated.

[0008] Based on all the calculated similarities, a preset number of data samples corresponding to the sample to be queried are selected from the retrieval dataset;

[0009] The training process of the deep hashing model specifically includes:

[0010] For each training sample in the preset training sample set, obtain the first hash code of each positive sample corresponding to the training sample and the second hash code of each negative sample corresponding to the training sample, wherein both positive and negative samples are included in the preset training sample set, positive samples and training samples share at least one category, and negative samples and training samples do not share a category.

[0011] The central code of the training sample is determined based on all the first hash codes and all the second hash codes corresponding to the training sample.

[0012] Based on the training samples and their central codes, the initial hash model corresponding to the deep hash model is subjected to adversarial training using a minimax strategy to obtain a trained deep hash model.

[0013] The hash retrieval method based on adversarial training, wherein determining the central code of the training sample based on all first hash codes and all second hash codes corresponding to the training sample specifically includes:

[0014] The first sum is obtained by weighting all the first hash codes corresponding to the training samples, and the second sum is obtained by weighting all the second hash codes corresponding to the training samples.

[0015] Calculate the difference between the first sum and the second sum, and determine the central code of the training sample based on the difference and the sign function.

[0016] The hash retrieval method based on adversarial training, wherein the expression for the central code is:

[0017]

[0018] in, Indicates the central code Indicates the first Positive samples hash code, Indicates the first negative samples hash code, Indicates the number of positive samples. Indicates the number of negative samples. and All of these represent weighting coefficients.

[0019] The hash retrieval method based on adversarial training, wherein the weighting coefficients and the weighting coefficients The calculation formulas are as follows:

[0020] ,

[0021] in, Indicates the number of positive samples. Indicates the first Positive samples Corresponding similarity; Indicates the number of negative samples. Indicates the first negative samples The corresponding similarity.

[0022] The aforementioned hash retrieval method based on adversarial training, wherein the step of performing adversarial training on the initial hash model corresponding to the deep hash model using a minimax strategy based on the training samples and their central codes to obtain the trained deep hash model specifically includes:

[0023] The model parameters of the initial hash model corresponding to the deep hash model are fixed, and the training samples are input into the initial hash model to generate adversarial samples by maximizing the loss function of the initial hash model with a preset attack strategy.

[0024] The adversarial sample is input into the initial hash model, and the model parameters of the initial hash model are optimized with the goal of minimizing the loss function to obtain a trained deep hash model.

[0025] The hash retrieval method based on adversarial training, wherein the expression for the loss function is:

[0026]

[0027]

[0028]

[0029] in, Indicates the counter-loss term. Represents the quantified loss term. Represents the hash loss term. Indicates training samples The central code, This represents the model parameters of the initial hash model. Indicates the length of the hash code. Indicated by The initial hash network for the parameters. express Activation function Represents a symbolic function. express Norm.

[0030] The hash retrieval method based on adversarial training, wherein the preset attack strategy is:

[0031] ;

[0032] in, Indicates training samples, This represents the adversarial example corresponding to the training sample. Indicates will Project to of In the ball, Indicates the step size. Represents a symbolic function.

[0033] A second aspect of this application provides a hash retrieval device based on adversarial training, using electronic devices, the device comprising:

[0034] The calculation module is used to determine the query hash code of the sample to be queried through a trained deep hash model, and to calculate the similarity between the query hash code and the sample hash code of each data sample in the retrieved dataset.

[0035] The selection module is used to select a preset number of data samples corresponding to the query sample from the retrieval dataset based on all calculated similarities.

[0036] The training process of the deep hashing model specifically includes:

[0037] For each training sample in the preset training sample set, obtain the first hash code of each positive sample corresponding to the training sample and the second hash code of each negative sample corresponding to the training sample, wherein both positive and negative samples are included in the preset training sample set, and positive samples share at least one category with training samples, while negative samples do not share a category with training samples.

[0038] The central code of the training sample is determined based on all the first hash codes and all the second hash codes corresponding to the training sample.

[0039] Based on the training samples and their central codes, the initial hash model corresponding to the deep hash model is subjected to adversarial training using a minimax strategy to obtain a trained deep hash model.

[0040] A third aspect of this application provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the steps in the hash retrieval method based on adversarial training as described above.

[0041] A fourth aspect of this application provides a terminal device, which includes: a processor, a memory, and a communication bus; the memory stores a computer-readable program that can be executed by the processor;

[0042] The communication bus enables communication between the processor and the memory;

[0043] When the processor executes the computer-readable program, it implements the steps in the hash retrieval method based on adversarial training as described above.

[0044] Beneficial Effects: Compared with existing technologies, this application provides a hash retrieval method and related apparatus based on adversarial training. The method includes generating a central key based on all positive and negative samples of the training samples, using the central key as supervision information to perform adversarial training on a deep hash model using a minimax strategy, and then performing hash retrieval on the query sample based on the adversarially trained deep hash model to obtain a preset number of data samples corresponding to the query sample. This application uses a central key with global semantic representation as supervision information. By using the similarity of the central key to all positive samples and the dissimilarity of negative samples, the adversarial learning of the deep hash model can be effectively guided. At the same time, using the minimax strategy to train the deep hash model can further enhance the adversarial robustness of the deep hash model, thereby improving the security of hash retrieval based on the deep hash model. Attached Figure Description

[0045] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0046] Figure 1 A comparison graph of classification and hashing in adversarial learning provided for this application.

[0047] Figure 2 A flowchart of the hash retrieval method based on adversarial training provided in this application.

[0048] Figure 3 This is a flowchart illustrating the training process of a deep hash model.

[0049] Figure 4 The schematic diagram of the hash retrieval device based on adversarial training provided in this application.

[0050] Figure 5 A schematic diagram of the terminal device provided in this application. Detailed Implementation

[0051] This application provides a hash retrieval method and related apparatus based on adversarial training. To make the purpose, technical solution, and effects of this application clearer and more explicit, the following detailed description is provided with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only for explaining this application and are not intended to limit this application.

[0052] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this application means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.

[0053] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.

[0054] It should be understood that the sequence number and size of each step in this embodiment do not imply the order of execution. The execution order of each process is determined by its function and internal logic, and should not constitute any limitation on the implementation process of this application embodiment.

[0055] Research has shown that with the continuous growth of large-scale multimedia data, Approximate Nearest Neighbor (ANN) retrieval has attracted much attention due to its excellent efficiency and effectiveness. Among all ANN retrieval methods, hashing offers the significant advantage of mapping high-dimensional data to compact binary code, and has low costs in terms of both time and space complexity, making it a focus of attention, especially deep hashing methods based on deep neural networks. However, deep hashing methods are vulnerable to adversarial attacks, posing serious security risks.

[0056] Therefore, some studies have shown that the ability of deep hashing methods to defend against adversarial examples can be improved by adversarial training. Adversarial training involves creating adversarial examples by adding imperceptible perturbations to the original samples, which greatly confuses the deep hashing model and leads to incorrect results. However, as... Figure 1 As shown, existing adversarial training methods are generally designed for adversarial attacks and defenses in classification tasks. In the output space of classification, label-guided adversarial attacks only require the adversarial sample to cross the decision boundary. However, adversarial attacks on deep hashing aim to integrate adversarial samples into the clustering of the embedding space. This results in a lack of explicit supervision signals during the adversarial process. In other words, deep hashing lacks globally discriminative semantic representation, making it impossible for deep hashing models to obtain effective supervision information during adversarial training. This affects the adversarial robustness of the trained deep hashing model, thus leaving deep hashing methods with security issues.

[0057] To address the aforementioned issues, in this embodiment, a central code is generated based on all positive and negative samples from the training samples. Using the central code as supervisory information, a minimax strategy is employed to adversarially train the deep hash model. Then, based on the adversarially trained deep hash model, a hash retrieval is performed on the query sample to obtain a predetermined number of data samples corresponding to the query sample. This application uses a central code with global semantic representation as supervisory information. By leveraging the similarity between the central code and all positive samples and the dissimilarity of negative samples, the adversarial learning of the deep hash model can be effectively guided. Simultaneously, training the deep hash model using the minimax strategy further enhances its adversarial robustness, thereby improving the security of hash retrieval based on the deep hash model.

[0058] The application content will be further explained below with reference to the accompanying drawings and the description of the embodiments.

[0059] This embodiment provides a hash retrieval method based on adversarial training that can be applied to electronic devices. The electronic device deploys a deep hashing model, or can invoke a deep hashing model. The electronic device acquires a sample to be queried and controls the deep hashing model to determine the query hash code of the sample. Then, it selects a preset number of data samples corresponding to the sample to be queried based on the similarity between the query hash code and the sample hash codes of each sample in the retrieval dataset. The electronic device can be a device with data processing capabilities, such as a PC or laptop. This application embodiment does not limit the specific type and structure of the electronic device.

[0060] Furthermore, the electronic device can directly deploy a trained deep hashing model, or it can first perform the deep hashing model training process and then deploy the trained deep hashing model. It is understood that both the deep hashing model training process and the hash retrieval process can be completed by the electronic device itself. Alternatively, the electronic device can act as a first electronic device to perform the hash retrieval process, while a second electronic device performs the deep hashing model training process. The second electronic device can communicate with the first electronic device, and after training the deep hashing model, it transmits the deep hashing model to the first electronic device so that the first electronic device can deploy the trained deep hashing model. Of course, in practical applications, the second electronic device may not communicate with the first electronic device, but instead deploy the deep hashing model trained by the second electronic device to the first electronic device via an external storage device (e.g., a USB flash drive), or via a network (e.g., the cloud).

[0061] like Figure 2 As shown, the hash retrieval method based on adversarial training provided in this embodiment may specifically include:

[0062] S10. Determine the query hash code of the sample to be queried using a trained deep hash model, and calculate the similarity between the query hash code and the sample hash codes of each data sample in the retrieved dataset.

[0063] Specifically, the deep hashing model is a trained deep learning model used to determine the query hash code of the sample to be queried. The sample to be queried can be obtained in response to a user operation. That is, the electronic device responds to the retrieval operation of the sample to be queried and retrieves the sample based on that operation. The retrieval sample set is a pre-existing set of data samples, including several data samples. Each data sample corresponds to a sample hash code, which is obtained using the deep hashing model. After obtaining the query hash code and the hash codes of each sample, the similarity between the query hash code and the hash codes of each sample is calculated in Hamming space.

[0064] S20. Based on all the calculated similarities, select a preset number of data samples corresponding to the sample to be queried from the retrieval dataset.

[0065] Specifically, after obtaining the similarity between the query sample and each data sample, the similarity between the query sample and each data sample is sorted in descending order, and a preset number of data samples are selected as the preset number of data samples corresponding to the query sample. The preset number is pre-set, for example, 10, 20, etc.

[0066] The deep hashing model in this embodiment is adversarially trained. During the adversarial training process, a central code generated based on all positive and negative samples from the training samples is used as supervision information. A minimax strategy is employed for adversarial training. By using a central code with global semantic representation as supervision information, the similarity between the central code and all positive samples and the dissimilarity between the central code and negative samples can effectively guide the adversarial learning of the deep hashing model. At the same time, training the deep hashing model with a minimax strategy can further enhance its adversarial robustness, thereby improving the security of hash retrieval based on the deep hashing model.

[0067] To further illustrate the deep hashing model in this embodiment, the model structure and training process of the deep hashing model will be described in detail below.

[0068] like Figure 3 As shown, a deep hashing model can include a feature extractor, a fully connected layer, and an activation function layer. The feature extractor is connected to the fully connected layer, and the fully connected layer is connected to the activation function layer. Of course, in practical applications, deep hashing models can also employ other network structures, such as convolutional neural networks. Furthermore, since a central key as supervisory information needs to be generated during adversarial training of the deep hashing model, this central key can be generated using a central key generator. That is, before training the deep hashing model, a central key can be generated for each training sample using a central key generator. Alternatively, the central key generator can be used in conjunction with the deep hashing model. For training samples used to train the deep hashing model, before inputting the training samples into the initial hashing model corresponding to the deep hashing model, a central key is generated for the training samples using a central key generator. Then, the training samples and their corresponding central key are used to perform adversarial training on the initial hashing model corresponding to the deep hashing model using a minimax strategy to obtain the trained deep hashing model.

[0069] Based on this, in one implementation, such as Figure 3 As shown, the training process of the deep hashing model specifically includes:

[0070] H10. For each training sample in the preset training sample set, obtain the first hash code of each positive sample corresponding to the training sample and the second hash code of each negative sample corresponding to the training sample.

[0071] H20. Determine the central code of the training sample based on all first hash codes and all second hash codes corresponding to the training sample;

[0072] H30. Based on the training samples and their central codes, the initial hash model corresponding to the deep hash model is subjected to adversarial training using a minimax strategy to obtain a trained deep hash model.

[0073] Specifically, in step H10, a preset training sample set is established. include There are C training samples labeled with C categories, where Indicates the first training samples, express The corresponding label vector, express Belongs to the There are several categories. It can belong to one category or multiple categories, that is It can support multi-label data. Furthermore, each training sample in the preset training sample set carries a hash code, where the hash code is a set of binary codes. The hash code set corresponding to the preset training sample set can be represented as follows: ,in, Indicates the number of training samples. The hash code length is represented by the hash code. The hash code maintains the semantic similarity between samples in the Hamming space so that the deep hash model trained on the preset training sample set can determine the hash code of the input item, and then realize efficient approximate nearest neighbor search based on the hash code of the input item.

[0074] Both positive and negative samples are included in a predefined training sample set. Positive samples and training samples share at least one class; that is, the class label carried by a positive sample contains at least one target class label, which is included in the class label carried by the training sample. In other words, the positive sample corresponds to... and the training samples There exists at least one vector element with a value of 1 that occupies the same position in both sample label vectors. Conversely, negative samples do not share categories with training samples; each category label carried by a negative sample is not included in the category labels carried by the training sample. In other words, the negative sample corresponds to... and the training samples There are no vector elements in the array whose element value is 1 and whose element position is the same. In a typical implementation, positive and negative samples can be determined based on similarity, where, for any vector with a class... samples The corresponding positive samples share at least one class with them, that is, And its corresponding negative samples do not share the same class, i.e. ,in, Indicates sample and samples The similarity.

[0075] Furthermore, in step H20, the central code preserves the similarity between the training sample and all positive samples, as well as the dissimilarity with all negative samples. Here, the central code is a hash code of length in Hamming space. The central code is a binary code that possesses global semantic discriminative power, meaning it is close to all positive samples and far from all negative samples in the Hamming space. Understandably, the central code is optimized in the global semantic space, maintaining similarity to all positive samples and independence from all negative samples. It's worth noting that "global" here means that the central code considers all positive and negative samples relevant to the query in the global semantic space.

[0076] In one implementation, determining the central code of the training sample based on all first hash codes and all second hash codes corresponding to the training sample specifically includes:

[0077] H21. Weight all the first hash codes corresponding to the training samples to obtain a first sum value, and weight all the second hash codes corresponding to the training samples to obtain a second sum value;

[0078] H22. Calculate the difference between the first sum and the second sum, and determine the central code of the training sample based on the difference and the sign function.

[0079] Specifically, the first sum is obtained by weighting the first hash codes of all positive samples, and the second sum is obtained by weighting the second hash codes of all negative samples. The weighting coefficients for all positive samples can be pre-set, determined based on the distance between the positive samples and the training samples in Hamming space, or determined based on the similarity between the positive samples and the training samples. Similarly, the weighting coefficients for negative samples can also be determined using the above method, with the method for determining the weighting coefficients for positive samples being the same as that for negative samples. After obtaining the first and second sums, the first sum can be subtracted from the second sum to obtain the difference between the first and second sums. Then, the difference is calculated using a sign function to obtain the central code of the training samples. Furthermore, it is worth noting that the first sum, the second sum, and the difference are all one-dimensional vectors with a length equal to the hash code length.

[0080] In one implementation, the expression for the central code is:

[0081]

[0082]

[0083]

[0084]

[0085] in, Indicates the central code Indicates the first Positive samples hash code, Indicates the first negative samples hash code, Indicates the number of positive samples. Indicates the number of negative samples. and All represent weighting coefficients. Indicates the number of positive samples. Indicates the first Positive samples Corresponding similarity; Indicates the number of negative samples. Indicates the first negative samples The corresponding similarity.

[0086] This embodiment adopts A determined central code can preserve the similarity between the training sample and all positive samples, as well as the dissimilarity with all negative samples. This is because, in order to preserve the similarity between the training sample and all positive samples, and the dissimilarity with all negative samples, the difference in Hamming space between the central code and the sum of the Hamming distances to all positive samples and the sum of the Hamming distances to all negative samples must be minimized. That is, for a given training sample... The central code of the training samples can be represented as ,in, It is the Hamming distance metric function. It is the i-th positive sample hash code, It is the j-th negative sample hash code, and These represent the number of positive and negative samples, respectively. and These represent the weighting coefficients for positive and negative samples, respectively.

[0087] Based on this, the central code for The optimal solution, where the objective function is... , And the central code for When the optimal solution is found, the central code It can be written directly as:

[0088]

[0089] This is because, according to and We can obtain:

[0090] (1)

[0091] in, It is a constant.

[0092] Due to the properties of the absolute value function, we can obtain:

[0093]

[0094] Similar to equation (1), Represented as:

[0095]

[0096] Therefore, it can be deduced that:

[0097]

[0098] Right now Therefore, given training samples The central code It can be done calculate.

[0099] Furthermore, in step H30, after obtaining the central code, the central code can be used as a full semantic representative to perform adversarial training on the deep hash model. Accordingly, the step of using a minimax strategy to perform adversarial training on the initial hash model corresponding to the deep hash model based on the training samples and their central code to obtain the trained deep hash model specifically includes:

[0100] H31. Fix the model parameters of the initial hash model corresponding to the deep hash model, and input the training samples into the initial hash model to generate adversarial samples by maximizing the loss function of the initial hash model with a preset attack strategy;

[0101] H32. Input the adversarial sample into the initial hash model and optimize the model parameters of the initial hash model with the goal of minimizing the loss function to obtain a trained deep hash model.

[0102] Specifically, the optimal adversarial example is found by maximizing the loss function of the initial hash model; that is, maximizing the loss function of the initial hash model is the adversarial attack for finding the optimal adversarial example. Minimizing the loss function is used to optimize network parameters to resist the influence of adversarial perturbations in the adversarial example. In this embodiment, the central code is used as the global semantic representative, and adversarial and defensive actions are carried out by maximizing and minimizing the loss function, thereby improving the adversarial robustness of the trained deep hash model.

[0103] Furthermore, to illustrate how using the central code as supervisory information can improve the robustness of the deep hash model, this embodiment demonstrates how to implement adversarial attacks on both non-targeted and targeted attacks.

[0104] For non-targeted attacks, the goal is to maximize the hash code distance between the adversarial sample and its semantically related positive samples, while minimizing the distance to its unrelated negative samples. In other words, the objective of the adversarial attack can be transformed into maximizing the Hamming distance between the hash code and the central code of the adversarial sample. Therefore, for a given training sample... Its corresponding adversarial examples exist Under the constraint of norm, the following objective can be optimized to solve the problem:

[0105] (2)

[0106] To ensure the imperceptibility of countering disturbances, the following approach is adopted. ( To constrain the pixel difference between adversarial examples and training samples to remain within a certain limit .because Formula (2) is equivalent to:

[0107]

[0108] in, This represents the tanh activation function. It is control Approaching Hyperparameters.

[0109] For targeted attacks, the only difference between non-targeted and targeted attacks is the objective function, which is different for a given training sample. and target category labels First through Get The central code Then the target function of the attack can be defined as:

[0110]

[0111] With adversarial examples By reducing the distance between the hash code and the central code of the target category label, the adversarial example gradually approaches the target category label semantically, while maintaining visual imperceptibility. Therefore, it is possible to... Input is fed into a deep hash-based retrieval system to retrieve content semantically related to the target category label.

[0112] Thus far, optimization functions for non-targeted attacks and targeted attacks have been presented. Based on the optimization functions corresponding to non-targeted attacks and targeted attacks, adversarial examples corresponding to the training samples can be generated using a preset attack strategy. The preset attack strategy can be...

[0113] ;

[0114] in, Indicates training samples, This represents the adversarial example corresponding to the training sample. Indicates will Project to of In the ball, Indicates the step size. Symbolic function

[0115] Of course, it is worth noting that in practical applications, other strategies can also be used for the preset attack strategy, such as the Fast Gradient Sign Method (FGSM) and the Basic Iterative Method (BIM).

[0116] Furthermore, the loss function uses a central code to guide adversarial training, and the expression of the loss function is as follows:

[0117]

[0118]

[0119]

[0120] in, Indicates the counter-loss term. Represents the quantified loss term. Represents the hash loss term (e.g., The objective function is DPH, DPSH, or HashNet, etc. Indicates training samples The central code, This represents the model parameters of the initial hash model. Indicates the length of the hash code. Indicated by The initial hash network for the parameters. express Activation function Represents a symbolic function. express Norm.

[0121] Based on the above, this embodiment utilizes the central code. To guide adversarial training, the problem of adversarial attacks on deep hashing is transformed into maximizing the Hamming distance between the hash codes of adversarial examples and the central code. This effectively generates optimal adversarial perturbations. Simultaneously, adversarial training on deep hashing is represented as a minimax optimization paradigm based on the central code. This study employs an adversarial training strategy based on the minimax optimization paradigm. The inner maximization of the adversarial sample seeks a model that maximizes the Hamming distance between the adversarial sample's hash code and the constructed central code. The outer minimization, on the other hand, attempts to optimize the model parameters to make the adversarial sample's hash code closer to the central code, thus mitigating the impact of adversarial perturbations. Therefore, using the central code as supervisory information and employing the minimax optimization paradigm for adversarial training can enhance the adversarial robustness of deep hashing-based retrieval models.

[0122] In summary, this embodiment provides a hash retrieval method based on adversarial training. The method includes generating a central key based on all positive and negative samples from the training samples; using the central key as supervisory information, employing a minimax strategy to adversarially train a deep hash model; and then performing hash retrieval on the query sample based on the adversarially trained deep hash model to obtain a predetermined number of data samples corresponding to the query sample. This application uses a central key with global semantic representation as supervisory information. By leveraging the similarity between the central key and all positive samples and the dissimilarity of negative samples, the adversarial learning of the deep hash model can be effectively guided. Simultaneously, training the deep hash model using a minimax strategy further enhances its adversarial robustness, thereby improving the security of hash retrieval based on the deep hash model.

[0123] Based on the aforementioned hash retrieval method based on adversarial training, this embodiment provides a hash retrieval device based on adversarial training, utilizing electronic devices such as... Figure 4 As shown, the device includes:

[0124] The calculation module 100 is used to determine the query hash code of the sample to be queried through a trained deep hash model, and to calculate the similarity between the query hash code and the sample hash code of each data sample in the retrieval dataset.

[0125] The selection module 200 is used to select a preset number of data samples corresponding to the query sample from the retrieval dataset based on all calculated similarities.

[0126] The training process of the deep hashing model specifically includes:

[0127] For each training sample in the preset training sample set, obtain the first hash code of each positive sample corresponding to the training sample and the second hash code of each negative sample corresponding to the training sample, wherein both positive and negative samples are included in the preset training sample set, and positive samples share at least one category with training samples, while negative samples do not share a category with training samples.

[0128] The central code of the training sample is determined based on all the first hash codes and all the second hash codes corresponding to the training sample.

[0129] Based on the training samples and their central codes, the initial hash model corresponding to the deep hash model is subjected to adversarial training using a minimax strategy to obtain a trained deep hash model.

[0130] Based on the above-described hash retrieval method based on adversarial training, this embodiment provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the steps in the hash retrieval method based on adversarial training as described in the above embodiment.

[0131] Based on the aforementioned hash retrieval method based on adversarial training, this application also provides a terminal device, such as... Figure 5 As shown, it includes at least one processor 20; a display screen 21; and a memory 22, and may also include a communications interface 23 and a bus 24. The processor 20, display screen 21, memory 22, and communications interface 23 can communicate with each other via the bus 24. The display screen 21 is configured to display a preset user guide interface in the initial setup mode. The communications interface 23 can transmit information. The processor 20 can invoke logical instructions in the memory 22 to execute the methods described in the above embodiments.

[0132] Furthermore, the logical instructions in the aforementioned memory 22 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.

[0133] The memory 22, as a computer-readable storage medium, can be configured to store software programs, computer-executable programs, such as program instructions or modules corresponding to the methods in the embodiments of this disclosure. The processor 20 executes functional applications and data processing by running the software programs, instructions, or modules stored in the memory 22, thereby implementing the methods in the above embodiments.

[0134] The memory 22 may include a program storage area and a data storage area. The program storage area may store the operating system and application programs required for at least one function; the data storage area may store data created based on the use of the terminal device. Furthermore, the memory 22 may include high-speed random access memory (RAM) and non-volatile memory. Examples include 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, as well as transient storage media.

[0135] Furthermore, the specific process of loading and executing multiple instruction processors in the aforementioned storage medium and terminal device has been described in detail in the above method, and will not be repeated here.

[0136] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A hash retrieval method based on adversarial training, characterized in that, The method, which utilizes an electronic device, includes: The query hash code of the sample to be queried is determined by a trained deep hash model, and the similarity between the query hash code and the sample hash code of each data sample in the retrieved dataset is calculated. Based on all the calculated similarities, a preset number of data samples corresponding to the sample to be queried are selected from the retrieval dataset; The training process of the deep hashing model specifically includes: For each training sample in the preset training sample set, obtain the first hash code of each positive sample corresponding to the training sample and the second hash code of each negative sample corresponding to the training sample, wherein both positive and negative samples are included in the preset training sample set, positive samples and training samples share at least one category, and negative samples and training samples do not share a category. The central code of the training sample is determined based on all the first hash codes and all the second hash codes corresponding to the training sample. Based on the training samples and their central codes, the initial hash model corresponding to the deep hash model is subjected to adversarial training using the minimax strategy to obtain the trained deep hash model. The process of determining the central code of the training sample based on all the first hash codes and all the second hash codes corresponding to the training sample specifically includes: The first sum is obtained by weighting all the first hash codes corresponding to the training samples, and the second sum is obtained by weighting all the second hash codes corresponding to the training samples. Calculate the difference between the first sum and the second sum, and determine the central code of the training sample based on the difference and the sign function; The step of performing adversarial training on the initial hash model corresponding to the deep hash model based on the training samples and their central codes, using a minimax strategy, to obtain the trained deep hash model specifically includes: The model parameters of the initial hash model corresponding to the deep hash model are fixed, and the training samples are input into the initial hash model to generate adversarial samples by maximizing the loss function of the initial hash model with a preset attack strategy. The adversarial sample is input into the initial hash model, and the model parameters of the initial hash model are optimized with the goal of minimizing the loss function to obtain a trained deep hash model.

2. The hash retrieval method based on adversarial training according to claim 1, characterized in that, The expression for the central code is: in, Indicates the central code. Indicates the first Positive samples hash code, Indicates the first negative samples hash code, Indicates the number of positive samples. Indicates the number of negative samples. and All of these represent weighting coefficients.

3. The hash retrieval method based on adversarial training according to claim 2, characterized in that, The weighting coefficients and the weighting coefficients The calculation formulas are as follows: , in, Indicates the number of positive samples. Indicates the first Positive samples Corresponding similarity; Indicates the number of negative samples. Indicates the first negative samples The corresponding similarity.

4. The hash retrieval method based on adversarial training according to claim 1, characterized in that, The expression for the loss function is: in, Indicates the counter-loss term. Represents the quantified loss term. Represents the hash loss term. Indicates training samples The central code, This represents the model parameters of the initial hash model. Indicates the length of the hash code. Indicated by The initial hash network for the parameters. express Activation function Represents a symbolic function. express Norm, This represents the adversarial example corresponding to the training sample.

5. The hash retrieval method based on adversarial training according to claim 1, characterized in that, The preset attack strategy is as follows: ; in, Indicates training samples, This represents the adversarial example corresponding to the training sample. Indicates will Project to of In the ball, Indicates the step size. Represents a symbolic function.

6. A hash retrieval device based on adversarial training, wherein the adversarial training-based hash retrieval device is applied to the adversarial training-based hash retrieval method according to any one of claims 1-5, characterized in that, The application of electronic devices, the means comprising: The calculation module is used to determine the query hash code of the sample to be queried through a trained deep hash model, and to calculate the similarity between the query hash code and the sample hash code of each data sample in the retrieved dataset. The selection module is used to select a preset number of data samples corresponding to the query sample from the retrieval dataset based on all calculated similarities. The training process of the deep hashing model specifically includes: For each training sample in the preset training sample set, obtain the first hash code of each positive sample corresponding to the training sample and the second hash code of each negative sample corresponding to the training sample, wherein both positive and negative samples are included in the preset training sample set, and positive samples share at least one category with training samples, while negative samples do not share a category with training samples. The central code of the training sample is determined based on all the first hash codes and all the second hash codes corresponding to the training sample. Based on the training samples and their central codes, the initial hash model corresponding to the deep hash model is subjected to adversarial training using a minimax strategy to obtain a trained deep hash model.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores one or more programs, which can be executed by one or more processors to implement the steps in the hash retrieval method based on adversarial training as described in any one of claims 1-5.

8. A terminal device, characterized in that, include: Processor, memory, and communication bus; The memory stores a computer-readable program that can be executed by the processor; The communication bus enables communication between the processor and the memory; When the processor executes the computer-readable program, it implements the steps of the hash retrieval method based on adversarial training as described in any one of claims 1-5.