Search

CN-115424056-B - Model training method and device, image classification method, device and medium

CN115424056BCN 115424056 BCN115424056 BCN 115424056BCN-115424056-B

Abstract

The embodiment of the invention provides a model training method and device, an image classification method, equipment and medium, and relates to the technical field of artificial intelligence. According to the method, an image sample is input into an image classification model to obtain a feature matrix, a class weight value corresponding to each feature channel is obtained according to the feature matrix based on a Shapley calculation principle, a class activation diagram is obtained according to the class weight value of each feature channel, a predicted image class corresponding to the image sample is obtained according to the class activation diagram, and model weight is adjusted according to a loss value until convergence conditions of a preset loss function are reached, so that the image classification model is obtained. Based on the Shapley calculation principle, a class weight value corresponding to each characteristic channel is obtained, which is different from the weight of characteristics in images by using gradient direction propagation in the related technology, so that dependence among different elements in the characteristics is avoided being ignored or hidden, the classification accuracy of the trained image classification model is improved, and the application scene of image classification is expanded.

Inventors

  • CHEN ZHIYUAN
  • LI YANSHAN
  • ZHANG LI

Assignees

  • 深圳大学

Dates

Publication Date
20260512
Application Date
20220819

Claims (10)

  1. 1. An image classification model training method, comprising: Constructing an image sample set, wherein the image sample set comprises a plurality of image samples, and the image samples comprise images and category labels, the number of categories of the category labels is n, and the category labels represent image categories corresponding to the images; Inputting the image sample into an image classification model to obtain a feature matrix, wherein the feature matrix comprises feature graphs of a plurality of feature channels; acquiring a class weight value corresponding to each characteristic channel according to the characteristic matrix based on a Shapley calculation principle; obtaining a class activation diagram according to the class weight value of each characteristic channel; Obtaining a predicted image category corresponding to the image sample according to the class activation diagram; calculating a loss value between the predicted image category and the category label according to a preset loss function; adjusting the model weight of the image classification model according to the loss value until reaching the convergence condition of the preset loss function, thereby obtaining the image classification model; The class weight value corresponding to each feature channel is obtained according to the feature matrix based on a shape calculation principle, and the class weight value comprises at least one feature map subset of a current feature channel is generated according to a preset shape classification mode, marginal contribution values of the feature map subset are calculated, weighting factors of the feature map subset are calculated, weight values of the feature map subset are calculated according to the weighting factors and the marginal contribution values, class weight values of the current feature channel are calculated according to the weight values of the feature map subset, and the class weight values of each feature channel are calculated one by one.
  2. 2. The method of claim 1, wherein inputting the image sample into the image classification model yields a feature matrix, comprising: preprocessing the image in the image sample by using more than one preprocessing layer to obtain preprocessing characteristic information; And sequentially extracting the characteristics of the preprocessed characteristic information by using more than one characteristic extraction layer to obtain the characteristic matrix.
  3. 3. The image classification model training method of claim 1, wherein the generating marginal contribution values for the feature map subset from the feature map subset comprises: calculating a first contribution value according to the feature map subset; calculating a second contribution value according to the feature map subset and the feature map of the current feature channel; and obtaining the marginal contribution value of the feature map subset according to the first contribution value and the second contribution value.
  4. 4. The image classification model training method of claim 1, wherein the calculating the weighting factors for the subset of feature maps comprises: Acquiring the number of feature images contained in the feature image subset; and calculating the weighting factors according to the number of the feature images and the number of the types of the category labels.
  5. 5. The image classification model training method according to claim 1, wherein the calculating the class weight value of the current feature channel according to the weight values of the feature map subset comprises: generating more than one feature map subset of the current feature channel according to a preset shape classification mode; sampling the feature map subset at least once based on preset sampling times to obtain at least one feature map sampling subset; calculating marginal contribution values of at least one of the feature map sample subsets; calculating an average value of the marginal contribution values based on the preset sampling times to obtain the category weight value of the current characteristic channel; And calculating the class weight value of each characteristic channel one by one.
  6. 6. The method according to any one of claims 1 to 5, wherein before obtaining a class activation map according to the class weight value of each of the feature channels, the method comprises: summing the class weight values of each characteristic channel to obtain a sum weight value; Calculating the average value of the summation weight values to obtain average weight values; and binarizing the obtained average weight value to obtain the binarized class weight value.
  7. 7. An image classification method, comprising: Acquiring a target image; inputting the target image into an image classification model trained by the image classification model training method according to any one of claims 1 to 6, and obtaining the image category corresponding to the target image model.
  8. 8. An image classification model training device, comprising: The image sample set comprises a plurality of image samples, wherein the image samples comprise images and category labels, the number of categories of the category labels is n, and the category labels represent image categories corresponding to the images; the characteristic matrix acquisition unit is used for inputting the image sample into an image classification model to obtain a characteristic matrix, and the characteristic matrix comprises characteristic graphs of a plurality of characteristic channels; The class weight value calculation unit is used for acquiring class weight values corresponding to each characteristic channel according to the characteristic matrix based on a shape calculation principle; the class activation diagram acquisition unit is used for acquiring a class activation diagram according to the class weight value of each characteristic channel, and the class activation diagram is used for representing the probability score of the class label; The image category prediction unit is used for obtaining a predicted image category corresponding to the image sample according to the class activation diagram; a loss value calculation unit, configured to calculate a loss value between the predicted image class and the class label according to a preset loss function; The model weight adjusting unit is used for adjusting the model weight of the image classification model according to the loss value until reaching the convergence condition of the preset loss function, so as to obtain the image classification model; The class weight value corresponding to each feature channel is obtained according to the feature matrix based on a shape calculation principle, and the class weight value comprises at least one feature map subset of a current feature channel is generated according to a preset shape classification mode, marginal contribution values of the feature map subset are calculated, weighting factors of the feature map subset are calculated, weight values of the feature map subset are calculated according to the weighting factors and the marginal contribution values, class weight values of the current feature channel are calculated according to the weight values of the feature map subset, and the class weight values of each feature channel are calculated one by one.
  9. 9. An electronic device comprising a memory storing a computer program and a processor that when executing the computer program implements the image classification model training method of any one of claims 1 to 6 or the image classification method of claim 7.
  10. 10. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the image classification model training method of any one of claims 1 to 6, or the image classification method of claim 7.

