*train
python train.py config.py
*data
original data : 1,700장
transfer learning을 위한 데이터 : 200(11.8%) + 200(23.5%)+ 200(35.3%) + 285(52.1%) = 885장
original와 신규 과제 데이터는 유사함
*200장만 쓴 경우
: 크기가 작고 유사성이 높은 데이터 = 전략2 = 데이터셋의 크기가 커서 오버피팅은 문제가 안 될 것이기에, 원하는 만큼 학습 시켜도 됨. 데이터셋이 유사하다는 이점이 있으므로 모델이 이전에 학습한 지식을 활용하지 않을 이유가 없음
*885장을 쓴 경우
: 크기가 크고 유사성이 높은 데이터 = 전략3 = pre-trained model 의 마지막 classifier만 삭제하고, 기존의 convolutional base는 feature extractor로 사용하고, extracted 된 feature를 새 classifier에 넣어서 분류할 수 있도록 학습시킨다. 즉 새 classifier만 학습시킨다.
*transfer learning을 위한 데이터
: LabelmeCocoDataset 형태로 바꿔주기
*mmdetection transfer learning (fine tuning) v2.2.0
(1) inherit base configs
- To finetune a Mask RCNN model, the new config needs to inherit "_base_/models/mask_rcnn_r50_fpn.py" to build the basic model. To use the Cityscapes Dataset, the new config can also simply inherit "_base_/datasets/cityscapes_instance.py". For runtime settings such as training schedules, the new config needs to inherit "_base_/default_runtime.py".
- _base_ = [ '../_base_/models/mask_rcnn_r50_fpn.py', '../_base_/datasets/cityscapes_instance.py','../_base_/default_runtime.py']
(2) modify head
- the new config needs to modify the head according to the class numbers of the new datasets.
- by only changing "num_classes" in the roi_head, the weights of the pre-trained models are mostly reused except the final prediction head
(3) modify dataset
(4) modify training schedule
- the finetuning hyperparameters vary from the default schedule. it usually requires smaller learning rate and less training epochs.
optimzer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)
optimizer_config = dict(grad_clip=None)
lr_config = dict(policy='step', warmup='linear', warmup_iters=500, warmup_ratio=0.001, step=[7])
total_epochs = 8
log_config = dict(interval=100)
(5) use pre-trained model
- to use the pre-trained model, the new config add the link of pre-trained models in the "load_from".
- the users might need to download the model weights before training to avoid download time during training.
CUDA_VISIBLE_DEVICE=1 python train.py config.py
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
'스타트업 > AI' 카테고리의 다른 글
[AI] TF-IDF (0) | 2020.07.08 |
---|---|
[AI] TensorBoard (0) | 2020.07.07 |
[AI] Adaptive Transfer Learning (0) | 2020.07.02 |
[AI] transfer learning (0) | 2020.07.01 |
[AI] ICDAR SROIE (0) | 2020.06.19 |