https://arxiv.org/abs/1906.04950
Pay Attention to Convolution Filters: Towards Fast and Accurate Fine-Grained Transfer Learning
We propose an efficient transfer learning method for adapting ImageNet pre-trained Convolutional Neural Network (CNN) to fine-grained image classification task. Conventional transfer learning methods typically face the trade-off between training time and a
arxiv.org
요약
ImageNet pre-trained model 에서 잘 추출된 feature 들을 fine-grained 데이터셋에 transfer learning 을 수행할 때,
효율적으로 분류하는데 중요한 filter 들을 배우도록 유도하는 attention weight 를 도입해서,
필요없거나 중복되거나 덜 관련된 filter 들의 가중치를 줄이는 방식으로 빠른 시간에 높은 성능을 내도록 한다.
각각 convolution filter 마다 1 개의 attention weight 를 가지고, 1 로 초기화 된다.
Regularization Term 을 통해서 1 주변에 분포를 가지도록 유도한다.
결국 목적은 빠르게 transfer learning 을 수행하면서 높은 성능을 내는데 목표가 있고, 부가적으로 모델의 크기를 줄일 수 있는 pruning 효과와 network 의 decision 을 판단할 수 있는 interpretable 도 제공한다.
1. Abstract
fine-grained 모델을 위한 transfer learning 할 때, pre-trained model 의 각 convolution filter들에 attention module 을 추가함으로 convolution filter 의 중요도를 rank and adjust 한다.
이 방법으로 ImageNet pre-trained ResNet50 모델을 fine-grained 에 tranfer learning 을 수행하는데, 10 에폭만에 전통적인 transfer learning 기법들의 정확도를 넘어섰고, 처음부터 학습된 모델과 비슷한 정확도를 보여줬다.
우리의 모델에서 사용하는 the rank of convolutional signal 들은 더 높은 정확도를 달성하기 위한 convolution filter 들의 활성도를 보여주고, 세부적인 transfer learning 에서 noise 로 여겨질 수 있는 것들을 pruning 함으로 써 모델 사이즈를 줄일 수 있다.
이것들로 설명가능한 결과를 제공할 수 있다.
1.1 Problem and Implication
대부분 image classification 의 문제는 fine-grained classfication 문제이다. 예를들면, self-driving car 에서 도시마다 다른 거리의 모습들을 구분하는 것이나, medical imaging application 에서 다른 type의 cell 들을 구분해 내는 문제들이다.
그런데 대부분의 classification 에서 사용하는 pre-trained 모델은 ImageNet 을 통해서 훈련된 모델이고, 이는 매우 coarse-grained 한 데이터셋이다. 이 모델들은 널리 구체적인 task 에 대한 common feature extractor 으로 사용되어 왔다.
어떻게 효율적으로 pre-trained network 의 장점을 취하고, fine-grained image classification 에 적응시킬까?
목표 2가지
1) training process 를 가능한한 빠르게 만드는 것. 이상적으로 10 에폭보다 적게 가지는 것. 이건 pre-trained weight 를 사용하는 것으로 수행될 수 있다.
2) model accuracy 를 가능한한 높게 만드는 것. 이상적으로 처음부터 훈련시킨 모델비교할때, 잘 동작하도록 만드는 것.
우리는 산업에서도 머신러닝이 benefit 을 주기를 희망한다. 우리 방식을 사용한, fine-grained 오브젝트를 분류하도록 훈련시킨 작은 네트워크는 잘 훈련되고, 빠르게 수렴할 수 있다. 비슷한 클래스를 비교하는 expert network 는 전반적인 정확도 향상을 위한 larger ensemble or inference cascade 으로 여겨질 수 있다.
1.2 Transfer Learning
ImageNet 에서 훈련된 ResNet or Inception-V3 같은 높은 이미지분류 정확도를 보여주는 모델들은, 딥러닝 프레임워크에서 넓게 사용가능하다. Transfer learning 은 이러한 모델들을 구체적인 분류를 위한 starting point 로 네트워크를 adapt 한다. 일반적인 방법으로 특정 layer 의 weight 를 freeze 하고 ( 전통적으로 low-feature ), high level feature 이나 fully connected layer 을 retrain 한다.
만약에 새로운 데이터셋의 분포가 ImageNet과 비슷하다면 fully connected layer 만 retrain 하는 걸 추천한다. 만약 새로운 데이터셋의 분포가 ImageNet과 비슷하지 않다면, low-feature layer 만 고정하고 나머지는 retrain 하는 걸 추천한다.
1.3 Fine-Grained Image Classification
Fine-Grained Image Classification 은 source image 의 object 들이 매우 비슷하고 fine-grained feature 을 가지고 있다. 예를들어 동물종 분류는 네트워크가 color pattern or specific shapes feature 들을 pick up 하는걸 요구한다.
이 문제를 풀기위해서, 학계는 처음부터 모델을 학습하는 것을 move away 해왔다. 많은 연구자들은 중요한 디테일들과 learned feature 들을 동일시하도록 adapt 하는일을 시작해왔다. subset feature learning, mixture of convolution networks, adding visual attention 같은 메소드는 효과적이라고 증명되왔다. 그런데 이러한 많은 방법들이 매우 domain specific 이고, 중요하게 대부분 훈련시간이 길다.
1.4 Attention Methods
Attention 은 Neural Machine Translation 의 셋팅에서 처음 소개되었다. 각 RNN 의 state 에 weighted vector 을 통과시켜서 번역될 문장의 latent semantic meaning 을 capture 한다. 이 아이디어를 image captioning 에서도 사용되어 state-of-the-art 를 달성하였다.
1.5 Our Contribution
transfor learning for fine-grained image classification 의 문제를 풀기위해 3개의 아이디어를 묶었다. 특히 attention method 를 pre-trained image model 의 convolution filter 들을 fine-grained task 에 adpat 하기 위해 rank 한다. 결국 목적은 빠른 훈련과 validation accuracy 의 good balance 찾는 것이다.
pre-trained model 을 over-parameteried 되었다는 직관을 통해서, trainable attention weight 를 각 convolution filter 에 추가하고 loss 로 optimize 한다. 이 attention weight 는 initial state ( identity mapping 인 1 로 초기화 ) 에서 시작되고, 몇 iteration 후에는 convolution channel 이나 낮은 activation 값을 증폭시킨다. 예를들어서 특정 종 A 를 분류하기 좋은 vertical stripe pattern 을 detect 하는 convolution filter 에 attention weight 를 통해 값이 증폭되어 더욱 pay more attention 되도록 학습된다.
또한 pay less attention 도 학습시킬 수 있어서, fine-grained dataset 에서 필요없거나 관련없는 feature 들은 무시되도록 할 수 있다.
2. Related Work
2.1 Key Assumption 1 : Large Networks are Over-Parameterized
"The Lottery Ticket Hypothesis" 에서 이론적 + 실험적으로, 많은 layer 와 parameter 으로 구성된 성공적인 large network 들은 pruning 으로 생성된 성공적인 sub-network 을 통해서 만들어진다.
2.2 Key Assumption 2 : ImageNet Pre-Trained Convolution Channels are Good Feature Extractors
transfer learning 을 위한 base model 자체는 convolution channels 관점에서 아주 좋은 quality 를 가지고 있다고 가정한다. ImageNet 데이터셋은 general convolution feature extractor 으로 확인되었다.
2.3 Key Assumption 3: Convolution Channels Can be Ranked and Pruned
모든 convolution channel 들은 모두 useful 하지 않다고 가정한다. 모델 compression 과 network pruning 은 이 가정에 확실한 데이터를 제공한다. 대부분 convolution channel pruning 은 heuristic defined channel ranking method 로 수행된다. 예를들면 ranking channels by their $ell_1$ norm, ranking channels by combinatorially determine their effect on validation score, first-order Taylor expansion with respect to the channel to closely match the cost function of original network.
우리 접근방식은 image norm 이나 Taylor expansion 에 대한 human defined heuristic 방법 대신, network 가 스스로 filter 을 ranking 하길 바란다.
2.4 Key Assumption 4 : Attention Should Be Regularized
만일 단지 attention weight 를 1 로 할당하면, 네트워크는 매우 천천히 움직이거나, 흐르지 않은 상태로 유지할 것이다.
visual attention 논문에서 받은 중요한 lesson 은 attention 을 regularize 하는 것은 매우 중요하다는 것이다.
단지 attention 을 추가하는 것은 충분하지않다. 특히 우리 모델에서, the hierarchical relationship and strength of the convolution channels 에 대한 attention 에 scalar 1 을 더하고 convolution filter 을 freeze 하는건 충분하지 않다. 그래서 attention weight 에 some prior 을 더할건데 5.1.1 에서 더 다룬다.
3. Experimental Setup
3.1 Data Source and Pre-Processing
fine-grained 한 데이터셋 INaturalist 2018 을 사용하고, ImageNet 과 다른 분포를 가지는 데이터셋이다.
cropping 없이 224x224 ResNet, 299x299 Inception-V3 이미지 사이즈를 사용했다. 그리고 ImageNet 이랑 비슷하게 normalized 했고, class imbalance 문제를 해결하기위해 data augmentation 을 사용했다. 7-1.5-1.5 training validation testing split 을 사용했다.
3.2 Tools - skip
3.3 Baseline Model
대부분 ResNet 50 을 사용했고, 비교를 위해 ResNet34 , ResNet101, Inception-V3 도 사용했다.
3.4 Evolution of our model
transfer learning 에서 filter redundancy 문제를 해결하기 위해 Taylor expansion 을 통해 convolution filter 을 ranking 해서 mask 하는 pruning 을 사용하는데, 우리는 end-to-end 모델로 attention weight 를 사용함으로 써 useful signal 을 증폭시키고, 중복된건 suppresses 한다. 이는 pruning 과 비슷한 효과를 낸다.
4. FInal Model
각각 pre-trained convolution filter 에 attention module 을 붙인다. 이는 1 로 초기화되는 attention weight 을 convolution filter 에 곱해서 구현된다.
1-2 epoch 에는 FC layer 의 error 은 attention module 에 back propagated 되고, 다음에 전체 network 를 고정시키고 attention module 만 pre-trained 모델이 fine-grained task 의 feature extractor 로서 사용되게끔 학습시킨다. batchnorm layer 훈련은 overfitting 과 variance shift 를 피하기 위해, attention module 훈련과 함께 insperse 된다.
4.1 Pseudocode
# init attention weights
# fill it with 1
attn_weights = Param(FloatTensor(out_channels, in_channels, 1, 1))
# And we modify the "Forward" function
# in 2D convolution module
attn_paid = conv_weights*attn_weights
return F.conv2d(input, attn_paid, ...)
5. Experiment Result and Discussion
5.1 Investigation
5.1.1 What is the best attention loss/regularization?
맨처음에 attention weight 는 1 주변에 clustered 되고, attention weight 의 L1 or L2 loss 가 regularization term 으로 추가된다.
L1 은 sparse 한 분포를 polarized 되고, L2 는 그러진 않지만 좀더 빠르게 수렴한다. 둘다 정확도면에선 비슷하다.
더욱이 attention weight 가 분산되도록 하기위해 L2 norm 을 1 과의 distance penalty term 으로 변경했다.
$F$ : convolution filter layer 개수
$a_j$ : attention weight vector for filter $j$
$\lambda $ : hyperparameter
$l_1$ regularization 은 attention weight 을 sparsity 하게 만들어서 대부분 0 으로 감소되고, 놀랍게 몇개는 여전히 1 보다 큰 값을 가지면서 증폭된다. 우리는 이 weights 들이 fine-grained dataset classification 에 convolution filter 들의 subset 이 identify 하는걸 돕는걸 알 수 있다.
$l_2$ 는 비슷한데 smoother result 를 가진다. attention weight 분포가 1 주변에서 0 - 2 사이로 점진적으로 분포하는 걸 알 수 있다.
5.1.2 Data augmentation help?
Data augmentation 은 각 class 개수를 inverse 해서 확률값으로 sampling 된 weighted sampler 로 수행되었고, 이게 class imbalance 문제를 해결하고 regularization 으로서 overfitting 을 완화시켰다. Table 2 에서 augmentation 이 특히 attention 에서 많은 성능향상을 끼쳤다.
5.1.3 How does Different Model Architecture Affect the Score?
Table 3 에서 볼수 있듯, 다른 depth 와 model architecture 에서 실험해봤고, ResNet 깊이가 깊어질수록 점수는 올라간다. 이 네트워크가 더욱 깊어질수록 많은 convolution channel 들과, 결합할 준비가 된 interesing 한 intermediate feature 들이 존재한다는 사실로 이 결과를 설명할 수 있다. 다른 architecture 인 Inception-V3 로 바꿔도 성능이 저하되지않는 것으로봐서 convolution 을 포함한 ImageNet 모델에서 사용할 수 있을 것이다.
5.1.4 Is The Accuracy Good Enough ( Compare with 100 hours model )?
Inception-V3 모델로 처음부터 100 에폭으로 훈련해 top-3 accuracy 77% 정확도를 달성한 baseline model 과 비교했을때, 우리 모델은 highest top-3 accuracy 70% 를 15 에폭으로 달성했다. 따라서 attention model 은 높은 정확도만아니라 빠른 수렴에도 좋은 성능을 보인다. 이건 다양한 personalized model 에 사용될 수 있게 만든다.
5.2 Interpretability and Visualization
두 visualiation 은 우리 method 가 얼마나 효율적으로 좋은 signal 을 pick up 하는지를 보여준다.
ResNet 50 의 끝에서 3번째 convolution layer 에서 attention 으로 1, 2 rank 의 filter 를 보여준다.
ResNet 50 과 $l_2$ term 을 사용하여 few iteration 후의 모습이다.
figure 3 은 동물의 high level feature spine 의 모습이고, attention 은 fine-tuned dataset 의 classification 에 중요한 역할을 하는 feature 을 pick up 한다.
figure 4 는 또다른 high level feature 인데, 다른 종류의 개구리주변 다양한 환경을 식별하는 보조적인 feature 이다.
5.3 Surpise
5.3.1 attention shape
실험적으로 두가지를 진행했는데,
Out only 에서, input channel 에 동일한 attention weight 를 적용했다.
In x Out 에서, input channel 에 다른 attention weight 를 적용했다.
예를들어 ResNet 첫 convolution layer 에는 input channl 3 과 output channel 64 를 가지는데, 1 번은 64 개의 attention weight, 2 번은 3 x 64 attention weight 를 가진다.
Table 4 에서 보듯이 두번째 방법이 더 좋은 이점을 가지는데, 우리의 실험적인 결과는 단지 성능에 비교적으로 small boost 인것을 확인했다.
우리는 sophisticated attention scheme 이 더 높은 성능을 보여줄 것이라고 예상했기 때문에, 이 결과가 놀라웠다.
결과에 대한 하나의 possible 설명으로는 하나의 feature map ㅇ 에서 모든 filter 들의 convolution 결과가 모아지기 때문에 비슷할거라는 것이다.
별표 : convolution operator
$C_{out_j}$ : $j$ 번째 feature map
한 feature map 은 각 필터 그룹 $\sum_{C_{in}-1}^{0} $ 으로부터 convolution 된다. 그래서 우리는 같은 그룹에 있는 다른 필터들사이에 strong connection 이 있어서 attention weight 에 덜 효과적으로 만든다고 가정했다.
비슷한 성능에도 Out Only 방법이 더 빠른 수렴을 보여줬다.
5.3.2 Do Tranditional Transfer Learning Methods Still work?
(1) Fully connected Layer 만 훈련하기 : 이 방식은 fixed high level feature 에 좋은 linear transformation 을 제공하는데 몇 에폭만에 over-fit 된 경향을 보여줬다. 46% top-3 acc
(2) unfreezes the last block of ResNet : 좀 더 높은 정확도를 보여줌. 56% top-3 acc
(3) uses the entire pre-trained network as initialization : 놀랍게 이 방식이 65% 의 attention method 보다 더높은 정확도를 보여줬는데, 이건 모든 convolution filter 들이 subject to optimization 인 사실로 정당화 될수 있다. scalar weight 으로 convolution activation 을 증폭하는게 모든 filter 들을 fine-tune 하는 것보다 덜 복잡하다.
6. Lesson Learned
channel wise attention 의 fine-grained transfer learning 효율성을 연구했다. in and out convolution attention module 을 포함시켜 re-train 하는게 훈련시간도 적게들고, useful 한 filter 을 식별하는것도 빠르게 효율적으로 수행한다. 70% top-3 acc 까지 올렸고 100 epoch 에 처음부터 훈련시킨 Inception-V3 에 비하면 빠르고 높은 성능을 보여준다.
최고의 training strategy 인 attention penalty, level of cut, effect of augmentation 을 찾았고, 다른 layer 훈련 조합을 수행해봤다. FC layer 은 fine-grained data distribution 에 빠르게 adapt 했지만, 몇 epoch 뒤에 overfit 된 반면에, attention layer 는 FC layer 가 훈련된 이후에 몇 에폭만에 accuracy 를 효과적으로 boost 했다. 그런데 attention layer 이후에 output feature map 이 더이상 well-behaved 되지 않아서, attention module 사이에 batchnorm 을 interspersed 해서 훈련시킬때, 그 regularization 효과 때문에 정확도는 살짝 떨어지지만 attention module 이 더 좋은 결과를 만드는데 도움을 준다.
더욱이 attention weight 는 cross entropy loss 만 사용하면 1 주변에 cluster 되는데, attention penalty 를 추가하면 더 다양한 분포형태로 encourage 한다.
7. Future Work
1. 자연스럽게 모델 크기를 줄이고 정확도를 향상시키기 위해서 attention weight 값이 특정 threshold 값을 정할 수 있다. 이를 통해서 pruning 을 위한 좋은 feature 사용성 ranking 을 제공할 수 있다.
2. attention scheme 은 매우 높은 interpretable 을 제공할 수 있다.
3. reinforcement learning, 특히 meta learning 에서 attention module 이 pre-trained set 에서 분류해야할 fine-grained data 을 정확히 분류하는 방식을 배우도록 하는 전력에서 사용될 수 있다.