카테고리 없음

[DL] Dropouts and Batch Norms : 학습 성능을 높이는 친구들

standingR 2023. 12. 1. 16:30

 

Dropout, batch normalization은 기존 CNN에 새로운 layer를 추가하여 학습의 효율성과 성능을 끌어올리는 방법론

batch normalizationdata preprocessing, convex optimization 와 관련이 있고,

dropoutensemble learning 과 관련이 있으므로 꼭 다시 공부할 것

 

 

1. Dropout, batch normalization 사용하는 이유

 

기존 neural network 학습의 문제점인, neuronweight, bias가 초기에 비슷하게 initialization되었다면,

학습을 한다고 하더라도 계속 비슷한 neuron으로 변함

비슷한 역할을 하는 neuron들이 많아지기 때문에, neural network의 비효율성이 커짐

iteration 마다 일정 확률로 neurondeactivation 시키는 방법 비슷한 neuron들이 만들어지는 것을 막는 방법

 

 

2. Dropout

 

요약 :  Dropout은 뉴런을 죽여서, 비슷한 뉴런의 생성을 방지한다.

 

예시 코드 

import torch
import torch.nn as nn



test_input = torch.randn(size=(4, 5))
dropout = nn. Dropout(p=0.5)

# 학습이 일어나는 train
dropout.train()
test_output = dropout(test_input)
print("Training Process")
print(test_output, '\n')


# 학습이 일어난지 않는 eval : 이유는 이렇게 모델이 학습에 사용된 데이터가 아닌, 
# unseen data에 대한 성능을 측정해보는 과정을 validation 모델이기 떄문이다.

dropout.eval()
test_output = dropout(test_input)
print("Test Process")
print(test_output)

 

 

Training Process


tensor([[-1.3289, -2.8220, -0.0084, -0.0000, -1.6717],
        [-0.0000,  0.0000, -0.0000, -0.0000, -0.3098],
        [-0.7681, -4.2062,  1.1176, -3.1492, -0.0000],
        [ 0.0000,  0.0000, -0.0000, -0.0000,  3.2275]]) 

 

Test Process

tensor([[-0.6645, -1.4110, -0.0042, -1.8942, -0.8359],
        [-0.0666,  0.2816, -0.3064, -0.0382, -0.1549],
        [-0.3841, -2.1031,  0.5588, -1.5746, -0.6747],
        [ 1.4683,  2.1621, -0.0385, -0.3518,  1.6137]])

 

 

위에 코드에서 알수있듯이 drop out은 학습이 일어나는 시점에만 활성화되며, 일정확률로 뉴런을 죽인다. 

unseen data에 대한 성능을 측정해보는 과정을 validation 모델인 Test Process 는 학습이 일어나지 않기 때문에 dropout이 일어나지 않는다.