728x90

Inverse CDF Method의 경우 PDF 자체가 단순하여 0~1 범위로 형성되는 CDF를 구할 수 있고,

그렇기 때문에 Uniform distribution을 이용해 sampling이 가능하다.

 

그러나 PDF 자체가 복잡한 경우나 어떤 경우는 0~1로 형성되는 CDF를 구하는 것이 불가능하다.

이때 사용하는 것이 바로 Rejection sampling이다.

 

Rejection sampling은 일단 sampling이 쉽게 가능한 제안 분포(Proposal distribution) q를 설정하고 q에서

Inverse CDF Method를 통한 Sampling을 진행한 뒤, 원래 분포 p와 q의 likelihood 값을 비교하여 

 

q의 영역에 있으면 sampling된 sample을 기각하고, p의 영역에 있으면 그대로 놔둔다.

이를 반복하다 보면 q를 토대로 sampling을 시도했지만, p의 영역에 맞는 sample만 남기고

나머지는 기각시켰기 때문에, p의 distribution에 맞게 sampling이 되게 된다.

 

 

www.youtube.com/watch?v=kYWHfgkRc9s

untitledtblog.tistory.com/134

 

[머신 러닝] 기각 샘플링 (Rejection Sampling)

Rejection sampling (또는 acceptance-rejection method)은 어떠한 주어진 확률 분포에서 효율적으로 샘플을 생성하기 위해 많이 이용되는 알고리즘이다. 우리가 샘플을 추출하고자 하는 확률 분포 $p$에 대

untitledtblog.tistory.com

 

728x90

'Dic' 카테고리의 다른 글

Image HWC 순서  (0) 2021.05.01
Sampling / Importance sampling  (0) 2021.04.19
Sampling / Inverse CDF Method  (0) 2021.04.19
Sampling / Gibbs Sampling  (0) 2021.04.19
negative sampling  (0) 2021.03.21
728x90

가장 기본적인 sampling 방법이다.

기본적으로 pdf의 cdf를 구하게 되면 범위에 0~1로 설정되게 되고

이는 Uniform distribution을 통한 sampling과정을 통해 각 x에 맞는 sampling이 가능함을 의미한다.

 

자세한 사항은 아래 참고.

 

 

 

 

blog.naver.com/PostView.nhn?blogId=jinis_stat&logNo=221648391742

 

Sampling 방법 / Inverse CDF Method

Sampling Methods ​앞으로 monte carlo 섹션에서의 포스팅에서는, 샘플링 방법(Sampling Method)에 대...

blog.naver.com

 

728x90

'Dic' 카테고리의 다른 글

Sampling / Importance sampling  (0) 2021.04.19
Sampling / Rejection Sampling  (0) 2021.04.19
Sampling / Gibbs Sampling  (0) 2021.04.19
negative sampling  (0) 2021.03.21
jeffreys prior  (0) 2021.03.18
728x90

huidea.tistory.com/128

 

[기술면접] Markov Chain, Gibbs Sampling, 마르코프 체인, 깁스 샘플링 (day2 / 201010)

Q. Markov Chain을 고등학생에게 설명한다면 어떤 방식이 좋을까요? Q. Markov Chain 은 머신러닝 알고리즘 중 어디에 활용이 되나요? Q. 깁스 샘플링 은 무엇인가 Q. 깁스 샘플링 은 왜 쓰는가 ? Q. Markov Cha

huidea.tistory.com

www.secmem.org/blog/2019/01/11/mcmc/

 

Markov Chain Monte Carlo 샘플링의 마법

이번 포스트에서는 강력한 샘플링 기법 중 하나인 Markov Chain Monte Carlo(MCMC)에 대해 알아보겠습니다. MCMC의 활용도는 굉장히 넓어서 머신러닝을 비롯한 베이지안 통계학, 통계물리학, 컴퓨터비전,

www.secmem.org

blog.naver.com/PostView.nhn?blogId=jinis_stat&logNo=221689714417&categoryNo=0&parentCategoryNo=0&viewDate=&currentPage=1&postListTopCurrentPage=1&from=postView

 

Gibbs Sampler (깁스 샘플링)

​Gibbs Sampler (Geman and Geman, 1984)는 MCMC Alogrithm의 특별한 방법 중 하나이다. 즉, Gi...

blog.naver.com

 

728x90

'Dic' 카테고리의 다른 글

