A method for analyzing the explainability of a SAR image classification network based on attribution reasoning
By constructing an attention attribution measurement model based on attribution reasoning and non-critical token pruning technology, the problem of difficult-to-explain decision-making behavior of the Transformer model in SAR image classification tasks is solved, the interpretable analysis and lightweighting of the model decision path are achieved, and the transparency and accuracy of the model are improved.
Patent Information
- Application Number
- CN202411540761.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2044-10-31
AI Technical Summary
Deep learning models have the problem of difficult-to-explain decision-making behavior in SAR image classification tasks, especially when dealing with large-scale, high-dimensional data sets. The internal calculations of the model are highly abstract, which makes it more difficult to understand.
Using an attribution reasoning-based method, we construct an attention attribution measurement model, calculate the attribution reasoning matrix of each layer of the Transformer classification network, measure the contribution value of the attention head, and achieve lightweighting through non-critical Token pruning to improve the interpretability of the model.
By quantifying the contribution of each layer’s input token to network decision-making, we can achieve interpretable analysis of the Transformer network structure and feature transfer, thereby improving the transparency and accuracy of the model.
Smart Images

Figure CN119514702B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of intelligent interpretation of remote sensing images, and particularly relates to a SAR image classification network explainability analysis method based on attribution reasoning. BACKGROUND
[0002] With the development of deep learning methods, deep networks based on Transformer have shown excellent performance in SAR image classification tasks, but there are many difficult-to-explain problems in their decision-making behavior. The complex structure of the Transformer model is stacked by many layers, each layer contains a large number of parameters and complex nonlinear operations, and this complexity makes it difficult to understand the model's prediction mechanism. Especially when dealing with large-scale, high-dimensional data sets, the calculations performed inside the model become very abstract and even more difficult to understand.
[0003] In order to improve the transparency and reliability of deep learning models, scholars have carried out research. According to the timing of providing explanations to the model, current deep learning explainability methods are generally divided into two categories: pre-explainability methods and post-explainability methods. Pre-explainability models are generally simple in structure and easy to explain, and their model parameters, model nodes, and feature dimensions can be intuitively explained. However, directly using simple and explainable models is difficult to fit large data sets, and the accuracy of the model cannot be guaranteed. Post-explainability methods are used to explain trained models, and by building an explanation model, the working mechanism, decision-making process, and decision-making basis of the deep learning model are transparentized. Post-explainability methods are more versatile than pre-explainability methods and can adapt to different deep networks and task scenarios. According to the differences in explanation objects, post-explainability methods can be divided into global explainability methods and local explainability methods. However, so far, the research on deep learning explainability has not been fully developed. It is of great significance to research more universal and comprehensive deep learning network explainability methods for different complexity task scenarios.
[0004] Therefore, based on attribution reasoning, the application explains the working mechanism of the model from two perspectives of network structure analysis and network feature transmission to improve the explainability of the Transformer type network model. SUMMARY
[0005] In view of the above technical problems, the application provides a SAR image classification network explainability analysis method based on attribution reasoning, which can effectively measure the contribution of each level of network structure and locate the area of interest for model decision-making, thereby improving the explainability of the SAR image classification model based on Transformer.
[0006] The technical method adopted by the present application is: an SAR image classification network explainability analysis method based on attribution reasoning, characterized by comprising the following steps:
[0007] Step one, obtaining the SAR image data set and the trained Transformer classification network;
[0008] Step two, constructing an attention attribution measurement model, and calculating the attribution reasoning matrix of each level of the Transformer classification network;
[0009] Step 201: introduce a scaling factor θ to control the strength of the attention weight inside the Transformer model, according to the formula Calculate the attribution reasoning matrix of the hth head in a certain layer of the Transformer, where A = [A1, A2,..., A h ,..,A H ] represents the attention matrix of the multi-head attention mechanism in the layer, the symbol ⊙ represents the multiplication of the corresponding elements of the matrix, Ainf h ∈R n×n represents the attribution reasoning matrix corresponding to the hth head attention weight matrix A h , represents the gradient of the Transformer network F x (·) along A h ;
[0010] Step 202: use the Riemann sum formula to approximate the integral equation in step 201, that is, Where N is the number of sampling points;
[0011] Step three, measure the contribution value of the attention head, search for the connection relationship with high contribution value in the attention mechanism, and perform explainability analysis on the network structure;
[0012] Step 301: for the ith test set sample X i , the attribution reasoning matrix Ainf i of each layer of the Transformer is calculated by using the attribution measurement model l =[At i l,1 ,At i l,2 ,...,At i l,H , where l represents the lth layer, and H represents the total number of attention heads in the layer;
[0013] Step 302: for the ith test sample, the contribution score of the hth head in the lth layer is calculated by using the formula
[0014] Step 303: Traverse all samples of the test set in turn, and then use the formula The contribution scores are accumulated to obtain the attention head contribution of the lth layer;
[0015] Step 304: Normalize the attention head contribution of each layer, that is, The contribution distribution I of each attention head of the Transformer network on the SAR image dataset is obtained l = [I1, I2,..., I H ];
[0016] Step four, build an attribution score matrix to quantify the contribution of each layer input Token to the network decision, and perform explainability analysis on the key path of the network;
[0017] Step 401: According to step 202, the given sample X i corresponding to the lth layer attribution matrix Wherein represents the attribution matrix of the hth head in the lth layer.
[0018] Step 402: For the hth head in the lth layer, filter out the values on the diagonal line in the attribution matrix and the values lower than the threshold τ, to avoid the influence of strong autocorrelation pairs and weak correlation pairs on the contribution value evaluation, that is, Wherein represents the filtered attribution matrix, ones n×n represents a matrix with all values being 1, I n×n represents an identity matrix, and M n×n represents a binary matrix satisfying the condition .
[0019] Step 403: For the lth layer of the Transformer network, the contribution of all attention heads to the model decision needs to be considered, so the attribution matrices of each attention head are accumulated to obtain the single-layer attribution score matrix of the lth layer
[0020] Step 404: Accumulate the single-layer attribution score matrices of all levels after the lth layer to obtain the overall attribution score matrix of the lth layer of the Transformer network, that is,
[0021] Step 405: Calculate the contribution value of the tth Token in the lth layer, where as t,k represents the (t, k)th element of the lth layer attribution score matrix .
[0022] Step five, non-critical Token pruning is carried out to realize the lightweight of the input Token of the Transformer classification network;
[0023] Step 501: the pruning principle of non-critical Token is proposed: the feature Token pruned in the current level cannot appear in all subsequent levels, that is, the pruned feature Token should not participate in the subsequent propagation of the network; the total number of Token pruned in the current level should be greater than or equal to the total number of Token pruned in the previous level; for each sample, the key information flow in the network should be different;
[0024] Step 502: calculate the sample X i The index number of the key Token retained in the lth layer That is
[0025]
[0026]
[0027] Where k l Indicates the number of Tokens that need to be retained in the lth layer, is the contribution value of all Tokens in the lth layer calculated according to step 505, Indicates the index mask, which blocks the influence of the pruned Token on the subsequent information flow according to the principle of step 501;
[0028] Step 503: determine the sample X i According to the index number retained in each layer Realize the lightweight of the input Token of the network.
[0029] Compared with the prior art, the present application has the following beneficial effects:
[0030] 1. The present application constructs an attention attribution measurement model, obtains the attribution matrix of each level in the classification network, realizes the modeling of the correlation between the attention weight matrix and the model decision result, and provides a quantitative analysis basis for the explainability from different angles.
[0031] 2. Based on the attribution matrix, the present application constructs the contribution value of the attention head in the classification network, realizes the search for the connection relationship with high contribution value in the attention mechanism, and improves the explainability from the perspective of network structure analysis.
[0032] 3、The application constructs the attribution score matrix of Token in each level in the classification network based on the attribution matrix, realizes the quantification of the contribution degree of the input Token in each layer to the network decision, improves the explainability from the perspective of network feature transmission, and completes the model decision path reasoning.
[0033] The technical solutions of the application will be further described in detail below with reference to the drawings and embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0034] Figure 1 The method flowchart of the application.
[0035] Figure 2 The attention attribution measurement schematic diagram in the application.
[0036] Figure 3 The key Token reasoning schematic diagram in the application. DETAILED DESCRIPTION
[0037] The method of the application will be further described in detail below with reference to the drawings and embodiments of the application.
[0038] It should be noted that the embodiments in the present application and the attributes in the embodiments can be combined with each other without conflict. The application will be described in detail below with reference to the drawings and in combination with the embodiments.
[0039] It should be noted that the terms used herein are merely intended to describe specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, the singular form is intended to include the plural form, unless the context clearly indicates otherwise, and it should be understood that, when the terms "comprise" and / or "include" are used in the specification, there is a presence of the features, steps, operations, devices, components and / or combinations thereof.
[0040] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not necessarily limit to those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0041] For ease of description, spatially relative terms such as "above", "above", "on the upper surface of", "above", etc. may be used herein to describe the spatial positional relationship of a device or feature to other devices or features as shown in the figures. It should be understood that spatially relative terms are intended to include different orientations of the device in use or operation in addition to the orientation described in the figures. For example, if the device in the drawings is inverted, the device described as "above other devices or structures" or "above other devices or structures" will be positioned as "below other devices or structures" or "below other devices or structures". Thus, the exemplary term "above" can include both "above" and "below". The device can also be positioned in other different ways (rotated 90 degrees or in other orientations), and the spatially relative descriptions used here are interpreted accordingly.
[0042] like Figure 1 As shown, the present invention includes the following steps:
[0043] Step 1: Obtain the SAR image dataset and the trained Transformer classification network;
[0044] Step 2: Build an attention attribution measurement model and calculate the attribution inference matrix of each layer of the Transformer classification network;
[0045] Step 201: Introduce a scaling factor θ to control the strength of the attention weight inside the Transformer model. According to the formula Calculate the attribution inference matrix of the h-th head in a certain layer of Transformer, where A=[A1,A2,...,A h ,..,A H ] represents the attention matrix of the multi-head attention mechanism of this layer, and the symbol ⊙ represents the multiplication of the corresponding elements of the matrix. Ainf h ∈R n×n Represents the h-th head attention weight matrix A h The corresponding attribution inference matrix, Represents the Transformer network F x (·) Along A h gradient;
[0046] Step 202: Use the Riemann sum formula to approximate the integral equation in step 201, that is, Where N is the number of sampling points;
[0047] Step 3: Measure the contribution value of the attention head, search for connections with high contribution values in the attention mechanism, and perform interpretable analysis on the network structure;
[0048] Step 301: For the ith test set sample X i , the attribution measure model is used to calculate the attribution reasoning matrix of each layer of the Transformer , where l represents the lth layer, and H represents the total number of attention heads in the layer network.
[0049] Step 302: For the ith test sample, the contribution score of the hth head in the lth layer is calculated using the formula
[0050] Step 303: All samples in the test set are traversed in turn, and then the contribution scores are accumulated using the formula to obtain the attention head contribution of the lth layer.
[0051] Step 304: The attention head contribution of each layer is normalized, i.e. to obtain the contribution distribution I of each attention head of the Transformer network on the SAR image dataset l = [I1, I2,..., I H ];
[0052] Step four, construct the attribution score matrix to quantify the contribution of each layer input Token to the network decision, and perform explainability analysis on the key path of the network.
[0053] Step 401: According to step 202, the lth layer attribution matrix corresponding to the given sample X i is obtained , where represents the attribution matrix of the hth head in the lth layer.
[0054] Step 402: For the hth head in the lth layer, filter out the values on the diagonal and values lower than the threshold τ in the attribution matrix, to avoid the influence of strong autocorrelation pairs and weak correlation pairs on the contribution value evaluation, i.e. , where represents the filtered attribution matrix, ones n×n represents a matrix with all values being 1, I n×n represents an identity matrix, and M n×n represents a binary matrix satisfying the condition .
[0055] Step 403: For the lth layer of the Transformer network, the contribution of all attention heads to the model decision needs to be considered, so the attribution matrices of each attention head are accumulated to obtain the single-layer attribution score matrix of the lth layer
[0056] Step 404: Accumulate the single-layer attribution score matrix of all levels after the lth layer to obtain the overall attribution score matrix of the lth layer of the Transformer network, i.e.
[0057] Step 405: Calculate the contribution value of the tth Token in the lth layer, where as t,k represents the (t, k)th element of the attribution score matrix of the lth layer .
[0058] Step five, perform non-critical Token pruning to realize lightweight on the input Token of the Transformer classification network.
[0059] Step 501: Propose the pruning principle of non-critical Token: the feature Token pruned in the current level should not appear in all subsequent levels, i.e. the pruned feature Token should not participate in the subsequent propagation of the network; the total number of Tokens pruned in the current level should be greater than or equal to the total number of Tokens pruned in the previous layer; for each sample, the key information flow in the network should be different.
[0060] Step 502: Calculate the sample X i The index number R l i of the key Token retained in the lth layer, i.e.
[0061]
[0062]
[0063] where k l ' represents the number of Tokens that need to be retained in the lth layer, is the contribution value of all Tokens in the lth layer calculated according to step 505, represents the index mask, which blocks the influence of the pruned Token on the subsequent information flow according to the principle of step 501;
[0064] Step 503: Determine the key Token information flow of the sample X in the Transformer network according to the retained index number R i to realize lightweight on the input Token of the network.
Claims
1.A method for analyzing the explainability of a SAR image classification network based on attribution reasoning, characterized in that, The method comprises the following steps: Step one, obtaining a SAR image data set and a trained Transformer classification network; Step two, constructing an attention attribution measurement model, and calculating an attribution reasoning matrix of each level of the Transformer classification network; Step 201: Introduce a scaling factor θ to control the strength of the attention weights inside the Transformer model, according to the formula Compute the attribution reasoning matrix of the h-th head in a certain layer of the Transformer, where A = [A1, A2,..., A h ,..,A H ] represents the attention matrix of the multi-head attention mechanism in this layer, the symbol ⊙ represents the multiplication of the corresponding elements of the matrix, Ainf h ∈R n×n represents the attribution reasoning matrix corresponding to the h-th head attention weight matrix A h , represents the gradient of the Transformer network F x (·) along A h ; Step 202: using the Riemann sum formula to approximately calculate the integral equation in step 201, that is, where N is the number of sampling points; Step three, measuring the contribution value of the attention head, searching for the connection relationship with high contribution value in the attention mechanism, and performing explainability analysis on the network structure; Step 301: For the i-th test set sample X i , the attribution inference matrix Ainf of each layer of the Transformer is calculated using the attribution measure model i l = [At i l,1 , At i l,2 ,..., At i l,H ], where l represents the l-th layer, and H represents the total number of attention heads that the layer network has; Step 302: For the ith test sample, the contribution score of the hth head in the lth layer is calculated using the formula Step 302: For the ith test sample, the contribution score of the hth head in the lth layer is calculated using the formula Step 303: all samples of the test set are traversed in turn, and then the formula The contribution scores are accumulated to obtain the attention head contribution degree of the lth layer. Step 304: normalizing the contribution degree of each layer of attention head, that is obtain the contribution degree distribution I of each attention head of the Transformer network on the SAR image dataset l = [I1, I2,..., In] ; where n is the number of layers of the Transformer network H ] ; Step four, constructing an attribution score matrix to quantify the contribution degree of each layer input Token to network decision, and performing explainability analysis on the key path of the network; Step 401 : Obtain a given sample X according to step 202 i Corresponding attribution matrix of the lth layer wherein denotes the attribution matrix of the hth head in the lth layer; Step 402: For the h-th head in the l-th layer, filter out the values on the diagonal and the values lower than the threshold τ in the attribution matrix, to avoid the contribution value evaluation impact of strong self-correlation pairs and too weak correlation pairs, i.e. wherein denotes the filtered attribution matrix, ones n×n denotes a matrix with all values being 1, I n×n denotes a unit matrix, M n×n denotes a binary matrix satisfying the condition . Step 403: For the l-th layer of the Transformer network, the contribution of each attention head to the model decision needs to be considered, so the attribution matrix of each attention head is accumulated to obtain the single-layer attribution score matrix of the l-th layer Step 404: Accumulate the single-layer attribution score matrices of all levels after the lth layer to obtain the overall attribution score matrix of the lth layer of the Transformer network, i.e. Step 405: calculating the contribution value of the tth Token in the lth layer, where as t,k denotes the (t, k)th element of the lth layer attribution score matrix . Step five, performing non-key Token pruning to realize lightweight of the input Token of the Transformer classification network; Step 501: pruning principle of non-key Token: the feature Token pruned in the current level should not appear in all subsequent levels, that is, the pruned feature Token should not participate in the subsequent propagation of the network; the total number of Token pruned in the current level should be greater than or equal to the total number of Token pruned in the previous level; for each sample, the key information flow in the network should be different; Step 502: Compute sample X i Key Token index number reserved in the 1st layer That is where k l represents the number of Tokens that need to be reserved in the lth layer, is the contribution value of all Tokens in the lth layer calculated according to step 505, represents an index mask, according to the principle of step 501 to block the influence of the cut-off Tokens on the subsequent information flow; Step 503: determining the sample X according to the index number reserved by each layer i The key token information flow in the Transformer network realizes lightweight on the network input token.
Citation Information
Patent Citations
Deep learning-based interpretable SAR image target detection method and system
CN113902978A
Full-chain interpretable power distribution network single-phase earth fault type identification method and system
CN117929913A