Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Support for PyTorch 1.0, TorchVision 0.3.0, PASCAL VOC Dataset and Custom Dataset #194

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c93c3b7
add/fix voc dataset options
adityaarun1 May 23, 2018
b16090f
add xml2json converter file
adityaarun1 May 24, 2018
f366622
add voc_xml2json++ file
adityaarun1 May 24, 2018
e5cbd75
create directory if doesn't exist
adityaarun1 May 24, 2018
ef379ec
bug_fix
adityaarun1 May 24, 2018
bc59a63
minor fix and tested
adityaarun1 May 24, 2018
c7e7b4a
minor modifications
adityaarun1 May 24, 2018
96411f0
add documentation
adityaarun1 May 24, 2018
f9835d5
Merge branch 'master' of https://github.com/adityaarun1/Detectron.pyt…
adityaarun1 May 24, 2018
9c9a510
add support for voc12 and custom dataset
adityaarun1 May 24, 2018
f0be15f
update README.md
adityaarun1 May 24, 2018
a3e1908
minor fix
adityaarun1 May 24, 2018
35ce2ea
fix json conversion file
adityaarun1 May 24, 2018
0692636
minor fix
adityaarun1 May 24, 2018
d792f62
check segmentation converter
adityaarun1 May 24, 2018
6f75f31
updated converter file
adityaarun1 May 24, 2018
c62962f
formatting
adityaarun1 May 24, 2018
b439268
Update README.md
adityaarun1 May 24, 2018
7ece75b
fix voc testing code
adityaarun1 May 27, 2018
ab76a7d
minor fix
adityaarun1 May 27, 2018
58e0f18
minor fix
adityaarun1 May 27, 2018
01af0af
Update README.md
adityaarun1 May 27, 2018
e1d32cf
Merge branch 'master' of https://github.com/roytseng-tw/Detectron.pyt…
adityaarun1 May 27, 2018
4f74541
add/fix voc dataset options
adityaarun1 May 23, 2018
8e028b6
add xml2json converter file
adityaarun1 May 24, 2018
5902b41
add voc_xml2json++ file
adityaarun1 May 24, 2018
2d135cb
create directory if doesn't exist
adityaarun1 May 24, 2018
fb94d36
bug_fix
adityaarun1 May 24, 2018
8f904cb
minor fix and tested
adityaarun1 May 24, 2018
04fcdee
minor modifications
adityaarun1 May 24, 2018
d7a042f
add documentation
adityaarun1 May 24, 2018
7b9d9c7
add support for voc12 and custom dataset
adityaarun1 May 24, 2018
48b0fe7
update README.md
adityaarun1 May 24, 2018
14cd533
minor fix
adityaarun1 May 24, 2018
86f54d4
fix json conversion file
adityaarun1 May 24, 2018
8822517
minor fix
adityaarun1 May 24, 2018
80322f2
check segmentation converter
adityaarun1 May 24, 2018
b140a02
updated converter file
adityaarun1 May 24, 2018
a0ad2d2
formatting
adityaarun1 May 24, 2018
8c9e946
Update README.md
adityaarun1 May 24, 2018
fc9823c
fix voc testing code
adityaarun1 May 27, 2018
95dc2a5
minor fix
adityaarun1 May 27, 2018
06e2c31
minor fix
adityaarun1 May 27, 2018
62868a8
Update README.md
adityaarun1 May 27, 2018
f0842e1
Merge branch 'master' of https://github.com/adityaarun1/Detectron.pyt…
adityaarun1 Aug 28, 2018
eab1bb5
Fixed bug for 1 indexed VOC format
adityaarun1 Nov 14, 2018
47a0597
first attempt at migrating to Pytorch-1.0
adityaarun1 Jan 16, 2019
9c204ad
update compilation script
adityaarun1 Jan 16, 2019
3166c97
fix deprecation warnings
adityaarun1 Jan 17, 2019
75793bf
fix mynn.dataparallel issue
adityaarun1 Jan 17, 2019
6bf7060
update README
adityaarun1 Jan 17, 2019
6a37ce5
minor bugfix
adityaarun1 Jan 17, 2019
842183b
modifide code base for torchvision 0.3
adityaarun1 May 30, 2019
9f2dc7c
Update README.md
adityaarun1 May 30, 2019
c780eb3
Fix bug
adityaarun1 Sep 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ data/*
notebooks/*.pkl

/Outputs
lib/build
lib/detectron_pytorch.egg-info

# ------------------------------

Expand Down
63 changes: 50 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

</div>

**This code follows the implementation architecture of Detectron.** Only part of the functionality is supported. Check [this section](#supported-network-modules) for more information.
**This code follows the implementation architecture of Detectron.** Only part of the functionality is supported. Check [this section](#supported-network-modules) for more information. This code now supports **PyTorch 1.0** and **TorchVision 0.3**.

With this code, you can...

Expand All @@ -35,7 +35,7 @@ This implementation has the following features:

- **It supports multiple GPUs training**.

- **It supports three pooling methods**. Notice that only **roi align** is revised to match the implementation in Caffe2. So, use it.
- **It supports two pooling methods**. Notice that only **roi align** is revised to match the implementation in Caffe2. So, use it.

- **It is memory efficient**. For data batching, there are two techiniques available to reduce memory usage: 1) *Aspect grouping*: group images with similar aspect ratio in a batch 2) *Aspect cropping*: crop images that are too long. Aspect grouping is implemented in Detectron, so it's used for default. Aspect cropping is the idea from [jwyang/faster-rcnn.pytorch](https://github.com/jwyang/faster-rcnn.pytorch), and it's not used for default.

Expand All @@ -46,6 +46,9 @@ This implementation has the following features:
- (2018/05/25) Support ResNeXt backbones.
- (2018/05/22) Add group normalization baselines.
- (2018/05/15) PyTorch0.4 is supported now !
- (2019/08/28) Support PASCAL VOC and Custom Dataset
- (2019/01/17) **PyTorch 1.0 Supported now!**
- (2019/05/30) Code rebased on **TorchVision 0.3**. Compilation is now optional!

## Getting Started
Clone the repo:
Expand All @@ -59,9 +62,9 @@ git clone https://github.com/roytseng-tw/mask-rcnn.pytorch.git
Tested under python3.

- python packages
- pytorch>=0.3.1
- torchvision>=0.2.0
- cython
- pytorch>=1.0.0
- torchvision>=0.3.0
- cython>=0.29.2
- matplotlib
- numpy
- scipy
Expand All @@ -70,10 +73,10 @@ Tested under python3.
- packaging
- [pycocotools](https://github.com/cocodataset/cocoapi) — for COCO dataset, also available from pip.
- tensorboardX — for logging the losses in Tensorboard
- An NVIDAI GPU and CUDA 8.0 or higher. Some operations only have gpu implementation.
- An NVIDIA GPU and CUDA 8.0 or higher. Some operations only have gpu implementation.
- **NOTICE**: different versions of Pytorch package have different memory usages.

### Compilation
### Compilation [Optional]

Compile the CUDA code:

Expand All @@ -82,9 +85,7 @@ cd lib # please change to this directory
sh make.sh
```

If your are using Volta GPUs, uncomment this [line](https://github.com/roytseng-tw/mask-rcnn.pytorch/tree/master/lib/make.sh#L15) in `lib/mask.sh` and remember to postpend a backslash at the line above. `CUDA_PATH` defaults to `/usr/loca/cuda`. If you want to use a CUDA library on different path, change this [line](https://github.com/roytseng-tw/mask-rcnn.pytorch/tree/master/lib/make.sh#L3) accordingly.

It will compile all the modules you need, including NMS, ROI_Pooing, ROI_Crop and ROI_Align. (Actually gpu nms is never used ...)
It will compile all the modules you need, including NMS. (Actually gpu nms is never used ...)

Note that, If you use `CUDA_VISIBLE_DEVICES` to set gpus, **make sure at least one gpu is visible when compile the code.**

Expand Down Expand Up @@ -116,7 +117,7 @@ mkdir data
├── train2014
├── train2017
├── val2014
├──val2017
├── val2017
├── ...
```
Download coco mini annotations from [here](https://s3-us-west-2.amazonaws.com/detectron/coco/coco_annotations_minival.tgz).
Expand All @@ -127,8 +128,40 @@ mkdir data
```
ln -s path/to/coco data/coco
```

- **PASCAL VOC 2007 + 12**
Please follow the instructions in [py-faster-rcnn](https://github.com/rbgirshick/py-faster-rcnn#beyond-the-demo-installation-for-training-and-testing-models) to prepare VOC datasets. Actually, you can refer to any others. After downloading the data, creat softlinks in the `data/VOC<year>` folder as folows,
```
VOCdevkitPATH=/path/to/voc_devkit
mkdir -p $DETECTRON/detectron/datasets/data/VOC<year>
ln -s /${VOCdevkitPATH}/VOC<year>/JPEGImages $DETECTRON.PYTORCH/data/VOC<year>/JPEGImages
ln -s /${VOCdevkitPATH}/VOC<year>/json_annotations $DETECTRON.PYTORCH/data/VOC<year>/annotations
ln -s /${VOCdevkitPATH} $DETECTRON.PYTORCH/data/VOC<year>/VOCdevkit<year>
```
The directory structure of `JPEGImages` and `annotations` should be as follows,
```
VOC<year>
├── annotations
| ├── train.json
│   ├── trainval.json
│   ├── test.json
│   ├── ...
|
└── JPEGImages
├── <im-1-name>.jpg
├── ...
├── <im-N-name>.jpg
```
**NOTE:** The `annotations` folder requires you to have PASCAL VOC annotations in COCO json format, which is available for download [here](https://storage.googleapis.com/coco-dataset/external/PASCAL_VOC.zip). You can also convert the XML annotatinos files to JSON by running the following script,
```
python tools/pascal_voc_xml2coco_json_converter.py $VOCdevkitPATH $year
```
(In order to succesfully run the script above, you need to update the full path to the respective folders in the script).

- **Custom Dataset**
Similar to above, create a directory named `CustomDataset` in the `data` folder and add symlinks to the `annotations` directory and `JPEGImages` as shown for Pascal Voc dataset. You also need to link the custom dataset devkit to `CustomDataDevkit`.

Recommend to put the images on a SSD for possible better training performance
Recommend to put the images on a SSD for possible better training performance

### Pretrained Model

Expand Down Expand Up @@ -200,7 +233,11 @@ Use `--bs` to overwrite the default batch size to a proper value that fits into

Specify `—-use_tfboard` to log the losses on Tensorboard.

**NOTE**: use `--dataset keypoints_coco2017` when training for keypoint-rcnn.
**NOTE**:
- use `--dataset keypoints_coco2017` when training for keypoint-rcnn.
- use `--dataset voc2007` when training for PASCAL VOC 2007.
- use `--dataset voc2012` when training for PASCAL VOC 2012.
- use `--dataset custom_dataset --num_classes $NUM_CLASSES` when training for your custom dataset. Here, `$NUM_CLASSES` is the number of object classes **+ 1** (for background class) present in your custom dataset.

### The use of `--iter_size`
As in Caffe, update network once (`optimizer.step()`) every `iter_size` iterations (forward + backward). This way to have a larger effective batch size for training. Notice that, step count is only increased after network update.
Expand Down
42 changes: 41 additions & 1 deletion lib/datasets/dataset_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@
ANN_FN:
_DATA_DIR + '/coco/annotations/image_info_test2017.json'
},
'voc_2007_train': {
IM_DIR:
_DATA_DIR + '/VOC2007/JPEGImages',
ANN_FN:
_DATA_DIR + '/VOC2007/annotations/voc_2007_train.json',
DEVKIT_DIR:
_DATA_DIR + '/VOC2007/VOCdevkit2007'
},
'voc_2007_trainval': {
IM_DIR:
_DATA_DIR + '/VOC2007/JPEGImages',
Expand All @@ -209,12 +217,44 @@
DEVKIT_DIR:
_DATA_DIR + '/VOC2007/VOCdevkit2007'
},
'voc_2012_train': {
IM_DIR:
_DATA_DIR + '/VOC2012/JPEGImages',
ANN_FN:
_DATA_DIR + '/VOC2012/annotations/train.json',
DEVKIT_DIR:
_DATA_DIR + '/VOC2012/VOCdevkit2012'
},
'voc_2012_trainval': {
IM_DIR:
_DATA_DIR + '/VOC2012/JPEGImages',
ANN_FN:
_DATA_DIR + '/VOC2012/annotations/voc_2012_trainval.json',
_DATA_DIR + '/VOC2012/annotations/trainval.json',
DEVKIT_DIR:
_DATA_DIR + '/VOC2012/VOCdevkit2012'
},
'custom_data_train': {
IM_DIR:
_DATA_DIR + '/CustomData/JPEGImages',
ANN_FN:
_DATA_DIR + '/CustomData/annotations/train.json',
DEVKIT_DIR:
_DATA_DIR + '/CustomData/CustomDataDevkit'
},
'custom_data_trainval': {
IM_DIR:
_DATA_DIR + '/CustomData/JPEGImages',
ANN_FN:
_DATA_DIR + '/CustomData/annotations/trainval.json',
DEVKIT_DIR:
_DATA_DIR + '/CustomData/CustomDataDevkit'
},
'custom_data_test': {
IM_DIR:
_DATA_DIR + '/CustomData/JPEGImages',
ANN_FN:
_DATA_DIR + '/CustomData/annotations/test.json',
DEVKIT_DIR:
_DATA_DIR + '/CustomData/CustomDataDevkit'
}
}
4 changes: 2 additions & 2 deletions lib/datasets/voc_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ def voc_eval(detpath,
i + 1, len(imagenames)))
# save
logger.info('Saving cached annotations to {:s}'.format(cachefile))
with open(cachefile, 'w') as f:
with open(cachefile, 'wb') as f:
cPickle.dump(recs, f)
else:
# load
with open(cachefile, 'r') as f:
with open(cachefile, 'rb') as f:
recs = cPickle.load(f)

# extract gt objects for this class
Expand Down
54 changes: 0 additions & 54 deletions lib/make.sh
Original file line number Diff line number Diff line change
@@ -1,60 +1,6 @@
#!/usr/bin/env bash

CUDA_PATH=/usr/local/cuda/

python setup.py build_ext --inplace
rm -rf build

# Choose cuda arch as you need
CUDA_ARCH="-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 "
# -gencode arch=compute_70,code=sm_70 "

# compile NMS
cd model/nms/src
echo "Compiling nms kernels by nvcc..."
nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH

cd ../
python build.py

# compile roi_pooling
cd ../../
cd model/roi_pooling/src
echo "Compiling roi pooling kernels by nvcc..."
nvcc -c -o roi_pooling.cu.o roi_pooling_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python build.py

# # compile roi_align
# cd ../../
# cd model/roi_align/src
# echo "Compiling roi align kernels by nvcc..."
# nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
# cd ../
# python build.py

# compile roi_crop
cd ../../
cd model/roi_crop/src
echo "Compiling roi crop kernels by nvcc..."
nvcc -c -o roi_crop_cuda_kernel.cu.o roi_crop_cuda_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python build.py

# compile roi_align (based on Caffe2's implementation)
cd ../../
cd modeling/roi_xfrom/roi_align/src
echo "Compiling roi align kernels by nvcc..."
nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python build.py
Empty file removed lib/model/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions lib/model/nms/.gitignore

This file was deleted.

Empty file removed lib/model/nms/__init__.py
Empty file.
Empty file removed lib/model/nms/_ext/__init__.py
Empty file.
15 changes: 0 additions & 15 deletions lib/model/nms/_ext/nms/__init__.py

This file was deleted.

37 changes: 0 additions & 37 deletions lib/model/nms/build.py

This file was deleted.

10 changes: 0 additions & 10 deletions lib/model/nms/make.sh

This file was deleted.

12 changes: 0 additions & 12 deletions lib/model/nms/nms_gpu.py

This file was deleted.

Loading