학교공부/Deep Learning

[Deep Learning] cs231n 6강 내용 정리 (1)

yunmap 2017. 10. 15. 19:02

Activation Function

(1) sigmoid

+ squashes numbers to range [0, 1]

- saturated neurons kill the gradients

- sigmoid outputs are not zero centered (각 gradient가 한 방향으로 밖에 못 움직인다.)

- exp() is a bit compute expensive (minor 한 문제)

(2) tanh

+ squashes numbers to range [-1, 1]

+ zero-centered

- kill gradients when saturated

(3) ReLU

+ Does not saturate (in positive region)

+ very computationally efficient

+ converges much faster than sigmoid/tanh in practice (6배)

+ more biologically plausible (closer to what happening in neuron)

- not zero centered

- negative region에 대한 annoyance

이 그림에서 각 선 이후 부분의 data만 살아남는데 active ReLU에선 일부가 살아남는 반면, dead ReLU에선 아무것도 살아나지 못한다.

Dead ReLU : never activate (= never update)

원인 1 : bad initialization

원인 2 : too high learning rate (training 도중에 active에서 dead로 변한다.)

약간의 positive bias를 더함으로써 dead ReLU를 해결하려고 하지만, 효과적인진 모르고 잘 사용하지 않는 방법임.

(4) Leaky ReLU

+ Does not saturate

+ computationally efficient

+ converges much faster than sigmoid/tanh (거의 6배)

+ will not die

+ zero centered

(5) Exponential Linear Units (ELU)

+ Does not saturate (in positive region)

+ very computationally efficient

+ converges much faster than sigmoid/tanh in practice (6배)

+ more biologically plausible (closer to what happening in neuron)

+ Closer to zero mean outputs

+ Negative saturation regime compared with Leaky ReLU adds some robustness to noise

(Negative일 때의 값이 Leaky보다 더 작게 나온다. 0보다 작은 것은 음수를 보완하기 위해 noise로 본다.) 

- computation requires exp()

(6) Maxout "Neuron"

+ does not have the basic form of dot product -> nonlinearity

+ generalized ReLU and Leaky ReLU

+ Linear Regime

+ Does not saturate

+ Does not die

- doubles the number of parameters/neuron

ReLU를 사용하되, learning rate를 잘 설정하라.

Leaky ReLU, Maxout, ELU 도 사용해봐라.

tanh도 사용해보되, 기대는 하지 말라.

sigmoid는 사용하지 마!!!

 

Data preprocessing : original data -> zero-centered data -> normalized data (zero-centered가 아닐 때의 단점을 피하기 위해)

decorrelated data : data has diagonal covariance matrix

whitened data : covariance matrix is the identity matrix

AlexNet : Subtract the mean image (mean image = input image의 size와 같다.)

VGGNet : Subtract per-channel mean (mean along each channel = 3 numbers. RGB)

 

Weight initialization

Q. What happens when W=0 init is used?

A. All the neuron will do same thing. (bias로 인해 dead는 안될지도 모름. gradient도 같고, update same way. 다만 loss 때문에 미세하게 다를 수는 있지만 결론적으론 neuron이 비슷해진다.)

Q. What happens when initialize Weight with small random number?

A. Works okay for small networks, but problems with deeper networks.

시간이 지날수록 activation들이 become zero가 된다.

Q. Think about the backward pass. What do the gradients look like?

A. gradient가 점점 작아져서 그냥 X가 된다. (not update)

Q. What happens when initialize Weight with big random number?

A. Almost all neurons completely saturated, either -1 and 1. Gradient will be all zero.

 

Xavier initialization : 다음 layer에 가기 전에 크기를 scale 해준다. (Scale by number of input's node)

But, when using the ReLU nonlinearlity it breaks (half를 죽이니까)

그래서 scale 과정에 분모의 fan_in에 additional /2를 해준다. (He el al.)

 

Batch normalization : keep activation in a gausian range

weight initialize 대신 training이 시작할 때 set 하여 good spot에 도달하도록 한다. -> 모든 layer에 gausian.

(1) compute the empirical mean and variance independently for each dimension

(2) normalize

Batch normalization is usually inserted after fully connected or convolutioal layers and before nonlinearity.

이 과정까지는 학습 가능한 값이 없다.

한 activation map에 속하는 layer(batch)는 하나의 mean과 standard deviation 값을 가진다.

이 과정까지 computational graph로 나타낼 수 있으므로 back prop이 가능하지만 update 되는 과정에 learnable 한 것이 없음. (update 불가)

Q. Do we necessarily want a unit gaussian input to a tanh layer?

Q. Control how much saturation to have

r(k) = standard deviation of x

b(k) = mean of x

가 생기는데, 이 변수들은 back prop 시 update가 된다. (learnable 하다.)

이 변수들은 to recover the identity mapping. (Saturaion의 양을 정하는 데에 좋다.) scale and shift

scale and shift 하는 이유 : 평균 0, 분산 1을 맞추는 것(activation의 sensitive 한 영역에 몰자.)이 버려져야 하는 정보도 담게 돼서 더 별로다. 

 

Batch normalization

- improves gradient flow through the network

- allows higher learning rate

- reduces the strong dependence on initialization

- acts as a form of regularization in a funny way, and slightly reduces the need for dropout, maybe

(tieing all of batch together. no longer deterministic)

Normalizing input! not weight!

Batch size가 작으면 더 많은 example을 이용하여 mean을 구해도 된다.

- test에서는 train에서 구한 mean/std를 이용한다.

 

Babysitting the Learning Process

(1) preprocess the data

(2) choose the architecture

(3) double check that the loss is reasonable.

disable regularization을 한 뒤 train data에 대해 loss가 작은지 확인.

enable regularization을 한 뒤 loss가 이전보다 올라가는지 호가인. (sanity check)

단, training data의 작은 portion에 overfit 될 수 있음을 주의해야 함.

(4) start with small regularization and find learning rate that makes the loss go down (여러 값을 lr로 시도해 보아라.)

loss가 거의 변하지 않는 경우 -> learning rate가 너무 작다.

loss가 거의 변하지 않더라도 train/val accuracy가 거의 20%에 빠르게 도달하고 있는 것을 확인하면 (softmax일 때) weight가 맞는 방향으로 바뀌었기 때문이다.

loss가 Nan이 나오는 경우 -> learning rate가 너무 높다. cost가 explode 한 것.

learning rate는 [1e-3,,,1e-5] 즈음이 적당함.

 

Hyperparameter Optimization

(1) cross-validation strategy

(i) only a few epochs to get rough idea of what params work

(ii) longer running time, finer search (세밀하게 조정)

만약 cost가 원래 cost의 3배보다 크면 explosion 될 확률이 매우 높기 때문에 break out early 해야 한다.

cross validation 결과가 제일 좋은 것에서도 lr 또는 reg가 양 끝 값이라면 다른 것을 채택해야 한다.

(범위의 양 끝 값은 나쁘다.)

(2) Random search vs grid search

Random search가 낫다.

(3) hyperparameters to play with :

- network architecture

- larning rate, its decay schedule, update type

- regularization (L2, Dropout strength)

 

this is because of bad initialization.