Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 2.64 KB

TRANSFER_LEARNING.md

File metadata and controls

39 lines (28 loc) · 2.64 KB

English | 简体中文

Transfer Learning

Transfer learning aims at learning new knowledge from existing knowledge. For example, take pretrained model from ImageNet to initialize detection models, or take pretrained model from COCO dataset to initialize train detection models in PascalVOC dataset.

In transfer learning, if different dataset and the number of classes is used, the dimensional inconsistency will causes in loading parameters related to the number of classes; On the other hand, if more complicated model is used, need to motify the open-source model construction and selective load parameters. Thus, PaddleDetection should designate parameter fields and ignore loading the parameters which match the fields.

Transfer Learning in PaddleDetection

In transfer learning, it's needed to load pretrained model selectively. The following two methods can be used:

  1. Set finetune_exclude_pretrained_params in YAML configuration files. Please refer to configure file
  2. Set -o finetune_exclude_pretrained_params in command line. For example:
export PYTHONPATH=$PYTHONPATH:.
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
python -u tools/train.py -c configs/faster_rcnn_r50_1x.yml \
                        -o pretrain_weights=https://paddlemodels.bj.bcebos.com/object_detection/faster_rcnn_r50_1x.tar \
                           finetune_exclude_pretrained_params=['cls_score','bbox_pred']
  • Note:
  1. The path in pretrain_weights is the open-source model link of faster RCNN from COCO dataset. For full models link, please refer to MODEL_ZOO
  2. The parameter fields are set in finetune_exclude_pretrained_params. If the name of parameter matches field (wildcard matching), the parameter will be ignored in loading.

If users want to fine-tune by own dataet, and remain the model construction, need to ignore the parameters related to the number of classes. PaddleDetection lists ignored parameter fields corresponding to different model type. The table is shown below:

model type ignored parameter fields
Faster RCNN cls_score, bbox_pred
Cascade RCNN cls_score, bbox_pred
Mask RCNN cls_score, bbox_pred, mask_fcn_logits
Cascade-Mask RCNN cls_score, bbox_pred, mask_fcn_logits
RetinaNet retnet_cls_pred_fpn
SSD ^conv2d_
YOLOv3 yolo_output