Skip to content

Commit 18f8ab5

Browse files
authored
add ResNeSt to Faster R-CNN (#1259)
* add ResNeSt to Faster R-CNN add custom voc dataset * fix style * fix style * trigger ci * add docs * docs update * add custom voc dataset * small fix
1 parent cb07ee2 commit 18f8ab5

File tree

8 files changed

+283
-33
lines changed

8 files changed

+283
-33
lines changed

docs/model_zoo/detection.rst

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,30 @@ Checkout SSD demo tutorial here: :ref:`sphx_glr_build_examples_detection_demo_ss
190190
Faster-RCNN
191191
-----------
192192

193-
Faster-RCNN models of VOC dataset are evaluated with native resolutions with ``shorter side >= 800`` but ``longer side <= 1300`` without changing aspect ratios.
193+
Faster-RCNN models of VOC dataset are evaluated with native resolutions with ``shorter side >= 800`` but ``longer side <= 1333`` without changing aspect ratios.
194194

195195
Checkout Faster-RCNN demo tutorial here: :ref:`sphx_glr_build_examples_detection_demo_faster_rcnn.py`
196196

197197
.. table::
198198
:widths: 50 5 25 20
199199

200-
+-------------------------------------------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
201-
| Model | Box AP | Training Command | Training Log |
202-
+===========================================+=================+=========================================================================================================================================+=======================================================================================================================================+
203-
| faster_rcnn_resnet50_v1b_coco [2]_ | 37.0/57.8/39.6 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet50_v1b_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet50_v1b_coco_train.log>`_ |
204-
+-------------------------------------------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
205-
| faster_rcnn_resnet101_v1d_coco [2]_ | 40.1/60.9/43.3 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet101_v1d_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet101_v1d_coco_train.log>`_ |
206-
+-------------------------------------------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
207-
| faster_rcnn_fpn_resnet50_v1b_coco [4]_ | 38.4/60.2/41.6 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet50_v1b_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet50_v1b_coco_train.log>`_ |
208-
+-------------------------------------------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
209-
| faster_rcnn_fpn_resnet101_v1d_coco [4]_ | 40.8/62.4/44.7 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet101_v1d_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet101_v1d_coco_train.log>`_ |
210-
+-------------------------------------------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
211-
| faster_rcnn_fpn_bn_resnet50_v1b_coco [5]_ | 39.3/61.3/42.9 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_bn_resnet50_v1b_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_bn_resnet50_v1b_coco_train.log>`_ |
212-
+-------------------------------------------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
200+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
201+
| Model | Box AP | Training Command | Training Log |
202+
+=============================================+=================+===========================================================================================================================================+=========================================================================================================================================+
203+
| faster_rcnn_resnet50_v1b_coco [2]_ | 37.0/57.8/39.6 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet50_v1b_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet50_v1b_coco_train.log>`_ |
204+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
205+
| faster_rcnn_resnet101_v1d_coco [2]_ | 40.1/60.9/43.3 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet101_v1d_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_resnet101_v1d_coco_train.log>`_ |
206+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
207+
| faster_rcnn_fpn_resnet50_v1b_coco [4]_ | 38.4/60.2/41.6 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet50_v1b_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet50_v1b_coco_train.log>`_ |
208+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
209+
| faster_rcnn_fpn_resnet101_v1d_coco [4]_ | 40.8/62.4/44.7 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet101_v1d_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_resnet101_v1d_coco_train.log>`_ |
210+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
211+
| faster_rcnn_fpn_bn_resnet50_v1b_coco [5]_ | 39.3/61.3/42.9 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_bn_resnet50_v1b_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_bn_resnet50_v1b_coco_train.log>`_ |
212+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
213+
| faster_rcnn_fpn_syncbn_resnest50_coco [7]_ | 42.7/64.1/46.4 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_syncbn_resnest50_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_syncbn_resnest50_coco_train.log>`_ |
214+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
215+
| faster_rcnn_fpn_syncbn_resnest101_coco [7]_ | 44.9/66.4/48.9 | `shell script <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_syncbn_resnest101_coco.sh>`_ | `log <https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/logs/detection/faster_rcnn_fpn_syncbn_resnest101_coco_train.log>`_ |
216+
+---------------------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
213217

214218
YOLO-v3
215219
-------
@@ -284,3 +288,6 @@ Note that ``dcnv2`` indicate that models include Modulated Deformable Convolutio
284288
.. [6] Zhou, Xingyi, Dequan Wang, and Philipp Krähenbühl. \
285289
"Objects as Points." \
286290
arXiv preprint arXiv:1904.07850 (2019).
291+
.. [7] Hang Zhang, Chongruo Wu, Zhongyue Zhang, Yi Zhu, Zhi Zhang, Haibin Lin, Yue Sun, Tong He, Jonas Muller, R. Manmatha, Mu Li and Alex Smola \
292+
"ResNeSt: Split-Attention Network" \
293+
arXiv preprint (2020).

gluoncv/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from . import batchify
66
from .imagenet.classification import ImageNet, ImageNet1kAttr
77
from .dataloader import DetectionDataLoader, RandomTransformDataLoader
8-
from .pascal_voc.detection import VOCDetection
8+
from .pascal_voc.detection import VOCDetection, CustomVOCDetection
99
from .mscoco.detection import COCODetection
1010
from .mscoco.detection import COCODetectionDALI
1111
from .mscoco.instance import COCOInstance

gluoncv/data/pascal_voc/detection.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""Pascal VOC object detection dataset."""
22
from __future__ import absolute_import
33
from __future__ import division
4-
import os
4+
5+
import glob
56
import logging
7+
import os
68
import warnings
9+
710
import numpy as np
11+
812
try:
913
import xml.etree.cElementTree as ET
1014
except ImportError:
@@ -87,8 +91,9 @@ def __getitem__(self, idx):
8791
def _load_items(self, splits):
8892
"""Load individual image indices from splits."""
8993
ids = []
90-
for year, name in splits:
91-
root = os.path.join(self._root, 'VOC' + str(year))
94+
for subfolder, name in splits:
95+
root = os.path.join(
96+
self._root, ('VOC' + str(subfolder)) if isinstance(subfolder, int) else subfolder)
9297
lf = os.path.join(root, 'ImageSets', 'Main', name + '.txt')
9398
with open(lf, 'r') as f:
9499
ids += [(root, line.strip()) for line in f.readlines()]
@@ -122,9 +127,9 @@ def _load_label(self, idx):
122127
ymax = (float(xml_box.find('ymax').text) - 1)
123128
try:
124129
self._validate_label(xmin, ymin, xmax, ymax, width, height)
130+
label.append([xmin, ymin, xmax, ymax, cls_id, difficult])
125131
except AssertionError as e:
126-
raise RuntimeError("Invalid label at {}, {}".format(anno_path, e))
127-
label.append([xmin, ymin, xmax, ymax, cls_id, difficult])
132+
logging.warning("Invalid label at %s, %s", anno_path, e)
128133
return np.array(label)
129134

130135
def _validate_label(self, xmin, ymin, xmax, ymax, width, height):
@@ -145,3 +150,30 @@ def _preload_labels(self):
145150
"""Preload all labels into memory."""
146151
logging.debug("Preloading %s labels into memory...", str(self))
147152
return [self._load_label(idx) for idx in range(len(self))]
153+
154+
155+
class CustomVOCDetection(VOCDetection):
156+
"""Custom Pascal VOC detection Dataset.
157+
Classes are generated from dataset
158+
generate_classes : bool, default False
159+
If True, generate class labels base on the annotations instead of the default classe labels.
160+
"""
161+
162+
def __init__(self, generate_classes=False, **kwargs):
163+
super(CustomVOCDetection, self).__init__(**kwargs)
164+
if generate_classes:
165+
self.CLASSES = self._generate_classes()
166+
167+
def _generate_classes(self):
168+
classes = set()
169+
all_xml = glob.glob(os.path.join(self._root, 'Annotations', '*.xml'))
170+
for each_xml_file in all_xml:
171+
tree = ET.parse(each_xml_file)
172+
root = tree.getroot()
173+
for child in root:
174+
if child.tag == 'object':
175+
for item in child:
176+
if item.tag == 'name':
177+
classes.add(item.text)
178+
classes = sorted(list(classes))
179+
return classes

gluoncv/model_zoo/model_store.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@
5959
('da9756faa5b9b4e34dedcf83ee0733d5895796ad', 'ssd_512_mobilenet1.0_coco'),
6060
('447328d89d70ae1e2ca49226b8d834e5a5456df3', 'faster_rcnn_resnet50_v1b_voc'),
6161
('5b4690fb7c5b62c44fb36c67d0642b633697f1bb', 'faster_rcnn_resnet50_v1b_coco'),
62+
('6df46961827647d418b11ffaf616a6a60d9dd16e', 'faster_rcnn_fpn_syncbn_resnest50_coco'),
6263
('a465eca35e78aba6ebdf99bf52031a447e501063', 'faster_rcnn_resnet101_v1d_coco'),
6364
('233572743bc537291590f4edf8a0c17c14b234bb', 'faster_rcnn_fpn_resnet50_v1b_coco'),
6465
('1194ab4ec6e06386aadd55820add312c8ef59c74', 'faster_rcnn_fpn_resnet101_v1d_coco'),
66+
('baebfa1b7d7f56dd33a7687efea4b014736bd791', 'faster_rcnn_fpn_syncbn_resnest101_coco'),
6567
('e071cf1550bc0331c218a9072b59e9550595d1e7', 'mask_rcnn_resnet18_v1b_coco'),
6668
('a3527fdc2cee5b1f32a61e5fd7cda8fb673e86e5', 'mask_rcnn_resnet50_v1b_coco'),
6769
('4a3249c584f81c2a9b5d852b742637cd692ebdcb', 'mask_rcnn_resnet101_v1d_coco'),

gluoncv/model_zoo/model_zoo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@
127127
'faster_rcnn_resnet50_v1b_coco': faster_rcnn_resnet50_v1b_coco,
128128
'faster_rcnn_fpn_resnet50_v1b_coco': faster_rcnn_fpn_resnet50_v1b_coco,
129129
'faster_rcnn_fpn_syncbn_resnet50_v1b_coco': faster_rcnn_fpn_syncbn_resnet50_v1b_coco,
130+
'faster_rcnn_fpn_syncbn_resnest50_coco': faster_rcnn_fpn_syncbn_resnest50_coco,
130131
'faster_rcnn_resnet50_v1b_custom': faster_rcnn_resnet50_v1b_custom,
131132
'faster_rcnn_resnet101_v1d_voc': faster_rcnn_resnet101_v1d_voc,
132133
'faster_rcnn_resnet101_v1d_coco': faster_rcnn_resnet101_v1d_coco,
133134
'faster_rcnn_fpn_resnet101_v1d_coco': faster_rcnn_fpn_resnet101_v1d_coco,
134135
'faster_rcnn_fpn_syncbn_resnet101_v1d_coco': faster_rcnn_fpn_syncbn_resnet101_v1d_coco,
136+
'faster_rcnn_fpn_syncbn_resnest101_coco': faster_rcnn_fpn_syncbn_resnest101_coco,
135137
'faster_rcnn_resnet101_v1d_custom': faster_rcnn_resnet101_v1d_custom,
138+
'faster_rcnn_fpn_syncbn_resnest269_coco': faster_rcnn_fpn_syncbn_resnest269_coco,
136139
'custom_faster_rcnn_fpn': custom_faster_rcnn_fpn,
137140
'mask_rcnn_resnet50_v1b_coco': mask_rcnn_resnet50_v1b_coco,
138141
'mask_rcnn_fpn_resnet50_v1b_coco': mask_rcnn_fpn_resnet50_v1b_coco,

gluoncv/model_zoo/rcnn/faster_rcnn/faster_rcnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def custom_faster_rcnn_fpn(classes, transfer=None, dataset='custom', pretrained_
585585
module_list.append('bn')
586586
net = get_model(
587587
'_'.join(['faster_rcnn'] + module_list + [base_network_name, str(transfer)]),
588-
pretrained=True)
588+
pretrained=True, per_device_batch_size=kwargs['per_device_batch_size'])
589589
reuse_classes = [x for x in classes if x in net.classes]
590590
net.reset_class(classes, reuse_weights=reuse_classes)
591591
return net

0 commit comments

Comments
 (0)