Dense sparse-dense training for dnn and Other Models
Learning how to explain neural networks: PatternNet and PatternAttribution
1. Learning how to explain neural networks
PatternNet and PatternAttribution
PJ Kindermans et al. 2017
손규빈
고려대학교 산업경영공학과
Data Science & Business Analytics 연구실
2. / 29
목차
1. 과거 방법론들의 전반적인 문제점
2. 과거 방법론 분석
1) DeConvNet
2) Guided BackProp
3. Linear model 구상
1) Deterministic distractor
2) Additive isotropic Gaussian noise
4. Approaches
5. Quality criterion for signal estimator
6. Learning to estimate signal
1) Existing estimators
2) PatternNet & PatternAttribution
7. Experiments
2
3. / 29
0. 요약
Data는 중요한 의미를 담고 있는 Signal과 쓸모없는 부분인 Distractor로 구성된다.
시각화를 한다면 Signal 부분에 중점을 두어야 한다.
Model의 weight는 Distractor에 영향을 많이 받기 때문에
시각화를 할 때 weight에만 의존하면 좋지 않은 결과를 낸다.
output y와 distractor의 correlation으로 signal의 질을 판단, 평가할 수 있다.
충분히 학습된 모델의 { weight, input, output } 값으로 linear, non-linear
두 방식으로 signal을 구할 수 있고, 이 시그널로 시각화한다.
3
4. / 29
1. 과거 방법론들의 문제점
Deep learning을 설명하기 위한 다양한 시도들이 있어왔음
•DeConvNet, Guided BackProp, LRP(Layer-wise Relevance Propagation)
위 모델들의 주요 가정은 중요한 정보가 압축된 Output을 뒤로 Backpropagation 시키
면 input에 중요한 정보들이 어떻게 함축되어있는지 알 수 있다는 것
4
5. / 29
1. 과거 방법론들의 문제점(Cont’d)
하지만 과거 방법론들이 추출한 saliency map들이 겉으론 그럴싸해보여도,
이론적으로 완벽하게 input data의 중요한 부분들을 추출하진 못함
Data는 Signal과 Distractor 두 가지로 구분할 수 있는데
•Relevant signal: Data를 나타내는 중요한 부분, 핵심 내용
•Distracting component: Data와 관계없는 noise
Signal이 아니라 Distractor에 크게 좌지우지되는 Weight vector로 모델을 설명함
•일반적으로 Deep learning model이 하는 일은 Data에서 Distractor를 제거하는 것
•그래서 weight vector를 filter라고 부른다
5
- Distractor의 direction에
따라 weight vector의
direction이 마구 변하는
것을 볼 수 있음
- Weight vector의 역할은
distractor의 제거이므로
당연한 현상
6. / 29
2.1 과거 방법론 - DeConvNet by Zeiler & Fergus
DeconvNet 이전까지는
•input layer와 바로 맞닿아있는 첫 번째 layer의 효과에 대해서만 설명하거나 -> 설명 부족
•Hessian matrix를 이용해서 다른 layer의 효과도 설명
-> layer를 넘어갈수록 복잡해지기 때문에 quadratic approximation으론 한계가 있음
주요 컨셉
•Gradient descent를 활용하여 특정 neuron을 활성화시키는 input space의 패턴 찾기
•같은 맥락에서 비슷한 연구들 존재
•Simonyan et al. -> fully connected layer에서 saliency map을 찾는 연구
•Girchick et al. -> image의 어떤 patch가 filter를 activation 시키는지 찾기
6
(1) Adaptive Deconvolutional Networks for Mid and High Level Feature Learning - Matthew D. Zeiler and Rob Fergus, 2011
(2) Visualizing and Understanding Convolutioinal Networks - Matthew D. Zeiler and Rob Fergus, 2014
7. / 29
2.1 과거 방법론 - DeConvNet by Zeiler & Fergus (Cont’d)
사용한 네트워크 구조(AlexNet)
1. 각 layer들은 Convolution layer로 구성되어 있음
2. Convolution layer 뒤에는 항상 ReLU 붙음
3. (Optionally) Max pooling layer 사용
DeConvNet 절차
1. image를 기존 학습된 ConvNet model(우측)에 통과
2. 살펴볼 feature map을 선정하고,
다른 모든 feature map들을 0으로 만든 다음,
DeConvNet layer(좌측)에 통과
(i) Unpool
(ii) Rectify
(iii)Reconstruction
7
(1) Adaptive Deconvolutional Networks for Mid and High Level Feature Learning - Matthew D. Zeiler and Rob Fergus, 2011
(2) Visualizing and Understanding Convolutioinal Networks - Matthew D. Zeiler and Rob Fergus, 2014
8. / 29
2.1 과거 방법론 - DeConvNet by Zeiler & Fergus (Cont’d)
Unpooling
•Max pooling은 non-invertible -> Approximation
•그래서 pooling을 할 때마다 해당 layer에서의 최대값
위치를 record해두고, DeConvNet에서 Switch하는
방식을 사용한다.
Rectification
•ReLU를 사용하기 때문에 feature map은 항상 0 이상
•DeConvNet에서도 양수 값을 만들기 위해 ReLU 통과
Convolutional Filtering(Reconstruction)
•기존 learned conv filter를 vertically, horizontally
flip시켜서 사용(transposed)
•한 개 activation만을 BackProp시키는 것과 같은 의미
8
(1) Adaptive Deconvolutional Networks for Mid and High Level Feature Learning - Matthew D. Zeiler and Rob Fergus, 2011
(2) Visualizing and Understanding Convolutioinal Networks - Matthew D. Zeiler and Rob Fergus, 2014
< 논문(1)의 figure >
< from towardsdatascience.com >
9. / 29
2.1 과거 방법론 - DeConvNet by Zeiler & Fergus (Cont’d)
Occlusion Sensitivity test
•특정 부분을 회색 상자로 가림
해당 부분이 가려졌을 때
•(b) total activation의 변화
•(d) probability score 변화
•(e) most probable class 변화
(c) projection 결과
•검은 테두리는 해당 이미지
•다른 3개는 다른 이미지에 대한
예시
해석: Convolution filter가
이미지의 특정 부분(객체)을
잘 잡아내고 있다. 9
10. / 29
2.2 과거 방법론 - Guided BackProp by Springenberg
해당 논문의 목적
•새로운 모델이 개발될 때 사실상 베이스는 동일한데 자꾸 복잡해져가고 있다.
•네트워크를 구성하는 요소 중 최고의 성능을 내는데 있어 가장 중요한 부분이 무엇일지 찾아보자
•모델 평가 방법이 “deconvolution approach”(Guided BackProp)
논문의 결론
•Convolution layer만으로 모든 네트워크를 구성
•max-pooling layer를 쓰지 말고 -> Strided convolution layer 사용(stride 2, 3x3 filter)
10(3) Striving for Simplicity: The All Convolutional Net - Jost Tobias Springenberg et al. 2014
11. / 29
2.2 과거 방법론 - Guided BackProp by Springenberg(Cont’d)
Max-pooling을 Strided Convolution layer로 대체할 수 있는 이유
•Pooling equation
•Convolution equation
=> pooling, convolution 둘 모두 같은 input을 받으며
pooling은 activation function을 p-norm을 사용한 것과 같다.
11(3) Striving for Simplicity: The All Convolutional Net - Jost Tobias Springenberg et al. 2014
si,j,u(f ) = (
⌊k/2⌋
∑
h=−⌊k/2⌋
⌊k/2⌋
∑
w=−⌊k/2⌋
| fg(h,w,i,j,u) |p
)1/p
Notation
• f : feature map
• W,H : width, height
• N : Number of channels
• k : pooling size
• r : stride
• g(h,w,i,j,u) = (r*i + h,
r*j + w, u)
• p : order of p-norm,
p가 무한으로 갈 때
max-pooling과 같은 의미
• theta : convolutional
weight
• sigma : activation function
• o : # of output channel
ci,j,o(f ) = σ(
⌊k/2⌋
∑
h=−⌊k/2⌋
⌊k/2⌋
∑
w=−⌊k/2⌋
N
∑
u=1
θh,w,u,o ⋅ fg(h,w,i,j,u))
12. / 29
2.2 과거 방법론 - Guided BackProp by Springenberg(Cont’d)
실험에서 비교한 네트워크 종류
•A, B, C : Convolutional filter size가 다름
•C에서 3가지 형태로 좀 더 다양화: 특히 우측 빨간 표시된 두 모델 비교
12(3) Striving for Simplicity: The All Convolutional Net - Jost Tobias Springenberg et al. 2014
가장 우수
13. / 29
2.2 과거 방법론 - Guided BackProp by Springenberg(Cont’d)
All-CNN-C 모델을 Deconvolution 방식으로 평가
•직전에 소개한 Zeiler & Fergus(2014)의 Deconvolution 방법은
해당 모델에 Max-Pooling layer가 없어서 성능이 좋지 않게 나옴
Guided BackProp
•Convolution layer만 사용하기 때문에 switch 필요없음
•Activation 값이 0 이상이고, Gradient도 0 이상인 것만 전파
a) Zeiler&Fergus(2014)
13
14. / 29
2.3 과거 방법론 - Weight vector에만 집중
DeConvNet, Guided BackProp 방법 모두
Weight(Conv filter) 연산 결과에 관심
Weight가 Data의 Signal을 따라가지 않으므로 이러한 방법들은
Data의 중요한 부분을 잡아내지 못할 수 있음
14
15. / 29
3.1 단순한 Linear Model 구상 - Deterministic distractor
단순한 Linear model을 통해 signal과 distractor의 움직임 관찰
15
Notation
• w : filter or weight
• x : data
• y : condensed output
• s : relevant signal
• d : distracting component.
원하는 output에 대해 아무런
정보도 가지고 있지 않은 부분
• a_s : direction of signal.
원하는 output의 퍼진 모양
• a_d : direction of distractor
s = asyx = s + d
d = adϵ
as = (1,0)T
ad = (1,1)T
y ∈ [−1,1]
ϵ ∼ 𝒩(μ, σ2
)
•Data x 는 signal s와 distractor d의 합
•위 수식에서 을 만족하기 위해선
• 이고, 이어야 하기 때문
wT
x = y w = [1, − 1]T
wT
asy = y wT
adϵ = 0
16. / 29
3.1 단순한 Linear Model 구상 - Deterministic distractor
16
, 두 식 모두를 충족시켜야 함
•weight는 distractor를 제거해야하기 때문에 distractor의 direction과 orthogonal 하려고 함
•즉 w는 signal의 direction과 align하지 않는다.
•weight는 distractor와 orthogonal 함을 유지하면서,
크기 조정을 통해 을 유지하려 한다.
Weight vector는 distractor에 의해 크게 좌지우지 됨
weight vector만으로 어떤 input pattern이 output에 영향을 끼치는지 알 수 없음
wT
asy = y wT
adϵ = 0
- signal direction은 그대로 유지
- distractor direction이 바뀌니
weight direction 역시 바뀜
wT
as = 1
17. / 29
3.2 단순한 Linear Model 구상 - No distractor, Additive isotropic Gaussian noise
17
Isotropic Gaussian noise를 선택한 이유
•zero mean: noise의 mean은 bias를 통해 얼마
든지 상쇄될 수 있으므로 단순히 0으로 정한다.
•correlation이나 structure가 없기 때문에
weight vector를 잘 학습한다고 해서
noise가 제거되지 않는다.
•Gaussian noise를 추가하는 것은
L2 regularization과 같은 효과를 낸다.
즉 weight를 shirink 시킨다.
위 조건 때문에 을 만족하는
가장 작은 weight vector는
와 같은 방향의 vector
< Gaussian pattern >
yn = βxn + ϵ
N
∏
n=1
𝒩(yn |βxn, σ2
)
N
∏
n=1
𝒩(yn |βxn, σ2
)𝒩(β|0,λ−1
)
N
∑
n=1
−
1
σ2
(yn − βxn)2
− λβ2
+ const
< Gaussian noise & L2 regularization >
——> likelihood,
⬇ Logarithm
wT
as = 1
as
as
w′
w′′
w
1
18. / 29
4. Approaches
18
Functions
•data x에서 output y를 뽑아낼 때 쓰는 방법. ex) gradients, saliency map
•y를 x로 미분해서 input의 변화가 어떻게 output을 변하게하는지 살펴본다.
•해당 model의 gradient를 쓰는 것이고 결국 이 gradient는 weight다.
Signal
•Signal: 모델의 neuron을 activate 시키는 데이터의 구성 요소
•Output에서 input space까지 gradient를 backprop시켜서 변화 관찰
•DeConvNet, Guded BackProp은 전파된 것이 signal이라 보장 못한다.
Attribution
•특정 Signal이 얼마나 output에 기여하는지 나타내는 지표
•Linear model에선 signal과 weight vector의 element-wise 곱으로 나타내어짐
•Deep taylor decomposition 논문에선 activation 값을 input에 대한
contribution으로 분해하고, LRP에선 relevance라 칭한다.
y = wT
x
∂y/∂x = w
PatternNet
PatternAttribution
19. / 29
5. Quality criterion for signal estimator
19
이전 수식에서 유도
wT
x = y
wT
s + wT
d = y
(x = s + d)wT
(s + d) = y
wT
s = y (wT
d = 0)
(wT
)−1
wT
s = (wT
)−1
y
̂s = uu−1
(wT
)−1
y
̂s = u(wT
u)−1
y
u = random vector
(wT
u ≠ 0)
Quality measure ρ
S(x) = ̂s
ρ(S) = 1 − maxvcorr(wT
x, vT
(x − S(x)))
̂d = x − S(x) y = wT
x, ,
= 1 − maxv
vT
cov[y, ̂d]
σ2
vT ̂d
σ2
y
•좋은 signal estimator는 correlation을 0으로 -> 큰
•w는 이미 잘 학습된 모델의 weight라 가정
•correlation은 scale에 invariant 하기 때문에
의 분산은 의 분산과 같을 것이란 제약조건 추가
•S(x)를 고정시키고 optimal 를 찾는데
학습 방식은 d와 y에 대한 Least-squares regression
ρ
vT ̂d y
v
illposed problem.
이대론 풀리지 않는다.
다른 방식이 필요
20. / 29
6.1 기존 Signal estimator 방식
20
The identity estimator
•data에 distractor 없이, signal만 존재한다 가정
•data가 이미지일 때 signal은 이미지 그대로이다.
•단순한 linear model일 때 attribution 구하는 수식.
(distractor가 존재하더라도, attribution에 포함)
•실제 데이터에 distractor가 없을 수 없고,
forward pass에선 제거되지만
backward pass에선 element wise 곱에 의해 유지
•시각화에 noise가 많이 보인다(LRP)
Sx(x) = x
r = w ⊙ x = w ⊙ s + w ⊙ d
The filter based estimator
•관측된 signal은 weight의 direction에 속함을 가정
ex) DeConvNet, Guided BackProp
•weight는 normalize 되어야 함
•linear model일 때 attribution 공식은 다음과 같고
signal을 썩 제대로 재구성하지 못함
Sw(x) =
w
wTw
wT
x
r =
w ⊙ w
wTw
y
21. / 29
6.2 PatternNet & PatternAttribution
21
학습 방식 및 가정
• criterion을 최적화하는 학습방식
•모든 가능한 벡터 에서 y와 d의 correlation이 0일 때
signal estimator S가 optimal이라 할 수 있다.
•Linear model일 때 y와 d의 covariance는 0이다
cov[y, x] − cov[y, S(x)] = 0
ρ
v
cov[y, x] = cov[y, S(x)]
cov[y, ̂d] = 0
ρ(S) = 1 − maxvcorr(wT
x, vT
(x − S(x)))
= 1 − maxv
vT
cov[y, ̂d]
σ2
vT ̂d
σ2
y
Quality measure
22. / 29
6.2 PatternNet & PatternAttribution
22
The linear estimator
•linear neuron은 data x에서 linear한 signal만 추출 가능
•위 식에서처럼 y에다 linear 연산을 했을 때 signal 나옴
•linear model일 때 y, d의 covariance는 0이므로
Sa(x) = awT
x = ay
cov[x, y]
= cov[S(x), y]
= cov[awT
x, y]
= a ⋅ cov[y, y]
⇒ a =
cov[x, y]
σ2
y
•만약 d와 s가 orthogonal 하다면
DeConvNet과 같은 filter-based 방식
과 일치한다.
•Convolution layer에서 매우 잘 동작
•FC layer에 ReLU가 연결되어있는 부분
에선 correlation을 완전히 제거할 수 없
으므로 아래 표처럼 criterion 수치 낮음
VGG16에서
criterion 비교
막대그래프 순서대로
random, S_w,
S_a, S_a+-
23. / 29
6.2 PatternNet & PatternAttribution
23
The two-component(Non-linear) estimator
•앞선 linear estimator와 같은 trick을 쓰지만
y 값의 부호에 따라 각각 다르게 처리한다.
•뉴런이 활성화되어있는지의 여부에 대한 정보는
distractor에도 존재 y가 음수인 부분도 계산 필요
•ReLU 때문에 오직 positive domain만
locally 업데이트 되기 때문에 이를 보정
•covariance 공식은 다음과 같고
•부호에 따라 따로 계산, 가중치로 합한다.
Sa+−(x) =
{
a+w⊺
x if w⊺
x > 0
a−w⊺
x otherwise
x =
{
s+ + d+ if y > 0
s− + d− otherwise
cov(x, y) = 𝔼[xy] − 𝔼[x]𝔼[y]
cov(x, y) = π+(𝔼+[xy] − 𝔼+[x]𝔼[y])
+(1 − π+)(𝔼−[xy] − 𝔼−[x]𝔼[y])
cov(s, y) = π+(𝔼+[sy] − 𝔼+[s]𝔼[y])
+(1 − π+)(𝔼−[sy] − 𝔼−[s]𝔼[y])
•cov(x,y), cov(s,y)가 일치할 때, 양의 부호에 대해 풀면
a+ =
𝔼+[xy] − 𝔼+[x]𝔼[y]
w⊺ 𝔼+[xy] − w⊺ 𝔼+[x]𝔼[y]
25. / 29
6.2 PatternNet & PatternAttribution
25
PatternNet and PatternAttribution
•PatternNet, Linear
•cov[x,y], cov[s,y]가 같아서
•a를 계산할 때 x, y로만 계산 가능
•PatternNet, Non-linear
•ReLU activation 특성 고려
•양/음 나눠서 a 값 계산
•Non-linear 모델에서 성능 좋음
•PatternAttribution
•a 값에 w를 element-wise 곱한 결과로
•해석하기 쉬운 좀 더 깔끔한
heat map을 생성할 수 있다. r = w ⊙ a+
a =
cov[x, y]
σ2
y
a+ =
𝔼+[xy] − 𝔼+[x]𝔼[y]
w⊺ 𝔼+[xy] − w⊺ 𝔼+[x]𝔼[y]
26. / 29
7. Experiments
26
값 비교, VGG16 on ImageNetρ(S)
•Convolution layer
•본 논문에서 제시한 linear estimator가 단순하면서도 좋은 성능을 보이고 있음
•본 논문의 non-linear estimator 역시 다른 filter-based, random 보다 월등한 성능
•FC layer with ReLU
•본 논문의 linear estimator 성능 급격히 떨어짐
•non-linear estimator 성능 유지
27. / 29
7. Experiments
27
Qualitative evaluation
•특정 이미지 한 장에 대해 비교 해석
•Methods 구분
•Sx : Identity estimator
•Sw : DeConvNet, Guided BackProp
•Sa : Linear
•Sa+- : Non-linear
•우측으로 갈 수록 좀 더 structure를
자세하고 세밀하게 잡아낸다.