Bernoulli sampling-based interpretable CNN training method and apparatus, and medium
By employing an interpretable CNN training method based on Bernoulli sampling, interpretable class-specific filters are learned, addressing the inherent interpretability deficiency of CNNs in the security domain. This achieves a balance between the interpretability and discriminative power of CNNs, thereby improving the security and reliability of the system.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- TONGJI UNIV
- Filing Date
- 2024-11-28
- Publication Date
- 2026-06-04
AI Technical Summary
Existing convolutional neural networks (CNNs) lack inherent interpretability in safety-critical fields such as autonomous driving and healthcare, making it difficult to understand and verify the model's decision-making process, thus affecting the safety and reliability of the system.
An interpretable CNN training method based on Bernoulli sampling is adopted. By learning the filter-class correspondence matrix P, using Bernoulli distribution reparameterization technique for end-to-end training, interpretable class-specific filters are learned, non-class-specific filter feature maps are masked, the total loss function is calculated and stochastic gradient descent is used to update the network parameters, thereby achieving the interpretability of CNN.
It significantly improves the interpretability metrics of CNNs while maintaining their original discriminative capabilities, enhancing users' trust in and security of deep learning systems.
Smart Images

Figure CN2024135100_04062026_PF_FP_ABST
Abstract
Description
Interpretable CNN training methods, apparatus, and media based on Bernoulli sampling Technical Field
[0001] This invention relates to the field of deep training technology, and in particular to an interpretable CNN training method, apparatus and medium based on Bernoulli sampling. Background Technology
[0002] Convolutional Neural Networks (CNNs) possess exceptional discriminative power and can be applied to numerous fields in real-world production and daily life. However, in safety-critical areas such as autonomous driving and healthcare, the interpretability of neural networks is a crucial attribute that must be considered. Interpretable neural networks not only aid in understanding and validating the model's decision-making process but also provide diagnostic information when problems arise, ensuring the safety and reliability of deep learning systems.
[0003] In recent years, research on the interpretability of CNNs has received increasing attention. Early ex-post interpretation methods focused on generating offline explanations for trained neural networks, with a representative paper being Zhou, B., et al. (2016), Learning deep features for discriminative localization. However, ex-post methods cannot improve the intrinsic interpretability of neural networks because they are independent of the neural network's training process and cannot guide the learning of neural network parameters. Recently, researchers have begun to focus on training interpretable neural networks. For example, Zhang, Q., et al. (2018), Interpretable convolutional neural networks. This paper encourages specifying that filters in convolutional layers respond only to specific parts of an image object. However, this method still relies on ex-post interpretation to match the semantics learned by the filters from a predefined set of semantic concepts, and cannot directly reveal the interpretable information of the filters. This means that further research is needed on how to learn interpretable filters during training to improve the intrinsic interpretability of neural networks, thereby better applying them to high-security fields and enhancing user trust in deep learning systems. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of insufficient interpretability in the prior art by providing an interpretable CNN training method, apparatus and medium based on Bernoulli sampling.
[0005] The objective of this invention can be achieved through the following technical solutions:
[0006] An interpretable CNN training method based on Bernoulli sampling includes the following steps:
[0007] S1: Input image X into the CNN to obtain weights [W1,…,W i ,…,W N The response characteristic map of N filters H = [H1, ..., H2] i ,…,H N ], where W i H represents the trainable weight matrix of the i-th filter. i This represents the response feature map of the i-th filter;
[0008] S2: A trainable filter-class correspondence matrix P∈[0,1] K×N Using each element as a parameter, Bernoulli sampling is performed to obtain a binary allocation matrix Z∈{0,1}. K×N Z yi =1 indicates that the i-th filter belongs exclusively to the y-th image category, and K is the total number of image categories in the dataset;
[0009] S3: Calculate the average filter weight matrix for each image category based on the binarized assignment matrix Z. And calculate the sum of pairwise differences L1 between each average weight matrix;
[0010] S4: Allocation vector Z based on the binarized allocation matrix y The non-class-specific filter of image X is masked by the Hadamard product of the response feature map H, thereby obtaining the mask feature map. Z y Let y represent the y-th row of the assignment matrix Z, where y represents the true class label of image X;
[0011] S5: Combine the response feature map H and the mask feature map Input the classification prediction probability vectors y1 and y2 into the fully connected layer of the CNN respectively, and calculate the cross-entropy loss L2 and L3 between y1, y2 and the true class label y respectively;
[0012] S6: Calculate the total training loss -λL1+L2+L3, where λ is the weight coefficient. Based on the total training loss, update the CNN parameters and filter-class correspondence matrix P using stochastic gradient descent to achieve network training.
[0013] S7: Use the trained network to classify images and obtain interpretable image classification results.
[0014] Furthermore, the CNN is divided into a feature extractor and a classifier, with an arbitrarily specified convolutional layer having N filters as the boundary. The input of the feature extractor is the original image data, and the output is the response feature map of the N filters of the specified convolutional layer. The input of the classifier is the complete or masked feature map of the specified N filters, and the output is the image classification probability score.
[0015] Furthermore, during network training, Bernoulli trials are performed with the response matrix P as a parameter to sample the binarized filter-image correspondence, quantize the differences between filters, and mask the non-class-specific filter feature maps of the input images.
[0016] Furthermore, the calculation expression for the allocation matrix Z in step S2 is: Z yi =P yi +η yi
[0017] In the formula, Z yi P represents the element in the y-th row and i-th column of matrix Z. yi η represents the element in the y-th row and i-th column of matrix P. yi η is a constant. yi The calculation expression is:
[0018] In the formula, It is a random variable that follows a uniform distribution between 0 and 1.
[0019] Furthermore, step S3 includes the following steps:
[0020] S31: Average filter weight for the y-th image category The calculation expression is:
[0021] In the formula, ⊙ represents the Hadamard product, and element Z yi First, it is broadcast into matrix W. y The two matrices have the same shape, and then the product is calculated element by element;
[0022] S32: Calculate the average weight difference L1 of class-specific filters for different classes. The expression for calculating the average weight difference L1 is as follows:
[0023] In the formula, L1 represents the average weight difference of class-specific filters for different classes. Let be the average weight matrix of the filters for the i-th image category. Let be the average weight matrix of the filters for the j-th image category.
[0024] Further, step S4 includes the following steps:
[0025] S41: Use the classification prediction probability score y1 of the complete feature map of the input image X as the multi-class distribution parameter to sample pseudo-labels. The calculation expression for the pseudo-tag is:
[0026] In the formula, a zero element is inserted at the beginning of vector y1, y 1j τ represents the j-th element of vector y1. k This represents the k-th element of vector τ. It is a random variable that follows a uniform distribution between 0 and 1;
[0027] S42: Based on pseudo-labels The index allocation matrix Z of the first The row obtains a binary assignment vector.
[0028] S43: By calculating the allocation vector The mask feature map is obtained by using the Hadamard product of the feature map H and filtering with a non-class-specific filter.
[0029] In the formula, ⊙ represents the Hadamard product. Represents the allocation vector The i-th element, H i This represents the response characteristic map of the i-th filter.
[0030] Further, step S5 includes the following steps:
[0031] S51: Combine feature map H and mask feature map Inputting these into the fully connected layers of the CNN yields classification prediction probability vectors y1 and y2.
[0032] S52: Calculate the cross-entropy loss between the predicted results y1 and y2 and the true class label y of image X, respectively. The expression for calculating the cross-entropy loss is:
[0033] In the formula, y k Let y be the k-th element of the one-hot label vector y. 1k For the k-th element of the predicted result vector y1, y 2k This is the k-th element of the predicted result vector y2.
[0034] Further, step S6 includes the following steps:
[0035] S61: The expression for calculating the total loss function for training a neural network is: -λL1+L2+L3
[0036] In the formula, the weight parameter is fixed at λ = 1;
[0037] S62: Calculate the total loss function The first-order partial derivative with respect to the neural network parameter θ The expression for calculating the first-order partial derivative with respect to the response matrix P is:
[0038] The neural network parameters θ and response matrix P are updated using stochastic gradient descent. The expression for the update calculation is as follows:
[0039] In the formula, lr = 0.001 is the training rate of stochastic gradient descent.
[0040] In a second aspect, an interpretable CNN training apparatus based on Bernoulli sampling is provided, comprising a memory, a processor, and a program stored in the memory, wherein the processor executes the program to implement an interpretable CNN training method based on Bernoulli sampling as described above.
[0041] A third aspect of the invention is a storage medium having a program stored thereon, which, when executed, implements an interpretable CNN training method based on Bernoulli sampling as described above.
[0042] Compared with the prior art, the present invention has the following beneficial effects:
[0043] 1) This invention proposes a learning filter-class correspondence matrix, using a reparameterization technique based on Bernoulli distribution sampling, which supports end-to-end training of Bernoulli probability parameters, learns interpretable class-specific filters, transforms standard CNNs into more interpretable CNNs, has strong adaptability, and can be flexibly combined with various CNN architectures.
[0044] 2) The CNN obtained by the interpretable CNN learning method of the present invention shows a significant improvement over the standard CNN in multiple interpretability metrics, while maintaining the original discrimination ability, thus verifying the effectiveness of the method. Attached Figure Description
[0045] Figure 1 is a flowchart of the learning process of the interpretable CNN of the present invention.
[0046] Figure 2 is a diagram of the network structure of the interpretable CNN of the present invention. Detailed Implementation
[0047] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. These embodiments are based on the technical solution of the present invention and provide detailed implementation methods and specific operating procedures. However, the scope of protection of the present invention is not limited to the following embodiments.
[0048] Example 1
[0049] This invention relates to an interpretable CNN training method, apparatus, and medium based on Bernoulli sampling, as shown in Figure 1. The method includes the following steps:
[0050] S1: Input image X into the CNN to obtain weights [W1,…,W i ,…,W N The response characteristic map of N filters H = [H1, ..., H2] i ,…,H N ], where W i H represents the trainable weight matrix of the i-th filter. i This represents the response feature map of the i-th filter;
[0051] S2: A trainable filter-class correspondence matrix P∈[0,1] K×N Using each element as a parameter, Bernoulli sampling is performed to obtain a binary allocation matrix Z∈{0,1}. K×N Z yi =1 indicates that the i-th filter belongs exclusively to the y-th image category, and K is the total number of image categories in the dataset;
[0052] The expression for calculating the allocation matrix Z is: Z yi =P yi +η yi
[0053] In the formula, Z yi P represents the element in the y-th row and i-th column of matrix Z. yi η represents the element in the y-th row and i-th column of matrix P. yi η is a constant. yi The calculation expression is:
[0054] In the formula, It is a random variable that follows a uniform distribution between zero and one.
[0055] S3: Calculate the average filter weight matrix for each image category based on the binarized assignment matrix Z. And calculate the sum of pairwise differences between each average weight matrix.
[0056] S31: Average filter weight for the y-th image category The calculation expression is:
[0057] In the formula, ⊙ represents the Hadamard product, and element Z yi First, it is broadcast into matrix W. yThe two matrices have the same shape, and then the product is calculated element by element;
[0058] S32: Calculate the average weight difference L1 of class-specific filters for different classes. The expression for calculating the average weight difference L1 is as follows:
[0059] In the formula, L1 represents the average weight difference of class-specific filters for different classes. Let be the average weight matrix of the filters for the i-th image category. Let be the average weight matrix of the filters for the j-th image category.
[0060] S4: Allocation vector Z based on the binarized allocation matrix y The non-class-specific filter of image X is masked by the Hadamard product of the response feature map H, thereby obtaining the mask feature map. Z y Let y represent the y-th row of the assignment matrix Z, where y represents the true class label of image X;
[0061] S41: Use the classification prediction probability score y1 of the complete feature map of the input image X as the multi-class distribution parameter to sample pseudo-labels. The calculation expression for the pseudo-tag is:
[0062] In the formula, a zero element is inserted at the beginning of vector y1, y 1j τ represents the j-th element of vector y1. k This represents the k-th element of vector τ. It is a random variable that follows a uniform distribution between 0 and 1;
[0063] S42: Based on pseudo-labels The index allocation matrix Z of the first The row obtains a binary assignment vector.
[0064] S43: By calculating the allocation vector The mask feature map is obtained by using the Hadamard product of the feature map H and filtering with a non-class-specific filter.
[0065] In the formula, ⊙ represents the Hadamard product. Represents the allocation vector The i-th element, H i This represents the response characteristic map of the i-th filter.
[0066] S5: Combine the response feature map H and the mask feature map Input the classification prediction probability vectors y1 and y2 into the fully connected layer of the CNN respectively, and calculate the cross-entropy loss L2 and L3 between y1, y2 and the true class label y respectively;
[0067] S51: Combine feature map H and mask feature map Inputting these into the fully connected layers of the CNN yields classification prediction probability vectors y1 and y2.
[0068] S52: Calculate the cross-entropy loss between the predicted results y1 and y2 and the true class label y of image X, respectively. The expression for calculating the cross-entropy loss is:
[0069] In the formula, y k Let y be the k-th element of the one-hot label vector y. 1k For the k-th element of the predicted result vector y1, y 2k This is the k-th element of the predicted result vector y2.
[0070] S6: Calculate the total training loss -λL1+L2+L3, where λ is the weight coefficient, and use stochastic gradient descent to update the CNN parameters and filter-class correspondence matrix P to achieve network training and obtain an interpretable CNN.
[0071] S61: The expression for calculating the total loss function for training a neural network is: -λL1+L2+L3
[0072] In the formula, the weight parameter is fixed at λ = 1;
[0073] S62: Calculate the first-order partial derivative of the total loss function L with respect to the neural network parameter θ. The expression for calculating the first-order partial derivative with respect to the response matrix P is:
[0074] The neural network parameters θ and response matrix P are updated using stochastic gradient descent. The expression for the update calculation is as follows:
[0075] In the formula, lr = 0.001 is the training rate of stochastic gradient descent.
[0076] S7: Use the trained network to classify images and obtain interpretable image classification results.
[0077] Example 2
[0078] Based on Embodiment 1 of the present invention, the algorithm structure diagram for image classification is shown in Figure 2. The original image is input into the feature extractor to generate a complete feature map. On one hand, the complete feature map is input into the classifier to obtain the first classification prediction result. On the other hand, the complete feature map and the first classification prediction result are input into the sampling result of the filter-image category correspondence matrix to perform Hadamard product to generate a mask feature map. Subsequently, the mask feature map is input into the classifier again to generate a second classification prediction result, which is the final classification result.
[0079] A CNN can be divided into a feature extractor and a classifier by using any specified convolutional layer with N filters (or kernels). The input to the feature extractor is the original image data, and the output is the response feature map of the N filters of the specified convolutional layer; the input to the classifier is the complete or masked feature map of these N filters, and the output is the image classification probability score.
[0080] Introducing a filter – image category response matrix P∈[0,1] K×N This method learns the correspondence between N filters in a specified convolutional layer and K image categories in a dataset. During network training, Bernoulli trials are performed with the response matrix P as a parameter to sample and binarize the filter-image assignment relationship. Based on this assignment relationship, the differences between class-specific filters of different classes are quantified, and the non-class-specific filter feature maps of the input images are masked.
[0081] The learning objective of interpretable CNNs is to maximize the differences between class-specific filters of different classes and enable the network to accurately classify based on full or masked feature maps.
[0082] Standard CNN (STD) and internationally advanced interpretable CNN learning methods, including Class-Specific Gate (CSG) Neural Networks and Interpretable Combinatorial CNN (ICCNN), were selected. ResNet-18 was used as the backbone network, and validation was performed on the CIFAR-10 and STL-10 datasets. Discriminant metric ACC1 and three interpretability metrics, MIS, ACC2, and ACC3, were used as evaluation metrics. ACC1 represents the classification accuracy of the complete feature map, ACC2 represents the classification accuracy of the class-specific filter feature map, and ACC3 represents the classification accuracy of the non-class-specific filter feature map. MIS represents the mutual information between the filter and its corresponding class label. The corresponding class is read from the learned filter-image class correspondence matrix P. The i-th filter corresponds to the argmax-th class. y P y Image correspondence. The MIS calculation expression is: MIS = mean i (max y (MI(H i ||y))
[0083] In the formula, H i Let be the feature map of the i-th filter, y be the true class label of the image, and MI(·||·) represent mutual information. All evaluation metrics range from 0 to 1. For ACC1, ACC2, and MIS, higher values indicate better performance; for ACC3, lower values indicate better performance.
[0084] Table 1 shows the performance of CNNs learned by different methods on two benchmark datasets.
[0085] As can be seen from Table 1, the interpretable CNN of the present invention has a significant improvement in interpretability compared with standard neural networks and neural networks learned by other methods, while maintaining the high discriminative ability of standard neural networks.
[0086] Table 2 shows the performance of different backbone networks on the CIFAR-10 dataset.
[0087] As can be seen from Table 2, the interpretable CNN learning method of the present invention is compatible with a variety of mainstream backbone networks, which indicates that the learning method of the present invention has broad applicability and can provide flexibility for model selection and deployment in practical applications.
[0088] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0089] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0090] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.
Claims
1. An interpretable CNN training method based on Bernoulli sampling, characterized in that, Includes the following steps: S1: Input image X into the CNN to obtain weights [W1,…,W i ,…,W N The response characteristic map of N filters H = [H1, ..., H2] i ,…,H N ], where W i H represents the trainable weight matrix of the i-th filter. i This represents the response feature map of the i-th filter; S2: A trainable filter-class correspondence matrix P∈[0,1] K×N Using each element as a parameter, Bernoulli sampling is performed to obtain a binary allocation matrix Z∈{0,1}. K×N Z yi =1 indicates that the i-th filter belongs exclusively to the y-th image category, and K is the total number of image categories in the dataset; S3: Calculate the average filter weight matrix for each image category based on the binarized assignment matrix Z. And calculate the sum of pairwise differences L1 between each average weight matrix; S4: Allocation vector Z based on the binarized allocation matrix y The non-class-specific filter of image X is masked by the Hadamard product of the response feature map H, thereby obtaining the mask feature map. Z y Let y represent the y-th row of the assignment matrix Z, where y represents the true class label of image X; S5: Combine the response feature map H and the mask feature map Input the classification prediction probability vectors y1 and y2 into the fully connected layer of the CNN respectively, and calculate the cross-entropy loss L2 and L3 between y1, y2 and the true class label y respectively; S6: Calculate the total training loss -λL1+L2+L3, where λ is the weight coefficient. Based on the total training loss, update the CNN parameters and the filter-class correspondence matrix P using stochastic gradient descent to obtain the trained network. S7: Use the trained network to classify images and obtain interpretable image classification results.
2. The interpretable CNN training method based on Bernoulli sampling according to claim 1, characterized in that, The CNN is divided into a feature extractor and a classifier, with an arbitrarily specified convolutional layer having N filters as the boundary. The input of the feature extractor is the original image data, and the output is the response feature map of the N filters of the specified convolutional layer. The input of the classifier is the complete or masked feature map of the N filters, and the output is the image classification probability score.
3. The interpretable CNN training method based on Bernoulli sampling according to claim 1, characterized in that, During network training, Bernoulli trials are performed with response matrix P as a parameter to sample the binarized filter-image correspondence, quantize the differences between filters, and mask the non-class-specific filter feature map of the input image.
4. The interpretable CNN training method based on Bernoulli sampling according to claim 1, characterized in that, The expression for calculating the allocation matrix Z in step S2 is: Z yi =P yi +η yi In the formula, Z yi P represents the element in the y-th row and i-th column of matrix Z. yi η represents the element in the y-th row and i-th column of matrix P. yi η is a constant. yi The calculation expression is: In the formula, It is a random variable that follows a uniform distribution between 0 and 1.
5. The interpretable CNN training method based on Bernoulli sampling according to claim 1, characterized in that, Step S3 includes the following steps: S31: Average filter weight for the y-th image category The calculation expression is: In the formula, ⊙ represents the Hadamard product, and element Z yi First, it is broadcast into matrix W. y The two matrices have the same shape, and then the product is calculated element by element; S32: Calculate the average weight difference L1 of class-specific filters for different classes. The expression for calculating the average weight difference L1 is as follows: In the formula, L1 represents the average weight difference of class-specific filters for different classes. Let be the average weight matrix of the filters for the i-th image category. Let be the average weight matrix of the filters for the j-th image category.
6. The interpretable CNN training method based on Bernoulli sampling according to claim 1, characterized in that, Step S4 includes the following steps: S41: Use the classification prediction probability score y1 of the complete feature map of the input image X as the multi-class distribution parameter to sample pseudo-labels. The calculation expression for the pseudo-tag is: In the formula, a zero element is inserted at the beginning of vector y1, y 1j τ represents the j-th element of vector y1. k This represents the k-th element of vector τ. It is a random variable that follows a uniform distribution between 0 and 1; S42: Based on pseudo-labels The index allocation matrix Z of the first The row obtains a binary assignment vector. S43: By calculating the allocation vector The mask feature map is obtained by using the Hadamard product of the feature map H and filtering with a non-class-specific filter. In the formula, ⊙ represents the Hadamard product. Represents the allocation vector The i-th element, H i This represents the response characteristic map of the i-th filter.
7. The interpretable CNN training method based on Bernoulli sampling according to claim 1, characterized in that, Step S5 includes the following steps: S51: Combine feature map H and mask feature map Inputting these into the fully connected layers of the CNN yields classification prediction probability vectors y1 and y2. S52: Calculate the cross-entropy loss between the predicted results y1 and y2 and the true class label y of image X, respectively. The expression for calculating the cross-entropy loss is: In the formula, y k Let y be the k-th element of the one-hot label vector y. 1k For the k-th element of the predicted result vector y1, y 2k This is the k-th element of the predicted result vector y2.
8. The interpretable CNN training method based on Bernoulli sampling according to claim 1, characterized in that, Step S6 includes the following steps: S61: The expression for calculating the total loss function for training a neural network is: -λL1+L2+L3 In the formula, the weight parameter is fixed at λ = 1; S62: Calculate the first-order partial derivative of the total loss function L with respect to the neural network parameter θ. The expression for calculating the first-order partial derivative with respect to the response matrix P is: The neural network parameters θ and response matrix P are updated using stochastic gradient descent. The expression for the update calculation is as follows: In the formula, lr = 0.001 is the training rate of stochastic gradient descent.
9. An interpretable CNN training apparatus based on Bernoulli sampling, comprising a memory, a processor, and a program stored in the memory, characterized in that, When the processor executes the program, it implements an interpretable CNN training method based on Bernoulli sampling as described in any one of claims 1-8.
10. A storage medium having a program stored thereon, characterized in that, When the program is executed, it implements an interpretable CNN training method based on Bernoulli sampling as described in any one of claims 1-8.