Image similarity determination method and device, computer equipment, readable storage medium and program product
By using the initial twin network in image similarity detection for training and model parameter update, the problem of insufficient detection accuracy in the prior art is solved, and a higher precision image similarity detection is achieved.
Patent Information
- Application Number
- CN202411712464.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-07
AI Technical Summary
The prior art has limited detection accuracy in image similarity detection, making it difficult to meet the demand for high accuracy.
The initial twin network is used for training. By dividing the training images into training images, verification images and test images, and updating the model parameters of the intermediate twin network after the training round is over, and finally outputting the target similarity between every two target images in the target twin network.
It effectively improves the detection accuracy of image similarity detection and can more accurately judge the similarity between two images.
Smart Images

Figure CN119579926A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of deep learning technology, and in particular to a method, apparatus, computer device, computer-readable storage medium and computer program product for determining image similarity. Background Art
[0002] With the development of deep learning technology, more and more scenarios need to detect image similarity, such as face recognition, image detection, target tracking, etc. At present, the commonly used method is to detect image similarity based on SIFT (Scale-Invariant Feature Transform) algorithm, which has certain robustness to image illumination, rotation, displacement, etc. However, the overall detection accuracy of this method is limited and it is difficult to meet the requirements of high precision. Summary of the invention
[0003] Based on this, it is necessary to provide a method, device, computer equipment, computer-readable storage medium and computer program product for determining image similarity that can improve detection accuracy in response to the above technical problems.
[0004] In a first aspect, the present application provides a method for determining image similarity, the method comprising:
[0005] Acquire a plurality of sample images, and divide the plurality of sample images into training images, verification images, and test images according to a preset ratio;
[0006] Inputting the training image into an initial twin network to train the initial twin network, wherein the twin network includes a plurality of sub-networks, and the sub-networks have the same network structure;
[0007] For each training round, after the training round ends, updating the model parameters of the intermediate twin network trained in the training round based on the verification image;
[0008] After the training process of the initial twin network is completed, the model parameters of the trained target twin network are updated based on the test image;
[0009] Acquire multiple target images, input the multiple target images into the target twin network after parameter update, and output the target similarity between every two target images.
[0010] In one embodiment, updating the model parameters of the intermediate twin network trained in the training round based on the verification image includes:
[0011] Input the verification image into the intermediate twin network, and output the verification similarity between every two verification images;
[0012] In a case where the verification similarity is not within the first similarity range, obtaining parameter adjustment values of the model parameters of the intermediate twin network based on the verification similarity;
[0013] Based on the parameter adjustment value, the model parameters of the sub-network in the intermediate twin network are updated.
[0014] In one embodiment, updating the model parameters of the trained target twin network based on the test image includes:
[0015] Input the test image into the target twin network, and output the test similarity between every two test images;
[0016] In a case where the test similarity is not within the second similarity range, obtaining parameter adjustment values of the model parameters of the target twin network based on the test similarity;
[0017] Based on the parameter adjustment value, the model parameters of the sub-network in the target twin network are updated.
[0018] In one embodiment, before updating the model parameters of the trained target twin network based on the test image, the method further includes:
[0019] Obtaining the corresponding loss value of the target twin network;
[0020] When the loss value is not within a preset loss value range, obtaining a gradient of a model parameter of the target twin network based on the loss value;
[0021] Based on the gradient, the model parameters of the sub-network in the target twin network are updated.
[0022] In one embodiment, the model parameters include weights and biases; and updating the model parameters of the sub-network in the target twin network based on the gradient includes:
[0023] For the target twin network, obtain the weight gradient corresponding to the weight and the bias gradient corresponding to the bias;
[0024] The weight of the sub-network is updated based on the weight gradient, and the bias of the sub-network is updated based on the bias gradient.
[0025] In one embodiment, the step of inputting the plurality of target images into the target twin network after parameter update and outputting the target similarity between every two target images further includes:
[0026] When the target similarity is within a third similarity range, the two target images corresponding to the target similarity are determined to be the same image.
[0027] In a second aspect, the present application further provides a device for determining image similarity, the device comprising:
[0028] A first acquisition module is used to acquire a plurality of sample images and divide the plurality of sample images into training images, verification images and test images according to a preset ratio;
[0029] An input module, used for inputting the training image into an initial twin network to train the initial twin network, wherein the twin network includes a plurality of sub-networks, and the network structures of the sub-networks are the same;
[0030] A first updating module is used for updating, for each training round, model parameters of the intermediate twin network trained in the training round based on the verification image after the training round ends;
[0031] A second updating module is used to update the model parameters of the trained target twin network based on the test image after the training process of the initial twin network is completed;
[0032] The second acquisition module is used to acquire multiple target images, input the multiple target images into the target twin network after parameter update, and output the target similarity between every two target images.
[0033] In a third aspect, the present application further provides a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method in any one of the above embodiments when executing the computer program.
[0034] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method in any one of the above embodiments are implemented.
[0035] In a fifth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the method in any one of the above embodiments are implemented.
[0036] The above-mentioned image similarity determination method, device, computer equipment, computer-readable storage medium and computer program product obtain multiple sample images, divide the multiple sample images into training images, verification images and test images according to a preset ratio; input the training images into the initial twin network to train the initial twin network, the twin network includes multiple sub-networks, and the network structure of the sub-networks is the same; for each training round, after the training round is completed, based on the verification image, the model parameters of the intermediate twin network obtained in the training round are updated; after the training process of the initial twin network is completed, based on the test image, the model parameters of the trained target twin network are updated; obtain multiple target images, input the multiple target images into the target twin network after the parameter update, and output the target similarity between every two target images. The method provided by the present application can effectively improve the detection accuracy of image similarity detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0038] Figure 1 is a schematic flow chart of a method for determining image similarity in one embodiment;
[0039] Figure 2 is a schematic diagram of residual learning in one embodiment;
[0040] Figure 3 A schematic diagram of a flow chart of a model parameter updating method in one embodiment;
[0041] Figure 4 is a structural block diagram of an image similarity determination device in one embodiment;
[0042] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0044] In one embodiment, Figure 1As shown, a method for determining image similarity is provided. This embodiment uses the method applied to a terminal as an example for illustration. It can be understood that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0045] S102: Acquire multiple sample images, and divide the multiple sample images into training images, verification images, and test images according to a preset ratio.
[0046] Optionally, after acquiring the sample image, the sample image needs to be preprocessed. The content of image preprocessing may include, but is not limited to, cropping, scaling, and normalization processing, wherein cropping is the process of retaining a certain part of the image and removing other parts, scaling is the process of scaling the image to a uniform size, for example, scaling all sample images to a size of 224*224, and normalization processing is processing the image data to the same range. The formula for normalization processing can be shown as follows:
[0047]
[0048] Where normalized_image is the image data of the sample image after normalization, image is the image data of the sample image before normalization, mean is the mean value of the image data, and std is the standard deviation of the image data.
[0049] Optionally, the sample image may be divided into a training image, a verification image, and a test image in a ratio of 8:1:1.
[0050] S104. Input the training image into the initial twin network to train the initial twin network. The twin network includes multiple sub-networks, and the network structures of the sub-networks are the same.
[0051] Among them, the twin network is composed of multiple sub-networks with the same structure but shared parameters. The multiple sub-networks process multiple different samples of input data respectively, and the outputs of the multiple sub-networks are usually used to calculate the similarity or distance between two samples.
[0052] Optionally, the sub-network in the twin network can be a ResNet50 (Residual Network 50) network, where ResNet50 is a deep convolutional neural network (CNN), which is a member of the ResNet (residual network) series. In the process of training ResNet50, it is necessary to define the cross entropy loss function and optimizer, and set hyperparameters such as the learning rate; in the process of cyclic training, it is necessary to perform steps such as forward propagation, loss calculation, back propagation, and parameter synchronization update; at the end of each round of training, the performance of the twin network is evaluated using the verification image, and the best twin network is saved, and the hyperparameters of the twin network are adjusted; the performance of the final trained twin network is evaluated using the test image, and key indicators are calculated and recorded, for example, the key indicators may include accuracy, recall rate, and F1 score; the weights and parameters of the final trained twin network are saved for future prediction or further training.
[0053] Optionally, the cross entropy loss function is a loss function used in machine learning and deep learning to measure the difference between the predicted value and the true value. The optimizer is used to adaptively adjust the learning rate for each parameter by calculating the first-order moment estimate and the second-order moment estimate of each parameter, so that the update of different parameters can be handled more flexibly during the training process. The core of the back propagation algorithm is to calculate the gradient of the loss function for each parameter and update the parameters according to these gradients. The smaller the value of the cross entropy loss, the closer the probability distribution predicted by the network model is to the one-hot encoding of the true category, and the better the performance of the network model. The cross entropy loss function is shown in the following formula:
[0054]
[0055] In the formula, C is the total number of categories, y i is the unique hot encoding of the true category, that is, when the sample belongs to the i-th category, y i =1, otherwise y i =0, p i The network model predicts the probability that the sample belongs to the i-th category.
[0056] Optionally, during the training of ResNet50, residual learning is required, and the residual learning is shown in the following formula:
[0057] y = F(x, {W;}) + x
[0058] The residual learning block contains two branches or two mappings, namely identity mapping and residual mapping. The residual learning block refers to the basic building block used to build a residual network in a deep learning network. Identity mapping is used to map each element in a set to itself, and residual mapping is used to map input data to output data. Figure 2 As shown, identity mapping refers to Figure 2 The curved line on the right side of the figure, the result of identity mapping is x, residual mapping refers to another branch, that is, the F(x) part, the F(x) part is the convolution calculation part, and weightlayer refers to the weight layer. The residual learning block outputs the F(x) part and its own mapping result x, that is, F(x)+x, and finally activates this output with relu, where relu (Rectified Linear Unit) is an activation function widely used in deep learning.
[0059] S106. For each training round, after the training round ends, the model parameters of the intermediate twin network trained in the training round are updated based on the verification image.
[0060] Optionally, the verification image can be input into the intermediate twin network to obtain the corresponding similarity of the verification image, and the model parameters of the intermediate twin network are updated based on this similarity.
[0061] S108. After the training process of the initial twin network is completed, the model parameters of the trained target twin network are updated based on the test image.
[0062] Optionally, the test image can be input into the target twin network to obtain the corresponding similarity of the test image, and the model parameters of the target twin network can be updated based on this similarity.
[0063] S110, obtain multiple target images, input the multiple target images into the target twin network after parameter update, and output the target similarity between every two target images.
[0064] Among them, the target similarity is used to characterize whether two target images are the same image.
[0065] In the above-mentioned method for determining image similarity, multiple sample images are obtained, and the multiple sample images are divided into training images, verification images and test images according to a preset ratio; the training images are input into the initial twin network to train the initial twin network, and the twin network includes multiple sub-networks, and the network structure of the sub-networks is the same; for each training round, after the training round is completed, based on the verification image, the model parameters of the intermediate twin network obtained in the training round are updated; after the training process of the initial twin network is completed, based on the test image, the model parameters of the trained target twin network are updated; multiple target images are obtained, and the multiple target images are input into the target twin network after the parameter update, and the target similarity between each two target images is output. The method provided by the present application can effectively improve the detection accuracy of image similarity detection.
[0066] In some embodiments, Figure 3 As shown, based on the verification image, the model parameters of the intermediate twin network obtained in the training round are updated, including:
[0067] S302: Input the verification image into the intermediate twin network and output the verification similarity between every two verification images.
[0068] S304: When the verification similarity is not within the first similarity range, obtain parameter adjustment values of the model parameters of the intermediate twin network based on the verification similarity.
[0069] S306. Based on the parameter adjustment value, the model parameters of the sub-network in the intermediate twin network are updated.
[0070] Among them, there is a verification similarity that is not within the first similarity range, which means that the accuracy of the intermediate twin network is low, and the model parameters of the intermediate twin network need to be adjusted to improve the accuracy of the intermediate twin network.
[0071] In this embodiment, based on the parameter adjustment value, the model parameters of the sub-network in the intermediate twin network are updated, which can effectively improve the accuracy of the intermediate twin network.
[0072] In some embodiments, the model parameters of the trained target twin network are updated based on the test image, including: inputting the test image into the target twin network, and outputting the test similarity between every two test images; when the test similarity is not within the second similarity range, obtaining parameter adjustment values of the model parameters of the target twin network based on the test similarity; and updating the model parameters of the sub-network in the target twin network based on the parameter adjustment values.
[0073] Among them, there is a test similarity that is not within the second similarity range, which means that the accuracy of the target twin network is low, and the model parameters of the target twin network need to be adjusted to improve the accuracy of the target twin network.
[0074] In this embodiment, based on the parameter adjustment value, the model parameters of the sub-network in the target twin network are updated, which can effectively improve the accuracy of the target twin network.
[0075] In some embodiments, before updating the model parameters of the trained target twin network based on the test image, it also includes: obtaining the corresponding loss value of the target twin network; when the loss value is not within the preset loss value range, obtaining the gradient of the model parameters of the target twin network based on the loss value; based on the gradient, updating the model parameters of the sub-network in the target twin network.
[0076] Among them, the loss value is the function value of the loss function of the twin network; the gradient of the model parameters is used to describe the rate of change of the model parameters relative to the loss function.
[0077] In this embodiment, the model parameters of the sub-network in the target twin network are updated based on the gradient, which can effectively improve the accuracy of the target twin network.
[0078] In some embodiments, the model parameters include weights and biases; based on the gradient, the model parameters of the sub-network in the target twin network are updated, including: for the target twin network, obtaining the weight gradient corresponding to the weight and the bias gradient corresponding to the bias; updating the weight of the sub-network based on the weight gradient, and updating the bias of the sub-network based on the bias gradient.
[0079] Optionally, for the weight wjk (the connection weight from neuron j to neuron k) and bias bk (the bias of neuron k), their gradients can be calculated by the following formula:
[0080] Weight gradient: , where aj is the output of neuron j and δk is the error term of neuron k.
[0081] Bias gradient: , that is, the gradient of the bias is directly equal to the error term of the neuron.
[0082] Parameter update: Based on the calculated gradient, the gradient descent method can be used to update the weights and biases. The update formula is usually: Weight update: , where η is the learning rate. Bias update: .
[0083] Optionally, an error term is used to measure the contribution of each neuron to the final loss function. For the output layer neuron j, the error term δj is usually defined as the partial derivative of the loss function L with respect to the weighted input zj of the output layer neuron j, that is, For hidden layer neurons, the error term is calculated by the error term of the next layer and the connection weights.
[0084] In this embodiment, the weight of the sub-network is updated based on the weight gradient, and the bias of the sub-network is updated based on the bias gradient, which can effectively improve the accuracy of the target twin network.
[0085] In some embodiments, multiple target images are input into the target twin network after parameter update, and after the target similarity between every two target images is output, it also includes: when the target similarity is within a third similarity range, the two target images with corresponding target similarity are determined as the same image.
[0086] Optionally, when the target similarity is greater than a similarity threshold, two target images corresponding to the target similarity are determined to be the same image.
[0087] In this embodiment, when the target similarity is within the third similarity range, the two target images corresponding to the target similarity are determined to be the same image, so that the determination of whether the two target images are the same image is more accurate.
[0088] In one embodiment, another method for determining image similarity is provided, the method comprising the following contents:
[0089] Input data: The input of the Siamese neural network is an image, usually a three-dimensional tensor, where each element represents a pixel in the image.
[0090] Original network extracts features: The original network is the first network in the twin neural network, which is mainly responsible for extracting features from the input image. The original network usually contains multiple convolutional layers and pooling layers, which can extract local features in the image.
[0091] Twin network stabilization features: The twin network is the second network in the twin neural network, which is mainly responsible for stabilizing the features extracted by the original network. The twin network usually also contains multiple convolutional layers and pooling layers, but its parameters are different from the original network to prevent confusion of the original network's features. The twin network also includes a fully connected layer to connect the features of the original network with the output results.
[0092] Output result of the twin network: After the twin network stabilizes the features of the original network through the fully connected layer, it outputs a two-dimensional tensor, which represents the feature vector of the input image.
[0093] Output network output results: The last layer of the twin neural network is usually the output layer, which is mainly responsible for converting the feature vector output by the twin network into the output result. The parameters of the output layer are different from those of the original network and the twin network to prevent confusion of the output results.
[0094] Model training: The training process of the twin neural network is completed through the back propagation algorithm. During the training process, the output results of the twin neural network are compared with the true labels, and the error function is used to guide the adjustment of the model, making the output results of the model more accurate.
[0095] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0096] Based on the same inventive concept, the embodiment of the present application also provides an image similarity determination device for implementing the above-mentioned image similarity determination method. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above-mentioned method, so the specific limitations in one or more image similarity determination device embodiments provided below can refer to the limitations of the image similarity determination method above, and will not be repeated here.
[0097] In an exemplary embodiment, Figure 4 As shown, an image similarity determination device 400 is provided, comprising: a first acquisition module 401, an input module 402, a first update module 403, a second update module 404 and a second acquisition module 405, wherein:
[0098] The first acquisition module 401 is used to acquire multiple sample images and divide the multiple sample images into training images, verification images and test images according to a preset ratio.
[0099] The input module 402 is used to input the training image into the initial twin network to train the initial twin network. The twin network includes multiple sub-networks, and the network structures of the sub-networks are the same.
[0100] The first updating module 403 is used to update the model parameters of the intermediate twin network trained in each training round based on the verification image after the training round ends.
[0101] The second updating module 404 is used to update the model parameters of the trained target twin network based on the test image after the training process of the initial twin network is completed.
[0102] The second acquisition module 405 is used to acquire multiple target images, input the multiple target images into the target twin network after parameter update, and output the target similarity between every two target images.
[0103] In some embodiments, the first update module 403 is also used to input the verification image into the intermediate twin network, and output the verification similarity between every two verification images; when the verification similarity is not within the first similarity range, obtain the parameter adjustment value of the model parameter of the intermediate twin network based on the verification similarity; based on the parameter adjustment value, update the model parameters of the sub-network in the intermediate twin network.
[0104] In some embodiments, the second update module 404 is also used to input the test image into the target twin network and output the test similarity between every two test images; when the test similarity is not within the second similarity range, obtain the parameter adjustment value of the model parameter of the target twin network based on the test similarity; based on the parameter adjustment value, update the model parameters of the sub-network in the target twin network.
[0105] In some embodiments, the image similarity determination apparatus 400 further includes:
[0106] The third acquisition module is used to obtain the corresponding loss value of the target twin network.
[0107] The fourth acquisition module is used to obtain the gradient of the model parameters of the target twin network based on the loss value when the loss value is not within a preset loss value range.
[0108] The third updating module is used to update the model parameters of the sub-network in the target twin network based on the gradient.
[0109] In some embodiments, the model parameters include weights and biases; the third update module is also used to obtain the weight gradient corresponding to the weight and the bias gradient corresponding to the bias for the target twin network; the weight of the sub-network is updated based on the weight gradient, and the bias of the sub-network is updated based on the bias gradient.
[0110] In some embodiments, the image similarity determining device 400 is specifically configured to determine two target images corresponding to the target similarity as the same image when the target similarity is within a third similarity range.
[0111] Each module in the above-mentioned image similarity determination device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0112] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (Near Field Communication, NFC) or other technologies. When the computer program is executed by the processor, a method for determining image similarity is implemented.
[0113] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0114] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0115] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0116] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0117] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0118] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0119] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0120] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for determining image similarity, characterized in that: The method comprises: Acquire a plurality of sample images, and divide the plurality of sample images into training images, verification images, and test images according to a preset ratio; Inputting the training image into an initial twin network to train the initial twin network, wherein the twin network includes a plurality of sub-networks, and the sub-networks have the same network structure; For each training round, after the training round ends, updating the model parameters of the intermediate twin network trained in the training round based on the verification image; After the training process of the initial twin network is completed, the model parameters of the trained target twin network are updated based on the test image; Acquire multiple target images, input the multiple target images into the target twin network after parameter update, and output the target similarity between every two target images.
2. The method according to claim 1, characterized in that The updating of the model parameters of the intermediate twin network obtained by training in the training round based on the verification image includes: Input the verification image into the intermediate twin network, and output the verification similarity between every two verification images; In a case where the verification similarity is not within the first similarity range, obtaining parameter adjustment values of the model parameters of the intermediate twin network based on the verification similarity; Based on the parameter adjustment value, the model parameters of the sub-network in the intermediate twin network are updated.
3. The method according to claim 1, characterized in that: The updating of the model parameters of the trained target twin network based on the test image includes: Input the test image into the target twin network, and output the test similarity between every two test images; In a case where the test similarity is not within the second similarity range, obtaining parameter adjustment values of the model parameters of the target twin network based on the test similarity; Based on the parameter adjustment value, the model parameters of the sub-network in the target twin network are updated.
4. The method according to claim 1, characterized in that: Before updating the model parameters of the trained target twin network based on the test image, the method further includes: Obtaining the corresponding loss value of the target twin network; When the loss value is not within a preset loss value range, obtaining a gradient of a model parameter of the target twin network based on the loss value; Based on the gradient, the model parameters of the sub-network in the target twin network are updated.
5. The method according to claim 4, characterized in that The model parameters include weights and biases; and updating the model parameters of the sub-network in the target twin network based on the gradient includes: For the target twin network, obtain the weight gradient corresponding to the weight and the bias gradient corresponding to the bias; The weight of the sub-network is updated based on the weight gradient, and the bias of the sub-network is updated based on the bias gradient.
6. The method according to claim 1, characterized in that After inputting the plurality of target images into the target twin network after parameter update and outputting the target similarity between every two target images, the method further includes: When the target similarity is within a third similarity range, the two target images corresponding to the target similarity are determined to be the same image.
7. An image similarity determination device, characterized in that: The device comprises: A first acquisition module is used to acquire a plurality of sample images and divide the plurality of sample images into training images, verification images and test images according to a preset ratio; An input module, used for inputting the training image into an initial twin network to train the initial twin network, wherein the twin network includes a plurality of sub-networks, and the network structures of the sub-networks are the same; A first updating module is used for updating, for each training round, model parameters of the intermediate twin network trained in the training round based on the verification image after the training round ends; A second updating module is used to update the model parameters of the trained target twin network based on the test image after the training process of the initial twin network is completed; The second acquisition module is used to acquire multiple target images, input the multiple target images into the target twin network after parameter update, and output the target similarity between every two target images.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.