README.md 11.9 KB
Newer Older
Z
Zhi Tian 已提交
1
# FCOS: Fully Convolutional One-Stage Object Detection
F
Francisco Massa 已提交
2

C
chhshen 已提交
3
This project hosts the code for implementing the FCOS algorithm for object detection, as presented in our paper:
F
Francisco Massa 已提交
4

T
Tian Zhi 已提交
5
    FCOS: Fully Convolutional One-Stage Object Detection;
C
chhshen 已提交
6
    Zhi Tian, Chunhua Shen, Hao Chen, and Tong He;
C
chhshen 已提交
7 8
    In: Proc. Int. Conf. Computer Vision (ICCV), 2019.
    arXiv preprint arXiv:1904.01355 
Z
Zhi Tian 已提交
9 10

The full paper is available at: [https://arxiv.org/abs/1904.01355](https://arxiv.org/abs/1904.01355). 
F
Francisco Massa 已提交
11

T
Tian Zhi 已提交
12
Implementation based on Detectron2 is included in [AdelaiDet](https://github.com/aim-uofa/AdelaiDet#coco-object-detecton-baselines-with-fcos).
T
Tian Zhi 已提交
13

T
Tian Zhi 已提交
14
**A real-time model with 46FPS and 40.3 in AP on COCO minival is also available [here](https://github.com/aim-uofa/AdelaiDet/blob/master/configs/FCOS-Detection/README.md#fcos-real-time-models).**
C
chhshen 已提交
15

F
Francisco Massa 已提交
16
## Highlights
Z
Zhi Tian 已提交
17
- **Totally anchor-free:**  FCOS completely avoids the complicated computation related to anchor boxes and all hyper-parameters of anchor boxes.   
T
Tian Zhi 已提交
18
- **Better performance:** The very simple one-stage detector achieves much better performance (38.7 vs. 36.8 in AP with ResNet-50) than Faster R-CNN. Check out more models and experimental results [here](#models).
T
Tian Zhi 已提交
19
- **Faster training and testing:** With the same hardwares and backbone ResNet-50-FPN, FCOS also requires less training hours (6.5h vs. 8.8h) than Faster R-CNN. FCOS also takes 12ms less inference time per image than Faster R-CNN (44ms vs. 56ms).
20
- **State-of-the-art performance:** Our best model based on ResNeXt-64x4d-101 and deformable convolutions achieves **49.0%** in AP on COCO test-dev (with multi-scale testing).
F
Francisco Massa 已提交
21

T
Tian Zhi 已提交
22
## Updates
T
Tian Zhi 已提交
23
   - FCOS with Fast And Diverse (FAD) neural architecture search is avaliable at [FAD](https://github.com/MalongTech/research-fad). (30/10/2020)
T
Tian Zhi 已提交
24
   - Script for exporting [ONNX models](https://github.com/tianzhi0549/FCOS/tree/master/onnx). (21/11/2019)
T
Tian Zhi 已提交
25
   - New NMS (see [#165](https://github.com/tianzhi0549/FCOS/pull/165)) speeds up ResNe(x)t based models by up to 30% and MobileNet based models by 40%, with exactly the same performance. Check out [here](#models). (12/10/2019)
T
Tian Zhi 已提交
26 27 28 29 30 31
   - New models with much improved performance are released. The best model achieves **49%** in AP on COCO test-dev with multi-scale testing. (11/09/2019)
   - FCOS with VoVNet backbones is available at [VoVNet-FCOS](https://github.com/vov-net/VoVNet-FCOS). (08/08/2019)
   - A trick of using a small central region of the BBox for training improves AP by nearly 1 point [as shown here](https://github.com/yqyao/FCOS_PLUS). (23/07/2019)
   - FCOS with HRNet backbones is available at [HRNet-FCOS](https://github.com/HRNet/HRNet-FCOS). (03/07/2019)
   - FCOS with AutoML searched FPN (R50, R101, ResNeXt101 and MobileNetV2 backbones) is available at [NAS-FCOS](https://github.com/Lausannen/NAS-FCOS). (30/06/2019)
   - FCOS has been implemented in [mmdetection](https://github.com/open-mmlab/mmdetection). Many thanks to [@yhcao6](https://github.com/yhcao6) and [@hellock](https://github.com/hellock). (17/05/2019)
T
Tian Zhi 已提交
32

Z
Zhi Tian 已提交
33 34 35
## Required hardware
We use 8 Nvidia V100 GPUs. \
But 4 1080Ti GPUs can also train a fully-fledged ResNet-50-FPN based FCOS since FCOS is memory-efficient.  
F
Francisco Massa 已提交
36 37

## Installation
Z
Zhi Tian 已提交
38
#### Testing-only installation 
Z
Zhi Tian 已提交
39
For users who only want to use FCOS as an object detector in their projects, they can install it by pip. To do so, run:
Z
Zhi Tian 已提交
40 41
```
pip install torch  # install pytorch if you do not have it
T
Tian Zhi 已提交
42
pip install git+https://github.com/tianzhi0549/FCOS.git
Z
Zhi Tian 已提交
43 44
# run this command line for a demo 
fcos https://github.com/tianzhi0549/FCOS/raw/master/demo/images/COCO_val2014_000000000885.jpg
Z
Zhi Tian 已提交
45
```
Z
Zhi Tian 已提交
46
Please check out [here](fcos/bin/fcos) for the interface usage.
Z
Zhi Tian 已提交
47 48

#### For a complete installation 
C
chhshen 已提交
49
This FCOS implementation is based on [maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark). Therefore the installation is the same as original maskrcnn-benchmark.
F
Francisco Massa 已提交
50

Z
Zhi Tian 已提交
51 52
Please check [INSTALL.md](INSTALL.md) for installation instructions.
You may also want to see the original [README.md](MASKRCNN_README.md) of maskrcnn-benchmark.
F
Francisco Massa 已提交
53

Z
Zhi Tian 已提交
54 55 56
## A quick demo
Once the installation is done, you can follow the below steps to run a quick demo.
    
Z
Zhi Tian 已提交
57 58
    # assume that you are under the root directory of this project,
    # and you have activated your virtual environment if needed.
59
    wget https://cloudstor.aarnet.edu.au/plus/s/ZSAqNJB96hA71Yf/download -O FCOS_imprv_R_50_FPN_1x.pth
Z
Zhi Tian 已提交
60 61 62
    python demo/fcos_demo.py


Z
Zhi Tian 已提交
63 64
## Inference
The inference command line on coco minival split:
F
Francisco Massa 已提交
65

Z
Zhi Tian 已提交
66
    python tools/test_net.py \
Z
Zhi Tian 已提交
67 68
        --config-file configs/fcos/fcos_imprv_R_50_FPN_1x.yaml \
        MODEL.WEIGHT FCOS_imprv_R_50_FPN_1x.pth \
Z
Zhi Tian 已提交
69
        TEST.IMS_PER_BATCH 4    
F
Francisco Massa 已提交
70

Z
Zhi Tian 已提交
71
Please note that:
Z
Zhi Tian 已提交
72
1) If your model's name is different, please replace `FCOS_imprv_R_50_FPN_1x.pth` with your own.
Z
Zhi Tian 已提交
73
2) If you enounter out-of-memory error, please try to reduce `TEST.IMS_PER_BATCH` to 1.
T
Tian Zhi 已提交
74
3) If you want to evaluate a different model, please change `--config-file` to its config file (in [configs/fcos](configs/fcos)) and `MODEL.WEIGHT` to its weights file.
Z
Zhi Tian 已提交
75
4) Multi-GPU inference is available, please refer to [#78](https://github.com/tianzhi0549/FCOS/issues/78#issuecomment-526990989).
H
Hao Chen 已提交
76
5) We improved the postprocess efficiency by using multi-label nms (see [#165](https://github.com/tianzhi0549/FCOS/pull/165)), which saves 18ms on average. The inference metric in the following tables has been updated accordingly.
F
Francisco Massa 已提交
77

T
Tian Zhi 已提交
78
## Models
Z
Zhi Tian 已提交
79
For your convenience, we provide the following trained models (more models are coming soon).
F
Francisco Massa 已提交
80

Z
Zhi Tian 已提交
81 82
**ResNe(x)ts:**

Z
Zhi Tian 已提交
83
*All ResNe(x)t based models are trained with 16 images in a mini-batch and frozen batch normalization (i.e., consistent with models in [maskrcnn_benchmark](https://github.com/facebookresearch/maskrcnn-benchmark)).*
Z
Zhi Tian 已提交
84

Z
Zhi Tian 已提交
85 86
Model | Multi-scale training | Testing time / im | AP (minival) | Link
--- |:---:|:---:|:---:|:---:
H
Hao Chen 已提交
87 88 89 90 91 92 93 94
FCOS_imprv_R_50_FPN_1x | No | 44ms | 38.7 | [download](https://cloudstor.aarnet.edu.au/plus/s/ZSAqNJB96hA71Yf/download)
FCOS_imprv_dcnv2_R_50_FPN_1x | No | 54ms | 42.3 | [download](https://cloudstor.aarnet.edu.au/plus/s/plKgHuykjiilzWr/download)
FCOS_imprv_R_101_FPN_2x | Yes | 57ms | 43.0 | [download](https://cloudstor.aarnet.edu.au/plus/s/hTeMuRa4pwtCemq/download)
FCOS_imprv_dcnv2_R_101_FPN_2x | Yes | 73ms | 45.6 | [download](https://cloudstor.aarnet.edu.au/plus/s/xq2Ll7s0hpaQycO/download)
FCOS_imprv_X_101_32x8d_FPN_2x | Yes | 110ms | 44.0 | [download](https://cloudstor.aarnet.edu.au/plus/s/WZ0i7RZW5BRpJu6/download)
FCOS_imprv_dcnv2_X_101_32x8d_FPN_2x | Yes | 143ms | 46.4 | [download](https://cloudstor.aarnet.edu.au/plus/s/08UK0OP67TogLCU/download)
FCOS_imprv_X_101_64x4d_FPN_2x | Yes | 112ms | 44.7 | [download](https://cloudstor.aarnet.edu.au/plus/s/rKOJtwvJwcKVOz8/download)
FCOS_imprv_dcnv2_X_101_64x4d_FPN_2x | Yes | 144ms | 46.6 | [download](https://cloudstor.aarnet.edu.au/plus/s/jdtVmG7MlugEXB7/download)
95

Z
Zhi Tian 已提交
96
*Note that `imprv` denotes `improvements` in our paper Table 3. These almost cost-free changes improve the performance by ~1.5% in total. Thus, we highly recommend to use them. The following are the original models presented in our initial paper.*
97

Z
Zhi Tian 已提交
98
Model | Multi-scale training | Testing time / im | AP (minival) | AP (test-dev) | Link
Z
Zhi Tian 已提交
99
--- |:---:|:---:|:---:|:---:|:---:
H
Hao Chen 已提交
100 101 102 103
FCOS_R_50_FPN_1x | No | 45ms | 37.1 | 37.4 | [download](https://cloudstor.aarnet.edu.au/plus/s/dDeDPBLEAt19Xrl/download)
FCOS_R_101_FPN_2x | Yes | 59ms | 41.4 | 41.5 | [download](https://cloudstor.aarnet.edu.au/plus/s/vjL3L0AW7vnhRTo/download)
FCOS_X_101_32x8d_FPN_2x | Yes | 110ms | 42.5 | 42.7 | [download](https://cloudstor.aarnet.edu.au/plus/s/U5myBfGF7MviZ97/download)
FCOS_X_101_64x4d_FPN_2x | Yes | 113ms | 43.0 | 43.2 | [download](https://cloudstor.aarnet.edu.au/plus/s/wpwoCi4S8iajFi9/download)
104

Z
Zhi Tian 已提交
105
**MobileNets:**
Z
Zhi Tian 已提交
106

T
Tian Zhi 已提交
107
*We update batch normalization for MobileNet based models. If you want to use SyncBN, please install pytorch 1.1 or later.*
Z
Zhi Tian 已提交
108

Z
Zhi Tian 已提交
109 110
Model | Training batch size | Multi-scale training | Testing time / im | AP (minival) | Link
--- |:---:|:---:|:---:|:---:|:---:
H
Hao Chen 已提交
111 112 113
FCOS_syncbn_bs32_c128_MNV2_FPN_1x | 32 | No | 26ms | 30.9 | [download](https://cloudstor.aarnet.edu.au/plus/s/3GKwaxZhDSOlCZ0/download)
FCOS_syncbn_bs32_MNV2_FPN_1x | 32 | No | 33ms | 33.1 | [download](https://cloudstor.aarnet.edu.au/plus/s/OpJtCJLj104i2Yc/download)
FCOS_bn_bs16_MNV2_FPN_1x | 16 | No | 44ms | 31.0 | [download](https://cloudstor.aarnet.edu.au/plus/s/B6BrLAiAEAYQkcy/download)
Z
Zhi Tian 已提交
114

T
Tian Zhi 已提交
115
[1] *1x and 2x mean the model is trained for 90K and 180K iterations, respectively.* \
Z
Zhi Tian 已提交
116 117
[2] *All results are obtained with a single model and without any test time data augmentation such as multi-scale, flipping and etc..* \
[3] *`c128` denotes the model has 128 (instead of 256) channels in towers (i.e., `MODEL.RESNETS.BACKBONE_OUT_CHANNELS` in [config](https://github.com/tianzhi0549/FCOS/blob/master/configs/fcos/fcos_syncbn_bs32_c128_MNV2_FPN_1x.yaml#L10)).* \
Z
Zhi Tian 已提交
118 119
[4] *`dcnv2` denotes deformable convolutional networks v2. Note that for ResNet based models, we apply deformable convolutions from stage c3 to c5 in backbones. For ResNeXt based models, only stage c4 and c5 use deformable convolutions. All models use deformable convolutions in the last layer of detector towers.* \
[5] *The model `FCOS_imprv_dcnv2_X_101_64x4d_FPN_2x` with multi-scale testing achieves 49.0% in AP on COCO test-dev. Please use `TEST.BBOX_AUG.ENABLED True` to enable multi-scale testing.*
120

Z
Zhi Tian 已提交
121
## Training
F
Francisco Massa 已提交
122

Z
Zhi Tian 已提交
123
The following command line will train FCOS_imprv_R_50_FPN_1x on 8 GPUs with Synchronous Stochastic Gradient Descent (SGD):
124

Z
Zhi Tian 已提交
125 126 127 128
    python -m torch.distributed.launch \
        --nproc_per_node=8 \
        --master_port=$((RANDOM + 10000)) \
        tools/train_net.py \
Z
Zhi Tian 已提交
129
        --config-file configs/fcos/fcos_imprv_R_50_FPN_1x.yaml \
Z
Zhi Tian 已提交
130
        DATALOADER.NUM_WORKERS 2 \
Z
Zhi Tian 已提交
131
        OUTPUT_DIR training_dir/fcos_imprv_R_50_FPN_1x
Z
Zhi Tian 已提交
132 133
        
Note that:
T
Tian Zhi 已提交
134
1) If you want to use fewer GPUs, please change `--nproc_per_node` to the number of GPUs. No other settings need to be changed. The total batch size does not depends on `nproc_per_node`. If you want to change the total batch size, please change `SOLVER.IMS_PER_BATCH` in [configs/fcos/fcos_R_50_FPN_1x.yaml](configs/fcos/fcos_R_50_FPN_1x.yaml).
Z
Zhi Tian 已提交
135 136
2) The models will be saved into `OUTPUT_DIR`.
3) If you want to train FCOS with other backbones, please change `--config-file`.
137 138
4) If you want to train FCOS on your own dataset, please follow this instruction [#54](https://github.com/tianzhi0549/FCOS/issues/54#issuecomment-497558687).
5) Now, training with 8 GPUs and 4 GPUs can have the same performance. Previous performance gap was because we did not synchronize `num_pos` between GPUs when computing loss. 
F
Francisco Massa 已提交
139

Z
Zhi Tian 已提交
140 141
## ONNX
Please refer to the directory [onnx](onnx) for an example of exporting the model to ONNX.
Z
Zhi Tian 已提交
142
A converted model can be downloaded [here](https://cloudstor.aarnet.edu.au/plus/s/38fQAdi2HBkn274/download).
Z
Zhi Tian 已提交
143 144
We recommend you to use PyTorch >= 1.4.0 (or nightly) and torchvision >= 0.5.0 (or nightly) for ONNX models.

145
## Contributing to the project
T
Tian Zhi 已提交
146
Any pull requests or issues are welcome.
147

148
## Citations
C
chhshen 已提交
149
Please consider citing our paper in your publications if the project helps your research. BibTeX reference is as follows.
150
```
C
chhshen 已提交
151
@inproceedings{tian2019fcos,
T
Tian Zhi 已提交
152 153
  title   =  {{FCOS}: Fully Convolutional One-Stage Object Detection},
  author  =  {Tian, Zhi and Shen, Chunhua and Chen, Hao and He, Tong},
C
chhshen 已提交
154
  booktitle =  {Proc. Int. Conf. Computer Vision (ICCV)},
T
Tian Zhi 已提交
155
  year    =  {2019}
156 157
}
```
C
chhshen 已提交
158 159 160 161 162 163 164 165 166
```
@article{tian2021fcos,
  title   =  {{FCOS}: A Simple and Strong Anchor-free Object Detector},
  author  =  {Tian, Zhi and Shen, Chunhua and Chen, Hao and He, Tong},
  booktitle =  {IEEE T. Pattern Analysis and Machine Intelligence (TPAMI)},
  year    =  {2021}
}
```

167

Z
Zhi Tian 已提交
168 169
# Acknowledgments
We would like to thank [@yqyao](https://github.com/yqyao) for the tricks of center sampling and GIoU.  We also thank [@bearcatt](https://github.com/bearcatt) for his suggestion of positioning the center-ness branch with box regression (refer to [#89](https://github.com/tianzhi0549/FCOS/issues/89#issuecomment-516877042)).    
170

F
Francisco Massa 已提交
171 172
## License

Z
Zhi Tian 已提交
173
For academic use, this project is licensed under the 2-clause BSD License - see the LICENSE file for details. For commercial use, please contact the authors.