Skip to content

Commit e451588

Browse files
author
Chaorui Deng
committed
init commit
0 parents  commit e451588

File tree

255 files changed

+19682
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+19682
-0
lines changed

.flake8

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is an example .flake8 config, used when developing *Black* itself.
2+
# Keep in sync with setup.cfg which is used for source packages.
3+
4+
[flake8]
5+
ignore = E203, E266, E501, W503
6+
max-line-length = 80
7+
max-complexity = 18
8+
select = B,C,E,F,W,T4,B9

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# compilation and distribution
2+
__pycache__
3+
_ext
4+
*.pyc
5+
*.so
6+
maskrcnn_benchmark.egg-info/
7+
build/
8+
dist/
9+
10+
# pytorch/python/numpy formats
11+
*.pth
12+
*.pkl
13+
*.npy
14+
15+
# ipython/jupyter notebooks
16+
*.ipynb
17+
**/.ipynb_checkpoints/
18+
19+
# Editor temporaries
20+
*.swn
21+
*.swo
22+
*.swp
23+
*~
24+
25+
# Pycharm editor settings
26+
.idea
27+
28+
# project dirs
29+
/datasets
30+
/models

ABSTRACTIONS.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## Abstractions
2+
The main abstractions introduced by `maskrcnn_benchmark` that are useful to
3+
have in mind are the following:
4+
5+
### ImageList
6+
In PyTorch, the first dimension of the input to the network generally represents
7+
the batch dimension, and thus all elements of the same batch have the same
8+
height / width.
9+
In order to support images with different sizes and aspect ratios in the same
10+
batch, we created the `ImageList` class, which holds internally a batch of
11+
images (os possibly different sizes). The images are padded with zeros such that
12+
they have the same final size and batched over the first dimension. The original
13+
sizes of the images before padding are stored in the `image_sizes` attribute,
14+
and the batched tensor in `tensors`.
15+
We provide a convenience function `to_image_list` that accepts a few different
16+
input types, including a list of tensors, and returns an `ImageList` object.
17+
18+
```python
19+
from maskrcnn_benchmark.structures.image_list import to_image_list
20+
21+
images = [torch.rand(3, 100, 200), torch.rand(3, 150, 170)]
22+
batched_images = to_image_list(images)
23+
24+
# it is also possible to make the final batched image be a multiple of a number
25+
batched_images_32 = to_image_list(images, size_divisible=32)
26+
```
27+
28+
### BoxList
29+
The `BoxList` class holds a set of bounding boxes (represented as a `Nx4` tensor) for
30+
a specific image, as well as the size of the image as a `(width, height)` tuple.
31+
It also contains a set of methods that allow to perform geometric
32+
transformations to the bounding boxes (such as cropping, scaling and flipping).
33+
The class accepts bounding boxes from two different input formats:
34+
- `xyxy`, where each box is encoded as a `x1`, `y1`, `x2` and `y2` coordinates, and
35+
- `xywh`, where each box is encoded as `x1`, `y1`, `w` and `h`.
36+
37+
Additionally, each `BoxList` instance can also hold arbitrary additional information
38+
for each bounding box, such as labels, visibility, probability scores etc.
39+
40+
Here is an example on how to create a `BoxList` from a list of coordinates:
41+
```python
42+
from maskrcnn_benchmark.structures.bounding_box import BoxList, FLIP_LEFT_RIGHT
43+
44+
width = 100
45+
height = 200
46+
boxes = [
47+
[0, 10, 50, 50],
48+
[50, 20, 90, 60],
49+
[10, 10, 50, 50]
50+
]
51+
# create a BoxList with 3 boxes
52+
bbox = BoxList(boxes, image_size=(width, height), mode='xyxy')
53+
54+
# perform some box transformations, has similar API as PIL.Image
55+
bbox_scaled = bbox.resize((width * 2, height * 3))
56+
bbox_flipped = bbox.transpose(FLIP_LEFT_RIGHT)
57+
58+
# add labels for each bbox
59+
labels = torch.tensor([0, 10, 1])
60+
bbox.add_field('labels', labels)
61+
62+
# bbox also support a few operations, like indexing
63+
# here, selects boxes 0 and 2
64+
bbox_subset = bbox[[0, 2]]
65+
```

