Paper
arxiv.org/abs/1912.02413
BBN: Bilateral-Branch Network with Cumulative Learning for Long-Tailed Visual Recognition
Our work focuses on tackling the challenging but natural visual recognition task of long-tailed data distribution (i.e., a few classes occupy most of the data, while most classes have rarely few samples). In the literature, class re-balancing strategies (e
arxiv.org
Code
github.com/Megvii-Nanjing/BBN
Megvii-Nanjing/BBN
The official PyTorch implementation of paper BBN: Bilateral-Branch Network with Cumulative Learning for Long-Tailed Visual Recognition - Megvii-Nanjing/BBN
github.com
Introduction
Imbalanced 문제는 주로 re-balancing 방법을 통해 접근하여 해결해왔다.
re-balancing
1. re-weighting
2. re-sampling
re-weighting 방법은 학습할 때, sample수가 적은 class의 경우 더 큰 weight를 통해 큰 loss값을 주고
sample수가 작은 class의 경우 저 작은 weight를 부여함으로 작은 loss값을 준다.
www.analyticsvidhya.com/blog/2020/10/improve-class-imbalance-class-weights/
How to Improve Class Imbalance using Class Weights in Machine Learning
Learn how to deal with imbalanced classes in machine learning by improving the class imbalance using Python.
www.analyticsvidhya.com
resampling 방법은 sample수가 적은 class에 대해서 sample을 추가적으로 생성하는 방법을 택한다.
가장 대표적인 방법이 SMOTE이다. (Synthetic Minority Oversampling TEchnique)
machinelearningmastery.com/smote-oversampling-for-imbalanced-classification/
SMOTE for Imbalanced Classification with Python
Imbalanced classification involves developing predictive models on classification datasets that have a severe class imbalance. The challenge of working with imbalanced datasets is that most machine learning techniques will ignore, and in turn have poor per
machinelearningmastery.com
SMOTE는 먼저 minority class에서 random으로 example을 select하고 그 example에 대해 k개의 nearest neighbor를 찾는다.
이때 새로 만들어지는 synthetic instance는 k nearest neighbor 에서 하나를 설정하고 (b), a와 b featrure를 linear combination하여 만들어낸다.
하지만 이러한 re-balancing 접근 방법은 deep feature의 학습에서 영향을 받게 되고
결국 데이터 전체적으로 under fitting되는 단점이 존재한다.
본 논문에서는 re balancing 전략이 어떤 식으로 동작하는지를 살펴보고
deep network를 representation learning과 classifier learning 2가지로 나눠서 수행한다.
representation learning은 일단 일반적인 plain training을 의미한다고 보면 된다.
그리고 classifier learning은 representation learning 때 학습한 것을 paramater 고정시키고,
classifier만 'scratch'부터 새로 학습시킨다.
본 실험은 Representation learning과 Classifier learning을 각각 re-sampling방법과 Cross entropy 방법으로 나누어서
학습해본 결과이다. 실험결과 Representation learning은 re-sampling, Classifier learning은 Cross-entropy 방법을 사용하는 것이 좋다는 결과가 나왔다.
그래서 본 논문에서는 BBN 모델을 제안하며 , 이는 Representation learning과 classifirer learning을 따로 수행하는 형태의 learning방법을 의미한다.
이 모델은 2가지의 branch로 이루어져 있다.
1. Conventional learning branch
원래 long-tail distribution pattern을 그대로 학습하는 용도로 사용된다. (typical uniform sampler 사용)
2. Re-balancing branch
Re-Balancing Sampler는 tail 쪽 data를 좀더 많이 sampling한다.
이때, a는 Adaptor에 의해 생성되고 , universal feature에서 tail data에 대한 feature를 learning하도록
조절하는 역할을 한다.
그리고 a는 각 branch의 parameter를 update하는 control하는 용도로도 사용된다.
그러면 re-balancing 방법은 어떻게 동작하는 것일까?
deep network는 feature extractor part와 classifier part로 나뉜다.
class re-balancing straregies는 train data distribution을 test data distribution\
의 형태로 바꿔주어서 classification 성능을 향상시킬 수는 있다.
그러나 이러한 방식에 대해 본 논문에서는 가설을 하나 제기한다.
이러한 방법은 classifier learning의 성능은 향상시키지만
universal representative ability 에는 성능을 저하시키는 영향을 준다.
위의 그림을 다시 살펴보자.
Representation learning 방법을 하나로 고정시킨채로 살펴보면
Classifier learning을 CE로 하는 것 보다 RW, RS 형태로 하는 것이 더 성능이 좋은 것을 확인할 수 있다.
이는 classifier weight를 조정하는 re-balancing operation이 test distribution에 적합하여 더 좋은 성능을 내는 것이다.
이와 다르게 Classifier learning 방법을 하나로 고정시킨채 살펴보면
Representation learning의 경우 CE로 했을때 가장 좋은 성능을 보임을 알 수 있다.
즉 discriminative한 deep feature을 학습하는 것에는 RW/RS한 방법이 좋지 않음을 확인할 수 있다.
그래서 본 논문에서는 아래와 같은 framework를 만들고 실제로 적용한다.
logit은 아래와 같이 weighting한다.
이때 a는 다음과 같은 수식으로 정의되며, T_max는 최대 epoch, T는 현재 epoch으로 정의된다.
uniform sampler
uniform sampler는 data distribution의 형태 그대로 sampling 하기 때문에,
data가 많은 many class에 대한 학습이 더 많이 진행되게 되고 따라서 feature의 학습 즉,
representation learning이 더욱 잘 되게 된다.
re-balancing branch
이와 다르게 rebalancing branch는 extreme한 imbalance를 해결하기 위한 것으로
tail class에 대한 classification accuracy를 상승시키기 위한 것이다.
Code
실제 코드 구성은 위와 같다.
uniform sampler로 부터 sampling한 image_a
rebalancing sampler로 부터 sampling한 image_b
두개의 image를 각각 conventional branch와 rebalancing branch에 입력으로 사용하고
feature_a, feature_b를 추출한다.
이를 통해서 논문의 내용대로 a값을 이용해 이를 조합하고,
loss 또한 image 두개의 label을 이용해 조합하여 loss값을 준다. (mix_up 형태)
Inference Phase
Inference 단계에서는 같은 sample이 두개의 branch에 입력으로 들어가게 되며,
a는 0.5를 적용한다.
Data sampler - detailed with code
Data sample을 위한 각 클래스간의 sampling 확률 도출 방법은 다음과 같다.
(밑의 식은 reversed sampling)
Visualization of classfier weights
classifier의 weight의 l-2 norm의 크기는 classifier의 preference를 의미한다.
(www.microsoft.com/en-us/research/wp-content/uploads/2017/07/one-shot-face.pdf )
그렇기 때문에 class별 weight의 l_2의 분포값이 작을수록 balance에 맞게 학습된 것을 의미한다.
BNN-CB의 경우 conventional branch를 의미하며, original dataset에 대해서 학습된 것처럼,
majority class에 더 높은 preference를 가지는 것을 확인할 수 있다.
BNN-RB의 경우 reblanced branch를 의미하며, rebalanced distribution에 대해서 학습된 것처럼,
minority class에 더 높은 preference를 가지는 것을 확인할 수 있다.
이 2개를 합친 BNN_ALL의 경우 std가 가장 작은 것을 볼 수 있다.
즉 class에 대한 preference가 골고루 퍼져있음을 알 수 있다.
Conclusion
이 논문은 다음과 같은 장점을 노렸다고 생각한다.
original data로 부터 feature learning의 장점을 얻기 위해
Conventional branch를 통해서 original distribution에 대해 학습을 진행한다.
이를통해서 backbone네트워크는 좀더 좋은 feature를 학습하게 된다.
이전 실험이 먼저 representation learning을 한 이후에 classifier learning를 RW, RS 형태로 진행한 것 처럼
알파(a) 값을 조정하여 처음에는 uniform sampler로 부터 학습을 시작하고, 이로부터 feature가 잘 학습된 backbone 네트워크로부터 RS/RW 효과를 내는 re-balancing branch로 부터 학습을 늘린다.
mix-up형태를 사용한 이유는 어찌되었든, conventional learning branch는 최종적으로 W_c가 majority class에 preference를 더 가지도록 학습이 된다. 그리고 Re-Balancing Branch는 W_r이 Minority class에 preference를 가지도록 학습이 된다. 그러나 mix-up형태를 취함으로서 이러한 편향을 balance한 형태로 맞추어 줄 수 있다고 생각되어 진다.