Sampling / Rejection Sampling  (0) 2021.04.19
Sampling / Inverse CDF Method  (0) 2021.04.19
negative sampling  (0) 2021.03.21
jeffreys prior  (0) 2021.03.18
Kernel (Bayesian statistics)  (0) 2021.03.18
728x90

Paper

arxiv.org/abs/2005.12320

 

SCAN: Learning to Classify Images without Labels

Can we automatically group images into semantically meaningful clusters when ground-truth annotations are absent? The task of unsupervised image classification remains an important, and open challenge in computer vision. Several recent approaches have trie

arxiv.org

 

Code

github.com/wvangansbeke/Unsupervised-Classification

 

wvangansbeke/Unsupervised-Classification

SCAN: Learning to Classify Images without Labels (ECCV 2020), incl. SimCLR. - wvangansbeke/Unsupervised-Classification

github.com

 

Introduction

 

 

본 논문은 기존 unsupervised clustering 논문들과 다르게 two-step 형태의 approach를 사용했다는 것이 특징이다.

SCAN (Semantic Clustering by Adopting Nearest neighbors)의 과정은 다음과 같다.

 

- 첫번째는 기존의 Deep cluster가 represetation learning을 통한 classifier output을 통한 clustering 때문에 cluster degeneracy를 발생시키는 문제점을 대비해서 nearest neighbors를 이용해 clustering을 진행한다.

nearest neighbor도 same semantic class에 속하기 때문에 이것이 가능하다. (Fig 2)

 

- 두번째는 nearest neighbor들을 learning의 prior로 활용한다는 점이다. 이는 기존의 방법이 특정 sample과 그 sample에 하나의 augmentation을 적용한 sample을 가깝게 embedding 되도록 학습하는 것에 비해 nearest neighbor들을 가깝게 embedding 시킨다는 차이점이 있다.

 

 

Method

 

- 기존의 방법은 CNN의 prediction을 이용해 k-means clustering을 형성하고, k-means clustering을 통해 형성된 label을 통해 다시 CNN의 학습을 진행하는 것을 반복한다. 그러나 k-means의 초기 label은 네트워크가 학습이 덜 진행된 상태에서 결정되는 부분이기 때문에 high-level information을 추출한 상태가 아니게 되고 최종 목표인 semantic clustering에 오히려 방해가 되게 된다.

 

- 이를 해결하기 위해 representation-learning (self-supervised learning)을 활용한다. 기존의 self-supervised learning의 경우 특정 image에 transformation을 적용하고 각각에 대해 다른 label을 적용하여 다른곳에 embedding 되도록 한다. 그러나 이러한 방식은 유사한 이미지가 비슷한 곳에 위치되어야 하는 semantic clustering에 맞지 않기 때문에 다음과 같이 transformation을 적용한 것과 같은 곳에 위치하도록 loss function을 구성한다. (contrastive learning 참고) 

 

- 이와 같은 방법으로 유사한 class가 가깝게 위치하는 경향을 띄는 것을 실험으로 증명하였다. (Fig 1,2)

 

- 이러한 것이 가능한 이유는 다음과 같다. 첫번째는 모델 Φ_θ가 loss function에 의해서 특정 information을 추출하도록 유도된다. 두번째는 모델 Φ가 추출하는 feature의 크기는 한정되어 있기 때문에 필요없는 information은 버리고, 필요한 high-level information만 추출한다. 

 

- 이러한 motivation으로 먼저 SimCLR이나 Moco와 같은 self-supervised learning을 이용해 feature를 학습하고 이 feature를 이용해 clustering을 진행한다. 그러나 단순히 이러한 방식으로는 cluster degeneracy를 막을 수 없다.

 

-때문에 본 논문에서는 nearest neighbor를 이용한다.

 

-먼저 self-supervised learning을 이용해 feature space를 형성한다. sample X_i에 대해서 K-nearest neighbor를 찾고 이를 N_X_i로 정의한다. 이때, N_X_i가 X_i랑 같은 label로 형성되는 것이 중요한 데, fig 2를 보면 같은 label로 형성되는 비율이 나와 있다. 결과적으로 유의미하게 같은 label로 형성된다고 판단되기에 저자는 k-nearest neighbor를 semantic clustering의 prior로 활용한다.

 

-위의 X_i와 N_X_i를 이용해 classification을 수행하는 새로운 모델 Φ_η을 학습한다. 이때 Φ_η는 맨 마지막단은 softmax function으로 구성되어 있으며,Φ_η(X_i)는 Φ_η 함수의 softmax output을 의미하며, Φ^c_η(X_i)는 X_i가 cluster c에 속하는 확률값만을 따로 추출한 것이다. 

 

