This is a demo on how to train tensorpack's Mask R-CNN on a custom dataset. We use the balloon dataset as an example.
- Download and unzip the dataset:
wget https://github.com/matterport/Mask_RCNN/releases/download/v2.1/balloon_dataset.zip
unzip balloon_dataset.zip
-
(included already) Since this dataset is not in COCO format, we add a new file dataset/balloon.py to load the dataset. Refer to dataset/dataset.py on the required interface of a new dataset.
-
(included already) Register the names of the new dataset in
train.py
andpredict.py
, by callingregister_balloon("/path/to/balloon_dataset")
-
Download a model pretrained on COCO from tensorpack model zoo:
wget http://models.tensorpack.com/FasterRCNN/COCO-MaskRCNN-R50FPN2x.npz
- Start fine-tuning on the new dataset:
./train.py --config DATA.BASEDIR=~/data/balloon MODE_FPN=True \
"DATA.VAL=('balloon_val',)" "DATA.TRAIN=('balloon_train',)" \
TRAIN.BASE_LR=1e-3 TRAIN.EVAL_PERIOD=0 "TRAIN.LR_SCHEDULE=[1000]" \
"PREPROC.TRAIN_SHORT_EDGE_SIZE=[600,1200]" TRAIN.CHECKPOINT_PERIOD=1 DATA.NUM_WORKERS=1 \
--load COCO-MaskRCNN-R50FPN2x.npz --logdir train_log/balloon
- You can train as long as you want, but it only takes a few minutes to produce nice results. You can visualize the results of the latest model by:
./predict.py --config DATA.BASEDIR=~/data/balloon MODE_FPN=True \
"DATA.VAL=('balloon_val',)" "DATA.TRAIN=('balloon_train',)" \
--load train_log/balloon/checkpoint --predict ~/data/balloon/val/*.jpg
This command will produce images like this in your window: