Awesome
AlphaRotate: A Rotation Detection Benchmark using TensorFlow
<!-- Documentation: [https://rotationdetection.readthedocs.io/](https://rotationdetection.readthedocs.io/) --> <!-- :rocket::rocket::rocket: **News:** The MMDetection version cooperating with MMLab will be released soon, stay tuned.:rocket::rocket::rocket: -->:rocket::rocket::rocket: News: MMRotate has been released at https://github.com/open-mmlab/mmrotate <img src="https://img.shields.io/github/stars/open-mmlab/mmrotate?style=social" /> :rocket::rocket::rocket:
Abstract
AlphaRotate is mainly maintained by Xue Yang with Shanghai Jiao Tong University supervised by Prof. Junchi Yan.
Papers and codes related to remote sensing/aerial image detection: DOTA-DOAI <img src="https://img.shields.io/github/stars/SJTU-Thinklab-Det/DOTA-DOAI?style=social" />.
Techniques:
- Dataset: DOTA, HRSC2016, ICDAR2015, ICDAR2017 MLT, MSRA-TD500, UCAS-AOD, FDDB, OHD-SJTU, SSDD++, Total-Text
- Baackbone: ResNet, MobileNetV2, EfficientNet, DarkNet53
- Neck: FPN, BiFPN
- Detectors:
- R<sup>2</sup>CNN (Faster-RCNN-H): R2CNN_Faster-RCNN_Tensorflow <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/R2CNN_Faster-RCNN_Tensorflow?style=social" />, DOTA-DOAI <img src="https://img.shields.io/github/stars/SJTU-Thinklab-Det/DOTA-DOAI?style=social" />, R2CNN_FPN_Tensorflow (Deprecated) <img src="https://img.shields.io/github/stars/yangxue0827/R2CNN_FPN_Tensorflow?style=social" />
- Double Head
- RRPN (Faster-RCNN-R): TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/RRPN_Faster-RCNN_Tensorflow?style=social" />
- SCRDet (ICCV19): R<sup>2</sup>CNN++ <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/R2CNN-Plus-Plus_Tensorflow?style=social" />, IoU-Smooth L1 Loss <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/RetinaNet_Tensorflow_Rotation?style=social" />
- RetinaNet-H, RetinaNet-R: TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/RetinaNet_Tensorflow_Rotation?style=social" />
- RefineRetinaNet (CascadeRetinaNet)
- ATSS
- FCOS
- RSDet (AAAI21): TF code <img src="https://img.shields.io/github/stars/Mrqianduoduo/RSDet-8P-4R?style=social" />
- RSDet++ (FCOS-RSDet)
- R<sup>3</sup>Det (AAAI21): TF code <img src="https://img.shields.io/github/stars/Thinklab-SJTU/R3Det_Tensorflow?style=social" />, PyTorch code1 <img src="https://img.shields.io/github/stars/SJTU-Thinklab-Det/r3det-on-mmdetection?style=social" />, PyTorch code2 <img src="https://img.shields.io/github/stars/SJTU-Thinklab-Det/r3det-pytorch?style=social" />, Pytorch code3 <img src="https://img.shields.io/github/stars/open-mmlab/mmrotate?style=social" />
- Circular Smooth Label (CSL ECCV20): TF code <img src="https://img.shields.io/github/stars/Thinklab-SJTU/CSL_RetinaNet_Tensorflow?style=social" />, PyTorch code <img src="https://img.shields.io/github/stars/open-mmlab/mmrotate?style=social" />
- Densely Coded Label (DCL CVPR21): TF code <img src="https://img.shields.io/github/stars/Thinklab-SJTU/DCL_RetinaNet_Tensorflow?style=social" />
- GWD (ICML21): PyTorch code <img src="https://img.shields.io/github/stars/open-mmlab/mmrotate?style=social" />
- BCD (TPAMI22): PyTorch code <img src="https://img.shields.io/github/stars/open-mmlab/mmrotate?style=social" />
- KLD (NeurIPS21): PyTorch code <img src="https://img.shields.io/github/stars/open-mmlab/mmrotate?style=social" />
- RIDet (GRSL): PyTorch code <img src="https://img.shields.io/github/stars/ming71/RIDet?style=social" />
- KFIoU (ICLR23): PyTorch code <img src="https://img.shields.io/github/stars/open-mmlab/mmrotate?style=social" />
- Mixed method: R<sup>3</sup>Det-DCL, R<sup>3</sup>Det-GWD, R<sup>3</sup>Det-BCD, R<sup>3</sup>Det-KLD, FCOS-RSDet, R<sup>2</sup>CNN-BCD, R<sup>2</sup>CNN-KF
- Loss: CE, Focal Loss, Smooth L1 Loss, IoU-Smooth L1 Loss, Modulated Loss
- Others: SWA, exportPb, MMdnn
The above-mentioned rotation detectors are all modified based on the following horizontal detectors:
- Faster RCNN: TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/Faster-RCNN_Tensorflow?style=social" />
- R-FCN: TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/R-FCN_Tensorflow?style=social" />
- FPN: TF code1 <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/FPN_Tensorflow?style=social" />, TF code2 (Deprecated) <img src="https://img.shields.io/github/stars/yangxue0827/FPN_Tensorflow?style=social" />
- Cascade RCNN: TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/Cascade-RCNN_Tensorflow?style=social" />
- Cascade FPN RCNN: TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/Cascade_FPN_Tensorflow?style=social" />
- RetinaNet: TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/RetinaNet_Tensorflow?style=social" />
- RefineDet: MxNet code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/RefineDet_MxNet?style=social" />
- FCOS: TF code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/FCOS_Tensorflow?style=social" />, MxNet code <img src="https://img.shields.io/github/stars/DetectionTeamUCAS/FCOS_GluonCV?style=social" />
Projects
Latest Performance
<!-- More results and trained models are available in the [MODEL_ZOO.md](MODEL_ZOO.md). -->All trained weights can also be downloaded from HuggingFace.
DOTA (Task1)
Baseline
Backbone | Neck | Training/test dataset | Data Augmentation | Epoch | NMS |
---|---|---|---|---|---|
ResNet50_v1d 600->800 | FPN | trainval/test | × | 13 (AP50) or 17 (AP50:95) is enough for baseline (default is 13) | gpu nms (slightly worse <1% than cpu nms but faster) |
SOTA
Method | Backbone | DOTA1.0 | Model | MS | Data Augmentation | Epoch | Configs |
---|---|---|---|---|---|---|---|
R<sup>2</sup>CNN-BCD | ResNet152_v1d-FPN | 79.54 | Baidu Drive (h2u1) | √ | √ | 34 | dota1.0 |
RetinaNet-BCD | ResNet152_v1d-FPN | 78.52 | Baidu Drive (0puk) | √ | √ | 51 | dota1.0 |
R<sup>3</sup>Det-BCD | ResNet50_v1d-FPN | 79.08 | Baidu Drive (v60g) | √ | √ | 51 | dota1.0 |
R<sup>3</sup>Det-BCD | ResNet152_v1d-FPN | 79.95 | Baidu Drive (v60g) | √ | √ | 51 | dota1.0 |
Note:
- Single GPU training: SAVE_WEIGHTS_INTE = iter_epoch * 1 (DOTA1.0: iter_epoch=27000, DOTA1.5: iter_epoch=32000, DOTA2.0: iter_epoch=40000)
- Multi-GPU training (better): SAVE_WEIGHTS_INTE = iter_epoch * 2
My Development Environment
- python3.5 (anaconda recommend)
- cuda 10.0
- opencv-python 4.1.1.26 (important)
- tfplot 0.2.0 (optional)
- tensorflow-gpu 1.13
- tqdm 4.54.0
- Shapely 1.7.1
Installation
Manual configuration (cuda version < 11)
pip install -r requirements.txt
pip install -v -e . # or "python setup.py develop"
Or, you can simply install AlphaRotate with the following command:
pip install alpharotate # Not suitable for dev.
Docker (cuda version < 11)
docker images: yangxue2docker/yx-tf-det:tensorflow1.13.1-cuda10-gpu-py3
Note: For 30xx series graphics cards (cuda version >= 11), I recommend this blog to install tf1.xx, or download image from tensorflow-release-notes according to your development environment, e.g. nvcr.io/nvidia/tensorflow:20.11-tf1-py3
cd alpharotate/libs/utils/cython_utils
rm *.so
rm *.c
rm *.cpp
python setup.py build_ext --inplace (or make)
cd alpharotate/libs/utils/
rm *.so
rm *.c
rm *.cpp
python setup.py build_ext --inplace
Download Model
Pretrain weights
Download a pretrain weight you need from the following three options, and then put it to $PATH_ROOT/dataloader/pretrained_weights.
- MxNet pretrain weights (recommend in this repo, default in NET_NAME): resnet_v1d, resnet_v1b, refer to gluon2TF.
- Tensorflow pretrain weights: resnet50_v1, resnet101_v1, resnet152_v1, efficientnet, mobilenet_v2, darknet53 (Baidu Drive (1jg2), Google Drive).
- PyTorch pretrain weights, refer to pretrain_zoo.py and Others.
Trained weights
- Please download trained models by this project, then put them to $PATH_ROOT/output/pretained_weights.
Train
-
If you want to train your own dataset, please note:
(1) Select the detector and dataset you want to use, and mark them as #DETECTOR and #DATASET (such as #DETECTOR=retinanet and #DATASET=DOTA) (2) Modify parameters (such as CLASS_NUM, DATASET_NAME, VERSION, etc.) in $PATH_ROO./configs/#DATASET/#DETECTOR/cfgs_xxx.py (3) Copy $PATH_ROO./configs/#DATASET/#DETECTOR/cfgs_xxx.py to $PATH_ROO./configs/cfgs.py (4) Add category information in $PATH_ROOT/libs/label_name_dict/label_dict.py (5) Add data_name to $PATH_ROOT/dataloader/dataset/read_tfrecord.py
-
Make tfrecord
If image is very large (such as DOTA dataset), the image needs to be cropped. Take DOTA dataset as a example:cd $PATH_ROOT/dataloader/dataset/DOTA python data_crop.py
If image does not need to be cropped, just convert the annotation file into xml format, refer to example.xml.
cd $PATH_ROOT/dataloader/dataset/ python convert_data_to_tfrecord.py --root_dir='/PATH/TO/DOTA/' --xml_dir='labeltxt' --image_dir='images' --save_name='train' --img_format='.png' --dataset='DOTA'
-
Start training
cd $PATH_ROOT/tools/#DETECTOR python train.py
Test
-
For large-scale image, take DOTA dataset as a example (the output file or visualization is in $PATH_ROOT/tools/#DETECTOR/test_dota/VERSION):
cd $PATH_ROOT/tools/#DETECTOR python test_dota.py --test_dir='/PATH/TO/IMAGES/' --gpus=0,1,2,3,4,5,6,7 -ms (multi-scale testing, optional) -s (visualization, optional) or (recommend in this repo, better than multi-scale testing) python test_dota_sota.py --test_dir='/PATH/TO/IMAGES/' --gpus=0,1,2,3,4,5,6,7 -s (visualization, optional)
Notice: In order to set the breakpoint conveniently, the read and write mode of the file is' a+'. If the model of the same #VERSION needs to be tested again, the original test results need to be deleted.
-
For small-scale image, take HRSC2016 dataset as a example:
cd $PATH_ROOT/tools/#DETECTOR python test_hrsc2016.py --test_dir='/PATH/TO/IMAGES/' --gpu=0 --image_ext='bmp' --test_annotation_path='/PATH/TO/ANNOTATIONS' -s (visualization, optional)
Tensorboard
cd $PATH_ROOT/output/summary
tensorboard --logdir=.
Citation
If you find our code useful for your research, please consider cite.
@article{yang2021alpharotate,
author = {Yang, Xue and Zhou, Yue and Yan, Junchi},
title = {AlphaRotate: A Rotation Detection Benchmark using TensorFlow},
journal = {arXiv preprint arXiv:2111.06677},
year = {2021},
}
Reference
1、https://github.com/endernewton/tf-faster-rcnn
2、https://github.com/zengarden/light_head_rcnn
3、https://github.com/tensorflow/models/tree/master/research/object_detection
4、https://github.com/fizyr/keras-retinanet