An interpretable image classification method and system
Patent Information
- Application Number
- CN202410580885.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-11
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2044-05-11
AI Technical Summary
由于事后解释未使模型本身成为一种可解释的分类方法,对推动可解释图像分类方法研究发展的作用相对有限
[0042]1.能够较明显提高图像分类任务的准确率;
Smart Images

Figure CN118429713B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image classification technology, and more specifically to an interpretable image classification method and system. Background Technology
[0002] Image classification is an important application of deep learning technology in the field of computer vision. It requires a deep learning model to take an image as input and output the confidence score of the image belonging to each category. The model then selects the category label with the highest confidence score as the prediction result for the input image. Image classification is the foundation of many other image recognition technologies, and after decades of development, it has yielded a relatively mature theoretical system and practical applications.
[0003] To improve the accuracy of image classification, many research findings are based on designing more complex model structures or increasing network depth, thereby increasing the number of model parameters to obtain stronger feature extraction and fitting capabilities. In recent years, thanks to the improvement of high-performance graphics cards and distributed computing technologies, many companies and research institutions have launched large-scale models with hundreds of billions or even trillions of parameters. Today, accuracy is no longer the main bottleneck restricting the development of image classification methods. However, this trend has exacerbated the problem of uninterpretability of deep learning models. The extremely complex structure has led to existing models becoming increasingly large and difficult-to-analyze black box systems.
[0004] With the improvement of regulations and the increasing discussion and reflection on the ethics of artificial intelligence in society, more and more researchers are beginning to pay attention to the interpretability of image classification models. In some more sensitive and fault-tolerant fields, such as autonomous driving and medical fields, complex models that are difficult to interpret may lead to unpredictable and serious errors. Therefore, the lack of research on interpretability has limited the translation of many research results into practical applications.
[0005] Based on the timing of interpretation, research on the interpretability of deep learning can be broadly categorized into pre-interpretation and post-interpretation. Post-interpretation, also known as passive interpretation, occurs after the model has completed training and primarily involves designing interpretability analysis algorithms to study the features the model is interested in. Pre-interpretation, also known as active interpretation, occurs before the model has completed training. Unlike post-interpretation, pre-interpretation mainly involves specially designing the model structure or training algorithm to enable it to inherently possess the ability to interpret the features it focuses on. Therefore, models designed based on pre-interpretation are often called self-explaining models. Since post-interpretation does not make the model itself an interpretable classification method, its role in promoting the development of interpretable image classification methods is relatively limited. Therefore, how to design an interpretable image classification method with good pre-interpretation interpretability is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0006] In view of this, the present invention provides an interpretable image classification method and system that overcomes the above-mentioned defects.
[0007] To achieve the above objectives, the present invention adopts the following technical solution:
[0008] An interpretable image classification method, the specific steps of which are as follows:
[0009] Obtain the image data to be classified;
[0010] The image data to be classified is input into an interpretable image classification model to obtain the category label of the category; the interpretable image classification model consists of a classification model trained iteratively for two classes based on a first loss function and a spatial attention network trained iteratively for two classes based on a second loss function with hyperparameters;
[0011] Output the category labels.
[0012] Optionally, the steps for obtaining the interpretable image classification model are as follows:
[0013] Step 21: Obtain image data of the target application scenario, and construct training and testing sets based on the image data;
[0014] Step 22: Based on the training images in the training set, use the first loss function and optimizer to perform zero-class iterative training on the initial training model to obtain the first classification model;
[0015] Step 23: Input the training images from the training set into the spatial attention network to obtain an attention matrix; calculate the Hadamard product between the attention matrix and the training images to obtain a weighted image; input the weighted image into the first classification model to obtain the category label of the category; iteratively train the spatial attention network using the second loss function and the optimizer according to the category label, and simultaneously iteratively train the first classification model using the first loss function and the optimizer according to the category label to obtain a second classification model;
[0016] Step 24: Adjust the hyperparameters of the second loss function based on the accuracy of the second classification model and the accuracy of the first classification model. Determine whether to iteratively train the second classification model according to the iteration termination condition. If yes, update the hyperparameters of the second loss function and execute step 23; otherwise, output the interpretable image classification model.
[0017] Optionally, the training images need to be preprocessed before use, specifically by: processing the training images in the training set into images of the same size, and standardizing the training images according to the mean and variance of the training images in the training set.
[0018] Optionally, the spatial attention network includes a downsampling module and a receptive field expansion module, wherein the downsampling module consists of n C It consists of n convolutional layers. C All parameters of the convolutional layers are identical; the receptive field expansion module consists of n D It consists of n dilated convolutional layers, wherein the dilation rate of the first dilated convolutional layer is 1, and the dilated convolutional layers from the second to the nth layer are... D The expansion rate of each of the hollow convolutional layers is a prime number that increases sequentially.
[0019] Optionally, the attention matrix needs to be normalized and scaled before calculating the Hadamard product.
[0020] Optionally, the second loss function includes the first loss function and the attention loss function; the expression for the attention loss function is:
[0021]
[0022] In the formula, X is the set of elements of the attention matrix, x i Let i be the i-th element of the set. Let n be the average value of the set's elements, and n be the total number of elements. is the hyperparameter of the attention loss function.
[0023] Optionally, the hyperparameters of the second loss function are adjusted using a binary search hyperparameter adjustment algorithm, with the following specific steps:
[0024] Step 241: Set initial parameters, specifically: set the total number of iterations to N, and initialize the left boundary of the search. Initialize the right boundary of the search Initialize the current iteration number i = 1, and initialize the model accuracy Acc corresponding to the right boundary. right Acc is the classification accuracy of the first classification model after the zeroth iteration. stage0 ;
[0025] Step 242: Determine if i≤N is true. If yes, proceed to step 243; otherwise, end.
[0026] Step 243: Set hyperparameters Adjust to initialize the left boundary of the search With initial search right boundary The average value;
[0027] Step 244: Perform one round of iterative training and calculate the classification accuracy Acc of the second classification model. cur ;
[0028] Step 245: Determine Acc cur <Acc right If the condition is met, adjust the left boundary and proceed to step 247; otherwise, adjust the hyperparameters. Adjust to the left The model is then trained iteratively, and the accuracy of the second classification model after several rounds is denoted as Acc. delta ;
[0029] Step 246: Determine Acc cur <Acc delta If the condition is met, adjust the left boundary. And execute 247; otherwise, adjust the right boundary, i.e. Simultaneously set Acc right =Acc cur And execute 247;
[0030] Step 247: Set i = i + 1, then return to step 242.
[0031] An interpretable image classification system includes:
[0032] The image acquisition module is used to acquire image data to be classified.
[0033] The image classification module is used to input the image data to be classified into the interpretable image classification model to obtain the category label of the category; the interpretable image classification model consists of a classification model trained iteratively for two classes based on a first loss function and a spatial attention network trained iteratively for two classes based on a second loss function with hyperparameters;
[0034] The category output module is used to output the category labels.
[0035] Optionally, the image classification module includes:
[0036] The training set construction module is used to acquire image data of the target application scenario and construct training and testing sets based on the image data.
[0037] The first model training module is used to perform zero-class iterative training on the initial training model using a first loss function and an optimizer based on the training images in the training set to obtain a first classification model.
[0038] The second model training module is used to input the training images from the training set into the spatial attention network to obtain an attention matrix; calculate the Hadamard product between the attention matrix and the training images to obtain a weighted image; input the weighted image into the first classification model to obtain the category label of the category; perform iterative training of the spatial attention network using a second loss function and the optimizer based on the category label, and simultaneously perform first-class iterative training of the first classification model using the first loss function and the optimizer based on the category label to obtain a second classification model;
[0039] The third model training module is used to adjust the hyperparameters of the second loss function based on the accuracy of the second classification model and the accuracy of the first classification model, and to determine whether to perform iterative training on the second classification model based on the iteration termination condition. If yes, it updates the hyperparameters of the second loss function, generates an execution instruction, and sends the execution instruction to the second model training module; if no, it outputs the interpretable image classification model.
[0040] Optionally, the image classification module further includes a preprocessing module for processing the training images in the training set into images of the same size, and for standardizing the training images according to the mean and variance of the training images in the training set.
[0041] As can be seen from the above technical solutions, the present invention discloses an interpretable image classification method and system, which has the following advantages compared with the prior art:
[0042] 1. It can significantly improve the accuracy of image classification tasks;
[0043] 2. It has good interpretability; the classification basis can be analyzed using only the model's output.
[0044] 3. It can achieve convergence with fewer iterations using a binary search algorithm;
[0045] 4. It has good versatility, can be used to modify various classification models, and is suitable for most application scenarios. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0047] Figure 1This is a schematic diagram of the overall method flow provided by the present invention;
[0048] Figure 2 This is a schematic diagram of the method flow in Embodiment 2 of the present invention;
[0049] Figure 3 A schematic diagram of the spatial attention network structure provided in an embodiment of the present invention;
[0050] Figure 4 This is a schematic diagram of the hyperparameter adjustment algorithm provided in an embodiment of the present invention. Detailed Implementation
[0051] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0052] Example 1
[0053] This embodiment discloses an interpretable image classification method, such as... Figure 1 As shown, the specific steps are as follows:
[0054] Step 1: Obtain the image data to be classified;
[0055] Step 2: Input the image data to be classified into the interpretable image classification model to obtain the category label of the category; the interpretable image classification model consists of a classification model trained iteratively for two classes based on the first loss function and a spatial attention network trained iteratively for two classes based on the second loss function with hyperparameters;
[0056] Step 3: Output the category labels.
[0057] In one embodiment, the steps for obtaining an interpretable image classification model are as follows:
[0058] Step 21: Obtain image data of the target application scenario, and construct training and testing sets based on the image data, specifically as follows:
[0059] Image data for the target application scenario is collected, and the images are manually labeled with category tags to form the original image dataset, which is then divided into training and test sets.
[0060] Step 22: Based on the training images in the training set, use the first loss function and optimizer to perform the zeroth class iterative training on the initial training model to obtain the first classification model;
[0061] Furthermore, the first loss function can be any suitable classification loss function, calculated based on the output class label and the actual class label of the image. The optimizer can use SGD, Adam, or other suitable optimizers to perform backpropagation and parameter updates based on the classification loss.
[0062] In one embodiment, the training images in the training set need to be preprocessed before use, specifically by processing the training images in the training set into images of the same size, and standardizing the training images according to the mean and variance of the training images in the training set.
[0063] Furthermore, the training images are uniformly cropped and scaled to the same size, and the mean and variance of the training images in the training set are calculated to complete the standardization. Other data augmentation techniques can be introduced as needed.
[0064] Step 23: Input the training images from the training set into the spatial attention network to obtain the attention matrix; calculate the Hadamard product between the attention matrix and the training images to obtain the weighted image; input the weighted image into the first classification model to obtain the category label; iteratively train the spatial attention network using the second loss function and optimizer based on the category label, and simultaneously iteratively train the first classification model using the first loss function and optimizer based on the category label to obtain the second classification model.
[0065] Furthermore, during the acquisition of the second classification model, the weighted image is used as input, and calculations are performed based on the classification output and the actual class label of the image. Using SGD, Adam, or other suitable optimizers, backpropagation and parameter updates are performed only on the first classification model based on the classification loss, without updating the model parameters of the spatial attention network.
[0066] In one embodiment, the attention matrix needs to be normalized and scaled before calculating the Hadamard product.
[0067] Furthermore, the normalization process is as follows: the normalization function is used to process each element of the attention matrix in turn, limiting the value range to [0,1);
[0068] The size scaling process involves scaling the attention matrix to the same size as the preprocessed training image.
[0069] Step 24: Adjust the hyperparameters of the second loss function based on the accuracy of the second classification model and the accuracy of the first classification model. Determine whether to iteratively train the second classification model according to the iteration termination condition. If yes, update the hyperparameters of the second loss function and execute step 23; otherwise, output an interpretable image classification model.
[0070] The iteration termination condition is to determine whether the current number of iterations is less than or equal to the preset number of iterations. If yes, the second classification model continues to be iteratively trained; otherwise, the iterative training is terminated.
[0071] In this embodiment, during the training of the interpretable image classification model, an appropriate learning rate is set, and after each round of training iterations, it is determined whether the learning rate needs to be adjusted based on the training results. After multiple rounds of training, if the classification effect reaches the target or a sufficient number of rounds have been completed, training is terminated, and subsequent steps continue.
[0072] In one embodiment, the spatial attention network includes a downsampling module and a receptive field expansion module, wherein the downsampling module consists of n C It consists of n convolutional layers. C All convolutional layers have the same parameters; the receptive field expansion module consists of n D It consists of n dilated convolutional layers, wherein the dilation rate of the first dilated convolutional layer is 1, and the dilated convolutional layers from the second to the nth layer are... D The expansion rate of each of the hollow convolutional layers is a prime number that increases sequentially.
[0073] Furthermore, the spatial attention network consists of two parts: a downsampling module and a receptive field expansion module. The downsampling module comprises n... C The system consists of n regular convolutional layers, each using a 3×3 kernel size, a stride of 2, and a padding width of 1. Each convolutional layer is followed by batch normalization and uses ReLU as the activation function. The receptive field expansion module consists of n D The system consists of several dilated convolutional layers, each using a 3×3 kernel size and a stride of 1. The dilation rates of each dilated convolutional layer are sequentially increasing prime numbers. The dilation rate of the first dilated convolutional layer is 1. The edge padding width of each dilated convolutional layer is the same as its dilation rate. In the aforementioned design, n C The value of n can be set according to the actual situation. C The larger the value, the larger the parameter scale of the spatial attention network, the stronger its fitting ability, and the longer the training time. D The value of n is affected by C To ensure the receptive field size of the last dilated convolutional layer is smaller than the original image size, the input image is processed sequentially through each regular convolutional layer of the downsampling module, increasing the number of feature map channels while reducing the feature map size. Then, the output of the last layer of the downsampling model is used as input and processed through each dilated convolutional layer of the receptive field expansion module, expanding the receptive field while maintaining the number of feature map channels and size. Finally, the output of the last layer of the receptive field expansion module is processed by a channel compression layer, reducing the number of feature map channels to 1 while keeping the size unchanged, serving as the final output of the spatial attention network.
[0074] In one embodiment, the second loss function includes a first loss function and an attention loss function, wherein the expression for the attention loss function is:
[0075]
[0076] In the formula, X is the set of elements of the attention matrix, x i Let i be the i-th element of the set. Let n be the average value of the set's elements, and n be the total number of elements. is the hyperparameter of the attention loss function.
[0077] Furthermore, the first loss function is a classification loss function, and the second loss function consists of two parts: a classification loss function and an attention loss function. The classification loss can use any suitable classification loss function, calculated based on the classification output and the actual class label of the image. The attention loss is based on a weakly supervised learning design and is calculated based on the attention matrix output by the spatial attention network, requiring no additional annotations. The calculations of the attention loss and the total training loss function are as follows:
[0078]
[0079] in, Let ω be the cross-entropy loss function. C and ω A These are the weighting coefficients for the classification loss function and the attention loss function, respectively. Through derivation, when the attention matrix X contains a proportion of... When the element has a value of 1 and the rest have a value of 0, the attention loss function It reaches a minimum value of 0. Therefore, it can be... The hyperparameter of this loss function corresponds to the proportion of image information expected to be used by the model for classification. Using SGD, Adam, or other suitable optimizers, backpropagation and parameter updates are performed only on the spatial attention network based on the total loss, without updating the model parameters of the classification network.
[0080] In one embodiment, the hyperparameter adjustment method for the second loss function adopts a binary search hyperparameter adjustment algorithm, and the specific steps are as follows:
[0081] Step 241: Set initial parameters, specifically: set the total number of iterations to N, and initialize the left boundary of the search. Initialize the right boundary of the search Initialize the current iteration number i = 1, and initialize the model accuracy Acc corresponding to the right boundary. right Acc is the classification accuracy of the first classification model after the zeroth iteration. stage0 ;
[0082] Step 242: Determine if i≤N is true. If yes, proceed to step 243. If no, end.
[0083] Step 243: Set hyperparameters Adjust to initialize the left boundary of the search With initial search right boundary The average value;
[0084] Step 244: Perform one round of iterative training and calculate the classification accuracy Acc of the second classification model. cur ;
[0085] Step 245: Determine Acc cur <Acc right If the condition is met, adjust the left boundary and proceed to step 247; otherwise, adjust the hyperparameters. Adjust to the left The model is then trained iteratively, and the accuracy of the second classification model after several rounds is denoted as Acc. delta ;
[0086] Step 246: Determine Acc cur <Acc delta If the condition is met, adjust the left boundary. And execute 247; otherwise, adjust the right boundary, i.e. Simultaneously set Acc right =Acc cur And execute 247;
[0087] Step 247: Set i = i + 1, then return to step 242.
[0088] In one embodiment, the method further includes evaluating the final classification accuracy of the model and performing interpretability analysis. Specifically, it uses the attention matrix generated by the spatial attention network as a basis for visualization analysis. Since the attention matrix has been normalized and weighted, all elements range from 0 to 1, and its size is the same as the original image. During visualization, the weighted image obtained by performing a Hadamard product between the attention matrix and the training image can be used as the analysis object. When the R, G, and B channels of each pixel position in the image are multiplied by the same value, the visualization effect is equivalent to adding a grayscale mask to the image. The smaller the weight, the blurrier the corresponding position in the training image, indicating a lower level of model attention; the larger the weight, the clearer the corresponding position in the training image, indicating a higher level of model attention. Based on this, this method can analyze the classification basis using only the model's output without relying on other interpretability tools, achieving the goal of interpretability.
[0089] Another aspect of this embodiment also includes an interpretable image classification system, comprising:
[0090] The image acquisition module is used to acquire image data to be classified.
[0091] The image classification module is used to input the image data to be classified into the interpretable image classification model to obtain the category label of the category. The interpretable image classification model consists of a classification model trained iteratively for two classes based on a first loss function and a spatial attention network trained iteratively for two classes based on a second loss function with hyperparameters.
[0092] The category output module is used to output category labels.
[0093] In one embodiment, the image classification module includes:
[0094] The training set construction module is used to acquire image data of the target application scenario and construct training and test sets based on the image data;
[0095] The first model training module is used to perform zero-class iterative training on the initial training model using the first loss function and optimizer based on the training images in the training set, so as to obtain the first classification model.
[0096] The second model training module is used to input training images from the training set into the spatial attention network to obtain the attention matrix; calculate the Hadamard product between the attention matrix and the training images to obtain a weighted image; input the weighted image into the first classification model to obtain the category label of the category; iteratively train the spatial attention network using a second loss function and optimizer based on the category label, and simultaneously iteratively train the first classification model using a first loss function and optimizer based on the category label to obtain the second classification model.
[0097] The third model training module is used to adjust the hyperparameters of the second loss function based on the accuracy of the second classification model and the accuracy of the first classification model. Based on the hyperparameters of the second loss function, it determines whether to iteratively train the second classification model. If yes, it generates an execution instruction and sends the execution instruction to the second model training module; otherwise, it outputs an interpretable image classification model.
[0098] In one embodiment, the image classification module further includes a preprocessing module for processing the training images in the training set into images of the same size, and for standardizing the training images based on the mean and variance of the training images in the training set.
[0099] Example 2
[0100] This embodiment discloses an interpretable image classification method, such as... Figure 2 As shown, the specific steps are as follows:
[0101] Step 1: Download and process common publicly available image classification datasets; specifically: download the CIFAR-10, CIFAR-100, ImageNet, Cassava Disease, and DTD datasets. The CIFAR-10, CIFAR-100, and ImageNet datasets have already been pre-split into training and test sets, while the Cassava Disease and DTD datasets require randomly splitting the labeled data into training and test sets in a 7:3 ratio.
[0102] Step 2: Preprocess the training set images. Specifically, in the preprocessing process, the images are uniformly scaled to a size of 224×224, while the images from the CIFAR-10 and CIFAR-100 datasets remain at their original size of 32×32. Then, each training image is padded with zeros of width 4 at the edges and randomly cropped again to a size of 224×224. The images from the CIFAR-10 and CIFAR-100 datasets are randomly cropped to a size of 32×32. Finally, the R, G, and B channels of each image are standardized using (0.485, 0.456, 0.406) as the mean and (0.229, 0.224, 0.225) as the variance.
[0103] Step 3: Input the preprocessed training images from Step 2 into the classification network to obtain the classification output. Specifically, DenseNet121, MobileNet_v2, ResNet18, ViT (Base_patch16_224), and SwinTransformer (Base_patch4_window7_224) are used as the classification network skeleton, and the output dimension of the classification head is adjusted according to the number of class labels in each training set for multiple sets of experiments. Note that because Transformer-based classification models perform poorly on small datasets, ViT (Base_patch16_224) and SwinTransformer (Base_patch4_window7_224) are not used on the CIFAR-10 and CIFAR-100 datasets.
[0104] Step 4: Based on the classification output obtained in Step 3, train the classification network using a loss function and an optimizer; specifically: use the cross-entropy loss function as the classification loss, and the hyperparameter ω of the total loss... A =1, ω C =1. SGD is used as the optimizer, with its momentum coefficient set to 0.9 and weight decay coefficient set to 5 × 10⁻⁶. -4 .
[0105] Step 5: Repeat steps 2 to 4 for several rounds to complete the classification network training; specifically: set the initial learning rate to 0.1, and reduce the learning rate to 0.1 times the previous value after each of the 135th, 185th and 235th rounds of training, for a total of 300 rounds.
[0106] Step Six: Input the preprocessed training images from Step Two into the spatial attention network, such as... Figure 3 As shown, the attention matrix output is obtained; specifically, the hyperparameter n of the spatial attention network part. C Let's take 3. After calculation, n is now... D The value should be 7, and the expansion rates of each void convolutional layer are 1, 2, 3, 5, 7, 11, and 13, respectively.
[0107] Step 7: Normalize the attention matrix; specifically, the normalization function used is an improvement and combination of the ReLU and Sigmoid functions, called SigReLU, and the calculation formula is as follows:
[0108]
[0109] Step 8: Scale the attention matrix to the same size as the preprocessed training image; specifically, scale the attention matrix using a bilinear interpolation algorithm.
[0110] Step 9: Calculate the Hadamard product based on the attention matrix and the preprocessed training images to obtain the weighted image.
[0111] Step 10: Input the weighted image into the classification network to obtain the classification output.
[0112] Step 11: Based on the classification output obtained in Step 10, train the spatial attention network using a loss function and an optimizer; specifically, use the cross-entropy loss function and SGD as the optimizer. Set the momentum coefficient of SGD to 0.9 and the weight decay coefficient to 5 × 10⁻⁶. -4 Backpropagation and parameter updates are performed only on the spatial attention network; the model parameters of the classification network are not updated.
[0113] Step 12: Repeat steps 6 to 11 several times to complete the training of the spatial attention network; specifically: set the initial learning rate to 0.01, and after training for 135, 185 and 235 rounds respectively, reduce the learning rate to 0.1 times the previous rate, for a total of 300 rounds.
[0114] Step 13: Following the same process, complete steps 6 to 10 to obtain the categorized output.
[0115] Step Fourteen: Based on the classification output obtained in Step Thirteen, train the classification network using a loss function and an optimizer; specifically, use the cross-entropy loss function and SGD as the optimizer. Set the momentum coefficient of SGD to 0.9 and the weight decay coefficient to 5 × 10⁻⁶. -4 Backpropagation and parameter updates are performed only on the classification network; the model parameters of the spatial attention network are not updated.
[0116] Step 15: Repeat steps 13 to 14 several times to complete the classification network training; specifically: set the initial learning rate to 0.1, and after each training round 135, 185, and 235, reduce the learning rate to 0.1 times the previous rate, for a total of 300 training rounds.
[0117] Step 16: Calculate the classification accuracy of the trained model and adjust the hyperparameters. Then, return to step six to repeat the iteration, or end the iteration; specifically: use as follows Figure 4 The hyperparameter tuning algorithm based on binary search shown here adjusts the hyperparameters. Adjustments were made, and a total of four iterations were conducted.
[0118] Step 17: Evaluate the final classification accuracy of the model and perform interpretability analysis.
[0119] The experimental results of the interpretable image classification method based on spatial attention mechanism and weakly supervised learning described in this embodiment compared with traditional classification methods are shown in Table 1 below.
[0120] Table 1 Comparison of image classification accuracy between the method described in this invention and traditional methods.
[0121]
[0122] As shown in the table above, the method described in this embodiment, compared with existing methods, achieves significantly better classification accuracy on all datasets, regardless of the classification model used. Furthermore, in most cases, the method described in this embodiment achieves a noticeable improvement in metrics after the first iteration. Even if there are minor temporary drops in accuracy during training, it can regain superior results compared to traditional methods in subsequent iterations. Therefore, the method described in this invention has good versatility.
[0123] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0124] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. An interpretable image classification method, characterized in that, The specific steps are as follows: Obtain the image data to be classified; The image data to be classified is input into an interpretable image classification model to obtain the category label of the category; the interpretable image classification model consists of a classification model trained iteratively for two classes based on a first loss function and a spatial attention network trained iteratively for two classes based on a second loss function with hyperparameters; Output the category labels; The steps for obtaining the interpretable image classification model are as follows: Step 21: Obtain image data of the target application scenario, and construct training and testing sets based on the image data; Step 22: Based on the training images in the training set, use the first loss function and optimizer to perform zero-class iterative training on the initial training model to obtain the first classification model; Step 23: Input the training images from the training set into the spatial attention network to obtain an attention matrix; calculate the Hadamard product between the attention matrix and the training images to obtain a weighted image; input the weighted image into the first classification model to obtain the category label of the category; iteratively train the spatial attention network using the second loss function and the optimizer according to the category label, and simultaneously iteratively train the first classification model using the first loss function and the optimizer according to the category label to obtain a second classification model; Step 24: Adjust the hyperparameters of the second loss function based on the accuracy of the second classification model and the accuracy of the first classification model. Determine whether to iteratively train the second classification model according to the iteration termination condition. If yes, update the hyperparameters of the second loss function and execute step 23; otherwise, output the interpretable image classification model. The second loss function includes the first loss function and the attention loss function; the expression for the attention loss function is: ; In the formula, For the set of elements of the attention matrix, For the set of One element, The average value of the set elements. The total number of elements, represents the hyperparameters of the attention loss function; The hyperparameter adjustment method for the second loss function adopts a binary search hyperparameter adjustment algorithm, and the specific steps are as follows: Step 241: Set initial parameters, specifically: set the total number of iterations to... Initialize the search left boundary Initialize the right boundary of the search. Initialize the current iteration count Initialize the model accuracy corresponding to the right boundary. The classification accuracy of the first classification model after the zeroth iteration. ; Step 242, Judgment Is it true? If yes, proceed to step 243; otherwise, end. Step 243: Set hyperparameters Adjust to initialize the left boundary of the search With initial search right boundary The average value; Step 244: Perform one round of iterative training and calculate the classification accuracy of the second classification model. ; Step 245, Judgment If the condition is met, adjust the left boundary and proceed to step 247; otherwise, adjust the hyperparameters. Adjust to the left The model is then iteratively trained, and the accuracy of the second classification model after several rounds is denoted as... ; Step 246, Judgment If the condition is met, adjust the left boundary. If not, then adjust the right boundary, i.e. At the same time, set and execute 247; Step 247, Settings Return to step 242.
2. The interpretable image classification method according to claim 1, characterized in that, The training images need to be preprocessed before use, specifically by processing the training images in the training set into images of the same size, and standardizing the training images according to the mean and variance of the training images in the training set.
3. An interpretable image classification method according to any one of claims 1-2, characterized in that, The spatial attention network includes a downsampling module and a receptive field expansion module. The downsampling module consists of... It consists of several convolutional layers. All parameters of the convolutional layers are identical; the receptive field expansion module consists of... The system consists of several dilated convolutional layers, wherein the dilation rate of the first dilated convolutional layer is 1, and the dilated convolutional layers from the second to the third... The expansion rate of each of the hollow convolutional layers is a prime number that increases sequentially.
4. The interpretable image classification method according to claim 1, characterized in that, Before calculating the Hadamard product, the attention matrix needs to be normalized and scaled.
5. An interpretable image classification system, characterized in that, An interpretable image classification method according to claim 1 includes: The image acquisition module is used to acquire image data to be classified. The image classification module is used to input the image data to be classified into the interpretable image classification model to obtain the category label of the category; the interpretable image classification model consists of a classification model trained iteratively for two classes based on a first loss function and a spatial attention network trained iteratively for two classes based on a second loss function with hyperparameters; The category output module is used to output the category labels.
6. The interpretable image classification system according to claim 5, characterized in that, The image classification module includes: The training set construction module is used to acquire image data of the target application scenario and construct training and test sets based on the image data. The first model training module is used to perform zero-class iterative training on the initial training model using a first loss function and an optimizer based on the training images in the training set to obtain a first classification model. The second model training module is used to input the training images from the training set into the spatial attention network to obtain an attention matrix; calculate the Hadamard product between the attention matrix and the training images to obtain a weighted image; input the weighted image into the first classification model to obtain the category label of the category; perform iterative training of the spatial attention network using a second loss function and the optimizer based on the category label, and simultaneously perform first-class iterative training of the first classification model using the first loss function and the optimizer based on the category label to obtain a second classification model; The third model training module is used to adjust the hyperparameters of the second loss function based on the accuracy of the second classification model and the accuracy of the first classification model, and to determine whether to perform iterative training on the second classification model based on the iteration termination condition. If yes, it updates the hyperparameters of the second loss function, generates an execution instruction, and sends the execution instruction to the second model training module; if no, it outputs the interpretable image classification model.
7. An interpretable image classification system according to claim 6, characterized in that, The image classification module further includes a preprocessing module, which processes the training images in the training set into images of the same size and standardizes the training images according to the mean and variance of the training images in the training set.
Citation Information
Patent Citations
Image classification method based on improved cross entropy loss function
CN116310542A