Andrej Karpathy가 작성한 딥러닝 개발자 레시피 정리
Neural Network는
*leaky abstraction : 한 계층의 역할과 책임이 불필요하게 다른 계층으로 전이되는 문제
직접 sample을 보고 distribution을 이해한다 → 사람은 이걸 잘하는지
이해하는데 어떤 사고과정을 거쳤나 곰곰히 돌이켜보면 어떤 모델을 사용할지 감이 잡히기도 한다
Sorting이나 filtering을 통해 dataset의 outlier등을 살펴본다.
모든 것을 간소화해서 버그가 없는지 확인한다
Data augmentation, model 구조 등을 간소화
Evaluation 할 때는 batch가 아닌 전체 test set에 대해 loss 계산
Softmax의 경우 첫 loss는 아래와 같아야 한다.
Output의 평균이 50이라면 final layer의 bias 평균이 50이 되도록 initialize 한다,
If you havewan imbalanced dataset of a ratio 1:10 of positives:negatives, set the bias on your logits such that your network predicts probability of 0.1 at initialization.
Accuracy등 해석할 수 있는 metric을 사용해라
될 수 있다면 직접 evaluation 해봐라 →사람의 metric이 얼마나 되는지 확인
적은 example만 포함하여 over-fitting을 시켜 lowest achievable loss까지 train 시켜본다.
Train 끝나고 visualize해서 정말 잘 학습했는지 확인
모델을 조!금! 늘려보고 training loss가 잘 감소하나 확인
Input이 제대로 들어가는지 항상 확인할것!
작은 batch에 대해 testing할 때 model의 prediction이 어떤식으로 변하는지 visualize해보자
Amount of jittering 으로 learning rate가 적당한지 확인할 수 있다
One way to debug this (and other related problems) is to set the loss to be something trivial like the sum of all outputs of example i, run the backward pass all the way to the input, and ensure that you get a non-zero gradient only on the i-th input. The same strategy can be used to e.g. ensure that your autoregressive model at time t only depends on 1..t-1. More generally, gradients give you information about what depends on what in your network, which can be useful for debugging.
Detail부터 작성하고 generalize해라
작은 것 부터 시작해서 잘 작동하는지 확인하고 scaling 하는게 핵심
위의 과정에서 잘 동작하는 멍청한 모델을 얻었다
1에서 뭐가 안된다 싶으면 Model 구조 외의 issue, bugs, misconfiguration 존재함을 암시한다
일단 비슷한 project를 찾아서 복붙하고 시작해라
잘되는걸 고쳤을 때 안되면 고친 부분에 문제가 있음을 알 수 있다
경험상 Adam이 learning rate 포함한 여러 hyper-parameters에 forgiving하다
ConvNet의 경우 거의 항상 well-tuned SGD가 Adam보다 조금 나음
→ 더 나은 region이 좁고 problem specific하긴 함
한 번에 하나씩만 바꾸자 그래야 뭐가 잘못됐는지 알지
왠만하면 learning rate decay는 빼고 마지막에 tuning합시다
이제 training set에 대해 over-fit된 모델을 얻었으니 regularize를 해보자
training accuracy를 낮추고 validation accuracy를 취할 차례
이게 사실 제일 좋은 방법임 하니면 앙상블
Half fake data같은 Aggressive augmentation 시도해 볼것
나쁠게 없다
Input dimension이 클 필요가 없다 → ex) resolution
Remove features that may contain spurious signal. Any added spurious input is just another opportunity to overfit if your dataset is small. Similarly, if low-level details don’t matter much try to input a smaller image.
As an example, it used to be trendy to use Fully Connected layers at the top of backbones for ImageNet but these have since been replaced with simple average pooling, eliminating a ton of parameters in the process.
BN쓸 때 mean, std가 완벽하지 않아서 더 wiggle해진다 → more regularization이 가능해짐
Dropout써라 BN이랑 조화가 안좋으니 너무 많이 쓰지는 말고(근거)
ConvNet에서는 dropout2d(spatial dropout)를 써라 →Filter마다 dropout
Validation loss보고 over-fit인지 아닌지 판단
Larger model이 over-fit되기 쉽긴하다 근데,
early stopping version of larger model이 smaller model보다 outperform할 때가 많다.
위 과정이 다 끝나고 나면 first-layer의 weight를 visualize 해보자
filter의 Edge가 선명하면 make sense, noise같이 생겼으면 뭔가 잘못됐을 가능성 농후
hyper-parameter search할 때 random search가 더 낫다
Bayesian hyper-parameter optimization이 잘 된다고는 하는데, 인턴 시키는게 더 낫더라 ^^
다 됐는데 그 중에서도 성능을 더 높이고 싶을 때
2% 정도 accuracy를 높일 수 있다
inference할 때 감당이 안되면 knowledge distillation을 써봐라
네트워크 학습은 생각보다 오래 지속된다
까먹고 방학동안 학습하게 냅뒀더니 SOTA를 찍었더라