A method and system for quantifying semantic differences between neural network representations
By learning the semantic concept weights of intermediate layer filters in a neural network using the Net2Vec method and calculating the intersection-union ratio difference of the dataset, the shortcomings in measuring the semantic information differences between neural network representations are addressed, enabling accurate analysis of the internal mechanisms of neural networks.
Patent Information
- Application Number
- CN202310922777.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-26
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2043-07-26
AI Technical Summary
Existing technologies cannot accurately measure the semantic information differences between neural network representations, making it difficult to analyze the internal mechanisms of neural networks.
The Net2Vec method is used to learn the semantic concept weights corresponding to each filter in the intermediate layer on the reference dataset, calculate the cross-union ratio difference of the representation datasets, and integrate them to obtain the semantic differences between the neural network representations.
It provides an accurate method for measuring semantic differences, which can analyze the internal mechanisms of neural networks and is applicable to the difference analysis of multimodal neural networks.
Smart Images

Figure CN116992930B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision and interpretability technology, specifically relating to a method and system for quantifying semantic differences between neural network representations. Background Technology
[0002] In recent years, while deep neural networks have achieved remarkable results on various tasks, they remain difficult-to-understand "black boxes." Visualizing the semantic concepts encoded by the intermediate layers of neural networks is a natural way to interpret them. The activation maximization method finds a representative feature that maximizes the activation of a neuron, channel, or layer. Visualizations can be used to roughly decode the semantic concepts contained in the intermediate layers of a neural network. For example, low-level filters typically encode basic concepts such as edges and textures, while high-level filters often encode higher-level objects and patterns. Beyond visualization, some researchers have focused on exploring the relationship between intermediate layer filters and semantic concepts. The paper "David Bau, Bolei Zhou, Aditya Khosla, Aude Oliva, and Antonio Torralba. Network dissection: Quantifying interpretability of deep visual representations. In Proc. CVPR, 2017." collects a new dataset, BRODEN, which provides pixel-level labels for visual concepts and discovers alignments between individual filters and specific concepts. The paper "Ruth Fong and Andrea Vedaldi.Net2vec: Quantifying and explaining how concepts are encoded by filters in deep neural networks. In Proc. CVPR, 2018." demonstrates how deep neural networks (DNNs) use multiple filters to represent specific semantic concepts and studies concept embedding through combinations of multiple filters. However, most existing studies only visualize or statistically distribute the semantic concepts implied by neural network representations, i.e., the distribution of the number of filters or IoU values corresponding to each semantic concept in the statistical representation. This results in the inability to measure the semantic information differences between two neural network representations. When analyzing the internal mechanisms of neural networks, it is usually necessary to analyze various differences between the representations of two neural networks, such as differences in semantic information. Therefore, there is an urgent need to solve the problem of the inability to measure the semantic information differences between two neural network representations. Summary of the Invention
[0003] This invention addresses the problems existing in the prior art by providing a method and system for quantifying the semantic differences between neural network representations. First, it extracts the two neural network representations to be compared. Then, using the Net2Vec method, it learns the weights of each filter in the intermediate layer corresponding to each semantic concept on a reference dataset. Next, it calculates the intersection-union ratio (IU) of each representation with respect to all semantic concepts in the reference dataset. Finally, it integrates the difference between the IU of the two representations with respect to all semantic concepts to obtain the semantic difference between the two neural network representations. This invention solves the problem of the lack of accurate measurement of differences between neural network representations at the semantic information level, and provides an accurate measurement effect.
[0004] To achieve the above objectives, the technical solution adopted by the present invention is: a method for quantifying semantic differences between neural network representations, comprising the following steps:
[0005] S1, Extracting Representations: The two neural networks from which features need to be extracted make predictions on a reference dataset. During the prediction process, the intermediate layer outputs of the neural networks when predicting each sample are retained.
[0006] S2, learn the weights: use the Net2Vec method to learn the weights of each filter in the intermediate layer corresponding to each semantic concept on the reference dataset;
[0007] S3, Calculate the intersection-union ratio of the dataset: The activation values of each filter in the intermediate layer output retained in step S1 are linearly superimposed using the weights learned in step S2 to obtain the total activation value corresponding to each semantic concept. The total activation value is then binarized to obtain the mask for each sample corresponding to each semantic concept. Finally, the intersection-union ratio of the dataset corresponding to each representation for each semantic concept is calculated.
[0008] S4, Difference Integration: Calculate the difference between the intersection and union ratios of the representations of the two neural networks for all semantic concepts in the dataset, and integrate the differences to obtain the semantic differences between the representations of the two neural networks.
[0009] As an improvement to the present invention, the Net2Vec method in step S2 is specifically as follows:
[0010] The predicted segmentation mask M(x; w) is calculated using the Sigmoid function σ according to the following formula:
[0011]
[0012] Where, w∈R K The weights to be learned, K is the total number of filters in the intermediate layer, and A... k (x) is the activation map of the k-th filter with respect to the input x;
[0013] The weights w for concept c are learned by minimizing the binary cross-entropy loss function as follows:
[0014]
[0015] Where, N c It is the number of samples containing concept c, x∈X c Let represent a sample containing concept c, and Where |L c (x)| is the number of foreground pixels of concept c in the ground truth mask of sample x, S=h s ·w s This represents the total number of pixels in the truth mask.
[0016] As another improvement of the present invention, in step S3, the intersection-union ratio (Set IoU) of the dataset for concept c is:
[0017]
[0018] Among them, L c It is a truth-value segmentation mask.
[0019] As another improvement of the present invention, in step S4, the integration method of the difference between the intersection-union ratios of the representations of the two neural networks for all semantic concepts is as follows:
[0020]
[0021] Among them, α=I(min(IoU set (c j ;R2), IoU set (c j ;R1))>0) Judgment concept c j Is it a shared concept between two representations? If it is, then α = 1; otherwise, α = 0; I(·) is an indicator function, X R For the reference dataset, |L j (x)| is the concept c j The number of foreground pixels in the ground truth mask of sample x, |X R | represents the total number of samples in the reference dataset, S = h s ·w s This represents the total number of pixels in the truth mask. It is a semantic concept shared by the representations R1 and R2 of two neural networks. λ is a semantic concept that is not shared between two representations, and λ is the weight of a concept that appears or disappears in the representation R2 compared to the representation R1.
[0022] As another improvement of the present invention, the semantic concepts shared by the representations R1 and R2 of the two neural networks are calculated according to the following formula to obtain the semantic difference between R2 and R1:
[0023]
[0024] Among them, IoU set (c j ;R i ) j=1...C It is a characterization of R i The intersection-union ratio of the datasets corresponding to each semantic concept, where C is the total number of concepts;
[0025] The semantic difference between R2 and R1 is obtained by calculating the non-shared semantic concepts between the two representations using the following formula:
[0026]
[0027] As another improvement of the present invention, the value of λ is 2.
[0028] To achieve the above objectives, the present invention also adopts the following technical solution: a system for quantifying semantic differences between neural network representations, comprising a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the methods described above.
[0029] Compared with existing technologies, this invention offers the following technical advantages and effects: It designs a method and system for quantifying semantic differences between neural network representations. The method calculates the intersection-union ratio (IU) of the datasets corresponding to each semantic concept for each representation. By integrating the differences in IU between representations for all semantic concepts, the semantic difference between two representations is obtained. This invention solves the problem of the inability to measure semantic information differences between neural network representations, providing a method for accurately measuring the semantic information differences between neural network representations in the field of interpretability. Because it uses the Net2Vec method to learn the weights of each filter in the intermediate layer corresponding to each semantic concept on a reference dataset, and considers the learning difficulty of shared and non-shared semantic concepts between the two representations by assigning different weights, the measurement results are accurate and consistent with experimental experience. This invention can be used to compare the semantic differences between representations in different intermediate layers of a neural network, thereby semantically analyzing the internal mechanisms of the neural network. This invention can also be used to measure the semantic differences between different modal representations with activation map forms, such as RGB modality, depth modality, and infrared modality, providing a semantic measurement method for analyzing the differences between different modal representations in multimodal neural networks. Attached Figure Description
[0030] Figure 1 This is a flowchart of the steps of a method for quantifying semantic differences between neural network representations according to the present invention. Detailed Implementation
[0031] The present invention will be further illustrated below with reference to the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are for illustrative purposes only and are not intended to limit the scope of the invention.
[0032] Example 1
[0033] like Figure 1 As shown, a method for quantifying semantic differences between neural network representations is implemented as follows:
[0034] Step S1, extract the representations of the two neural networks (e.g., ResNet50) to be compared: make predictions on a reference dataset (e.g., BRODEN dataset) for the neural network from which features need to be extracted. During the prediction process, retain the intermediate layer outputs of the neural network when predicting each sample.
[0035] Step S2: Using the Net2Vec method, learn the weights of each filter in the intermediate layer corresponding to each semantic concept on the reference dataset.
[0036] First, the weights we need to learn are w∈R K This represents the total number of filters in the intermediate layer, and the predicted segmentation mask M(x;w) is calculated using the sigmoid function σ according to the following formula:
[0037]
[0038] Among them, A k (x) is the activation map of the k-th filter with respect to the input x;
[0039] Then, we learn the weights w for concept c by minimizing the binary cross-entropy loss function as follows:
[0040]
[0041] Where, N c It is the number of samples containing concept c, x∈X c Let represent a sample containing concept c, and Where |L c (x)| is the number of foreground pixels of concept c in the ground truth mask of sample x, S=h s ·w s This represents the total number of pixels in the truth mask.
[0042] Then, on the reference dataset, the SGD optimizer was used with a learning rate of 0.0001, momentum of 0.9, and batch size of 64, and the training was performed for 30 epochs to obtain the weights corresponding to each semantic concept.
[0043] Step S3: Calculate the dataset intersection-union ratio for each representation corresponding to each semantic concept: First, use the Net2Vec method to learn the weights of each filter in the intermediate layer corresponding to each semantic concept. Then, use the learned weights to linearly superimpose the activation values of each filter in the intermediate layer output retained in the previous step to obtain the total activation value corresponding to each semantic concept. Then, binarize the total activation value to obtain the mask for each sample corresponding to each semantic concept. Finally, calculate the dataset intersection-union ratio for each representation corresponding to each semantic concept.
[0044] The specific steps are as follows:
[0045] The Set IoU for concept c is calculated using the following formula:
[0046]
[0047] This formula calculates the segmentation mask M, which is obtained by linearly superimposing the activation values of each filter with weight w for concept c, and then binarizing the total activation values, and the ground truth segmentation mask L. c The crossover ratio (Jakkard coefficient) between nodes;
[0048] Then, calculate the intersection-union ratio of the dataset for each semantic concept.
[0049] Step S4: Integrate the difference between the intersection-union ratios of the two representations for all semantic concepts in the dataset;
[0050] The steps described above for integrating the difference between the intersection and union ratios of the two representations for all semantic concepts in the dataset are as follows:
[0051] First, we use R1 and R2 to represent the representations of the two neural networks, and IoU to represent the representations of the two neural networks. set (c j ;R i ) j=1...C Representation R i The dataset intersection-union ratio (R1) is calculated for each semantic concept, where C is the total number of concepts. Then, the semantic difference between R2 and R1 is calculated for the semantic concepts shared between the two representations according to the following formula:
[0052]
[0053] Then, the semantic difference between R2 and R1 is calculated for the non-shared semantic concepts between the two representations according to the following formula:
[0054]
[0055] Finally, we integrate all semantic concepts according to the above two equations and calculate the semantic difference between the two neural network representations:
[0056]
[0057] Among them, α=I(min(IoU set (c j ;R2), IoU set (c j ;R1))>0)Judgment concept c j Is it a shared concept between two representations? If it is a shared concept, then α = 1; otherwise, α = 0. I(·) is an indicator function, and X... R For the reference dataset, |L j (x)| is the concept c j The number of foreground pixels in the ground truth mask of sample x, |X R | represents the total number of samples in the reference dataset, S = h s ·w s This represents the total number of pixels in the truth mask.
[0058] We set λ=2 to emphasize the semantic differences arising from non-shared concepts between the two representations, namely, the semantic differences between R2 and R1 caused by the addition or disappearance of semantic concepts. For concept c j The percentage of pixels in the entire reference dataset is used to divide the semantic difference of each semantic concept by this formula to eliminate the semantic concept proportion bias present in the reference dataset.
[0059] When the semantic difference S.Var(R2;R1) is positive, it means that R2 has richer semantic information than R1, and vice versa.
[0060] It should be noted that the above content merely illustrates the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. For those skilled in the art, various improvements and modifications can be made without departing from the principle of the present invention, and all such improvements and modifications fall within the scope of protection of the claims of the present invention.
Claims
1. A method for quantifying semantic differences between neural network representations, characterized in that, Includes the following steps: S1, Extracting Representations: The two neural networks from which features need to be extracted make predictions on a reference dataset. During the prediction process, the intermediate layer outputs of the neural networks when predicting each sample are retained. S2, learn the weights: use the Net2Vec method to learn the weights of each filter in the intermediate layer corresponding to each semantic concept on the reference dataset; S3, Calculate the intersection-union ratio of the dataset: The activation values of each filter in the intermediate layer output retained in step S1 are linearly superimposed using the weights learned in step S2 to obtain the total activation value corresponding to each semantic concept. The total activation value is then binarized to obtain the mask for each sample corresponding to each semantic concept. Finally, the intersection-union ratio of the dataset corresponding to each representation for each semantic concept is calculated. S4, Difference Integration: Calculate the difference between the intersection and union ratios of the representations of the two neural networks for all semantic concepts in the dataset, and integrate the differences to obtain the semantic differences between the representations of the two neural networks.
2. The method for quantifying semantic differences between neural network representations as described in claim 1, characterized in that: The Net2Vec method in step S2 is specifically as follows: Use the Sigmoid function The predicted segmentation mask is calculated using the following formula. : ; in, It is the weight to be learned. It represents the total number of filters in the intermediate layer. It is the first Each filter is for the input. Activation graph; Learning for concepts is achieved by minimizing the binary cross-entropy loss function as follows. weight : ; in, It contains concepts The number of samples, Indicates the presence of a concept The sample, and ,in It is a concept In the sample The number of foreground pixels in the ground truth mask. This represents the total number of pixels in the truth mask.
3. The method for quantifying semantic differences between neural network representations as described in claim 2, characterized in that: In step S3, for the concept Set IoU: ; in, It is a truth-value segmentation mask.
4. A method for quantifying semantic differences between neural network representations as described in claim 2 or 3, characterized in that: In step S4, the integration method of the difference between the intersection-union ratios of the representations of the two neural networks for all semantic concepts in the dataset is as follows: ; in, Judgment concept Is it a shared concept between the two representations? If it is a shared concept, then... ;otherwise ; For indicator functions, For reference dataset, It is a concept In the sample The number of foreground pixels in the ground truth mask. For the total number of samples in the reference dataset, This represents the total number of pixels in the truth mask. It is a representation of two neural networks. and Shared semantic concepts Two representations that do not share semantic concepts 5. The method for quantifying semantic differences between neural network representations as described in claim 4, characterized in that: The representations of the two neural networks are calculated according to the following formula. and The shared semantic concepts between them are obtained Compared to Semantic differences: ; in, It is a representation The intersection-union ratio of the dataset for each semantic concept. It is the total number of concepts; The following formula is used to calculate the non-shared semantic concepts between two representations, yielding the following result. Compared to Semantic differences:
6. The method for quantifying semantic differences between neural network representations as described in claim 5, characterized in that: The .
7. A system for quantifying semantic differences between neural network representations, comprising a computer program, characterized in that: When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-6 above.
Citation Information
Patent Citations
Method and system for quantifying semantic variance between neural network representations
US12283082B1