Description

Model training method and device, image classification method, device and medium Technical Field The invention relates to the technical field of artificial intelligence, in particular to an image classification model training method and device, an image classification method, equipment and a storage medium. Background With the progress of machine learning, images can be classified according to the content in the images based on the image classification model obtained by training. And the accuracy of classifying images is generally related to the degree of training of the image classification model. At present, when an image classification model is trained, a sample image is generally input into the image classification model to be trained for training, and the image classification model obtained through training can realize image classification. In the related art, the weight which is transmitted in the gradient direction as the characteristic in the image is utilized in the image classification model, the dependence problem among different elements in the characteristic is ignored or hidden by the weight calculated in the mode, so that the image classification model obtained through training in the mode is only suitable for the image with low classification difficulty, and the classification accuracy is low when the image with high classification difficulty is classified. Therefore, how to improve the accuracy of image classification becomes a technical problem to be solved. Disclosure of Invention The embodiment of the invention mainly aims to provide an image classification model training method and device, an image classification method, equipment and a storage medium, which are used for improving the accuracy of image classification and expanding the application scene of image classification based on the dependency among different elements in characteristics. To achieve the above object, a first aspect of an embodiment of the present invention provides an image classification model training method, including: Constructing an image sample set, wherein the image sample set comprises a plurality of image samples, and the image samples comprise images and category labels, the number of categories of the category labels is n, and the category labels represent image categories corresponding to the images; Inputting the image sample into an image classification model to obtain a feature matrix, wherein the feature matrix comprises feature graphs of a plurality of feature channels; acquiring a class weight value corresponding to each characteristic channel according to the characteristic matrix based on a Shapley calculation principle; obtaining a class activation diagram according to the class weight value of each characteristic channel; Obtaining a predicted image category corresponding to the image sample according to the class activation diagram; calculating a loss value between the predicted image category and the category label according to a preset loss function; And adjusting the model weight of the image classification model according to the loss value until reaching the convergence condition of the preset loss function, thereby obtaining the image classification model. In some embodiments, the inputting the image sample into the image classification model to obtain the feature matrix includes: preprocessing the image in the image sample by using more than one preprocessing layer to obtain preprocessing characteristic information; And sequentially extracting the characteristics of the preprocessed characteristic information by using more than one characteristic extraction layer to obtain the characteristic matrix. In some embodiments, the obtaining, based on the Shapley calculation principle, a class weight value corresponding to each feature channel according to the feature matrix includes: generating at least one feature map subset of the current feature channel according to a preset shape classification mode; calculating marginal contribution values of the feature map subset; Calculating weighting factors of the feature map subset; calculating to obtain weight values of the feature map subset according to the weighting factors and the marginal contribution values; Calculating the category weight value of the current feature channel according to the weight value of the feature map subset; And calculating the class weight value of each characteristic channel one by one. In some embodiments, the generating the marginal contribution value of the feature map subset from the feature map subset includes: calculating a first contribution value according to the feature map subset; calculating a second contribution value according to the feature map subset and the feature map of the current feature channel; and obtaining the marginal contribution value of the feature map subset according to the first contribution value and the second contribution value. In some embodiments, the computing the weighting factor