Home

Awesome

CyCTR-PyTorch

This is a PyTorch re-implementation of NeurIPS 2021 paper "Few-Shot Segmentation via Cycle-Consistent Transformer".

News

(Feb. 2022) Fix some bugs and update some results.

Usage

Requirements

Python==3.8
GCC==5.4
torch==1.6.0
torchvision==0.7.0
cython
tensorboardX
tqdm
PyYaml
opencv-python
pycocotools

Build Dependencies

cd model/ops/
bash make.sh
cd ../../

Data Preparation

${YOUR_PROJ_PATH}
|-- data
`-- |-- coco
    `-- |-- annotations
        |   |-- instances_train2017.json
        |   `-- instances_val2017.json
        |-- train2017
        |   |-- 000000000009.jpg
        |   |-- 000000000025.jpg
        |   |-- 000000000030.jpg
        |   |-- ... 
        `-- val2017
            |-- 000000000139.jpg
            |-- 000000000285.jpg
            |-- 000000000632.jpg
            |-- ... 

Then, run

python prepare_coco_data.py

to prepare COCO-20^i data.

Train

Download the ImageNet pretrained backbones and put them into the initmodel directory.

Then, run this command:

    sh train.sh {*dataset*} {*model_config*}

For example,

    sh train.sh pascal split0_resnet50

Test Only

    sh test.sh {*dataset*} {*model_config*}

For example,

    sh test.sh pascal split0_resnet50

Results on 1-shot Pascal-5^i with ResNet50 backbone (checkpoints)

ModelSplit-0Split-1Split-2Split-3Mean
CyCTR_resnet5065.771.059.559.764.0

Results on 5-shot Pascal-5^i with ResNet50 backbone (checkpoints)

ModelSplit-0Split-1Split-2Split-3Mean
CyCTR_resnet5069.373.563.863.567.5

Results on 1-shot Pascal-5^i with ResNet101 backbone (checkpoints)

ModelSplit-0Split-1Split-2Split-3Mean
CyCTR_resnet5067.271.157.659.063.7

Results on 5-shot Pascal-5^i with ResNet101 backbone (checkpoints)

ModelSplit-0Split-1Split-2Split-3Mean
CyCTR_resnet5071.075.058.565.067.4

Acknowledgement

This project is built upon PFENet and Deformable-DETR, thanks for their great works!

Citation

If you find our codes or models useful, please consider to give us a star or cite with:

@article{zhang2021few,
  title={Few-shot segmentation via cycle-consistent transformer},
  author={Zhang, Gengwei and Kang, Guoliang and Yang, Yi and Wei, Yunchao},
  journal={Advances in Neural Information Processing Systems},
  volume={34},
  pages={21984--21996},
  year={2021}
}