Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2017 Distill] Feature Visualization #124

Open
Jasonlee1995 opened this issue Mar 29, 2023 · 0 comments
Open

[2017 Distill] Feature Visualization #124

Jasonlee1995 opened this issue Mar 29, 2023 · 0 comments
Labels
Principle Understanding the AI Vision Related with Computer Vision tasks

Comments

@Jasonlee1995
Copy link
Owner

Jasonlee1995 commented Mar 29, 2023

2017년까지의 feature visualization과 관련된 survey paper와 비슷한 블로그? 느낌의 article

읽기 좋게 서술되어있어, 흐름대로 요약


image

Neural network interpretability에 대한 연구는 크게 2가지로 나뉨

  1. Feature visualization : example generation을 통해 network가 무엇을 보는지 확인
  2. Attribution : example의 어떤 part가 network activation에 responsible한지 확인

이때 당시에 해당 분야가 신생 분야이기에 feature visualization, attribution 이외에도 saliency map와 같은 다양한 용어들이 사용되고 있으며, 현재 사용되는 용어와 다를 수 있음

해당 article은 제목 그대로 feature visualization만 다루며, 어떻게 feature visualization을 하는지 + 잘 작동하기 위한 detail들을 소개함
(단순히 feature visualization을 하면 그럴듯한 이미지가 나오지 않기에 이러한 trick들을 사용해야함)

1. Feature Visualization by Optimization

1.1. Optimization Objectives

image

image

Adversarial attack과 비슷하게, neural network는 고정해둔 채 target objective function이 maximize되도록 input noise를 optimize하는 방식으로 feature visualization을 함

여기서 target objective function은 관심이 되는 대상이 무엇인지에 따라 달라지게 됨
(관심 대상 : neuron, channel, layer, class logits, class probability)

여기서 주의할 점은 class probability를 maximize하는 것은 softmax로 인해 다른 class들의 probability를 minimize하는 방식으로 optimize될 수 있기에, class probability보다는 class logits를 사용
(실제로 visual quality에서도 class logits가 class probability보다 더 좋음)

1.2. Why visualize by optimization?

image

Optimization을 하지 않고 target objective function 값이 큰 data, 즉 argmax data들을 볼 수도 있음

Figure를 보면 알 수 있듯이, dataset examples를 보는 것은 model이 실제로 무엇을 보는지 이해하기 어려움이 있음
(개가 모여있는 이미지들을 보면 알 수 있는데, 눈이 주된 factor인지 코가 주된 factor인지 알기 어려움)

그에 반면, optimization approach는 실제 원인이 되는 것과 원인과 correlation된 것을 구분할 수 있기에 더 적합한 방식임
(it separates the things causing behavior from things that merely correlate with the causes)

2. Diversity

image

하지만 optimization approach도 단점이 있음

Optimization approach를 통해 구한 feature visualization이 neural network가 어떤 것을 학습했는지에 대한 모든 면을 보여주지 않고, 일부 단면만 보여줄 수 있음
(it’s entirely possible for genuine examples to still mislead us by only showing us one facet of what a feature represents)

Optimized approach를 통해 구한 feature visualization과 argmax dataset examples를 같이 보는 방법을 통해 이를 완화할 수 있음

하지만 argmax dataset examples를 구하기 위해서는 모든 data에 대해 inference를 진행해야하기에, 효율적이라고 볼 순 없음

Optimization approach의 단점을 극복하기 위해, diverse한 feature visualization을 보여주는 방식으로 연구가 발전되었음

2.1. Achieving Diversity with Optimization

image

image

image

Diverse한 feature visualization을 얻는 다양한 방법이 있는데, 가장 단순한 방법은 diversity term을 objective에 추가하는 것임

Diversity term의 예시로는 feature visualization examples간의 cosine similarity를 penalize한다던지, different style을 가지도록 force하는 방법이 있음
(해당 article에서는 different style을 가지도록 diversity term을 objective에 추가)

하지만 해당 방법은 examples를 다르게 만들라는 pressure로 인해, unnatural way로 optimize되기에 unrelated artifacts가 생성되거나 다른 examples를 만들 수 있다는 단점이 존재함

Diversity를 도입하더라도 optimization approach는 neural net을 이해하는데 있어 적절한 semantic units fundamental issue가 존재함
(예시로 Figure을 보면 알 수 있듯이, 어떤 feature visualization은 strange mixtures of ideas을 표현하고 있음)

3. Interaction between Neurons

image

왜 이러한 issue가 발생하냐면 combinations of neurons이 협동해서 image를 represent하기 때문임
(combinations of neurons work together to represent images in neural networks)

이를 이해하기 위해 neuron activations의 activation space를 도입하여 geometric 관점에서 해석
(activation space : all possible combinations of neuron activations)

해당 관점으로 보면, neuron activations를 activation space의 어떠한 vector들로 표현 가능해짐

Activation space에서의 basis vector가 어떠한 의미를 지니는지 살펴보면 어느정도 의미는 있으나 꼭 그렇지 않다는 것을 알 수 있음

말이 어려운데 basis vector가 random direction vector보다는 상대적으로 더 interpretable하긴 하지만, random direction vector도 의미가 있다는 말임
(random direction vector가 maximize되도록 optimize한 feature visualization도 interpretable하며, basis vector를 maximize한 feature visualization이 상대적으로 더 interpretable하다는 의미)

image

image

신기한 점은 이렇게 interpretable한 vector들 간의 arithmetic 연산이 feature visualization에도 적용이 된다는 것임

Figure을 보면 알 수 있듯이, black and white라는 의미를 가진 vector와 mosaic이라는 의미를 가진 vector의 합을 maximize한 feature visualization은 black and white version of the mosaic를 생성하게 됨

