Interpreting ResNet Model With LRP(Layer-wise Relevance Propagation)
使用Layer-wise Relevance Propagation
对ResNet
和VGG
网络进行可解释的分析。
Star and Fork!
本项目的所有代码和tutorials均源于PaddlePaddle的InterpretDL仓库,欢迎大家Star
和Fork
!
InterpretDL: Interpretation of Deep Learning Models based on PaddlePaddle
InterpretDL, short for interpretations of deep learning models, is a model interpretation toolkit for PaddlePaddle models. This toolkit contains implementations of many interpretation algorithms, including LIME, Grad-CAM, Integrated Gradients and more. Some SOTA and new interpretation algorithms are also implemented.
InterpretDL is under active construction and all contributions are welcome!
克隆InterpretDL仓库
# 下载比较慢 附上了压缩包
# !git clone https://github.com/PaddlePaddle/InterpretDL.git
%cd ~
! unzip -oq data/data98915/InterpretDL.zip
%cd InterpretDL/tutorials
/home/aistudio
/home/aistudio/InterpretDL/tutorials
# 安装依赖
!pip install scikit-image
!python setup.py install
Layer-wise Relevance Propagation (LRP) is an explanation technique applicable to models structured as neural networks, where inputs can be e.g. images, videos, or text
.
LRP operates by propagating the prediction f ( x ) f(x) f(x) backwards in the neural network, by means of purposely designed local propagation rules.
LRP rules could be easily expressed in terms of matrix-vector operations. In practice, state-of-the-art neural networks such as ResNet make use of more complex layers such as convolutions and pooling.
In this case, LRP rules are more conveniently implemented by casting the operations of the four-step procedure above as forward
and gradient
evaluations on these layers. These operations are readily available in neural network frameworks such as PaddlePaddle and Pytorch, and can therefore be reused for the purpose of implementing LRP.
Here, we take the ResNet
pretrained network for image classification.
LRP Rules for Deep Rectifier Networks
Basic Rule (LRP-0)
This rule redistributes in proportion to the contributions of each input to the neuron activation as they occur in Eq. below:
R j = ∑ k a j w j k ∑ 0 , j a j w j k R k R_j = \sum_k{\frac{a_j w_{jk}}{\sum_{0, j}{a_jw_{jk}}}R_k} Rj=k∑∑0,jajwjkajwjkRk
Epsilon Rule (LRP- ϵ \epsilon ϵ)
A first enhancement of the basic LRP-0 rule consists of adding a small positive term in the denominator:
R j = ∑ k a j w j k ϵ + ∑ 0 , j a j w j k R k R_j = \sum_k{\frac{a_j w_{jk}}{\epsilon + \sum_{0, j}{a_jw_{jk}}}R_k} Rj=k∑ϵ+∑0,jajw