Commit 49ab85e8 authored by Yuxin Wu's avatar Yuxin Wu

[MaskRCNN] improve name scope

parent 2334ca17
...@@ -64,13 +64,13 @@ MaskRCNN results contain both bbox and segm mAP. ...@@ -64,13 +64,13 @@ MaskRCNN results contain both bbox and segm mAP.
| Backbone | mAP<br/>(box/mask) | Detectron mAP <br/> (box/mask) | Time | Configurations <br/> (click to expand) | | Backbone | mAP<br/>(box/mask) | Detectron mAP <br/> (box/mask) | Time | Configurations <br/> (click to expand) |
| - | - | - | - | - | | - | - | - | - | - |
| R50-C4 | 33.1 | | 18h on 8 V100s | <details><summary>super quick</summary>`MODE_MASK=False FRCNN.BATCH_PER_IM=64 PREPROC.SHORT_EDGE_SIZE=600 PREPROC.MAX_SIZE=1024 TRAIN.LR_SCHEDULE=[150000,230000,280000]` </details> | | R50-C4 | 33.1 | | 18h on 8 V100s | <details><summary>super quick</summary>`MODE_MASK=False FRCNN.BATCH_PER_IM=64`<br/>`PREPROC.SHORT_EDGE_SIZE=600 PREPROC.MAX_SIZE=1024`<br/>`TRAIN.LR_SCHEDULE=[150000,230000,280000]` </details> |
| R50-C4 | 36.6 | 36.5 | 49h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=False` </details> | | R50-C4 | 36.6 | 36.5 | 49h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=False` </details> |
| R50-FPN | 37.5 | 37.9<sup>[1](#ft1)</sup> | 28h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=False MODE_FPN=True` </details> | | R50-FPN | 37.5 | 37.9<sup>[1](#ft1)</sup> | 28h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=False MODE_FPN=True` </details> |
| R50-C4 | 36.8/32.1 | | 39h on 8 P100s | <details><summary>quick</summary>`MODE_MASK=True FRCNN.BATCH_PER_IM=256 TRAIN.LR_SCHEDULE=[150000,230000,280000]` </details> | | R50-C4 | 36.8/32.1 | | 39h on 8 P100s | <details><summary>quick</summary>`MODE_MASK=True FRCNN.BATCH_PER_IM=256`<br/>`TRAIN.LR_SCHEDULE=[150000,230000,280000]` </details> |
| R50-C4 | 37.8/33.1 | 37.8/32.8 | 51h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True` </details> | | R50-C4 | 37.8/33.1 | 37.8/32.8 | 51h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True` </details> |
| R50-FPN | 38.1/34.9 | 38.6/34.5<sup>[1](#ft1)</sup> | 38h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True MODE_FPN=True` </details> | | R50-FPN | 38.1/34.9 | 38.6/34.5<sup>[1](#ft1)</sup> | 38h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True MODE_FPN=True` </details> |
| R101-C4 | 40.8/35.1 | | 63h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True BACKBONE.RESNET_NUM_BLOCK=[3,4,23,3]` </details> | | R101-C4 | 40.8/35.1 | | 63h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True `<br/>`BACKBONE.RESNET_NUM_BLOCK=[3,4,23,3]` </details> |
<a id="ft1">1</a>: Slightly different configurations. <a id="ft1">1</a>: Slightly different configurations.
......
...@@ -60,7 +60,7 @@ _C.DATA.NUM_CATEGORY = 80 # 80 categories ...@@ -60,7 +60,7 @@ _C.DATA.NUM_CATEGORY = 80 # 80 categories
_C.DATA.CLASS_NAMES = [] # NUM_CLASS strings. Needs to be populated later by data loader _C.DATA.CLASS_NAMES = [] # NUM_CLASS strings. Needs to be populated later by data loader
# basemodel ---------------------- # basemodel ----------------------
_C.BACKBONE.WEIGHTS = '/path/to/ImageNet-ResNet50.npz' _C.BACKBONE.WEIGHTS = '' # /path/to/weights.npz
_C.BACKBONE.RESNET_NUM_BLOCK = [3, 4, 6, 3] # for resnet50 _C.BACKBONE.RESNET_NUM_BLOCK = [3, 4, 6, 3] # for resnet50
# RESNET_NUM_BLOCK = [3, 4, 23, 3] # for resnet101 # RESNET_NUM_BLOCK = [3, 4, 23, 3] # for resnet101
_C.BACKBONE.FREEZE_AFFINE = False # do not train affine parameters inside BN _C.BACKBONE.FREEZE_AFFINE = False # do not train affine parameters inside BN
......
...@@ -141,11 +141,11 @@ def multilevel_rpn_losses( ...@@ -141,11 +141,11 @@ def multilevel_rpn_losses(
losses = [] losses = []
with tf.name_scope('rpn_losses'): with tf.name_scope('rpn_losses'):
for lvl in range(num_lvl): for lvl in range(num_lvl):
with tf.name_scope('Level{}'.format(lvl + 2)):
anchors = multilevel_anchors[lvl] anchors = multilevel_anchors[lvl]
label_loss, box_loss = rpn_losses( label_loss, box_loss = rpn_losses(
anchors.gt_labels, anchors.encoded_gt_boxes(), anchors.gt_labels, anchors.encoded_gt_boxes(),
multilevel_label_logits[lvl], multilevel_box_logits[lvl]) multilevel_label_logits[lvl], multilevel_box_logits[lvl],
name_scope='Level{}'.format(lvl + 2))
losses.extend([label_loss, box_loss]) losses.extend([label_loss, box_loss])
total_label_loss = tf.add_n(losses[::2], name='label_loss') total_label_loss = tf.add_n(losses[::2], name='label_loss')
......
...@@ -37,6 +37,7 @@ def rpn_head(featuremap, channel, num_anchors): ...@@ -37,6 +37,7 @@ def rpn_head(featuremap, channel, num_anchors):
return label_logits, box_logits return label_logits, box_logits
@under_name_scope()
def rpn_losses(anchor_labels, anchor_boxes, label_logits, box_logits): def rpn_losses(anchor_labels, anchor_boxes, label_logits, box_logits):
""" """
Args: Args:
......
...@@ -200,7 +200,6 @@ class ResNetC4Model(DetectionModel): ...@@ -200,7 +200,6 @@ class ResNetC4Model(DetectionModel):
if is_training: if is_training:
# rpn loss # rpn loss
with tf.name_scope('rpn_losses'):
rpn_label_loss, rpn_box_loss = rpn_losses( rpn_label_loss, rpn_box_loss = rpn_losses(
anchors.gt_labels, anchors.encoded_gt_boxes(), rpn_label_logits, rpn_box_logits) anchors.gt_labels, anchors.encoded_gt_boxes(), rpn_label_logits, rpn_box_logits)
......
...@@ -54,11 +54,17 @@ def auto_reuse_variable_scope(func): ...@@ -54,11 +54,17 @@ def auto_reuse_variable_scope(func):
return wrapper return wrapper
def under_name_scope(name=None): def under_name_scope(name_scope=None):
""" """
Args:
name_scope(str): the default scope to use. If None, will use the name of the function.
Returns: Returns:
A decorator which makes the function happen under a name scope. A decorator which makes the function run under a name scope.
The default name is the function itself. The name scope is obtained by the following:
1. The 'name_scope' keyword argument when the decorated function is called.
2. The 'name_scope' argument of the decorator.
3. (default) The name of the decorated function itself.
Example: Example:
...@@ -66,9 +72,13 @@ def under_name_scope(name=None): ...@@ -66,9 +72,13 @@ def under_name_scope(name=None):
@under_name_scope() @under_name_scope()
def rms(x): def rms(x):
return tf.sqrt( # will be under name scope 'rms' return tf.sqrt(
tf.reduce_mean(tf.square(x))) tf.reduce_mean(tf.square(x)))
rms(tensor) # will be called under name scope 'rms'
rms(tensor, name_scope='scope') # will be called under name scope 'scope'
Todo: Todo:
Add a reuse option. Add a reuse option.
""" """
...@@ -76,10 +86,10 @@ def under_name_scope(name=None): ...@@ -76,10 +86,10 @@ def under_name_scope(name=None):
def _impl(func): def _impl(func):
@functools.wraps(func) @functools.wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
if name is None: scopename = kwargs.pop('name_scope', name_scope)
if scopename is None:
scopename = func.__name__ scopename = func.__name__
else:
scopename = name
with tf.name_scope(scopename): with tf.name_scope(scopename):
return func(*args, **kwargs) return func(*args, **kwargs)
return wrapper return wrapper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment