728x90

Paper

arxiv.org/abs/1904.05068

 

Relational Knowledge Distillation

Knowledge distillation aims at transferring knowledge acquired in one model (a teacher) to another model (a student) that is typically smaller. Previous approaches can be expressed as a form of training the student to mimic output activations of individual

arxiv.org

 

Code

github.com/lenscloth/RKD

 

lenscloth/RKD

Official pytorch Implementation of Relational Knowledge Distillation, CVPR 2019 - lenscloth/RKD

github.com

 

Introduction

 

그동안의 knowledge distilation은 teacher model과 student model의 feature value를 point to point로 KL-divergence를 이용해 같아지도록 매칭시켰다. (softmax output , KL-divergence)

 

본 논문에서는 point-to-point matching이 아닌, feature같의 relationship을 distillation하는 방법을 제안한다. 

이는 아래 그림과 같다.

 

 

 

Relational knowledge distillation

 

논문에서 제안한 Relational knowledge distillation의 형태는 다음과 같다.

ψ는 feature vector간의 relation을 표현하는 함수이다. (relational potential function)

l은 둘간의 차이를 줄이는 loss function이다.

 

기존 distillation과 차이점은 아래와 같다.

 

 

본 논문에서는 relational potential function으로 distance-wise, angle-wise 2가지를 제안한다.

 

 

Distance-wise distillation loss

 

distance-wise potential function는 다음과 같다.

μ는 distance의 normalization factor로서 다음과 같이 정의된다.

(mini-batch에 있는 모든 pair들의 L2 distance의 평균)

 

normalization term은 teacher model의 distance의 scale과 student model의 distance의 scale을 맞추어주는 역할을 한다.

 

결과적으로 distance-wise distillation loss는 아래와 같이 정의된다.

 

 

Angle-wise distillation loss

 

Angle-wise potential function는 다음과 같다.

 

j image sample에 대한 embedding vector를 기준으로 i, k에 대해 angle을 계산한다.

 

loss function은 다음과 같다.

 

teature 모델과 student 모델의 embedding vector가 형성하는 각도를 같게 만들어준다.

 

 

 

Training with RKD

 

RKD는 여러형태로 적용될 수 있다. RKD만 단독으로 적용할 수도 있고, task-specific loss를 함께 사용하는 것도 가능하다. 

classification task의 경우 다음과 같이 표현될 수 있다.

 

Experiments

 

RKD에 대한 실험은 다음 3가지 task에 대해서 수행되었다.

: metric learning, classification, few-shot learning

 

용어는 다음과 같다.

 

RKD-D : distance-wise loss

RKD-A : angle-wise loss

RKD-DA : distance-wise, angle-wise together.

 

실험은 metric learning, classification, few-shot 3가지 분야에서 이루어졌다.

 

 

1) Metric learning

 

Metric learning은 유사한 이미지끼리는 가깝게 embedding하고, 다른 이미지끼리는 멀게 embedding되도록 obejective function을 정의하고 학습시키는 방식이다.

 

이러한 metric learning을 통해 학습된 embedding 모델은 image retrieval 방식으로 주로 평가된다. 

본 논문에서는 CUB-200-2011, Cars 196, Stanford Online Products에서 평가되었다.

 

evaluation metric으로는, recall@K가 사용되었다. 먼저 test image들을 모두 embedding 시킨다. 

그리고 각 test image들을 query로 사용하고 KNN 기법으로 query에 대한 이미지들을 retrieval한다.

(retrival할떄, query는 제외)

 

이때 query에 대해서 K개의 nearest neighbor중 같은 category의 image가 하나라도 포함되어 있으면

그 query에 대한 recall은 1이 된다. 즉 Recall@K는 모든 test set에 대해서 이 recall 값을 계산해서 평균값을 낸 것이다.

 

 

 

이때, loss는 Triplet loss를 사용하였다.

 

 

이때 최종 embedding vector에 대해서 l2 normalization을 수행한다. 

일반적으로 deep metric learning에서 embedding space를 제한하기 위해 l2 normalization은 많이 사용된다.

 

RKD는 teacher model과 student model의 final embedding ouput을 대상으로 적용된다.

이때, RKD의 경우 embedding space를 tripplet loss와 같이 normalization하지 않았으며, 

 

RKD-DA의 경우 RKD-D는 1, RKD-A는 2의 비율로 loss를 적용하였다.

 

RKD를 사용할 때, 추가적인 task loss(ex triplet loss)는 사용하지 않았다. 즉, teacher model의 embedding 정보를 통해서만 student model은 학습이 되었으며, 기존의 gt label은 student 모델을 학습하는데 사용되지 않았다.

 

self-distillation도 효과 있었다.

이때 self-distilation은 teacher model과 student model이 동일한 backbone network를 사용하였음을 의미하며,

generation은 distillation을 통해 생성된 student model을 다시 teacher model로 사용하여 distiallation을 다시 수행했다는 것을 의미한다. 

 

결과적으로 self-distillation을 한번만 했을때, 가장 효과가 좋았고, 그 이후로는 오히려 성능이 떨어지는 현상을 보였다.

 

 

또한 RKD는 특정 dataset에 특화되어 학습되는 경향을 보였다. (adaptation)

Cars 196이나 CUB-200-2011은 fine-grained dataset으로서, domain의 특징에 잘 맞추어서 학습되는 것이 중요하다.

 

RKD가 이러한 adaptation이 잘되는 학습방법임을 증명하기 위해서 Car196에 학습시킨 모델을 다른 dataset에 대해서 test해 보았다.

 

결과적으로 RKD-DA는 Cars196에 대한 성능이 좋은 반면에 다른 dataset에 대한 generalization 성능은 떨어지는 것을 확인할 수 있었다. 즉, 해당 데이터셋에 대한 discriminative한 feature를 더 잘 추출하는 경향이 있음을 알 수 있다. (왜?)

 

 

 

2) Image classification

 

classification에서는 기존에 사용되던 KD들과 성능을 비교하였다.

RKD 단독으로 사용했을 때는 오히려 HKD(Hinton's KD)가 더 높았으나, RKD와 다른 기존의 KD를 조합했을때, 모두 성능이 더 향상되었으며, 또한, 가장 높은 성능을 보였다. 

728x90

+ Recent posts