Commit d2c5cc16 authored by Yuxin Wu's avatar Yuxin Wu

Use a better timer when available.

parent 7877a7f7
...@@ -62,7 +62,7 @@ demonstrating its flexibility for actual research. ...@@ -62,7 +62,7 @@ demonstrating its flexibility for actual research.
Dependencies: Dependencies:
+ Python 2.7 or 3 + Python 2.7 or 3.3+
+ Python bindings for OpenCV (Optional, but required by a lot of features) + Python bindings for OpenCV (Optional, but required by a lot of features)
+ TensorFlow >= 1.3.0 (Optional if you only want to use `tensorpack.dataflow` alone as a data processing library) + TensorFlow >= 1.3.0 (Optional if you only want to use `tensorpack.dataflow` alone as a data processing library)
``` ```
......
...@@ -73,14 +73,15 @@ MaskRCNN results contain both box and mask mAP. ...@@ -73,14 +73,15 @@ MaskRCNN results contain both box and mask mAP.
| R50-C4 | 37.8/33.1 | 37.8/32.8 | 49h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True` </details> | | R50-C4 | 37.8/33.1 | 37.8/32.8 | 49h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True` </details> |
| R50-FPN | 38.2/34.9 | 38.6/34.5<sup>[1](#ft1)</sup> | 32h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True MODE_FPN=True` </details> | | R50-FPN | 38.2/34.9 | 38.6/34.5<sup>[1](#ft1)</sup> | 32h on 8 V100s | <details><summary>standard</summary>`MODE_MASK=True MODE_FPN=True` </details> |
| R50-FPN | 38.5/34.8 | 38.6/34.2<sup>[2](#ft2)</sup> | 34h on 8 V100s | <details><summary>standard+ConvHead</summary>`MODE_MASK=True MODE_FPN=True`<br/>`FPN.FRCNN_HEAD_FUNC=fastrcnn_4conv1fc_head` </details> | | R50-FPN | 38.5/34.8 | 38.6/34.2<sup>[2](#ft2)</sup> | 34h on 8 V100s | <details><summary>standard+ConvHead</summary>`MODE_MASK=True MODE_FPN=True`<br/>`FPN.FRCNN_HEAD_FUNC=fastrcnn_4conv1fc_head` </details> |
| R50-FPN | 39.5/35.2 | 39.5/34.4<sup>[2](#ft2)</sup> | 34h on 8 V100s | <details><summary>standard+ConvGNHead</summary>`MODE_MASK=True MODE_FPN=True`<br/>`FPN.FRCNN_HEAD_FUNC=fastrcnn_4conv1fc_gn_head` </details> | | R50-FPN | 39.5/35.2 | 39.5/34.4<sup>[2](#ft2)</sup> | 34h on 8 V100s | <details><summary>standard+ConvGNHead</summary>`MODE_MASK=True MODE_FPN=True`<br/>`FPN.FRCNN_HEAD_FUNC=fastrcnn_4conv1fc_gn_head` </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> | | 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.
<a id="ft2">2</a>: Numbers taken from [Group Normalization](https://arxiv.org/abs/1803.08494) <a id="ft2">2</a>: Numbers taken from [Group Normalization](https://arxiv.org/abs/1803.08494)
Performance in [Detectron](https://github.com/facebookresearch/Detectron/) can be reproduced. Performance in [Detectron](https://github.com/facebookresearch/Detectron/) can
be roughly reproduced, some are better but some are worse, probably due to many tiny implementation details.
Note that most of these numbers are better than what's in the paper. Note that most of these numbers are better than what's in the paper.
## Notes ## Notes
......
...@@ -218,5 +218,5 @@ def generate_fpn_proposals( ...@@ -218,5 +218,5 @@ def generate_fpn_proposals(
cfg.RPN.TRAIN_POST_NMS_TOPK if ctx.is_training else cfg.RPN.TEST_POST_NMS_TOPK) cfg.RPN.TRAIN_POST_NMS_TOPK if ctx.is_training else cfg.RPN.TEST_POST_NMS_TOPK)
tf.sigmoid(proposal_scores, name='probs') # for visualization tf.sigmoid(proposal_scores, name='probs') # for visualization
return tf.identity(proposal_boxes, name='boxes'), \ return tf.stop_gradient(proposal_boxes, name='boxes'), \
tf.identity(proposal_scores, name='scores') tf.stop_gradient(proposal_scores, name='scores')
...@@ -4,14 +4,18 @@ ...@@ -4,14 +4,18 @@
import tensorflow as tf import tensorflow as tf
from contextlib import contextmanager from contextlib import contextmanager
import time from time import time as timer
import traceback import traceback
import six
from .base import Callback from .base import Callback
from .hooks import CallbackToHook from .hooks import CallbackToHook
from ..utils import logger from ..utils import logger
from ..utils.utils import humanize_time_delta from ..utils.utils import humanize_time_delta
if six.PY3:
from time import perf_counter as timer # noqa
__all__ = ['Callbacks'] __all__ = ['Callbacks']
...@@ -26,9 +30,9 @@ class CallbackTimeLogger(object): ...@@ -26,9 +30,9 @@ class CallbackTimeLogger(object):
@contextmanager @contextmanager
def timed_callback(self, name): def timed_callback(self, name):
s = time.time() s = timer()
yield yield
self.add(name, time.time() - s) self.add(name, timer() - s)
def log(self): def log(self):
......
...@@ -52,7 +52,7 @@ def launch_train_with_config(config, trainer): ...@@ -52,7 +52,7 @@ def launch_train_with_config(config, trainer):
present a simple training interface. It basically does the following present a simple training interface. It basically does the following
3 things (and you can easily do them by yourself if you need more control): 3 things (and you can easily do them by yourself if you need more control):
1. Setup the input with automatic prefetching, 1. Setup the input with automatic prefetching heuristics,
from `config.data` or `config.dataflow`. from `config.data` or `config.dataflow`.
2. Call `trainer.setup_graph` with the input as well as `config.model`. 2. Call `trainer.setup_graph` with the input as well as `config.model`.
3. Call `trainer.train` with rest of the attributes of config. 3. Call `trainer.train` with rest of the attributes of config.
......
...@@ -3,14 +3,18 @@ ...@@ -3,14 +3,18 @@
from contextlib import contextmanager from contextlib import contextmanager
import time
from collections import defaultdict from collections import defaultdict
import six import six
import atexit import atexit
from time import time as timer
from .stats import StatCounter from .stats import StatCounter
from . import logger from . import logger
if six.PY3:
from time import perf_counter as timer # noqa
__all__ = ['total_timer', 'timed_operation', __all__ = ['total_timer', 'timed_operation',
'print_total_timer', 'IterSpeedCounter'] 'print_total_timer', 'IterSpeedCounter']
...@@ -38,10 +42,10 @@ def timed_operation(msg, log_start=False): ...@@ -38,10 +42,10 @@ def timed_operation(msg, log_start=False):
""" """
if log_start: if log_start:
logger.info('Start {} ...'.format(msg)) logger.info('Start {} ...'.format(msg))
start = time.time() start = timer()
yield yield
logger.info('{} finished, time:{:.4f}sec.'.format( logger.info('{} finished, time:{:.4f}sec.'.format(
msg, time.time() - start)) msg, timer() - start))
_TOTAL_TIMER_DATA = defaultdict(StatCounter) _TOTAL_TIMER_DATA = defaultdict(StatCounter)
...@@ -50,9 +54,9 @@ _TOTAL_TIMER_DATA = defaultdict(StatCounter) ...@@ -50,9 +54,9 @@ _TOTAL_TIMER_DATA = defaultdict(StatCounter)
@contextmanager @contextmanager
def total_timer(msg): def total_timer(msg):
""" A context which add the time spent inside to TotalTimer. """ """ A context which add the time spent inside to TotalTimer. """
start = time.time() start = timer()
yield yield
t = time.time() - start t = timer() - start
_TOTAL_TIMER_DATA[msg].feed(t) _TOTAL_TIMER_DATA[msg].feed(t)
...@@ -96,7 +100,7 @@ class IterSpeedCounter(object): ...@@ -96,7 +100,7 @@ class IterSpeedCounter(object):
self.name = name if name else 'IterSpeed' self.name = name if name else 'IterSpeed'
def reset(self): def reset(self):
self.start = time.time() self.start = timer()
def __call__(self): def __call__(self):
if self.cnt == 0: if self.cnt == 0:
...@@ -104,6 +108,6 @@ class IterSpeedCounter(object): ...@@ -104,6 +108,6 @@ class IterSpeedCounter(object):
self.cnt += 1 self.cnt += 1
if self.cnt % self.print_every != 0: if self.cnt % self.print_every != 0:
return return
t = time.time() - self.start t = timer() - self.start
logger.info("{}: {:.2f} sec, {} times, {:.3g} sec/time".format( logger.info("{}: {:.2f} sec, {} times, {:.3g} sec/time".format(
self.name, t, self.cnt, t / self.cnt)) self.name, t, self.cnt, t / self.cnt))
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