또한 interpretable vector들의 interpolate한 vector를 feature visualization한 결과, generative models의 latent space와 비슷하게 작동함을 확인할 수 있음

물론 meaningful direction을 선택하는 방법이라던지, 정말로 특정한 meaningful direction이 존재하는지 알 수 없으며 direction 간의 어떻게 interact하는지도 명확하지 않음
(어떤 vector가 interpretable한지, 그리고 interpolation 결과는 몇개의 case만 보인 것이기에 무수히 많은 vector에 대해 어떻게 interact하는지는 모른다는 의미)

뭔가 앞으로 나아가야할 방향성?을 제시하는 느낌

4. The Enemy of Feature Visualization

image

단순하게 optimization을 통해 feature visualization을 해보면, real life에서 볼 수 없는 nonsensical high-frequency noise patterns만 보이게 됨

이는 일종의 cheating이라고 생각할 수 있으며, 이러한 현상은 adversarial examples phenomenon과 엮어서 생각해볼 수 있음

image

물론 이러한 high frequency가 왜 형성이 되는지 완벽히 이해하고 있지는 않지만, strided convolution, pooling operations으로 인해 gradient에서 high-frequency patterns가 형성된다는 것이 원인일 수 있음

이를 통해 단순히 optimization만을 통해 feature visualization을 하면 안되고, 적절한 constraint를 사용해야 됨을 알 수 있음

4.1. The Spectrum of Regularization

Feature visualization에서 high frequency noise가 아닌 useful visualization을 얻기 위해, natural structure를 띄게끔 강제하는 무언가가 필요하게 됨

Natural structure을 띄게끔 강제하는 방법으로 prior, regularizer, constraint를 사용할 수 있으며, 주로 regularization approach가 흔히 사용됨

4.2. Three Families of Regularization

4.2.1. Frequency penalization

image

Frequency penalization은 high frequency noise를 직접적으로 target하여 penalize하는 방법임

예를 들어 variance between neighboring pixels를 penalize하는 방법 (total variation), optimization step마다 image를 blurring하는 방법 등이 있음

하지만 해당 방법은 noise뿐만 아니라 edge와 같은 high-frequency features도 discourage하기에, 선명한 느낌이 들지는 않음

물론 이는 blurring을 할 때 bilateral filter 등을 사용하면 어느정도 개선할 수는 있으나, 근본적인 해결책이라고 보기는 어려움

4.2.2. Transformation robustness

image

Slightly transform해도 still activate되는 example을 찾자라는게 motivation으로, 단순하게 매 optimization step마다 input image (feature visualization)을 stochastically jitter, rotate, scale한다고 생각하면 됨

Small amount만 적용해도 충분히 효과적이라고 하며, high-frequency regularizer과 같이 사용하면 매우 효과적이라고 함

4.2.2. Learned priors

이전까지 소개한 방법은 very simple heuristics한데, 이에서 벗어나 real data를 모델링하여 real data가 되도록 enforce하는 것임
(prior라는 표현은 real data를 의미하며, feature visualization이 learned prior가 되도록 강제하는 느낌이라고 이해하면 됨)

어찌 생각하면, 이는 dataset에서 search하는 것과 유사

해당 방법은 가장 photorealistic visualizations을 생성하지만, model이 보는 것과 prior로부터 온 것에 대해 구분하기 어렵다는 단점이 있음
(feature visualization이 activation maximize term + prior처럼 되도록 강제하는 term으로 생성되기에)

이와 관련된 다양한 연구들을 소개하고 있으니 자세한 사항은 article 참고

4.3. Preconditioning and Parameterization

image

High frequencies를 줄이기 위해 visualization에 blur를 하는 것이 아니라 gradient에 blur를 하는 느낌이라고 생각하면 됨

이렇게 gradient를 transforming하는 것을 보고 optimization에 preconditioning을 한다고 표현함

이는 loss surface에 아무런 변화를 주지 않는 대신, 어떠한 방향으로 이동하여 minimum으로 빠지는지를 조절함

즉 앞서 소개한 방법들은 objective를 추가하여 loss surface를 바꿔버리기에 우리가 모르는 어떠한 영향을 줄 수 있는 반면, 해당 방법은 그러한 side effect를 걱정하지 않아도 된다는 장점이 있음

그렇다면 어떠한 preconditioner을 사용해야 하는지를 고민하면 됨

가장 떠올리기 쉬운 좋은 방법은 data를 decorrelated하고 whitened하게 만들면 됨
(a good first guess is one that makes your data decorrelated and whitened)

이미지로 생각해보면, 이는 Fourier basis에서 gradient descent를 하는데 모두 동등한 크기를 갖도록 scaling을 해주면 되는 것임
(in the case of images this means doing gradient descent in the Fourier basis, with frequencies scaled so that they all have equal energy)

Figure을 보면 알 수 있듯이, loss surface는 동일한데 어떠한 preconditioner을 사용하는지에 따라 결과가 달라지게 됨

Adversarial attack에서 사용되는 $L \infty$ preconditioner는 high frequencies를 증가시키며, decorrelated space preconditioner는 high frequencies를 감소시킨다는 것을 확인할 수 있음

image

image

물론 preconditioning만으로는 부족한데, transformation robustness를 추가하면 매우 괜찮은 결과가 나옴

저자들은 preconditioner 없이도 신중하게 hyperparameter를 선택하면 같은 결과를 얻을 수 있는 것인지, 아니면 regularization과 같이 attracted local minima를 바꾸는 것인지에 대해 알 수 없다고 함

@Jasonlee1995 Jasonlee1995 added Principle Understanding the AI Vision Related with Computer Vision tasks labels Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Principle Understanding the AI Vision Related with Computer Vision tasks
Projects
None yet
Development

No branches or pull requests

1 participant