This repo contains the implementation of our state-of-the-art fewshot object detector, described in our CVPR 2021 paper, FSCE: Few-Shot Object Detection via Contrastive Proposal Encoding. FSCE is built upon the codebase FsDet v0.1, which released by an ICML 2020 paper Frustratingly Simple Few-Shot Object Detection.
@inproceedings{FSCEv1,
author = {Sun, Bo and Li, Banghuai and Cai, Shengcai and Yuan, Ye and Zhang, Chi},
title = {FSCE: Few-Shot Object Detection via Contrastive Proposal Encoding},
booktitle = {Proceedings of the IEEE conference on computer vision and pattern recognition (CVPR)},
pages = {TBD},
month = {June},
year = {2021}
}
Arxiv: https://arxiv.org/abs/2103.05950
If you have any questions, please contact Bo Sun (bos [at] usc.edu) or Banghuai Li(libanghuai [at] megvii.com)
FsDet is built on Detectron2. But you don't need to build detectron2 seperately as this codebase is self-contained. You can follow the instructions below to install the dependencies and build FsDet
. FSCE functionalities are implemented as class
and .py
scripts in FsDet which therefore requires no extra build efforts.
Dependencies
pip install -r requirements.txt
pip install cython; pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
pip install 'git+https://github.com/facebookresearch/fvcore'
pip install opencv-python
Build
python setup.py build develop # you might need sudo
Note: you may need to rebuild FsDet after reinstalling a different build of PyTorch.
We adopt the same benchmarks as in FsDet, including three datasets: PASCAL VOC, COCO and LVIS.
The datasets and data splits are built-in, simply make sure the directory structure agrees with datasets/README.md to launch the program.
The default seed that is used to report performace in research papers can be found here.
The code structure follows Detectron2 v0.1.* and fsdet.
YAML
) for train/test jobs. modeling/roi_heads/*
, modeling/contrastive_loss.py
, and modeling/utils.py
We follow the eaact training procedure of FsDet and we use random initialization for novel weights. For a full description of training procedure, see here.
python tools/train_net.py --num-gpus 8 \
--config-file configs/PASCAL_VOC/base-training/R101_FPN_base_training_split1.yml
python tools/ckpt_surgery.py \
--src1 checkpoints/voc/faster_rcnn/faster_rcnn_R_101_FPN_base1/model_final.pth \
--method randinit \
--save-dir checkpoints/voc/faster_rcnn/faster_rcnn_R_101_FPN_all1
This step will create a model_surgery.pth
frommodel_final.pth
.
Don't forget the --coco
and --lvis
options when work on the COCO and LVIS datasets, see ckpt_surgery.py
for all arguments details.
python tools/train_net.py --num-gpus 8 \
--config-file configs/PASCAL_VOC/split1/10shot_CL_IoU.yml \
--opts MODEL.WEIGHTS WEIGHTS_PATH
Where WEIGHTS_PATH
points to the model_surgery.pth
generated from the previous step. Or you can specify it in the configuration yml.
To evaluate the trained models, run
python tools/test_net.py --num-gpus 8 \
--config-file configs/PASCAL_VOC/split1/10shot_CL_IoU.yml \
--eval-only
Or you can specify TEST.EVAL_PERIOD
in the configuation yml to evaluate during training.
For ease of training and evaluation over multiple runs, fsdet provided several helpful scripts in tools/
.
You can use tools/run_experiments.py
to do the training and evaluation. For example, to experiment on 30 seeds of the first split of PascalVOC on all shots, run
python tools/run_experiments.py --num-gpus 8 \
--shots 1 2 3 5 10 --seeds 0 30 --split 1
After training and evaluation, you can use tools/aggregate_seeds.py
to aggregate the results over all the seeds to obtain one set of numbers. To aggregate the 3-shot results of the above command, run
python tools/aggregate_seeds.py --shots 3 --seeds 30 --split 1 \
--print --plot