Neural network training method, image retrieval method and device
Extracting features through shallow and deep convolutional neural networks and performing fusion processing solves the problem of insufficient image retrieval accuracy in the existing technology and achieves more efficient image similarity judgment and retrieval effects.
Patent Information
- Application Number
- CN202111555642.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-12-17
AI Technical Summary
The accuracy of existing image retrieval based on deep learning networks still needs to be improved, and it is difficult to effectively handle the similarity judgment between images.
Two different levels of convolutional neural networks (shallow and deep) are used to extract visual features and semantic features, and the network is trained through a loss function to learn image similarity in Hamming space, and the features are fused for dimensionality reduction and binarization. processing to improve retrieval accuracy.
Through feature fusion and binarization processing, the accuracy of image retrieval is improved, image information can be characterized more accurately, and the impact of real environment interference on the retrieval results is reduced.
Smart Images

Figure CN114219983B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a neural network training method, an image retrieval method and a device. Background Art
[0002] Currently, image retrieval can use deep learning networks to calculate the eigenvalues of images, and then determine whether images are related based on the distance between the eigenvalues.
[0003] However, the accuracy of image retrieval based on deep learning networks still needs to be improved. Summary of the invention
[0004] This application provides the following technical solutions:
[0005] A neural network training method, comprising:
[0006] Select two images from a data source as a first training image and a second training image respectively;
[0007] Inputting the first training image into a first shallow convolutional neural network and a first deep convolutional neural network respectively, to obtain visual features of the first training image obtained by the first shallow convolutional neural network and semantic features of the first training image obtained by the first deep convolutional neural network;
[0008] fusing the visual features and semantic features of the first training image to obtain a first fused feature;
[0009] Inputting the second training image into a second shallow convolutional neural network and a second deep convolutional neural network respectively, obtaining visual features of the second training image obtained by the second shallow deep hashing network and semantic features of the second training image obtained by the second deep convolutional neural network;
[0010] fusing the visual features and semantic features of the second training image to obtain a second fused feature;
[0011] Inputting the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value, wherein the loss function value is used to calculate the similarity between the first training image and the second training image in a Hamming space;
[0012] Determine whether the loss function value converges;
[0013] If not converged, the parameters of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network are updated, and the step of selecting two images from the data source as the first training image and the second training image is returned to execute until the loss function value converges.
[0014] Optionally, after fusing the visual features and semantic features of the first training image to obtain a first fused feature, the method further includes:
[0015] Performing dimension reduction on the first fusion feature to obtain a first target feature, and performing binarization processing on the first target feature to obtain a first target binary code;
[0016] After fusing the visual features and the semantic features of the second training image to obtain a second fused feature, the method further includes:
[0017] Performing dimension reduction on the second fusion feature to obtain a second target feature, and performing binarization processing on the second target feature to obtain a second target binary code;
[0018] The step of inputting the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value includes:
[0019] The first target binary code and the second target binary code are input into a preset loss function to obtain a loss function value.
[0020] Optionally, the initial weights of the parameters in the first shallow convolutional neural network and the initial weights of the parameters in the second shallow convolutional neural network are different from each other;
[0021] The initial weights of the parameters in the first deep convolutional neural network and the initial weights of the parameters in the second deep convolutional neural network are different from each other.
[0022] Optionally, the preset loss function is:
[0023]
[0024] Wherein, tanh() represents the hyperbolic tangent function; F represents the first fusion feature; G represents the second fusion feature; B1 represents the binary code generated by the first training image; B2 represents the binary code generated by the second training image; k represents the number of bits of the generated binary code; S represents the similarity matrix between the first training image and the second training image; S i,j represents the similarity relationship between the first training image and the second training image. If the first training image and the second training image contain the same label, then the first training image and the second training image are similar.i,j =1, otherwise S i,j =0;θ i,j represents the inner product between B1 and B2; Represents the sum of the squares of the absolute values of the elements in the matrix; τ, γ, β are non-negative parameters; B1 T represents the transpose of B1; B2 T represents the transpose of B2, (F) T represents the transpose of F; (G) T represents the transpose of G.
[0025] An image retrieval method, comprising:
[0026] In the case of receiving a retrieval request for an image to be processed, inputting the image to be processed into a shallow convolutional neural network to obtain visual features of the image to be processed obtained by the shallow convolutional neural network, wherein the shallow convolutional neural network is trained based on any one of the neural network training methods described above;
[0027] Inputting the image to be processed into a deep convolutional neural network to obtain semantic features of the image to be processed obtained by the deep convolutional neural network, wherein the deep convolutional neural network is trained based on any one of the neural network training methods described above;
[0028] fusing the visual feature and the semantic feature to obtain a fused feature;
[0029] Based on the fusion features and the fusion features of each image in the database, the similarity between the image to be processed and each image in the database is determined, and the images in the database whose similarity meets the set conditions are determined as similar images of the image to be processed.
[0030] Optionally, after fusing the visual feature and the semantic feature to obtain a fused feature, the method further includes:
[0031] Performing dimension reduction and binarization processing on the fused features to obtain a target binary code;
[0032] The determining, based on the fusion feature and the fusion feature of each image in the database, the similarity between the image to be processed and each image in the database comprises:
[0033] Based on the target binary code of the image to be processed and the target binary code of each image in the database, a Hamming distance between the image to be processed and each image in the database is calculated, and the similarity between the image to be processed and each image in the database is determined by the Hamming distance between the image to be processed and each image in the database;
[0034] The target binary code of each image in the database is obtained by performing dimensionality reduction and binarization processing on the fusion features of each image in the database.
[0035] A neural network training device, comprising:
[0036] A first determination module is used to select two images from a data source as a first training image and a second training image respectively;
[0037] A first feature extraction module, used to input the first training image into a first shallow convolutional neural network and a first deep convolutional neural network respectively, to obtain visual features of the first training image obtained by the first shallow convolutional neural network and semantic features of the first training image obtained by the first deep convolutional neural network;
[0038] A first fusion module, used for fusing the visual features and semantic features of the first training image to obtain a first fused feature;
[0039] A second feature extraction module, used to input the second training image into a second shallow convolutional neural network and a second deep convolutional neural network, respectively, to obtain visual features of the second training image obtained by the second shallow deep hashing network and semantic features of the second training image obtained by the second deep convolutional neural network;
[0040] A second fusion module, used for fusing the visual features and semantic features of the second training image to obtain a second fused feature;
[0041] a second determination module, configured to input the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value, wherein the loss function value is used to calculate the similarity between the first training image and the second training image in a Hamming space;
[0042] A judgment module, used to judge whether the loss function value converges;
[0043] An updating module is used to update the parameters of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network if the loss function value has not converged, and return to execute the step of selecting two images from the data source as the first training image and the second training image, respectively, until the loss function value converges.
[0044] An image retrieval device, comprising:
[0045] Feature extraction module for:
[0046] In the case of receiving a retrieval request for an image to be processed, inputting the image to be processed into a shallow convolutional neural network to obtain visual features of the image to be processed obtained by the shallow convolutional neural network, wherein the shallow convolutional neural network is trained based on any one of the neural network training methods described above; and
[0047] Inputting the image to be processed into a deep convolutional neural network to obtain semantic features of the image to be processed obtained by the deep convolutional neural network, wherein the deep convolutional neural network is trained based on any one of the neural network training methods described above;
[0048] A fusion module, used for fusing the visual feature and the semantic feature to obtain a fusion feature;
[0049] A determination module is used to determine the similarity between the image to be processed and each image in the database based on the fusion feature and the fusion feature of each image in the database, and determine the image in the database whose similarity meets the set conditions as a similar image to the image to be processed.
[0050] An electronic device comprises: a memory for storing at least one set of instruction sets;
[0051] The processor is used to call and execute the instruction set in the memory, and execute the image retrieval method as described above by executing the instruction set.
[0052] A computer storage medium stores a computer program, which is executed by a processor to implement the image retrieval method as described above.
[0053] Compared with the prior art, the beneficial effects of this application are:
[0054] In the present application, a first shallow convolutional neural network, a first deep convolutional neural network, a second shallow convolutional neural network, and a second deep convolutional neural network are trained by a preset loss function, so that the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network can learn to extract features related to image similarity. On this basis, shallow convolutional neural networks and deep convolutional neural networks are used to extract different types of features, and the features are fused so that the fused features can represent richer image information, so that the image can be retrieved using the fused features, which can improve the accuracy of image retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments 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 drawings can be obtained based on these drawings without paying any creative labor.
[0056] Figure 1 It is a flowchart of a neural network training method provided in Example 1 of the present application;
[0057] Figure 2 It is a flowchart of a neural network training method provided in Example 2 of the present application;
[0058] Figure 3 It is a schematic diagram of the structure of a neural network provided by this application;
[0059] Figure 4 is a flowchart of an image retrieval method provided in Example 3 of the present application;
[0060] Figure 5 is a flowchart of an image retrieval method provided in Example 4 of the present application;
[0061] Figure 6 It is a structural schematic diagram of a neural network training device provided by the present application;
[0062] Figure 7 It is a structural schematic diagram of an image retrieval device provided by this application. DETAILED DESCRIPTION
[0063] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0064] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0065] Reference Figure 1 , is a flowchart of a neural network training method provided in Example 1 of the present application. The method can be applied to electronic devices. The present application does not limit the product type of the electronic device. For example, Figure 1 As shown, the method may include but is not limited to the following steps:
[0066] Step S11: Select two images from a data source as a first training image and a second training image respectively.
[0067] Step S12: input the first training image into a first shallow convolutional neural network and a first deep convolutional neural network respectively, to obtain visual features of the first training image obtained by the first shallow convolutional neural network and semantic features of the first training image obtained by the first deep convolutional neural network.
[0068] The visual features of the first training image may include but are not limited to: color features and / or texture features of the first training image.
[0069] The semantic feature of the first training image can represent the semantic description information of the first training image.
[0070] The number of layers of the first shallow convolutional neural network is different from the number of layers of the first deep convolutional neural network, and the convolution kernel size of the first shallow convolutional neural network is different from the convolution kernel size of the first deep convolutional neural network.
[0071] Specifically, the first shallow convolutional neural network may be, but is not limited to, composed of four convolutional layers, and may map a 3-dimensional first training image of size 224x224 to a 128-dimensional visual feature of size 7x7.
[0072] The first deep convolutional neural network may be, but is not limited to, a ResNet50 network, which may map a 3-dimensional 224x224-sized first training image into a 512-dimensional 7x7-sized semantic feature.
[0073] Step S13: Fusing the visual features and semantic features of the first training image to obtain a first fused feature.
[0074] The fusion of the visual features and the semantic features of the first training image may include but is not limited to:
[0075] The visual features and semantic features of the first training image are concatenated in the channel dimension. For example, the 128-dimensional 7x7-sized visual features are concatenated with the 512-dimensional 7x7-sized semantic features to obtain the 640-dimensional 14x14-sized first fusion features.
[0076] Step S14: input the second training image into a second shallow convolutional neural network and a second deep convolutional neural network respectively, to obtain the visual features of the second training image obtained by the second shallow deep hash network and the semantic features of the second training image obtained by the second deep convolutional neural network.
[0077] The visual features of the second training image may include but are not limited to: color features and / or texture features of the second training image.
[0078] The semantic feature of the second training image can represent the semantic description information of the second training image.
[0079] The number of layers of the second shallow convolutional neural network is different from the number of layers of the second deep convolutional neural network, and the convolution kernel size of the second shallow convolutional neural network is different from the convolution kernel size of the second deep convolutional neural network.
[0080] Specifically, the second shallow convolutional neural network may be, but is not limited to, composed of four convolutional layers, and may map a 3-dimensional second training image of size 224x224 to a 128-dimensional visual feature of size 7x7.
[0081] The second deep convolutional neural network may be, but is not limited to, a ResNet50 network, which may map a 3-dimensional second training image of size 224x224 to a 512-dimensional semantic feature of size 7x7.
[0082] In this embodiment, the initial weights of the parameters in the first shallow convolutional neural network and the initial weights of the parameters in the second shallow convolutional neural network may be the same;
[0083] The initial weights of the parameters in the first deep convolutional neural network may be the same as the initial weights of the parameters in the second deep convolutional neural network.
[0084] Of course, the initial weights of the parameters in the first shallow convolutional neural network and the initial weights of the parameters in the second shallow convolutional neural network may also be different from each other, and the initial weights of the parameters in the first deep convolutional neural network and the initial weights of the parameters in the second deep convolutional neural network may also be different from each other.
[0085] Among them, the initial weights of the parameters in the first shallow convolutional neural network are different from the initial weights of the parameters in the second shallow convolutional neural network, and the initial weights of the parameters in the first deep convolutional neural network are different from the initial weights of the parameters in the second deep convolutional neural network, which can make the trained first shallow convolutional neural network different from the second shallow convolutional neural network, and the trained first deep convolutional neural network different from the second deep convolutional neural network, ensuring that the first shallow convolutional neural network and the first deep convolutional neural network and the second shallow neural network and the second deep convolutional neural network can more accurately learn the similarity between the first training image and the second training image, and the first shallow convolutional neural network and the first deep convolutional neural network and the second shallow convolutional neural network and the second deep convolutional neural network can more accurately extract features related to image similarity, further improving the accuracy of image retrieval.
[0086] Step S15: Fusing the visual features and semantic features of the second training image to obtain a second fused feature.
[0087] The fusion of the visual features and the semantic features of the second training image may include but is not limited to:
[0088] The visual features and semantic features of the second training image are concatenated in the channel dimension. For example, the 128-dimensional 7x7-sized visual features are concatenated with the 512-dimensional 7x7-sized semantic features to obtain the 640-dimensional 14x14-sized second fusion features.
[0089] Step S16: input the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value, and the loss function value is used to calculate the similarity between the first training image and the second training image in the Hamming space.
[0090] The loss function value is used to calculate the similarity between the first training image and the second training image in the Hamming space, which can be understood as: the loss function value is used to reduce the Hamming distance between similar points and increase the Hamming distance between dissimilar points.
[0091] The more similar the first training image is to the second training image, the smaller the Hamming distance between the first training image and the second training image is.
[0092] In this embodiment, the specific implementation method of the loss function is not limited, and at least it is sufficient to ensure that the loss function value can be used to calculate the similarity between the first training image and the second training image in the Hamming space.
[0093] Step S17: Determine whether the loss function value converges.
[0094] Judging whether the loss function value converges can be understood as: judging whether the change trend of the loss function value is a decreasing trend;
[0095] Or, determine whether the change trend of the loss function value is a decreasing trend. If so, determine whether the difference between the loss function value calculated this time and the loss function value calculated last time is less than a preset value.
[0096] If not, step S18 is executed. If converged, it can be considered that the training of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network has reached the set requirements, and the training is terminated.
[0097] Step S18, updating the parameters of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network, and returning to execute step S11 until the loss function value converges.
[0098] In this embodiment, the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network are trained by a pre-set loss function, so that the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network learn to extract features related to image similarity. On this basis, the shallow convolutional neural network and the deep convolutional neural network are used to extract different types of features, and the features are fused so that the fused features can represent richer image information, so that the image can be retrieved using the fused features, which can improve the accuracy of image retrieval. For example, images in real scenes, such as cables in the power grid field or images of workers repairing, are easily affected by the interference of real scenes, such as different light intensities, different shooting angles, different scenes, too cluttered backgrounds, objects blocked by foreign objects, etc. These factors will affect the image retrieval results to a large extent. In order to reduce the interference of the real environment, the present application extracts visual features and semantic features from the input image through two different convolutional neural networks, performs image retrieval based on visual features and semantic features, and ensures the accuracy of image retrieval.
[0099] As another optional embodiment of the present application, refer to Figure 2 , is a flowchart of a neural network training method provided in Example 2 of the present application. This embodiment is mainly an extension of the neural network training method described in Example 1 above. Figure 2 As shown, the method may include but is not limited to the following steps:
[0100] Step S21, selecting two images from a data source, as a first training image and a second training image respectively;
[0101] Step S22: inputting the first training image into a first shallow convolutional neural network and a first deep convolutional neural network respectively, to obtain visual features of the first training image obtained by the first shallow convolutional neural network and semantic features of the first training image obtained by the first deep convolutional neural network;
[0102] Step S23: Fusing the visual features and semantic features of the first training image to obtain a first fused feature.
[0103] In this embodiment, the feature fusion layer may fuse the visual features and semantic features of the first training image to obtain a first fused feature.
[0104] The detailed process of steps S21-S23 can refer to the relevant introduction of steps S11-S13 in Example 1, which will not be repeated here.
[0105] Step S24: perform dimension reduction on the first fusion feature to obtain a first target feature, and perform binarization processing on the first target feature to obtain a first target binary code.
[0106] In this embodiment, the hash layer may perform dimension reduction on the first fusion feature to obtain a first target feature, and perform binarization processing on the first target feature to obtain a first target binary code.
[0107] The hash layer may include three fully connected layers. The first fully connected layer linearly combines the fused features output by the feature fusion layer. The output of the first fully connected layer serves as the input of the second fully connected layer. The second fully connected layer deepens the network depth, increases the number of neurons, and improves the model learning ability. The output of the second fully connected layer serves as the input of the third fully connected layer. The third fully connected layer reduces the dimension of the features output by the second fully connected layer to a fixed number of bits (e.g., 16 bits, 32 bits, or 64 bits), and binarizes the reduced features and maps them to +1 and -1.
[0108] Binarization processing may include but is not limited to: using a sign function sign() for binarization processing, or using a hyperbolic tangent function tanh() for binarization processing. Among them, using the hyperbolic tangent function tanh() for binarization processing can ensure more accurate and convenient back propagation when updating the parameters of the neural network.
[0109] For example, when the first fused feature and the second fused feature are both 640-dimensional 14x14 features, the feature fusion layer can use a 14x14x640 convolution kernel to convolve with the feature, and the values obtained by the convolution are summed to obtain an output value, which is used as the input of the first fully connected layer. The first fully connected layer uses a global convolution with a convolution kernel of 14x14x640x4096 (4096 14x14x640 convolution kernels) to convolve with the feature to obtain a 4096-dimensional feature as the input of the second fully connected layer. The second fully connected layer processes the 4096-dimensional feature and still outputs the 4096-dimensional feature to the third fully connected layer. The third fully connected layer reduces the dimension of the 4096-dimensional feature and performs binarization.
[0110] Step S25, inputting the second training image into a second shallow convolutional neural network and a second deep convolutional neural network respectively, obtaining visual features of the second training image obtained by the second shallow deep hash network and semantic features of the second training image obtained by the second deep convolutional neural network;
[0111] Step S26: Fusing the visual features and semantic features of the second training image to obtain a second fused feature.
[0112] The detailed process of steps S25-S26 can refer to the relevant introduction of steps S14-S15 in Example 1, which will not be repeated here.
[0113] Step S27: perform dimension reduction on the second fusion feature to obtain a second target feature, and perform binarization processing on the second target feature to obtain a second target binary code.
[0114] Step S28: input the first target binary code and the second target binary code into a preset loss function to obtain a loss function value, wherein the loss function value is used to calculate the similarity between the first training image and the second training image in the Hamming space.
[0115] In this embodiment, the preset loss function may be, but is not limited to:
[0116]
[0117] Wherein, tanh() represents the hyperbolic tangent function; F represents the first fusion feature; G represents the second fusion feature; B1 represents the binary code generated by the first training image; B2 represents the binary code generated by the second training image; k represents the number of bits of the generated binary code; S represents the similarity matrix between the first training image and the second training image; S i,jrepresents the similarity relationship between the first training image and the second training image. If the first training image and the second training image contain the same label, then the first training image and the second training image are similar. i,j =1, otherwise S i,j =0;θ i,j represents the inner product between B1 and B2; Represents the sum of the squares of the absolute values of the elements in the matrix; τ, γ, β are non-negative parameters; B1 T represents the transpose of B1; B2 T represents the transpose of B2, (F) T represents the transpose of F; (G) T represents the transpose of G.
[0118] Among them, the second term in the loss function The similarity loss is represented by The similarity loss learns the similarity relationship between images through the label information of the images, where represents the similarity relationship between the first training image and the second training image. If the first training image and the second training image contain the same label, then the first training image and the second training image are similar, S i,j =1, otherwise S i,j = 0. If the first training image and the second training image are similar, their binary codes should be similar. If the Hamming input images are similar, their binary codes should be similar, and the Hamming distance is smaller. The optimization problem of the similarity loss can reduce the Hamming distance between similar points and increase the Hamming distance between dissimilar points, thus completing the learning of the similarity relationship between image pairs.
[0119] The third term in the loss function The representation uses the inner product of the original features and the binary code to measure the similarity between the first training image and the second training image. The smaller the inner product, the greater the similarity. Therefore, when the neural network is updated and optimized, this loss can be used to maintain the similarity between the original features and the binary code.
[0120] Step S28 is a specific implementation of step S16 in Example 1.
[0121] Step S29, determining whether the loss function value converges;
[0122] If not converged, execute step S210.
[0123] Step S210, update the parameters of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network, and return to execute step S21 until the loss function value converges.
[0124] The detailed process of steps S29-S210 can refer to the relevant introduction of steps S17-S18 in Example 1, which will not be repeated here.
[0125] In this embodiment, the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network, and the second deep convolutional neural network are trained by a pre-set loss function, so that the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network, and the second deep convolutional neural network can learn to extract features related to image similarity. On this basis, the shallow convolutional neural network and the deep convolutional neural network are used to extract different types of features, and the features are fused so that the fused features can represent richer image information, which can improve the accuracy of training and thus improve the accuracy of image retrieval. In addition, the fused features are subjected to dimensionality reduction and binarization processing to improve the efficiency of training. For example, Figure 3 As shown, picture i is input into the first shallow convolutional neural network and the first deep convolutional neural network, picture j is input into the second shallow convolutional neural network and the second deep convolutional neural network, the visual features obtained by the first shallow convolutional neural network and the semantic features obtained by the first deep convolutional neural network are output, and the visual features obtained by the second shallow convolutional neural network and the semantic features obtained by the second deep convolutional neural network are given to the feature fusion layer, the feature fusion layer fuses the visual features obtained by the first shallow convolutional neural network and the semantic features obtained by the first deep convolutional neural network to obtain the first fusion feature, and fuses the visual features of the second shallow convolutional neural network and the semantic features obtained by the second deep convolutional neural network to obtain the second fusion feature, which can ensure the richness of the features, improve the training accuracy, and thus improve the accuracy of image retrieval. The feature fusion layer inputs the first fusion feature and the second fusion feature into the hash layer, and the hash layer performs dimensionality reduction and binarization processing on the first fusion feature and the second fusion feature respectively to obtain the first target binary code and the second target binary code, and gives the first target binary code and the second target binary code to the loss function, and the loss function calculates the loss function value, which can reduce the amount of calculation and improve the training efficiency.
[0126] Reference Figure 4 , is a flow chart of an image retrieval method provided in Example 3 of the present application. The method can be applied to electronic devices. The present application does not limit the product type of the electronic device. For example, Figure 3 As shown, the method may include but is not limited to the following steps:
[0127] Step S31: when a search request for an image to be processed is received, the image to be processed is input into a shallow convolutional neural network to obtain visual features of the image to be processed obtained by the shallow convolutional neural network.
[0128] The shallow convolutional neural network is one of the first shallow convolutional neural network and the second shallow convolutional neural network trained based on the neural network training method introduced in Example 1 or 2.
[0129] Step S32: input the image to be processed into a deep convolutional neural network to obtain semantic features of the image to be processed obtained by the deep convolutional neural network.
[0130] The deep convolutional neural network is one of the first deep convolutional neural network and the second deep convolutional neural network trained based on the neural network training method introduced in Example 1 or 2.
[0131] Step S33: Fusing the visual feature and the semantic feature to obtain a fused feature.
[0132] Step S34: Based on the fusion features and the fusion features of each image in the database, determine the similarity between the image to be processed and each image in the database, and determine the images in the database whose similarity meets the set conditions as similar images of the image to be processed.
[0133] In this embodiment, the fusion features of each image in the database may be pre-generated, and the pre-generation process may include:
[0134] S341, inputting each image in the database into a shallow convolutional neural network respectively, to obtain visual features of the image obtained by the shallow convolutional neural network, wherein the shallow convolutional neural network is one of a first shallow convolutional neural network and a second shallow convolutional neural network trained by the neural network training method introduced in Example 1 or 2;
[0135] S342, inputting each image in the database into a deep convolutional neural network respectively, to obtain semantic features of the image obtained by the deep convolutional neural network, wherein the deep convolutional neural network is one of a first deep convolutional neural network and a second deep convolutional neural network trained by the neural network training method introduced in Example 1 or 2;
[0136] S343, fusing the visual features and the semantic features of each image in the database to obtain fused features, and constructing a mapping relationship between the fused features of each image and the image.
[0137] In this embodiment, based on the fusion feature and the fusion feature of each image in the database, the similarity between the image to be processed and each image in the database is determined.
[0138] When a search request for an image to be processed is received, the image to be processed and each image in the database are respectively input into the deep hash network to obtain the feature value output by the deep hash network.
[0139] In this embodiment, the deep hash network is trained based on the hash network training method introduced in the above method embodiment 1 or 2.
[0140] In this embodiment, based on the fusion feature and the fusion feature of each image in the database, determining the similarity between the image to be processed and each image in the database may include but is not limited to:
[0141] Based on the target features of the image to be processed and the target features of each image in the database, the Hamming distance between the image to be processed and each image in the database is calculated, and the similarity between the image to be processed and each image in the database is determined through the Hamming distance between the image to be processed and each image in the database.
[0142] In this embodiment, a shallow convolutional neural network and a deep convolutional neural network are used to extract different types of features of the image to be processed, and the features are fused so that the fused features can represent richer image information, so that the image can be retrieved using the fused features, which can improve the accuracy of image retrieval.
[0143] As another optional embodiment of the present application, refer to Figure 5 , is a flow chart of an image retrieval method provided in Example 4 of the present application. This embodiment is mainly an extension of the image retrieval method described in Example 3 above. Figure 5 As shown, the method may include but is not limited to the following steps:
[0144] Step S41: When a retrieval request for an image to be processed is received, the image to be processed is input into a shallow convolutional neural network to obtain visual features of the image to be processed obtained by the shallow convolutional neural network.
[0145] The shallow convolutional neural network is one of the first shallow convolutional neural network and the second shallow convolutional neural network trained based on the neural network training method introduced in Example 1 or 2.
[0146] Step S42: input the image to be processed into a deep convolutional neural network to obtain semantic features of the image to be processed obtained by the deep convolutional neural network.
[0147] The deep convolutional neural network is one of the first deep convolutional neural network and the second deep convolutional neural network trained based on the neural network training method introduced in Example 1 or 2.
[0148] Step S43: Fusing the visual feature and the semantic feature to obtain a fused feature.
[0149] The detailed process of steps S41-S43 can refer to the relevant introduction of steps S31-S33 in Example 3, which will not be repeated here.
[0150] Step S44: perform dimension reduction and binarization processing on the fused features to obtain a target binary code.
[0151] Step S45: Calculate the Hamming distance between the image to be processed and each image in the database based on the target binary code of the image to be processed and the target binary code of each image in the database, and determine the similarity between the image to be processed and each image in the database through the Hamming distance between the image to be processed and each image in the database.
[0152] The target binary code of each image in the database is obtained by performing dimensionality reduction and binarization processing on the fusion features of each image in the database.
[0153] Step S46: Determine the images in the database whose similarity meets the set conditions as similar images to the image to be processed.
[0154] Steps S45-S46 are a specific implementation of step S34 in Example 3.
[0155] In this embodiment, a shallow convolutional neural network and a deep convolutional neural network are used to extract different types of features of the image to be processed, and the features are fused. The fused features are reduced in dimension and binarized. The target binary code can represent richer image information, reduce the amount of calculation, and improve the accuracy and efficiency of image retrieval.
[0156] Next, the neural network training device provided by the present application is introduced. The neural network training device introduced below and the neural network training method introduced above can be referenced to each other.
[0157] See also Figure 6 The neural network training device includes: a first determination module 100, a first feature extraction module 200, a first fusion module 300, a second feature extraction module 400, a second fusion module 500, a second determination module 600, a judgment module 700 and an update module 800.
[0158] A first determination module 100 is used to select two images from a data source as a first training image and a second training image respectively;
[0159] A first feature extraction module 200, used to input the first training image into a first shallow convolutional neural network and a first deep convolutional neural network, respectively, to obtain visual features of the first training image obtained by the first shallow convolutional neural network and semantic features of the first training image obtained by the first deep convolutional neural network;
[0160] A first fusion module 300, configured to fuse the visual features and semantic features of the first training image to obtain a first fused feature;
[0161] A second feature extraction module 400, used to input the second training image into a second shallow convolutional neural network and a second deep convolutional neural network, respectively, to obtain visual features of the second training image obtained by the second shallow deep hashing network and semantic features of the second training image obtained by the second deep convolutional neural network;
[0162] A second fusion module 500, configured to fuse the visual features and semantic features of the second training image to obtain a second fused feature;
[0163] A second determination module 600, configured to input the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value, wherein the loss function value is used to calculate the similarity between the first training image and the second training image in a Hamming space;
[0164] A judgment module 700 is used to judge whether the loss function value converges;
[0165] The updating module 800 is used to update the parameters of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network and the second deep convolutional neural network if the loss function value has not converged, and return to execute the step of selecting two images from the data source as the first training image and the second training image, respectively, until the loss function value converges.
[0166] In this embodiment, the neural network training device may further include:
[0167] A first dimension reduction module is used to reduce the dimension of the first fusion feature to obtain a first target feature, and perform binarization processing on the first target feature to obtain a first target binary code;
[0168] A second dimension reduction module is used to reduce the dimension of the second fusion feature to obtain a second target feature, and perform binarization processing on the second target feature to obtain a second target binary code;
[0169] Accordingly, the second determining module 600 may be specifically configured to:
[0170] The first target binary code and the second target binary code are input into a preset loss function to obtain a loss function value.
[0171] In this embodiment, the initial weights of the parameters in the first shallow convolutional neural network and the initial weights of the parameters in the second shallow convolutional neural network are different from each other;
[0172] The initial weights of the parameters in the first deep convolutional neural network and the initial weights of the parameters in the second deep convolutional neural network are different from each other.
[0173] In this embodiment, the preset loss function may be:
[0174]
[0175] Wherein, tanh() represents the hyperbolic tangent function; F represents the first fusion feature; G represents the second fusion feature; B1 represents the binary code generated by the first training image; B2 represents the binary code generated by the second training image; k represents the number of bits of the generated binary code; S represents the similarity matrix between the first training image and the second training image; S i,j represents the similarity relationship between the first training image and the second training image. If the first training image and the second training image contain the same label, then the first training image and the second training image are similar. i,j =1, otherwise S i,j =0;θ i,j represents the inner product between B1 and B2; Represents the sum of the squares of the absolute values of the elements in the matrix; τ, γ, β are non-negative parameters; B1 T represents the transpose of B1; B2 T represents the transpose of B2, (F) T represents the transpose of F; (G) T represents the transpose of G.
[0176] Next, the image retrieval device provided by the present application is introduced. The image retrieval device introduced below and the image retrieval method introduced above can be referenced to each other.
[0177] See also Figure 7 The image retrieval device includes: a feature extraction module 10, a fusion module 20 and a determination module 30.
[0178] The feature extraction module 10 is used to:
[0179] In the case of receiving a retrieval request for an image to be processed, inputting the image to be processed into a shallow convolutional neural network to obtain visual features of the image to be processed obtained by the shallow convolutional neural network, wherein the shallow convolutional neural network is trained based on the neural network training method introduced in Example 1 or 2; and
[0180] Inputting the image to be processed into a deep convolutional neural network to obtain semantic features of the image to be processed obtained by the deep convolutional neural network, wherein the deep convolutional neural network is trained based on the neural network training method introduced in Example 1 or 2;
[0181] A fusion module 20, used for fusing the visual feature and the semantic feature to obtain a fusion feature;
[0182] The determination module 30 is used to determine the similarity between the image to be processed and each image in the database based on the fusion feature and the fusion feature of each image in the database, and determine the image in the database whose similarity meets the set conditions as a similar image of the image to be processed.
[0183] The above-mentioned image retrieval device may further include: a dimension reduction module, which is used to perform dimension reduction and binarization processing on the fused features to obtain a target binary code.
[0184] In this embodiment, the determination module 30 may be specifically used for:
[0185] Based on the target binary code of the image to be processed and the target binary code of each image in the database, a Hamming distance between the image to be processed and each image in the database is calculated, and the similarity between the image to be processed and each image in the database is determined by the Hamming distance between the image to be processed and each image in the database;
[0186] The target binary code of each image in the database is obtained by performing dimensionality reduction and binarization processing on the fusion features of each image in the database.
[0187] In another embodiment of the present application, an electronic device is provided, comprising: a memory for storing at least one set of instruction sets;
[0188] The processor is used to call and execute the instruction set in the memory, and execute the image retrieval method introduced in Example 3 or 4 by executing the instruction set.
[0189] In another embodiment of the present application, a computer storage medium is provided, on which a computer program is stored. The computer program is executed by a processor to implement the image retrieval method introduced in Example 3 or 4.
[0190] It should be noted that each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0191] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0192] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0193] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.
[0194] The above is a detailed introduction to a neural network training method, image retrieval method and device provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A neural network training method, characterized in that: include: Select two images from a data source as a first training image and a second training image respectively; Inputting the first training image into a first shallow convolutional neural network and a first deep convolutional neural network respectively, to obtain visual features of the first training image obtained by the first shallow convolutional neural network and semantic features of the first training image obtained by the first deep convolutional neural network; fusing the visual features and semantic features of the first training image to obtain a first fused feature; Inputting the second training image into a second shallow convolutional neural network and a second deep convolutional neural network respectively, obtaining visual features of the second training image obtained by the second shallow deep hashing network and semantic features of the second training image obtained by the second deep convolutional neural network; fusing the visual features and semantic features of the second training image to obtain a second fused feature; Inputting the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value, wherein the loss function value is used to calculate the similarity between the first training image and the second training image in a Hamming space; Determine whether the loss function value converges; If not converged, updating the parameters of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network, and the second deep convolutional neural network, and returning to execute the step of selecting two images from the data source as the first training image and the second training image, respectively, until the loss function value converges; The pre-set loss function is: Wherein, tanh() represents the hyperbolic tangent function; F represents the first fusion feature; G represents the second fusion feature; B1 represents the binary code generated by the first training image; B2 represents the binary code generated by the second training image; k represents the number of bits of the generated binary code; S represents the similarity matrix between the first training image and the second training image; S ij represents the similarity relationship between the first training image and the second training image. If the first training image and the second training image contain the same label, then the first training image and the second training image are similar. ij =1, otherwise S i,j =0;θ i,j represents the inner product between B1 and B2; Represents the sum of the squares of the absolute values of the elements in the matrix; τ, γ, β are non-negative parameters; B1 T represents the transpose of B1; B2 T represents the transpose of B2, (F)T represents the transpose of F, and (G)T represents the transpose of G.
2. The method according to claim 1, characterized in that After fusing the visual features and semantic features of the first training image to obtain a first fused feature, the method further includes: Performing dimension reduction on the first fusion feature to obtain a first target feature, and performing binarization processing on the first target feature to obtain a first target binary code; After fusing the visual features and the semantic features of the second training image to obtain a second fused feature, the method further includes: Performing dimension reduction on the second fusion feature to obtain a second target feature, and performing binarization processing on the second target feature to obtain a second target binary code; The step of inputting the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value includes: The first target binary code and the second target binary code are input into a preset loss function to obtain a loss function value.
3. The method according to claim 1, characterized in that The initial weights of the parameters in the first shallow convolutional neural network and the initial weights of the parameters in the second shallow convolutional neural network are different from each other; The initial weights of the parameters in the first deep convolutional neural network and the initial weights of the parameters in the second deep convolutional neural network are different from each other.
4. An image retrieval method, characterized in that: include: In the case of receiving a retrieval request for an image to be processed, inputting the image to be processed into a shallow convolutional neural network to obtain visual features of the image to be processed obtained by the shallow convolutional neural network, wherein the shallow convolutional neural network is trained based on the neural network training method according to any one of claims 1 to 3; Inputting the image to be processed into a deep convolutional neural network to obtain semantic features of the image to be processed obtained by the deep convolutional neural network, wherein the deep convolutional neural network is trained based on the neural network training method according to any one of claims 1 to 3; fusing the visual feature and the semantic feature to obtain a fused feature; Based on the fusion features and the fusion features of each image in the database, the similarity between the image to be processed and each image in the database is determined, and the images in the database whose similarity meets the set conditions are determined as similar images of the image to be processed.
5. The method according to claim 4, characterized in that After fusing the visual features and the semantic features to obtain the fused features, the method further includes: Performing dimension reduction and binarization processing on the fused features to obtain a target binary code; The determining, based on the fusion feature and the fusion feature of each image in the database, the similarity between the image to be processed and each image in the database comprises: Based on the target binary code of the image to be processed and the target binary code of each image in the database, a Hamming distance between the image to be processed and each image in the database is calculated, and the similarity between the image to be processed and each image in the database is determined by the Hamming distance between the image to be processed and each image in the database; The target binary code of each image in the database is obtained by performing dimensionality reduction and binarization processing on the fusion features of each image in the database.
6. A neural network training device, characterized in that: include: A first determination module is used to select two images from a data source as a first training image and a second training image respectively; A first feature extraction module, used to input the first training image into a first shallow convolutional neural network and a first deep convolutional neural network respectively, to obtain visual features of the first training image obtained by the first shallow convolutional neural network and semantic features of the first training image obtained by the first deep convolutional neural network; A first fusion module, used for fusing the visual features and semantic features of the first training image to obtain a first fused feature; A second feature extraction module, used to input the second training image into a second shallow convolutional neural network and a second deep convolutional neural network, respectively, to obtain visual features of the second training image obtained by the second shallow deep hashing network and semantic features of the second training image obtained by the second deep convolutional neural network; A second fusion module, used for fusing the visual features and semantic features of the second training image to obtain a second fused feature; a second determination module, configured to input the first fusion feature and the second fusion feature into a preset loss function to obtain a loss function value, wherein the loss function value is used to calculate the similarity between the first training image and the second training image in a Hamming space; A judgment module, used to judge whether the loss function value converges; An updating module, configured to update the parameters of the first shallow convolutional neural network, the first deep convolutional neural network, the second shallow convolutional neural network, and the second deep convolutional neural network if the loss function value has not converged, and return to execute the step of selecting two images from the data source as the first training image and the second training image, respectively, until the loss function value converges; The pre-set loss function is: Wherein, tanh() represents the hyperbolic tangent function; F represents the first fusion feature; G represents the second fusion feature; B1 represents the binary code generated by the first training image; B2 represents the binary code generated by the second training image; k represents the number of bits of the generated binary code; S represents the similarity matrix between the first training image and the second training image; S ij represents the similarity relationship between the first training image and the second training image. If the first training image and the second training image contain the same label, then the first training image and the second training image are similar. ij =1, otherwise S i,j =0;θ i,j represents the inner product between B1 and B2; Represents the sum of the squares of the absolute values of the elements in the matrix; τ, γ, β are non-negative parameters; B1 T represents the transpose of B1; B2 T represents the transpose of B2, (F)T represents the transpose of F; G )T represents the transpose of G.
7. An image retrieval device, characterized in that: include: Feature extraction module for: In the case of receiving a retrieval request for an image to be processed, inputting the image to be processed into a shallow convolutional neural network to obtain visual features of the image to be processed obtained by the shallow convolutional neural network, wherein the shallow convolutional neural network is trained based on the neural network training method according to any one of claims 1 to 3; and, Inputting the image to be processed into a deep convolutional neural network to obtain semantic features of the image to be processed obtained by the deep convolutional neural network, wherein the deep convolutional neural network is trained based on the neural network training method according to any one of claims 1 to 3; A fusion module, used for fusing the visual feature and the semantic feature to obtain a fusion feature; A determination module is used to determine the similarity between the image to be processed and each image in the database based on the fusion feature and the fusion feature of each image in the database, and determine the image in the database whose similarity meets the set conditions as a similar image of the image to be processed.
8. An electronic device, characterized in that: include: A memory for storing at least one set of instructions; A processor is used to call and execute the instruction set in the memory, and to execute the image retrieval method as claimed in claim 4 or 5 by executing the instruction set.
9. A computer storage medium, characterized in that A computer program is stored thereon, and the computer program is executed by a processor to implement the image retrieval method as claimed in claim 4 or 5.
Citation Information
Patent Citations
Small sample silk fabric image retrieval method combining shallow and deep features
CN113343019A