CODE_OF_CONDUCT.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Code of Conduct
2+
3+
Facebook has adopted a Code of Conduct that we expect project participants to adhere to.
4+
Please read the [full text](https://code.fb.com/codeofconduct/)
5+
so that you can understand what actions will and will not be tolerated.

CONTRIBUTING.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Contributing to Mask-RCNN Benchmark
2+
We want to make contributing to this project as easy and transparent as
3+
possible.
4+
5+
## Our Development Process
6+
Minor changes and improvements will be released on an ongoing basis. Larger changes (e.g., changesets implementing a new paper) will be released on a more periodic basis.
7+
8+
## Pull Requests
9+
We actively welcome your pull requests.
10+
11+
1. Fork the repo and create your branch from `master`.
12+
2. If you've added code that should be tested, add tests.
13+
3. If you've changed APIs, update the documentation.
14+
4. Ensure the test suite passes.
15+
5. Make sure your code lints.
16+
6. If you haven't already, complete the Contributor License Agreement ("CLA").
17+
18+
## Contributor License Agreement ("CLA")
19+
In order to accept your pull request, we need you to submit a CLA. You only need
20+
to do this once to work on any of Facebook's open source projects.
21+
22+
Complete your CLA here: <https://code.facebook.com/cla>
23+
24+
## Issues
25+
We use GitHub issues to track public bugs. Please ensure your description is
26+
clear and has sufficient instructions to be able to reproduce the issue.
27+
28+
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
29+
disclosure of security bugs. In those cases, please go through the process
30+
outlined on that page and do not file a public issue.
31+
32+
## Coding Style
33+
* 4 spaces for indentation rather than tabs
34+
* 80 character line length
35+
* PEP8 formatting following [Black](https://black.readthedocs.io/en/stable/)
36+
37+
## License
38+
By contributing to Mask-RCNN Benchmark, you agree that your contributions will be licensed
39+
under the LICENSE file in the root directory of this source tree.

FCOS_README.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# FCOS: Fully Convolutional One-Stage Object Detection
2+
3+
This project hosts the code for implementing the FCOS algorithm for object detection, as presented in our paper:
4+
5+
FCOS: Fully Convolutional One-Stage Object Detection;
6+
Tian Zhi, Chunhua Shen, Hao Chen, and Tong He;
7+
arXiv preprint arXiv:1904.01355 (2019).
8+
9+
The full paper is available at: [https://arxiv.org/abs/1904.01355](https://arxiv.org/abs/1904.01355).
10+
11+
## Highlights
12+
- **Totally anchor-free:** FCOS completely avoids the complicated computation related to anchor boxes and all hyper-parameters of anchor boxes.
13+
- **Memory-efficient:** FCOS uses 2x less training memory footprint than its anchor-based counterpart RetinaNet.
14+
- **Better performance:** The very simple detector achieves better performance (37.1 vs. 36.8) than Faster R-CNN.
15+
- **Faster training and inference:** With the same hardwares, FCOS also requires less training hours (6.5h vs. 8.8h) and faster inference speed (71ms vs. 126 ms per im) than Faster R-CNN.
16+
- **State-of-the-art performance:** Without bells and whistles, FCOS achieves state-of-the-art performances.
17+
It achieves **41.5%** (ResNet-101-FPN) and **43.2%** (ResNeXt-64x4d-101) in AP on coco test-dev.
18+
19+
## Updates
20+
### 17 May 2019
21+
- 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).
22+
23+
## Required hardware
24+
We use 8 Nvidia V100 GPUs. \
25+
But 4 1080Ti GPUs can also train a fully-fledged ResNet-50-FPN based FCOS since FCOS is memory-efficient.
26+
27+
## Installation
28+
29+
This FCOS implementation is based on [maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark). Therefore the installation is the same as original maskrcnn-benchmark.
30+
31+
Please check [INSTALL.md](INSTALL.md) for installation instructions.
32+
You may also want to see the original [README.md](MASKRCNN_README.md) of maskrcnn-benchmark.
33+
34+
## A quick demo
35+
Once the installation is done, you can follow the below steps to run a quick demo.
36+
37+
# assume that you are under the root directory of this project,
38+
# and you have activated your virtual environment if needed.
39+
wget https://cloudstor.aarnet.edu.au/plus/s/dDeDPBLEAt19Xrl/download -O FCOS_R_50_FPN_1x.pth
40+
python demo/fcos_demo.py
41+
42+
43+
## Inference
44+
The inference command line on coco minival split:
45+
46+
python tools/test_net.py \
47+
--config-file configs/fcos/fcos_R_50_FPN_1x.yaml \
48+
MODEL.WEIGHT models/FCOS_R_50_FPN_1x.pth \
49+
TEST.IMS_PER_BATCH 4
50+
51+
Please note that:
52+
1) If your model's name is different, please replace `models/FCOS_R_50_FPN_1x.pth` with your own.
53+
2) If you enounter out-of-memory error, please try to reduce `TEST.IMS_PER_BATCH` to 1.
54+
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.
55+
56+
For your convenience, we provide the following trained models (more models are coming soon).
57+
58+
Model | Total training mem (GB) | Multi-scale training | Testing time / im | AP (minival) | AP (test-dev) | Link
59+
--- |:---:|:---:|:---:|:---:|:--:|:---:
60+
FCOS_R_50_FPN_1x | 29.3 | No | 71ms | 37.1 | 37.4 | [download](https://cloudstor.aarnet.edu.au/plus/s/dDeDPBLEAt19Xrl/download)
61+
FCOS_R_101_FPN_2x | 44.1 | Yes | 74ms | 41.4 | 41.5 | [download](https://cloudstor.aarnet.edu.au/plus/s/vjL3L0AW7vnhRTo/download)
62+
FCOS_X_101_32x8d_FPN_2x | 72.9 | Yes | 122ms | 42.5 | 42.7 | [download](https://cloudstor.aarnet.edu.au/plus/s/U5myBfGF7MviZ97/download)
63+
FCOS_X_101_64x4d_FPN_2x | 77.7 | Yes | 140ms | 43.0 | 43.2 | [download](https://cloudstor.aarnet.edu.au/plus/s/wpwoCi4S8iajFi9/download)
64+
65+
[1] *1x and 2x mean the model is trained for 90K and 180K iterations, respectively.* \
66+
[2] *We report total training memory footprint on all GPUs instead of the memory footprint per GPU as in maskrcnn-benchmark*. \
67+
[3] *All results are obtained with a single model and without any test time data augmentation such as multi-scale, flipping and etc..* \
68+
[4] *Our results have been improved since our initial release. If you want to check out our original results, please checkout commit [f4fd589](https://github.com/tianzhi0549/FCOS/tree/f4fd58966f45e64608c00b072c801de7f86b4f3a)*.
69+
70+
## Training
71+
72+
The following command line will train FCOS_R_50_FPN_1x on 8 GPUs with Synchronous Stochastic Gradient Descent (SGD):
73+
74+
python -m torch.distributed.launch \
75+
--nproc_per_node=8 \
76+
--master_port=$((RANDOM + 10000)) \
77+
tools/train_net.py \
78+
--skip-test \
79+
--config-file configs/fcos/fcos_R_50_FPN_1x.yaml \
80+
DATALOADER.NUM_WORKERS 2 \
81+
OUTPUT_DIR training_dir/fcos_R_50_FPN_1x
82+
83+
Note that:
84+
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).
85+
2) The models will be saved into `OUTPUT_DIR`.
86+
3) If you want to train FCOS with other backbones, please change `--config-file`.
87+
4) The link of ImageNet pre-training X-101-64x4d in the code is invalid. Please download the model [here](https://cloudstor.aarnet.edu.au/plus/s/k3ys35075jmU1RP/download).
88+
5) If you want to train FCOS on your own dataset, please follow this instruction [#54](https://github.com/tianzhi0549/FCOS/issues/54#issuecomment-497558687).
89+
## Contributing to the project
90+
91+
Any pull requests or issues are welcome.
92+
93+
## Citations
94+
Please consider citing our paper in your publications if the project helps your research. BibTeX reference is as follows.
95+
```
96+
@article{tian2019fcos,
97+
title = {{FCOS}: Fully Convolutional One-Stage Object Detection},
98+
author = {Tian, Zhi and Shen, Chunhua and Chen, Hao and He, Tong},
99+
journal = {arXiv preprint arXiv:1904.01355},
100+
year = {2019}
101+
}
102+
```
103+
104+
105+
## License
106+
107+
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.

INSTALL.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
## Installation
2+
3+
### Requirements:
4+
- PyTorch == 1.1.0. Installation instructions can be found in https://pytorch.org/get-started/locally/.
5+
- torchvision==0.2.1
6+
- cocoapi
7+
- yacs
8+
- matplotlib
9+
- GCC >= 4.9
10+
- (optional) OpenCV for the webcam demo
11+
12+
### Option 1: Step-by-step installation
13+
14+
```bash
15+
# first, make sure that your conda is setup properly with the right environment
16+
# for that, check that `which conda`, `which pip` and `which python` points to the
17+
# right path. From a clean conda env, this is what you need to do
18+
19+
conda create --name FCOS
20+
conda activate FCOS
21+
22+
# this installs the right pip and dependencies for the fresh python
23+
conda install ipython
24+
25+
# FCOS and coco api dependencies
26+
pip install ninja yacs cython matplotlib tqdm
27+
28+
# follow PyTorch installation in https://pytorch.org/get-started/locally/
29+
# we give the instructions for CUDA 10.0
30+
conda install -c pytorch pytorch=1.1.0 torchvision=0.2.1 cudatoolkit=10.0
31+
32+
export INSTALL_DIR=$PWD
33+
34+
# install pycocotools. Please make sure you have installed cython.
35+
cd $INSTALL_DIR
36+
git clone https://github.com/cocodataset/cocoapi.git
37+
cd cocoapi/PythonAPI
38+
python setup.py build_ext install
39+
40+
# install PyTorch Detection
41+
cd $INSTALL_DIR
42+
git clone https://github.com/tianzhi0549/FCOS.git
43+
cd FCOS
44+
45+
# the following will install the lib with
46+
# symbolic links, so that you can modify
47+
# the files if you want and won't need to
48+
# re-build it
49+
python setup.py build develop
50+
51+
52+
unset INSTALL_DIR
53+
54+
# or if you are on macOS
55+
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py build develop
56+
```
57+
58+
### Option 2: Docker Image (Requires CUDA, Linux only)
59+
*The following steps are for original maskrcnn-benchmark. Please change the repository name if needed.*
60+
61+
Build image with defaults (`CUDA=10.0`, `CUDNN=7`, `FORCE_CUDA=1`):
62+
63+
nvidia-docker build -t maskrcnn-benchmark docker/
64+
65+
Build image with other CUDA and CUDNN versions:
66+
67+
nvidia-docker build -t maskrcnn-benchmark --build-arg CUDA=9.2 --build-arg CUDNN=7 docker/
68+
69+
Build image with FORCE_CUDA disabled:
70+
71+
nvidia-docker build -t maskrcnn-benchmark --build-arg FORCE_CUDA=0 docker/
72+
73+
Build and run image with built-in jupyter notebook(note that the password is used to log in jupyter notebook):
74+
75+
nvidia-docker build -t maskrcnn-benchmark-jupyter docker/docker-jupyter/
76+
nvidia-docker run -td -p 8888:8888 -e PASSWORD=<password> -v <host-dir>:<container-dir> maskrcnn-benchmark-jupyter

LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FCOS for non-commercial purposes
2+
3+
Copyright (c) 2019 the authors
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)