- 첫번째 식은 X의 Φ_η 모델에 대한 softmax output과  X의 nearest neighbor에 대한 softmax output을 dot product한 결과이다. 이때, dot product가 최대가 되는 경우는 두개의 prediction이 one-hot label로 같게 되는 경우이다. 

(그렇게 해서 값이 1이 나오면 log (1)이 되어 loss는 0이 된다.

 

- 그러나 첫번째 식만 있는 경우, 모든 sample을 하나의 cluster로 prediction하는 cluster degeneracy가 발생하게 되고 때문에, 두번째 식 entropy식을 이용해 하나의 cluster로 모두 assign되는 현상을 막는다.

 

- entropy식의 마이너스를 loss function으로 활용함으로 sample들이 다양한 cluster에 assign되도록 만들어준다.

 

-이때, cluster 수는 실제로는 모르는 것이 맞다. 기존 논문들은 일반적으로 evaluation을 위해 dataset의 실제 label수와 동등하게 cluster수를 설정하여 진행한다. 그러나 꼭 이렇게 설정할 필요는 없고 더 큰 수로 설정해서 각 cluster에 대한 확률이 좀 더 equally하게 나오도록 할 수도 있다. 이에 대한 실험은 Section 3.4에서 진행하였다.

 

- K-nearest neighbor의 K=0인 경우, nearest neighbor를 학습에 사용하지 않겠다는 의미이고, 기존의 논문들 처럼 image sample 하나만을 이용해 augmentation을 적용하고 이들끼리 가깝게 embedding되도록 네트워크를 학습시킨다.

본 논문에서는 K를 늘려가면서 실험을 진행했으며, K가 증가할수록 성능도 함께 증가했음을 보였다.

 

- mutual information을 이용해 optimization을 진행한 'Invariant'(badlec.tistory.com/202) 논문과 비교했을때는 좀 더 직접적으로 sample x와 augmentation한 sample x'을 가깝게 embedding 시키도록 하였다는 차이점이 있다.

 

-추가적으로 본 논문에서는 self-labeling fine-tuning을 통해 noisy nearest label로 인해 생기는 optimization 문제를 correcting하는 과정을 거친다. 

 

-본 논문에서 실험한 결과 sample을 classification network에 통과시켰을때, confidence가 높게 나오는 sample은 제대로 된 cluster에 잘 clustering이 됨을 확인하였다. 따라서 confidence에 대한 threshold를 지정하고 특정 threshold를 넘는 sample에 대해서는 classification network를 재학습하는데 이용한다. 

 

-위의 과정을 정리하면 아래와 같다.

 

 

Experiments

* RA - Random Augment

 

728x90
728x90

Paper

arxiv.org/abs/1807.06653

 

Invariant Information Clustering for Unsupervised Image Classification and Segmentation

We present a novel clustering objective that learns a neural network classifier from scratch, given only unlabelled data samples. The model discovers clusters that accurately match semantic classes, achieving state-of-the-art results in eight unsupervised

arxiv.org

 

Code

github.com/xu-ji/IIC

 

xu-ji/IIC

Invariant Information Clustering for Unsupervised Image Classification and Segmentation - xu-ji/IIC

github.com

 

Introduction

 

 

본 논문은 deep-clustering 논문과 같이 simple하게 clustering과 representation learning을 섞은 방법이 degenerate solutions을 만들어 낸다는 문제가 있다는 점을 지적했다.

 

Invariant Information Clustering (IIC) 방법은 x와 transformation이 적용된 x' sample간의 mutual information을 이용하여 objective function을 구성한 것이 특징이다.

 

IIC는 다른 method들에 비해 robust한데,

 

먼저 clustering degeneracy에 대해 robust하다. clustering degeneracy는 cluster의 prediction을 하나의 class로 prediction하는 현상으로 특히 k-means와 representation learning을 조합했을 때, 더 잘 나타난다.

 

이러한 현상을 IIC에서는 entropy maximisation term을 넣어서 하나의 class로 prediction할 경우 loss값이 커지게 만들어서 해결한다.

 

두번째는 모델이 label을 잘못 prediction함으로 생기는 noisy data가 발생한다는 것이다. 

이러한 문제를 IIC에서는 auxiliary output layer를 사용함으로 해결한다. 이때 output의 수는 원래 gt의 수보다 더 많게 설정된다. (Auxiliary over-clustering)

 

 

 

Method

 

 

 

 

IIC는 다음과 같이 x, x'의 representation의 mutual information 값을 maximization하는 방법을 사용한다.

 

위와 같은 식을 사용하면 x, x'의 representation을 같게 만들어주는 효과가 있다.

 

위의 mutual information식은 아래와 같이 표현이 가능하다.

 

위 식을 maximizing하는 것은 다음과 같다.

H(z)를 max로 만드는 것은 z의 확률이 equally하게 형성된다는 것을 의미하며, cluster label assign이 equally하게 되는 것을 의미한다. H(z|z')이 최소화 된다는 것의 의미는 한 sample이 어떤 label로 assign되었을때, 다른 sample도 label이 확정된다는 것을 의미한다. 

 

이때 , H(z)가 maximize됨으로 cluster degeneration을 막을 수 있다. (하나의 cluster만 형성되는 것을 막을 수 있음)

 

 

 

 

 

728x90
728x90

Paper

arxiv.org/abs/2012.11150

 

Improving Unsupervised Image Clustering With Robust Learning

Unsupervised image clustering methods often introduce alternative objectives to indirectly train the model and are subject to faulty predictions and overconfident results. To overcome these challenges, the current research proposes an innovative model RUC

arxiv.org

 

Code

github.com/deu30303/RUC

 

deu30303/RUC

Contribute to deu30303/RUC development by creating an account on GitHub.

github.com

 

Introduction

 

 

 

Unsupervised clustering의 경우 많은 연구가 진행되었지만 실제와 다른 label로 misclassified되는 문제가 주요하게 대두되었다. 본 논문에서는 RUC라는 방법을 제안해 이러한 문제를 해결했으며, 이와 같은 noise labeling 문제를 label-smoothing과 co-training으로 접근해 해결한다.

 

이러한 re-training method는 pseudo-label을 regularize하고 또한 overconfident 문제를 막는다.  

 

그래서 RUC는 크게 다음과 같은 2개의 key component가 있다.

(1) extracting clean samples

(2) retraining with the refined dataset

 

- 이를 위해 먼저 confidence값을 이용해 low confidence sample을 걸러낸다.

- 두번째는 metric-based로 non-parametric classifier를 이용해 given instance가 k-nearest sample와 same label을 공유하는지 살펴본다.

- 3번째는 위의 두가지 방법을 combine하여 credible한 sample을 찾아낸다.

 

그 다음으로는 위와 같은 방식으로 sampled 된 dataset을 이용하여 clustering model을 retraining한다.

MixMatch (badlec.tistory.com/200?category=1015684) 를 이용하며, clean sample을 labeld data, unsample sample을 unlabeled data로 활용한다. 

 

이때, label smoothing과 block learning을 이용해 denoising effect를 적용한다.

 

최종적으로 두개의 network를 co-training하는 방법을 사용해서 unclean sample들에 대한 효과를 경감시킨다.

 

 

Method

 

 

 

- 먼저 initial clustering의 결과를 noisy-labels 문제로 생각하는 것이 핵심이다.

- 그래서 training을 위해 pseudo-label이 된 데이터를 clean data와 unclean data로 구분하여 생각한다.

- 이때, clean data는 labeled data, unclean data는 unlabeled data로 구분하여 생각하고 이를 semi-supervised 형식으로 재학습하게 된다.

- semi-supervised 방식에서 활용하는 방법은 label smoothing과 co-trainining 방법이다. 

 

1. Extracting clean samples

 

- 먼저 trainig sample을 pseudo-label an supervised classifier gΦ을 이용하여 clean data X, unclean data U를 구분한다. 이때 구분하는 기준은 다음과 같이 3가지를 활용한다.

 

1-1) Confidence-based strategy

 

- 이 방법은 unsupervised classifier의 confidence score를 기반으로 clean sample을 지정하는 방법이다.

unsupervised classifier가 over-confidence하는 경향이 있기 때문에 threshold를 크게 잡아서 uncertain sample을 최대한 제거하는 방법을 활용한다.

 

1-2) Metric-based strategy

 

