An image processing method, apparatus and electronic device
By adjusting the initial image through gradient inversion to generate an encrypted image, the security risks of directly using neural networks for encryption in existing technologies are solved, achieving higher image security and complexity.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
- Filing Date
- 2022-09-23
- Publication Date
- 2026-06-02
AI Technical Summary
Existing image encryption methods rely on direct encryption via neural networks, which places high demands on the neural network and poses security risks when decrypting the original image.
The initial image to be encrypted is adjusted by gradient inversion, which indirectly generates the encrypted image and avoids direct encryption using neural networks. The first and second loss values are used to determine the update gradient to update the image pixel values and generate the target encrypted image.
It improves image security by ensuring the complexity of the relationship between the encrypted image and the original image, preventing the original image from being directly parsed during decryption, thus enhancing image security.
Smart Images

Figure CN115495762B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to an image processing method, apparatus and electronic device. Background Technology
[0002] Image encryption refers to a technology that utilizes the characteristics of digital images to design encryption algorithms to improve image security. Currently, conventional image encryption methods typically involve inputting the image to be encrypted into a neural network, which then encrypts the image and outputs the final encrypted image. However, this method of directly encrypting the image using a neural network places high demands on the network. Furthermore, during subsequent training tasks using the encrypted image, decryption directly retrieves the original image (the image to be encrypted), posing a security risk. Summary of the Invention
[0003] This application provides an image processing method, apparatus, and electronic device to improve image security by encrypting images without directly using neural networks.
[0004] This application provides an image processing method applied to an electronic device, the method comprising:
[0005] A first loss value is obtained; the first loss value is used to characterize the degree of consistency between the image to be encrypted and the obtained initial image corresponding to the image to be encrypted. The first loss value is determined based on a first type of image features and a second type of image features. The first type of image features are obtained by inputting the image to be encrypted into a trained first neural network, and the second type of image features are obtained by inputting the initial image into the obtained current key network.
[0006] A second loss value is obtained; the second loss value is determined based on the image prediction result and the image annotation result, wherein the image prediction result is obtained by inputting the second type of image features into a pre-trained second neural network, and the image annotation result is the result of the image to be encrypted being pre-annotated; the second loss value is used to characterize the degree of consistency between the image prediction result and the image annotation result.
[0007] Based on the first loss value and the second loss value, the update gradient corresponding to each pixel in the initial image is determined. Based on the update gradient corresponding to each pixel, the pixel value of each pixel in the initial image is updated to obtain the candidate encrypted image corresponding to the image to be encrypted.
[0008] Based on the candidate encrypted images corresponding to the image to be encrypted, a target encrypted image corresponding to the image to be encrypted is determined.
[0009] This application provides an image processing apparatus, which includes:
[0010] The first loss value acquisition module is used to obtain a first loss value; the first loss value is used to characterize the degree of consistency between the image to be encrypted and the obtained initialization image corresponding to the image to be encrypted. The first loss value is determined based on a first type of image features and a second type of image features. The first type of image features are obtained by inputting the image to be encrypted into a trained first neural network, and the second type of image features are obtained by inputting the initialization image into the obtained current key network.
[0011] The second loss value acquisition module is used to obtain a second loss value; the second loss value is determined based on the image prediction result and the image annotation result, wherein the image prediction result is obtained by inputting the second type of image features into a pre-trained second neural network, and the image annotation result is the result of the image to be encrypted being pre-annotated; the second loss value is used to characterize the degree of consistency between the image prediction result and the image annotation result.
[0012] The update module is used to determine the update gradient corresponding to each pixel in the initial image based on the first loss value and the second loss value, and update the pixel value of each pixel in the initial image according to the update gradient corresponding to each pixel to obtain the candidate encrypted image corresponding to the image to be encrypted.
[0013] The target encrypted image determination module is used to determine the target encrypted image corresponding to the image to be encrypted based on the candidate encrypted images corresponding to the image to be encrypted.
[0014] This application provides an electronic device, which includes a machine-readable storage medium and a processor; the machine-readable storage medium stores machine-executable instructions that can be executed by the processor; the processor is used to read the machine-executable instructions to implement the steps of the image processing method as described in the first aspect.
[0015] In summary, in this embodiment of the application, when encrypting the image to be encrypted, the initial image corresponding to the image to be encrypted is adjusted by gradient inversion, and the adjusted image is used as the target encrypted image of the image to be encrypted (referred to as the indirect generation of encrypted image). This achieves that the image to be encrypted is not directly encrypted using a neural network. Furthermore, this indirect generation of encrypted image ensures the complexity of the relationship between the original image, i.e., the image to be encrypted, and the aforementioned target encrypted image, thereby improving image security.
[0016] Furthermore, in this embodiment, based on the above-mentioned method of indirectly generating encrypted images to generate target encrypted images, when the target encrypted image is used for task training, compared with the existing method of directly parsing the original image (i.e., the above-mentioned image to be encrypted) when decrypting the encrypted image, this embodiment does not parse the original image (i.e., the above-mentioned image to be encrypted), thus further improving image security. Attached Figure Description
[0017] Figure 1 This is a flowchart of the method provided in the embodiments of this application.
[0018] Figure 2 This is a flowchart of the target encrypted image determination process provided in the embodiments of this application.
[0019] Figure 3 This is a flowchart of the specified truncation operation provided in the embodiments of this application.
[0020] Figure 4 This is a flowchart of the image encryption process provided in the embodiments of this application.
[0021] Figure 5 This is a diagram of the apparatus provided in the embodiments of this application.
[0022] Figure 6 This is a schematic diagram of the hardware structure of the device according to an embodiment of this application. Detailed Implementation
[0023] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0024] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0025] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0026] To enable those skilled in the art to better understand the technical solutions provided in the embodiments of this application, and to make the above-mentioned objectives, features and advantages of the embodiments of this application more apparent and understandable, the technical solutions in the embodiments of this application will be further described in detail below with reference to the accompanying drawings.
[0027] The embodiments of this application will now be described in detail.
[0028] See Figure 1 , Figure 1 This is a flowchart illustrating a method provided in an embodiment of this application. The method is applied to an electronic device; as an example, the electronic device may be a terminal, a server, etc., and this embodiment is not specifically limited to any particular device.
[0029] like Figure 1 As shown, the process may include the following steps:
[0030] S110: Obtain the first loss value; the first loss value is used to characterize the degree of consistency between the image to be encrypted and the obtained initial image corresponding to the image to be encrypted.
[0031] For example, the image to be encrypted is the original image that needs to be encrypted. For instance, a face image collected in a scenario where identity authentication is based on facial recognition.
[0032] For example, the initial image corresponding to the image to be encrypted is initially constructed based on the image to be encrypted. Here, the constructed initial image and its corresponding image to be encrypted have the same size. Optionally, in this embodiment, the pixel value of each pixel in the constructed initial image corresponding to the image to be encrypted is a preset pixel value. For example, the pixel value is the brightness value of the pixel, and the above-mentioned preset pixel value can be set according to actual needs, such as being set to 1, etc., which is not specifically limited in this application embodiment. As an embodiment, after the above-mentioned initial image is constructed, the initial image can be stored in a database. It should be noted that in this embodiment, the initial image corresponding to the image to be encrypted stored in the database will also be updated, which will be described with examples below.
[0033] For example, in this embodiment, the first loss value is determined based on a first type of image features and a second type of image features. Here, the first type of image features are obtained by inputting the image to be encrypted into a pre-trained first neural network, and the second type of image features are obtained by inputting the initial image corresponding to the image to be encrypted into the current key network.
[0034] For example, in this embodiment, the first neural network can be a pre-trained independent feature extraction model, or it can be at least one layer (e.g., the first P layers) in a pre-trained network model used to perform feature extraction. Examples will be given below, and will not be elaborated here. In this embodiment, the first type of image feature can be at least one of the following: texture features, color features, edge features, brightness features, etc., and this embodiment is not specifically limited to this.
[0035] For example, the current key network mentioned above can initially be a pre-established initial neural network, which will be trained based on the first loss value and the second loss value mentioned above, which will not be elaborated here.
[0036] Initially, when the current key network is an initial neural network, the model parameters of the initial neural network (such as the weight values of each layer) are set to random parameters to introduce random uncertainty into the initial neural network. In this embodiment, corresponding to the first type of image features mentioned above, the second type of image features can also be at least one of the following: texture features, color features, edge features, brightness features, etc.
[0037] Based on the above description, after obtaining the first type of image features and the second type of image features, the first loss value can be determined based on the first type of image features and the second type of image features. As for how to obtain the first loss value based on the first type of image features and the second type of image features, an example will be given below, and will not be elaborated here.
[0038] S120: Obtain the second loss value; the second loss value is used to characterize the degree of consistency between the image prediction result and the image annotation result.
[0039] For example, in this embodiment, the image prediction result is obtained by inputting the second type of image features into a pre-trained second neural network. Here, the second neural network can be a pre-trained independent neural network model, or it can be at least one layer in a pre-trained network model used to perform image prediction. For example, the first neural network and the second neural network are obtained by partitioning a pre-trained network model, where the first neural network includes the first P layers of the network model, and the second neural network includes the remaining layers of the network model excluding the first P layers, where P is greater than or equal to 1.
[0040] In this embodiment, the image prediction result can be a result based on classification prediction, a result based on detection prediction, etc., and this application embodiment does not make specific limitations.
[0041] For example, the above image annotation results are the results of the image to be encrypted being pre-annotated, such as classification annotation results, detection annotation results, etc., and the embodiments of this application are not specifically limited.
[0042] After obtaining the above image prediction and image annotation results, the second loss value can be determined based on the image prediction and image annotation results. As for how to determine the second loss value based on the image prediction and image annotation results, an example will be given below, and will not be elaborated here.
[0043] S130: Based on the first loss value and the second loss value, determine the update gradient corresponding to each pixel in the initialized image, and update the pixel value of each pixel in the initialized image according to the update gradient corresponding to each pixel to obtain the candidate encrypted image corresponding to the image to be encrypted.
[0044] For example, in this embodiment, there are many ways to determine the update gradient corresponding to each pixel in the initialized image based on the first loss value and the second loss value. For example, the update gradient corresponding to each pixel in the initialized image can be determined based on the first loss value and the second loss value according to the following gradient inversion formula. Specifically,
[0045]
[0046] Where grad represents updating the gradient; This represents the first loss value; The second loss value is represented by λ, which is a constant; Z represents the pixel value of each pixel in the initialized image; X represents the pixel value of each pixel in the image to be encrypted; W R W represents the model parameters of the current key network. C include: and These represent the model parameters of the first neural network; These are the model parameters for the second neural network.
[0047] For example, in this embodiment, there are many ways to update the pixel value of each pixel in the initialized image based on the update gradient corresponding to each pixel. For example, it can be updated using the following formula:
[0048] Z o =Z i -grad*l
[0049] Among them, Z o For the updated pixel value, Zi Initializes the unupdated pixel values of pixels in the image; grad represents the initialization gradient corresponding to the pixel values in the image, l r The learning rate. Learning rate l r It can be preset or dynamically determined based on current actual needs.
[0050] S140: Based on the candidate encrypted images corresponding to the image to be encrypted, determine the target encrypted image corresponding to the image to be encrypted.
[0051] For example, in this embodiment, there are many ways to determine the target encrypted image corresponding to the image to be encrypted based on the candidate encrypted images corresponding to the image to be encrypted. For example, the candidate encrypted image can be directly determined as the target encrypted image, or the target encrypted image can be obtained after performing a specified operation on the candidate encrypted image. This embodiment is not specifically limited.
[0052] The specified operation can be performed in various ways, such as specifying a truncation operation, specifying an iteration operation, etc. This application's embodiments are not specifically limited to these methods.
[0053] In this step S140, the method of determining the target encrypted image corresponding to the image to be encrypted based on the candidate encrypted images corresponding to the image to be encrypted is illustrated below, and will not be repeated here.
[0054] This concludes the process. Figure 1 The process is shown below.
[0055] pass Figure 1 As can be seen from the process, in this embodiment of the application, when encrypting the image to be encrypted, the initial image corresponding to the image to be encrypted is adjusted by gradient inversion, and the adjusted image is used as the target encrypted image of the image to be encrypted (referred to as the indirect generation of encrypted image). This achieves that the image to be encrypted is not directly encrypted using a neural network. Moreover, this indirect generation of encrypted image ensures the complexity of the relationship between the original image, i.e., the image to be encrypted, and the aforementioned target encrypted image, thereby improving image security.
[0056] Furthermore, in this embodiment, based on the above-mentioned method of indirectly generating encrypted images to generate target encrypted images, when the target encrypted image is used for task training, compared with the existing method of directly parsing the original image (i.e., the above-mentioned image to be encrypted) when decrypting the encrypted image, this embodiment does not parse the original image (i.e., the above-mentioned image to be encrypted), thus further improving image security.
[0057] Taking the first neural network and the second neural network as examples obtained by dividing the trained network model, the network model here can be a classification network model or a detection network model, and the embodiments of this application are not specifically limited.
[0058] For example, in this embodiment, the value of P can be set according to actual needs. For instance, when performing task training based on the aforementioned target encrypted image, if the task is complex, P can be set to a larger value, such as 5; conversely, when the task is simple, P can be set to a smaller value, such as 2.
[0059] The following describes how the first loss value is obtained in step S110 above:
[0060] As one embodiment, there are many ways to obtain the first loss value in step S110 above. For example, the first type of image features and the second type of image features are input into a pre-defined consistency loss function to obtain a consistency loss value, and the consistency loss value is determined as the first loss value. In this embodiment, there can be various consistency loss functions, such as the mean squared error loss function, the variance loss function, etc., and this embodiment of the application is not specifically limited.
[0061] As an example, when the consistency loss function is the mean squared error loss function, the first type of image features and the second type of image features are input into the pre-defined consistency loss function to obtain the consistency loss value, which can be specifically as follows:
[0062]
[0063] in, Z represents the consistency loss value, also known as the first loss value; X represents the pixel value of each pixel in the initialized image; W represents the model parameters of the current key network. These represent the model parameters of the first neural network; Indicates the calculation of f R (Z t W R )and The mean squared error loss; f R (Z t W R Z represents the algorithm function of the current key network; t represents the pixel value of each pixel in the t-th initialized image; N represents the number of initialized images or images to be encrypted. X represents the algorithm function of the first neural network; t The pixel values of each pixel in the t-th image to be encrypted.
[0064] The above provides an example of how to obtain the first loss value. It should be noted that the method for determining the first loss value is not limited.
[0065] In this embodiment, the first loss value is used to measure the ability of a candidate encrypted image to replace the image to be encrypted as the target encrypted image for task training. The smaller the first loss value, the more similar the candidate encrypted image is to the image to be encrypted, and the better its performance as the target encrypted image to replace the image to be encrypted for task training.
[0066] The following describes how the second loss value is obtained in step S120 above:
[0067] As an example, there are many ways to obtain the second loss value in step S120 above. For example, the image prediction result and the image annotation result are input into the loss function corresponding to the specified task category to obtain the second loss value; the specified task category is the task category to which the image prediction result belongs.
[0068] As an example, the task category can be various, such as classification tasks, detection tasks, etc., and this application embodiment does not specifically limit it. Specifically, when the task category is a classification task, the loss function is the cross-entropy loss function; when the task category is a detection task, the loss function is the regression loss function.
[0069] As an example, taking the L1 loss function as the regression loss function, the image prediction result and the image annotation result are input into the L1 loss function, and the second loss value can be obtained as follows:
[0070]
[0071] in, Z represents the second loss value; Z represents the pixel value of each pixel in the initialized image; W R Represents the model parameters of the current key network; These are the model parameters for the second neural network; This represents the algorithm function of the second neural network; Indicates calculation and Y t L1 loss; f R (Z t W R Z represents the algorithm function of the current key network; t Y represents the pixel value of each pixel in the t-th initialized image; t This represents the image annotation results for the image to be encrypted.
[0072] The above provides an example of how to obtain the second loss value. It should be noted that the method for determining the second loss value described above is not limited.
[0073] The embodiments of this application ensure that the final target encrypted image is more suitable for subsequent task training by using a second loss value, and at the same time, the randomness of the random parameters set when constructing the key network is passed to the target encrypted image, thereby improving the security of the encrypted image.
[0074] The following describes how the target encrypted image is determined in step S140 above:
[0075] See Figure 2 , Figure 2 A flowchart illustrating the implementation of step S140 in an embodiment of this application. Figure 2 As shown, the process may include the following steps:
[0076] S210: Determine whether the candidate encrypted image corresponding to the image to be encrypted meets the preset encryption requirements. If yes, proceed to step S220; otherwise, proceed to step S230.
[0077] For example, in this embodiment, the preset encryption requirements are set according to actual needs. For instance, if the first loss value used when determining the candidate encrypted image corresponding to the image to be encrypted is less than or equal to a first preset loss value threshold, and / or the second loss value is less than or equal to a second preset loss value threshold, then the candidate encrypted image corresponding to the current image to be encrypted is determined to meet the preset encryption requirements; or, after determining the candidate encrypted image corresponding to the image to be encrypted, the recorded number of encryption attempts is updated (for example, the recorded number of encryption attempts is increased by a set value such as 1). If the updated number of encryption attempts is greater than the preset number of encryption attempts threshold, then the candidate encrypted image corresponding to the current image to be encrypted is determined to meet the preset encryption requirements, etc. This embodiment is not specifically limited.
[0078] S220: Determine the candidate encrypted image corresponding to the image to be encrypted as the target encrypted image corresponding to the image to be encrypted, or perform a specified truncation operation on the candidate encrypted image corresponding to the image to be encrypted, and determine the resulting image as the target encrypted image corresponding to the image to be encrypted.
[0079] For example, step S220 is performed under the premise that the candidate encrypted image corresponding to the image to be encrypted meets the preset encryption requirements. Under this premise, as described in step S220, the candidate encrypted image corresponding to the image to be encrypted can be directly determined as the target encrypted image corresponding to the image to be encrypted, or a specified truncation operation can be performed on the candidate encrypted image corresponding to the image to be encrypted, and the resulting image can be determined as the target encrypted image corresponding to the image to be encrypted.
[0080] For example, in this embodiment, the specified truncation operation on the candidate encrypted image corresponding to the image to be encrypted is to prevent gradient explosion. In practice, there are many ways to implement this. Figure 4 Examples have been given, but will not be repeated here.
[0081] S230: Based on the first loss value and the second loss value, update the model parameters of the current key network, use the updated current key network as the current key network, update the initial image corresponding to the image to be encrypted according to the candidate encrypted image corresponding to the image to be encrypted, and return to the step of obtaining the first loss value.
[0082] For example, in this embodiment, the above model parameters are parameters within the current key network, such as the weights of each layer of the network. This application does not specifically limit the scope of the embodiments.
[0083] For example, in this embodiment, updating the model parameters of the current key network based on the first loss value and the second loss value can be done by using the conventional gradient backpropagation method, which will not be elaborated here.
[0084] It should be noted that, in this embodiment, as described above, the model parameters of the current key network can be updated based on the gradient backpropagation method. However, the model parameters of the first and second neural networks mentioned above are fixed and remain unchanged during image encryption and key network training. These model parameters can be the weights of each layer of the network.
[0085] For example, in this embodiment, there are many ways to update the initial image corresponding to the image to be encrypted based on the candidate encrypted image corresponding to the image to be encrypted. For example, the candidate encrypted image corresponding to the image to be encrypted is updated to the initial image corresponding to the image to be encrypted; or, a specified truncation operation is performed on the candidate encrypted image corresponding to the image to be encrypted, and the resulting image is updated to the initial image corresponding to the image to be encrypted.
[0086] This application embodiment trains both the current key network SecretNet and the candidate encrypted images corresponding to the image to be encrypted, which can determine the encryption level of the encrypted image and the training level of the key network according to actual needs, resulting in a high performance ceiling.
[0087] This concludes the process. Figure 2 Description of the process shown.
[0088] pass Figure 2 It demonstrates how to determine the target encrypted image corresponding to the image to be encrypted based on the candidate encrypted images corresponding to the image to be encrypted.
[0089] The following describes the specified truncation operation:
[0090] See Figure 3 , Figure 3 A flowchart illustrating the implementation of the specified truncation operation provided in the embodiments of this application. For example... Figure 3 As shown, the process may include the following steps:
[0091] S310: Update the pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted to the first pixel value.
[0092] For example, the first pixel value is the largest pixel value among all pixel values in the image to be encrypted, and the pixel that satisfies the first condition is the pixel that has a pixel value greater than the first pixel value.
[0093] S320: Update the pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted to the second pixel value.
[0094] For example, the second pixel value is the smallest pixel value among all pixel values in the image to be encrypted, and the pixel that satisfies the second condition is the pixel that has a pixel value less than the second pixel value.
[0095] This concludes the process. Figure 3 The process is shown below.
[0096] pass Figure 3 This implementation performs a specified truncation operation on the candidate encrypted images corresponding to the image to be encrypted, and determines the resulting image as the target encrypted image corresponding to the image to be encrypted.
[0097] The following is based on Figure 4 The above image processing procedure is described as follows:
[0098] like Figure 4 As shown, the image to be encrypted is input into a first neural network with fixed model parameters for feature extraction to obtain the first type of image features; the initial image corresponding to the image to be encrypted (i.e., the encrypted image in the figure) is input into the current key network for feature extraction to obtain the second type of image features; a consistency loss value (i.e., the first loss value) is determined based on the first and second type of image features; the second type of image features are input into a second neural network with fixed model parameters for result prediction to obtain the image prediction result; the task loss value (i.e., the second loss value) is determined using the image prediction result and the image annotation result; the pixel values of each pixel in the initial image are updated based on the first and second loss values; and the model parameters of the current key network are updated based on the first and second loss values until the obtained encrypted image meets the preset encryption requirements, thus obtaining the target encrypted image corresponding to the image to be encrypted and the trained key network.
[0099] As one embodiment of this application, after obtaining the target encrypted image corresponding to the image to be encrypted, it means that the current key network is now a trained key network. Then, the target encrypted image and the trained key network can be used for corresponding task training. For example, the target encrypted image can be input into the trained key network to obtain the features of the target encrypted image, and the features of the encrypted image can be used for task training.
[0100] There are many types of training tasks, such as detection tasks and classification tasks, and this application's embodiments are not limited to any particular type.
[0101] In this embodiment of the application, during task training, the target encrypted image is directly input into the trained key network for feature extraction. Instead of decrypting the original image, the extracted features of the encrypted image are directly used for task training, which improves security compared to directly decrypting the original image.
[0102] Corresponding to the embodiments of the aforementioned methods, embodiments of the present application also provide embodiments of the apparatus and the terminal to which it is applied.
[0103] like Figure 5 As shown, Figure 5 This is a block diagram illustrating an image processing apparatus according to an exemplary embodiment of this application. The image processing apparatus includes:
[0104] The first loss value acquisition module is used to obtain a first loss value. The first loss value is used to characterize the degree of consistency between the image to be encrypted and the obtained initial image corresponding to the image to be encrypted. The first loss value is determined based on a first type of image features and a second type of image features. The first type of image features are obtained by inputting the image to be encrypted into a pre-trained first neural network, and the second type of image features are obtained by inputting the initial image into the obtained current key network.
[0105] The second loss value acquisition module is used to obtain a second loss value. The second loss value is determined based on the image prediction result and the image annotation result. The image prediction result is obtained by inputting the second type of image features into the pre-trained second neural network, and the image annotation result is the result of the image to be encrypted being pre-annotated. The second loss value is used to characterize the degree of consistency between the image prediction result and the image annotation result.
[0106] The update module is used to determine the update gradient corresponding to each pixel in the initial image based on the first loss value and the second loss value, and update the pixel value of each pixel in the initial image according to the update gradient corresponding to each pixel to obtain the candidate encrypted image corresponding to the image to be encrypted.
[0107] The target encrypted image determination module is used to determine the target encrypted image corresponding to the image to be encrypted based on the candidate encrypted images corresponding to the image to be encrypted.
[0108] As an optional implementation of this application, the first neural network and the second neural network are obtained by dividing the trained network model. The first neural network includes the first P layers in the network model, and the second neural network includes the remaining layers in the network model excluding the first P layers, where P is greater than or equal to 1.
[0109] As an optional implementation of this application, the first loss value acquisition module is specifically used for:
[0110] The first type of image features and the second type of image features are input into the pre-defined consistency loss function to obtain the consistency loss value, which is then determined as the first loss value.
[0111] As an optional implementation of this application, the second loss value acquisition module is specifically used for:
[0112] The image prediction result and the image annotation result are input into the loss function corresponding to the specified task category to obtain the second loss value; the specified task category is the task category to which the image prediction result belongs.
[0113] Specifically, when the task category is a classification task, the loss function is the cross-entropy loss function; when the task category is a detection task, the loss function is the regression loss function.
[0114] As an optional implementation of this application, the target encrypted image determination module is specifically used for:
[0115] Determine whether the candidate encrypted images corresponding to the image to be encrypted meet the preset encryption requirements;
[0116] If so, determine the candidate encrypted image corresponding to the image to be encrypted as the target encrypted image corresponding to the image to be encrypted; or, perform a specified truncation operation on the candidate encrypted image corresponding to the image to be encrypted and determine the resulting image as the target encrypted image corresponding to the image to be encrypted.
[0117] If not, based on the first loss value and the second loss value, update the model parameters of the current key network, use the updated current key network as the current key network, update the initial image corresponding to the image to be encrypted according to the candidate encrypted image corresponding to the image to be encrypted, and return to the step of obtaining the first loss value.
[0118] As an optional implementation of this application, the above-mentioned specified truncation operation on the candidate encrypted image corresponding to the image to be encrypted includes:
[0119] The pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted that satisfy the first condition are updated to the first pixel value, and the pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted that satisfy the second condition are updated to the second pixel value; wherein, the first pixel value is the largest pixel value among all pixel values in the image to be encrypted, and the pixel value satisfying the first condition is the pixel value greater than the first pixel value; the second pixel value is the smallest pixel value among all pixel values in the image to be encrypted, and the pixel value satisfying the second condition is the pixel value less than the second pixel value.
[0120] As an optional implementation of this application, the above-mentioned updating the initial image corresponding to the image to be encrypted based on the candidate encrypted image corresponding to the image to be encrypted includes:
[0121] Update the candidate encrypted image corresponding to the image to be encrypted to the initial image corresponding to the image to be encrypted; or...
[0122] The pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted that satisfy the first condition are updated to the first pixel value. The pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted that satisfy the second condition are updated to the second pixel value. The updated candidate encrypted images are then updated to the initial image corresponding to the image to be encrypted. Wherein, the first pixel value is the largest pixel value among all pixel values in the image to be encrypted, and a pixel that satisfies the first condition is a pixel with a pixel value greater than the first pixel value. The second pixel value is the smallest pixel value among all pixel values in the image to be encrypted, and a pixel that satisfies the second condition is a pixel with a pixel value less than the second pixel value.
[0123] As an optional implementation of this application embodiment, the above-mentioned updating module is specifically used for:
[0124] Based on the first and second loss values, the update gradient corresponding to the pixel value of each pixel in the initialized image is determined according to the following gradient inversion formula:
[0125]
[0126] Where grad represents updating the gradient; This represents the first loss value; The second loss value is represented by λ, which is a constant; Z represents the pixel value of each pixel in the initialized image; X represents the pixel value of each pixel in the image to be encrypted; W R W represents the model parameters of the current key network. C include: and These represent the model parameters of the first neural network; These are the model parameters for the second neural network.
[0127] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0128] This concludes the process. Figure 5 Structural description of the device shown.
[0129] Correspondingly, embodiments of this application also provide Figure 5 The hardware structure diagram of the device shown is as follows: Figure 6 As shown, the electronic device can be a device implementing the above-described method. Figure 6 As shown, the hardware architecture includes a processor and memory.
[0130] Among them, the memory is used to store machine-executable instructions;
[0131] A processor is configured to read and execute machine-executable instructions stored in memory to implement the corresponding image processing method embodiment shown above.
[0132] As one embodiment, the memory can be any electronic, magnetic, optical, or other physical storage device that can contain or store information such as executable instructions, data, etc. For example, the memory can be volatile memory, non-volatile memory, or similar storage media. Specifically, the memory can be RAM (Random Access Memory), flash memory, storage drives (such as hard disk drives), solid-state drives, any type of storage disk (such as optical discs, DVDs, etc.), or similar storage media, or combinations thereof.
[0133] This concludes the process. Figure 6 Description of the electronic device shown.
[0134] The above description is merely a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of protection of this specification.
Claims
1. An image processing method, characterized in that, This method is applied to electronic devices, and the method includes: A first loss value is obtained; the first loss value is used to characterize the degree of consistency between the image to be encrypted and the obtained initial image corresponding to the image to be encrypted. The first loss value is determined based on a first type of image features and a second type of image features. The first type of image features are obtained by inputting the image to be encrypted into a trained first neural network, and the second type of image features are obtained by inputting the initial image into the obtained current key network. A second loss value is obtained; the second loss value is determined based on the image prediction result and the image annotation result, wherein the image prediction result is obtained by inputting the second type of image features into a pre-trained second neural network, and the image annotation result is the result of the image to be encrypted being pre-annotated; the second loss value is used to characterize the degree of consistency between the image prediction result and the image annotation result. Based on the first loss value and the second loss value, the update gradient corresponding to each pixel in the initial image is determined. Based on the update gradient corresponding to each pixel, the pixel value of each pixel in the initial image is updated to obtain the candidate encrypted image corresponding to the image to be encrypted. Based on the candidate encrypted images corresponding to the image to be encrypted, a target encrypted image corresponding to the image to be encrypted is determined.
2. The method according to claim 1, characterized in that, The first neural network and the second neural network are obtained by partitioning a pre-trained network model. The first neural network includes the first P layers of the network model, and the second neural network includes the remaining layers of the network model excluding the first P layers, where P is greater than or equal to 1.
3. The method according to claim 1, characterized in that, Obtaining the first loss value includes: The first type of image features and the second type of image features are input into the pre-defined consistency loss function to obtain a consistency loss value, and the consistency loss value is determined as the first loss value.
4. The method according to claim 1, characterized in that, Obtaining the second loss value includes: The image prediction result and the image annotation result are input into a loss function corresponding to a specified task category to obtain the second loss value; the specified task category is the task category to which the image prediction result belongs. Wherein, when the task category is a classification task, the loss function is the cross-entropy loss function; when the task category is a detection task, the loss function is the regression loss function.
5. The method according to claim 1, characterized in that, The step of determining the target encrypted image corresponding to the image to be encrypted based on the candidate encrypted images corresponding to the image to be encrypted includes: Determine whether the candidate encrypted images corresponding to the image to be encrypted meet the preset encryption requirements; If so, the candidate encrypted image corresponding to the image to be encrypted is determined as the target encrypted image corresponding to the image to be encrypted; or, a specified truncation operation is performed on the candidate encrypted image corresponding to the image to be encrypted, and the resulting image is determined as the target encrypted image corresponding to the image to be encrypted. If not, based on the first loss value and the second loss value, update the model parameters of the current key network, use the updated current key network as the current key network, update the initial image corresponding to the image to be encrypted according to the candidate encrypted image corresponding to the image to be encrypted, and return to the step of obtaining the first loss value.
6. The method according to claim 5, characterized in that, The specified truncation operation on the candidate encrypted image corresponding to the image to be encrypted includes: The pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted that satisfy the first condition are updated to the first pixel value, and the pixel values of the pixels in the candidate encrypted images corresponding to the image to be encrypted that satisfy the second condition are updated to the second pixel value; wherein, the first pixel value is the largest pixel value among all pixel values in the image to be encrypted, and the pixel value satisfying the first condition is the pixel value greater than the first pixel value; the second pixel value is the smallest pixel value among all pixel values in the image to be encrypted, and the pixel value satisfying the second condition is the pixel value less than the second pixel value.
7. The method according to claim 5, characterized in that, The step of updating the initial image corresponding to the image to be encrypted based on the candidate encrypted image corresponding to the image to be encrypted includes: Update the candidate encrypted image corresponding to the image to be encrypted to the initialized image corresponding to the image to be encrypted; or... The pixel values of pixels satisfying the first condition in the candidate encrypted image corresponding to the image to be encrypted are updated to the first pixel value; the pixel values of pixels satisfying the second condition in the candidate encrypted image corresponding to the image to be encrypted are updated to the second pixel value; and the updated candidate encrypted image is updated to the initial image corresponding to the image to be encrypted. Wherein, the first pixel value is the largest pixel value among all pixel values in the image to be encrypted, and a pixel satisfying the first condition is a pixel with a pixel value greater than the first pixel value; the second pixel value is the smallest pixel value among all pixel values in the image to be encrypted, and a pixel satisfying the second condition is a pixel with a pixel value less than the second pixel value.
8. The method according to claim 1, characterized in that, The step of determining the update gradient corresponding to the pixel value of each pixel in the initialized image based on the first loss value and the second loss value includes: Based on the first loss value and the second loss value, the update gradient corresponding to the pixel value of each pixel in the initialized image is determined according to the following gradient inversion formula: Where grad represents updating the gradient; This represents the first loss value; The second loss value is represented by λ, which is a constant; Z represents the pixel value of each pixel in the initialized image; X represents the pixel value of each pixel in the image to be encrypted; W R W represents the model parameters of the current key network. C include: and These represent the model parameters of the first neural network; These are the model parameters for the second neural network.
9. An image processing apparatus, characterized in that, The device includes: The first loss value acquisition module is used to obtain a first loss value; the first loss value is used to characterize the degree of consistency between the image to be encrypted and the obtained initialization image corresponding to the image to be encrypted. The first loss value is determined based on a first type of image features and a second type of image features. The first type of image features are obtained by inputting the image to be encrypted into a trained first neural network, and the second type of image features are obtained by inputting the initialization image into the obtained current key network. The second loss value acquisition module is used to obtain a second loss value; the second loss value is determined based on the image prediction result and the image annotation result, wherein the image prediction result is obtained by inputting the second type of image features into a pre-trained second neural network, and the image annotation result is the result of the image to be encrypted being pre-annotated; the second loss value is used to characterize the degree of consistency between the image prediction result and the image annotation result. The update module is used to determine the update gradient corresponding to each pixel in the initial image based on the first loss value and the second loss value, and update the pixel value of each pixel in the initial image according to the update gradient corresponding to each pixel to obtain the candidate encrypted image corresponding to the image to be encrypted. The target encrypted image determination module is used to determine the target encrypted image corresponding to the image to be encrypted based on the candidate encrypted images corresponding to the image to be encrypted.
10. An electronic device, characterized in that, Electronic devices include machine-readable storage media and processors; The machine-readable storage medium stores machine-executable instructions that can be executed by a processor; The processor is used to read the machine-executable instructions to implement the steps of the image processing method as described in any one of claims 1-8.