Image recognition model training method, device, electronic device and storage medium
By calculating and subtracting the image feature vector, an image feature vector without context offset is obtained and used for model training, the problem of context offset in deep network models in image recognition tasks is solved, and the effective application of the model in different tasks is realized.
Patent Information
- Application Number
- CN202210225261.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-09
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2042-03-09
AI Technical Summary
Existing deep network models are prone to context shifts in image recognition tasks, which makes the model unable to be effectively applied in different tasks.
By calculating the average image feature vector and fraction vector of each category, the second image feature is obtained, and then the first image feature vector of the sample image is subtracted from the second image feature vector to obtain a third image feature vector, which represents the image feature without context offset and is used for model training.
The context shift phenomenon of image recognition model when performing image recognition tasks is eliminated, so that the model can be applied more effectively in different recognition tasks.
Smart Images

Figure CN114612753B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image recognition technology, and in particular to a training method, device, electronic device and storage medium for an image recognition model. Background Art
[0002] With the development of deep network models, they are also used in image recognition tasks. However, since existing deep network models for image recognition are data-driven and rely on data probability statistics, context shift occurs. Context shift refers to when an object in a data set often appears in a location, the deep network model will directly judge the existence of the object because the location appears in the image.
[0003] In recent years, the method to eliminate the context offset phenomenon is to train the model based on a data set without context offset according to the specific recognition task. However, the data set used by this model still has context offset for other tasks. Therefore, this training model cannot be applied to other recognition tasks. Summary of the invention
[0004] In view of this, the purpose of the present application is to provide a training method, device, electronic device and storage medium for an image recognition model, which can obtain a second image feature by calculating the average image feature vector and score vector of each category, and then subtract the second image feature vector from the first image feature vector of the sample image to obtain a third image feature vector, where the third image feature is the image feature without context offset. The model is then trained using the image feature vector without context offset, so that the image recognition model obtained in this way will eliminate the context offset phenomenon when performing image recognition tasks.
[0005] In a first aspect, an embodiment of the present application provides a method for training an image recognition model, the method comprising:
[0006] Obtaining a first image feature vector corresponding to the sample image; calculating an average image feature vector of each category according to the categories corresponding to all sample images and the first image feature vector;
[0007] Input the sample image into the latest updated image recognition model to obtain the score vector corresponding to the sample image; the score vector contains the predicted score for each category;
[0008] For each sample image, determine a second image feature vector corresponding to the sample image according to the average image feature vector of all categories and the score vector corresponding to the sample image;
[0009] Subtracting a second image feature vector corresponding to the sample image from the image feature vector of the sample image to calculate a third image feature vector of the sample image;
[0010] The latest updated image recognition model is updated according to the third image feature vectors and their categories of all sample images.
[0011] In a possible implementation, after updating the image recognition model according to the third image feature vectors and their categories of all sample images, the method further includes:
[0012] Determine the accuracy of the latest updated image recognition model;
[0013] If the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the previous round, jump to the step of inputting the sample image into the latest updated image recognition model to obtain the score vector corresponding to the sample image;
[0014] If the accuracy of the latest updated image recognition model is less than or equal to the accuracy of the image recognition model updated in the previous round, the latest updated image recognition model is determined as the final image recognition model.
[0015] In a possible implementation, obtaining a first image feature vector corresponding to the sample image includes:
[0016] The sample image is input into the latest updated image recognition model to obtain the first image feature vector corresponding to the sample image.
[0017] In a possible implementation, calculating the average image feature vector of each category according to the categories corresponding to all sample images and the first image feature vector includes:
[0018] For each category, calculate the number of categories corresponding to all sample images that are the same as the category, and obtain the first value of the category;
[0019] Adding the first image feature vectors of all sample images belonging to the category, calculating the sum of the image feature vectors of the category, and obtaining a second value;
[0020] The second value corresponding to the category is divided by the first value corresponding thereto to calculate the average image feature vector of the category.
[0021] In a possible implementation, determining the second image feature vector corresponding to the sample image according to the average image feature vector of all categories and the score vector corresponding to the sample image includes:
[0022] Perform non-negative processing on the score vector corresponding to the sample image to obtain a non-negative score vector;
[0023] Normalize the non-negative score vector to obtain the probability weight vector corresponding to the sample image; the probability weight vector contains the predicted probability of each category;
[0024] The probability weight vector corresponding to the sample image is multiplied by a matrix composed of average image feature vectors of all categories to calculate a second image feature vector corresponding to the sample image.
[0025] In a second aspect, an embodiment of the present application further provides a training device for an image recognition model, the device comprising:
[0026] An acquisition module, used for acquiring a first image feature vector corresponding to a sample image;
[0027] A calculation module, used for calculating the average image feature vector of each category according to the categories and image feature vectors corresponding to all sample images;
[0028] An input module is used to input the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image; the score vector contains the predicted score for each category;
[0029] A determination module, used for determining, for each sample image, a second image feature vector corresponding to the sample image according to the average image feature vector of all categories and the score vector corresponding to the sample image;
[0030] The calculation module is further used to subtract the second image feature vector corresponding to the sample image from the image feature vector of the sample image to calculate a third image feature vector of the sample image;
[0031] The updating module is used to update the latest updated image recognition model according to the third image feature vectors and their categories of all sample images.
[0032] In a possible implementation manner, the device further includes: a jump module;
[0033] The determination module is also used to determine the accuracy of the latest updated image recognition model;
[0034] A jump module, used for jumping to the step of inputting the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image if the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the previous round;
[0035] The determination module is also used to determine the latest updated image recognition model as the final image recognition model if the accuracy of the latest updated image recognition model is less than or equal to the accuracy of the image recognition model updated in the previous round.
[0036] In a possible implementation, the acquisition module is specifically configured to input the sample image into a newly updated image recognition model to acquire a first image feature vector corresponding to the sample image.
[0037] In one possible implementation, the calculation module is specifically used to calculate, for each category, the number of categories corresponding to all sample images that is the same as the category, to obtain a first value of the category; add the image feature vectors of all sample images belonging to the category, calculate the sum of the image feature vectors of the category, and obtain a second value; divide the second value corresponding to the category by the first value corresponding to it, and calculate the average image feature vector of the category.
[0038] In one possible implementation, a determination module is specifically used to perform non-negative processing on the score vector corresponding to the sample image to obtain a non-negative score vector; normalize the non-negative score vector to obtain a probability weight vector corresponding to the sample image; the probability weight vector contains the predicted probability of each category; multiply the probability weight vector corresponding to the sample image and the matrix composed of the average image feature vectors of all categories to calculate the second image feature vector corresponding to the sample image.
[0039] In a third aspect, an embodiment of the present application further provides an electronic device comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of the training method of the image recognition model as described in any one of the items in the first aspect.
[0040] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the training method of the image recognition model in any one of the first aspects are executed.
[0041] The present application provides a training method, device, electronic device and storage medium for an image recognition model, the method comprising: obtaining a first image feature vector corresponding to a sample image; calculating the average image feature vector of each category according to the categories and the first image feature vector corresponding to all sample images; inputting the sample image into the latest updated image recognition model to obtain the score vector corresponding to the sample image; for each sample image, determining the second image feature vector corresponding to the sample image according to the average image feature vector of all categories and the score vector corresponding to the sample image; subtracting the second image feature vector corresponding to the sample image from the image feature vector of the sample image to calculate the third image feature vector of the sample image; updating the latest updated image recognition model according to the third image feature vectors and their categories of all sample images. The present application can obtain the second image feature by calculating the average image feature vector and the score vector of each category, and then subtracting the second image feature vector from the first image feature vector of the sample image to obtain the third image feature vector, which is the image feature without context offset, and then training the model with the image feature vector without context offset, so that the image recognition model obtained in this way will eliminate the context offset phenomenon when performing image recognition tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0043] Figure 1 A flowchart of a method for training an image recognition model provided in an embodiment of the present application is shown;
[0044] Figure 2 A flowchart of another method for training an image recognition model provided in an embodiment of the present application is shown;
[0045] Figure 3 A schematic diagram of the structure of a training device for an image recognition model provided in an embodiment of the present application is shown;
[0046] Figure 4 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0047] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of explanation and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn in real proportion. The flowchart used in this application shows the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowchart can be implemented out of sequence, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart under the guidance of the content of the present application, or remove one or more operations from the flowchart.
[0048] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0049] In order to enable those skilled in the art to use the contents of this application, the following implementation is provided in conjunction with a specific application scenario, the "field of image recognition technology". For those skilled in the art, the general principles defined herein may be applied to other embodiments and application scenarios without departing from the spirit and scope of this application. Although this application is mainly described around the "field of image recognition technology", it should be understood that this is only an exemplary embodiment.
[0050] The following is a detailed description of a training method for an image recognition model provided in an embodiment of the present application.
[0051] Reference Figure 1 As shown, it is a flowchart of a training method of an image recognition model provided in an embodiment of the present application. The exemplary steps of the embodiment of the present application are described below:
[0052] S101, obtaining a first image feature vector corresponding to a sample image; and calculating an average image feature vector of each category according to the categories corresponding to all sample images and the first image feature vector.
[0053] In an implementation manner of the present application, each sample image is input into a newly updated image recognition model to obtain a first image recognition feature corresponding to each sample image.
[0054] Here, the image recognition model includes a classifier layer and a reference backbone network layer. The sample image is input into the latest updated image recognition model to obtain the output result of the reference backbone network layer, that is, the first image recognition feature corresponding to the sample image.
[0055] Among them, the image feature vector is a vector of 1*image feature dimension.
[0056] Here, the classifier formula in this application is: This formula is an approximation of the backdoor adjustment formula. The value of γ is set to 0.03125, τ is 16, K is the number of copies of the image feature according to the feature dimension, w is the classification weight, x is the image feature, γ is the hyperparameter, τ is the temperature control parameter, and P is the prediction score of the sample image.
[0057] In an embodiment of the present application, after obtaining the first image feature vector corresponding to the sample image, for each category, the number of categories corresponding to all sample images that are the same as the category is calculated to obtain a first value for the category; the first image feature vectors of all sample images belonging to the category are added together to calculate the sum of the image feature vectors of the category to obtain a second value; the second value corresponding to the category is divided by the first value corresponding to the category to calculate the average image feature vector of the category.
[0058] For example, there are 3 categories of sample images, namely a, b, and c. The corresponding image categories of the ten sample images are a, b, c, a, c, c, b, c, a, and b respectively. Therefore, the number of image category a that is the same as each category in the categories corresponding to all sample images is 3, which is the first value of category a. The number of image category b that is the same as each category in the categories corresponding to all sample images is 3, which is the first value of category b. The number of image category c that is the same as each category in the categories corresponding to all sample images is 4, which is the first value of category c. The sum of the image feature vectors of category a is the sum obtained by adding the first image feature vectors of the 1st, 4th, and 9th sample images, which is the second value of category a. The sum of the image feature vectors of category b is the sum obtained by adding the first image feature vectors of the 2nd, 7th, and 10th sample images, which is the second value of category b. The sum of the image feature vectors of category c is the sum obtained by adding the first image feature vectors of the 3rd, 5th, 6th, and 8th sample images, which is category c. Finally, the second values of categories a, b, and c are divided by their corresponding first values to obtain the average feature vector of each category.
[0059] S102: Input the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image.
[0060] In the implementation manner of the present application, a sample image is input into the latest updated image recognition model to obtain the output result of the classifier, that is, the score vector.
[0061] The score vector contains the predicted scores for each category.
[0062] In an embodiment of the present application, before inputting a sample image into a newly updated image recognition model and obtaining a score vector corresponding to the sample image, it is necessary to perform a first stage of training on the image recognition model. First, the sample image is input into the image recognition model for model training. After the training, the accuracy of the newly updated image recognition model is determined. If the accuracy of the newly updated image recognition model is greater than or equal to a preset accuracy value, the newly updated image recognition model is used as the result of the first round of training. If the accuracy of the newly updated image recognition model is less than the preset accuracy value, the newly updated image recognition model continues to be trained.
[0063] Here, the sample images in the input image recognition model need to be preprocessed each time. First, the sample image size is uniformly converted to 448*448, and then data enhancement is performed, that is, the sample image is flipped horizontally or vertically with a random probability, and then a part of the sample image at a random position and a random size is removed, and the pixels at the removed position are set to 0.
[0064] Among them, the order of inversion and mining processing can be interchanged, and the mined area is less than 1 / 4 of the sample image. The purpose of data enhancement is to prevent the trained image recognition model from overfitting. That is to say, if the men in all sample images are wearing blue clothes, the trained image recognition model will mechanically think that as long as they are wearing blue clothes, they are men. After the enhancement processing, there will be a part of the sample images in which blue clothes and men will not appear at the same time, thus reducing the problem of overfitting of the image recognition model.
[0065] Among them, each sample image will be marked with the category corresponding to the sample image.
[0066] Here, after each training session, all sample images are input into the latest updated image recognition model to obtain the classification result corresponding to each sample image. The classification result of each sample image is compared with the category corresponding to the sample image. The number of comparison results of all sample images that are the same is taken as the statistical value, and then the statistical value is divided by the number of sample images to obtain the accuracy of the latest updated image recognition model.
[0067] For example, there are 3 sample images in total, and the categories corresponding to the three sample images are a, b, and c. The three sample images are input into the updated image recognition model, and the classification results of the three sample images are a, b, and b. The comparison results of two of the sample images are the same, and the comparison result of one sample image is different. Then, the accuracy of the latest updated image recognition model is 2 / 3.
[0068] In an implementation manner of the present application, the first image feature vector in step S101 is obtained by obtaining the most recently updated image recognition model at any time in the first stage of training, that is, an early image recognition model. Therefore, the calculated average feature vector will not contain contextual information, that is, causal relationship, and will not affect the unbiased features obtained later. The obtained image recognition model will better eliminate the context offset phenomenon when performing image recognition tasks.
[0069] S103 . For each sample image, determine a second image feature vector corresponding to the sample image according to the average image feature vectors of all categories and the score vector corresponding to the sample image.
[0070] In an embodiment of the present application, the score vector corresponding to the sample image is processed to be non-negative to obtain a non-negative score vector; the non-negative score vector is normalized to obtain a probability weight vector corresponding to the sample image; the probability weight vector contains the predicted probability of each category; the probability weight vector corresponding to the sample image and the matrix composed of the average image feature vectors of all categories are multiplied to calculate the second image feature vector corresponding to the sample image.
[0071] Among them, first of all, it is necessary to perform non-negative processing on the values in the score vector, that is, to process the negative values in the score vector into positive values, and then, normalize the non-negative score vector, that is, divide each value in the score vector by the sum of all values in the score vector to obtain the probability weight vector corresponding to the sample image, and finally multiply the probability weight vector corresponding to the sample image by the matrix composed of the average image feature vectors of all categories to obtain the second image feature vector corresponding to the sample image. The second image feature vector here is the image feature vector of the context offset of the sample image.
[0072] Among them, it is necessary to convert the average image feature vectors of all categories into a matrix of the number of categories × the number of dimensions of the image feature vector, and then multiply the probability weight vector corresponding to the sample image and the matrix composed of the average image feature vectors of all categories to obtain the second image feature vector corresponding to the sample image.
[0073] Here, because the probability weight vector corresponding to the sample image contains the predicted probability of each category, the probability weight vector corresponding to the sample image is a matrix of 1×the number of categories.
[0074] Here, only the probability weight vector corresponding to the sample image and the matrix composed of the average image feature vectors of all categories can be multiplied together, but the matrix composed of the average image feature vectors of all categories and the probability weight vector corresponding to the sample image cannot be multiplied together. This is because according to the matrix multiplication rule, the matrix of 1×the number of categories and the matrix of the number of categories×the number of dimensions of the image feature vector can be multiplied together to obtain a matrix of 1×the number of dimensions of the image feature vector. In other words, the second image feature vector corresponding to the sample image is a vector of 1×the number of dimensions of the image feature vector. Only in this way can the final target feature vector be a vector of 1×the number of dimensions of the image feature vector.
[0075] S104 : Subtract the second image feature vector corresponding to the sample image from the image feature vector of the sample image to calculate a third image feature vector of the sample image.
[0076] Here, the image feature vector of the sample image without context offset is obtained by subtracting the image feature vector of the context offset of the sample image from the image feature of each sample image, that is, subtracting the second image feature vector of the sample image.
[0077] S105: Update the latest updated image recognition model according to the third image feature vectors and their categories of all sample images.
[0078] In an embodiment of the present application, after obtaining an image feature vector without context offset, that is, the third image feature vector, the image feature vector without context offset is input into a newly updated image recognition model, and the newly updated image recognition model is updated.
[0079] The present application provides a training method for an image recognition model. Through the image recognition model after the first stage of training, a score vector of a sample image is obtained. According to the average image feature vector of all categories and the score vector corresponding to the sample image, a second image feature vector containing the causal relationship between the categories is obtained, that is, a second image feature vector with context offset. By subtracting the second image feature vector with context offset from the image feature vector of the sample image, a third image feature vector without context offset can be obtained. Then, the model is trained with the third image feature vector without context offset. When the image recognition model obtained in this way performs image recognition tasks, the context offset phenomenon will be eliminated.
[0080] Reference Figure 2 As shown, it is a flowchart of another method for training an image recognition model provided in an embodiment of the present application. The exemplary steps of the embodiment of the present application are described below:
[0081] S201. Determine the accuracy of the latest updated image recognition model.
[0082] Here, the method for determining the accuracy of the latest updated image recognition model is the same as the method for determining the accuracy in step S101, and will not be repeated here.
[0083] S202: If the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the previous round, jump to the step of inputting the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image.
[0084] In an embodiment of the present application, if the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the previous round, the process jumps to the step of inputting the sample image into the latest updated image recognition model to obtain the score vector corresponding to the sample image, that is, jumps to step S102.
[0085] Here, after jumping to step S102, the average image feature vector of all categories used is the average image feature vector obtained in the first stage, because the calculated average image feature vector is calculated by the image recognition model of the first stage, that is, the early image recognition model. The early image recognition model has not obtained too much contextual information through multiple trainings, so the image recognition model obtained by training will be better.
[0086] S203: If the accuracy of the latest updated image recognition model is less than or equal to the accuracy of the image recognition model updated in the previous round, determine the latest updated image recognition model as the final image recognition model.
[0087] In the implementation mode of the present application, step S202 and step S203 are to determine whether the image recognition model has converged, that is, the image recognition model training is completed. The condition for determining the completion of the image recognition model training is to determine whether the accuracy of the latest updated image recognition model is no longer improving. If the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the last round, then jump to the step of inputting the sample image into the latest updated image recognition model to obtain the score vector corresponding to the sample image. If the accuracy of the latest updated image recognition model is less than or equal to the accuracy of the image recognition model updated in the last round, the latest updated image recognition model is determined as the final image recognition model.
[0088] Reference Figure 3 FIG. 1 is a schematic diagram of a training device for an image recognition model provided in an embodiment of the present application, the device comprising:
[0089] An acquisition module 301 is used to acquire a first image feature vector corresponding to a sample image;
[0090] A calculation module 302, used to calculate an average image feature vector of each category according to the categories and image feature vectors corresponding to all sample images;
[0091] An input module 303 is used to input the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image; the score vector contains the prediction score of each category;
[0092] A determination module 304 is used to determine, for each sample image, a second image feature vector corresponding to the sample image according to the average image feature vector of all categories and the score vector corresponding to the sample image;
[0093] The calculation module 302 is further used to subtract the second image feature vector corresponding to the sample image from the image feature vector of the sample image to calculate a third image feature vector of the sample image;
[0094] The updating module 305 is used to update the latest updated image recognition model according to the third image feature vectors and their categories of all sample images.
[0095] In a possible implementation, the device further includes: a jump module 306;
[0096] The determination module 304 is also used to determine the accuracy of the latest updated image recognition model;
[0097] A jump module 306, which is used to jump to the step of inputting the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image if the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the previous round;
[0098] The determination module 304 is further configured to determine the latest updated image recognition model as the final image recognition model if the accuracy of the latest updated image recognition model is less than or equal to the accuracy of the image recognition model updated in the previous round.
[0099] In a possible implementation, the acquisition module 301 is specifically configured to input the sample image into a newly updated image recognition model to acquire a first image feature vector corresponding to the sample image.
[0100] In one possible implementation, the calculation module 302 is specifically used to calculate, for each category, the number of categories corresponding to all sample images that is the same as the category, to obtain a first value of the category; add the image feature vectors of all sample images belonging to the category, calculate the sum of the image feature vectors of the category, and obtain a second value; divide the second value corresponding to the category by the first value corresponding to it, and calculate the average image feature vector of the category.
[0101] In one possible implementation, the determination module 304 is specifically used to perform non-negative processing on the score vector corresponding to the sample image to obtain a non-negative score vector; normalize the non-negative score vector to obtain a probability weight vector corresponding to the sample image; the probability weight vector includes the predicted probability of each category; and multiply the probability weight vector corresponding to the sample image by a matrix composed of average image feature vectors of all categories to calculate a second image feature vector corresponding to the sample image.
[0102] The present application provides a training device for an image recognition model, the method comprising: an acquisition module 301, used to acquire a first image feature vector corresponding to a sample image; a calculation module 302, used to calculate the average image feature vector of each category according to the categories and image feature vectors corresponding to all sample images; an input module 303, used to input the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image; the score vector contains the predicted score of each category; a determination module 304, used to determine the second image feature vector corresponding to the sample image for each sample image according to the average image feature vector of all categories and the score vector corresponding to the sample image; the calculation module 302 is also used to subtract the second image feature vector corresponding to the sample image from the image feature vector of the sample image to calculate the third image feature vector of the sample image; an update module 305, used to update the model of the latest updated image recognition model according to the third image feature vectors and categories of all sample images. The present application obtains the second image feature by calculating the average image feature vector and the score vector of each category, and then subtracts the second image feature vector from the first image feature vector of the sample image to obtain the third image feature vector, which can eliminate the image features that interfere with the recognition result, that is, the context offset phenomenon.
[0103] like Figure 4 As shown, an electronic device 400 provided in an embodiment of the present application includes: a processor 401, a memory 402 and a bus, the memory 402 stores machine-readable instructions executable by the processor 401, when the electronic device is running, the processor 401 communicates with the memory 402 through the bus, and the processor 401 executes the machine-readable instructions to perform the steps of the training method of the image recognition model as described above.
[0104] Specifically, the above-mentioned memory 402 and processor 401 can be general-purpose memory and processor, which are not specifically limited here. When the processor 401 runs the computer program stored in the memory 402, it can execute the training method of the above-mentioned image recognition model.
[0105] Corresponding to the training method of the above-mentioned image recognition model, an embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the training method of the above-mentioned image recognition model are executed.
[0106] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in this application. In the several embodiments provided in this application, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0107] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0108] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0109] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the information processing method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, magnetic disks, or optical disks.
[0110] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A training method for an image recognition model, characterized in that: The method comprises: Obtaining a first image feature vector corresponding to the sample image; calculating an average image feature vector of each category according to the categories corresponding to all sample images and the first image feature vector; Input the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image; the score vector includes a prediction score for each category; For each sample image, according to the average image feature vector of all categories and the score vector corresponding to the sample image, a second image feature vector corresponding to the sample image is determined, including: performing non-negative processing on the score vector corresponding to the sample image to obtain a non-negative score vector; performing normalization processing on the non-negative score vector to obtain a probability weight vector corresponding to the sample image; the probability weight vector contains the predicted probability of each category; multiplying the probability weight vector corresponding to the sample image and a matrix composed of the average image feature vectors of all categories to calculate the second image feature vector corresponding to the sample image; Subtracting a second image feature vector corresponding to the sample image from the image feature vector of the sample image to calculate a third image feature vector of the sample image; The latest updated image recognition model is updated according to the third image feature vectors and their categories of all sample images.
2. The method for training an image recognition model according to claim 1, characterized in that: After updating the image recognition model according to the third image feature vectors and their categories of all sample images, the method further includes: Determining the accuracy of the most recently updated image recognition model; If the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the previous round, jump to the step of inputting the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image; If the accuracy of the latest updated image recognition model is less than or equal to the accuracy of the image recognition model updated in the previous round, the latest updated image recognition model is determined as the final image recognition model.
3. The training method of the image recognition model according to claim 1, characterized in that: The obtaining of a first image feature vector corresponding to the sample image includes: The sample image is input into the latest updated image recognition model to obtain the first image feature vector corresponding to the sample image.
4. The method for training an image recognition model according to claim 1, characterized in that: The step of calculating the average image feature vector of each category according to the categories corresponding to all sample images and the first image feature vector comprises: For each category, calculate the number of categories corresponding to all sample images that are the same as the category, and obtain a first value of the category; Adding the first image feature vectors corresponding to all sample images belonging to the category, calculating the sum of the image feature vectors of the category, and obtaining a second value; The second value corresponding to the category is divided by the first value corresponding thereto to calculate an average image feature vector of the category.
5. A training device for an image recognition model, characterized in that: The device comprises: An acquisition module, used for acquiring a first image feature vector corresponding to a sample image; A calculation module, used for calculating an average image feature vector of each category according to the categories corresponding to all sample images and the first image feature vector; An input module, used to input the sample image into the latest updated image recognition model to obtain a score vector corresponding to the sample image; the score vector contains a prediction score for each category; A determination module is used to determine, for each sample image, a second image feature vector corresponding to the sample image according to the average image feature vector of all categories and the score vector corresponding to the sample image, including: performing non-negative processing on the score vector corresponding to the sample image to obtain a non-negative score vector; performing normalization processing on the non-negative score vector to obtain a probability weight vector corresponding to the sample image; the probability weight vector contains the predicted probability of each category; multiplying the probability weight vector corresponding to the sample image and a matrix composed of the average image feature vectors of all categories to calculate the second image feature vector corresponding to the sample image; The calculation module is further used to calculate a third image feature vector of the sample image by subtracting a second image feature vector corresponding to the sample image from the image feature vector of the sample image; The updating module is used to update the latest updated image recognition model according to the third image feature vectors and categories of all sample images.
6. The image recognition model training device according to claim 5, characterized in that: The device further comprises: a jump module; The determination module is further used to determine the accuracy of the latest updated image recognition model; The jump module is used to jump to the step of inputting the sample image into the latest updated image recognition model to obtain the score vector corresponding to the sample image if the accuracy of the latest updated image recognition model is greater than the accuracy of the image recognition model updated in the previous round; The determination module is further configured to determine the latest updated image recognition model as the final image recognition model if the accuracy of the latest updated image recognition model is less than or equal to the accuracy of the image recognition model updated in the previous round.
7. The image recognition model training device according to claim 5, characterized in that: The acquisition module is specifically used for: The sample image is input into the latest updated image recognition model to obtain the first image feature vector corresponding to the sample image.
8. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of the image recognition model training method as described in any one of claims 1 to 4.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the training method of the image recognition model as described in any one of claims 1 to 4 are executed.
Citation Information
Patent Citations
Efficient fine-grained image recognition method on mobile equipment
CN110751212A
Image recognition model training method and device, computer equipment and storage medium
CN111291841A