- Confidence-based 방법은 문제점은 unsupervised classifier의 능력에 의존한다는 점이다. Metric-based 방법은 새로운 embedding network hψ를 활용한다 (SimCLR과 같은 pretext learning 활용). 이때,  hψ(x)의 label은 k-NN 방법을 활용한다. 그리고 최종적으로는 기존 network의 결과 y와 hψ의 kNN based 결과가 같은 경우 clean data라고 판별하고, 아닌 경우 unclean data라고 판별한다.

 

1-3) Hybrid strategy

 

- 이 방법의 Confidence, Metric based 방법을 둘다 사용한 것이다.

 

 

 

2. Retraining via Robust Learning

 

위의 방법을 이용해 clean dataset과 unclean dataset을 구분하면 refine classifier fθ를 학습시킨다. 이때 fθ의 역할은 initial unsupervised classifier의 incorrect prediction들을 correcting 하는 역할이다.

 

2-1) Semi-supervised learning (MixMatch)

 

-X와 U가 정해지면 이를 이용해 semi supervied learning을 적용할 수 있다. 이때 사용하는 방법은 MixMatch(badlec.tistory.com/200)이다. 

 

 

2-2) Label smoothing

 

Label Smoothing을 적용함으로 Label Noise를 줄일 수 있다. 때문에 본 논문에서는 semi-supervised learning에 label noise도 함께 적용한다.

 

(ε은 uniform distribution)

 

실제로 적용한 방식은 위의 방법으로 생성된 Smoothed label과 RandAugment를 적용한 sample의 ouput에 cross-entropy loss를 적용한다. 

 

위 loss를 적용한 최종 objective는 다음과 같다.

 

2-3) Co-training

 

Network 하나만을 이용하면, 하나의 network가 잘못된 pseudo-label에 over-fitting되는 경우 그 error가 계속해서 그 네트워크에 누적된다는 위험이 존재한다. 이를 막기 위해서 2개의 network를 이용하여 학습을 진행하는 co-training module을 활용한다. 이때 label set X와 unlabel set U에 둘다 co-refinement를 적용한다. labeled data x에 대해서 model 2개의 output을 조합한다.

 

w(2)는 network 2의 confidence value이다. 

 

unlabeled set U에 대해서는 아래와 같이 quessing 한다.

m은 augmentation을 의미하며, 여러 augmentation의 결과를 평균내어 나타낸다.

 

이를 정리하면 다음과 같다.

 

2-4) Co-refurbishing

 

마지막으로 학습과정에서 unclean sample중에서 prediction이 확실한 sample들은 clean sample로 추가해준다.

unlabeled data중에서 network를 통과했을때, prediction 확률이 특정 threshold값을 넘는 경우, clean dataset에 추가해준다.

 

 

728x90
728x90

Paper

arxiv.org/abs/1905.02249

 

MixMatch: A Holistic Approach to Semi-Supervised Learning

Semi-supervised learning has proven to be a powerful paradigm for leveraging unlabeled data to mitigate the reliance on large labeled datasets. In this work, we unify the current dominant approaches for semi-supervised learning to produce a new algorithm,

arxiv.org

 

Code

github.com/google-research/mixmatch

 

google-research/mixmatch

Contribute to google-research/mixmatch development by creating an account on GitHub.

github.com

 

Introduction

 

 

Method

- labelded data x에 대해서 Augmentation을 적용한다.

- unlabeled data x에 대해서 Augmentation을 적용한다.

- unlabeled data x에 대해서 Augmentation을 적용한 결과들을 평균내서 결과를 낸다. -> q_b_bar

- q_b_bar에 대해서 temperature Sharpen을 적용한 결과를 q_b (unlabeled target으로 사용)

- 그리고 Mixup을 통해 학습을 위한 데이터를 재생성한다.

- 먼저 Augmented labeled data X_hat과 Augmented unlabeled data u_hat을 이용하여 W set을 만든다. (concat)

- 형성된 W set을 이용해 MixUp을 사용한다. Mixup을 적용하여 새로운 X' , U'을 만든다. (자세한 건 논문참고)

- 만들어진 X', U'를 이용해서 아래의 loss function을 적용해 학습을 진행한다.

 

 

 

 

728x90
728x90

pypi.org/project/thop/

 

thop

A tool to count the FLOPs of PyTorch model.

pypi.org

 

728x90

'Pytorch' 카테고리의 다른 글

Pytorch : Dataloader num_workers  (0) 2021.06.01
Deep learning model code basic structure  (0) 2021.04.28
visualization  (0) 2020.08.05
torch.utils.data.DataLoader  (0) 2020.06.20
Data Nomalization  (0) 2019.10.08

+ Recent posts