Skip to content

Commit

Permalink
Use a better timer when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed Jul 14, 2018
1 parent 7877a7f commit d2c5cc1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ demonstrating its flexibility for actual research.

Dependencies:

+ Python 2.7 or 3
+ Python 2.7 or 3.3+
+ 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)
```
Expand Down
5 changes: 3 additions & 2 deletions examples/FasterRCNN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-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 | 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> |

<a id="ft1">1</a>: Slightly different configurations.

<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.

## Notes
Expand Down
4 changes: 2 additions & 2 deletions examples/FasterRCNN/model_fpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

tf.sigmoid(proposal_scores, name='probs') # for visualization
return tf.identity(proposal_boxes, name='boxes'), \
tf.identity(proposal_scores, name='scores')
return tf.stop_gradient(proposal_boxes, name='boxes'), \
tf.stop_gradient(proposal_scores, name='scores')
10 changes: 7 additions & 3 deletions tensorpack/callbacks/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

import tensorflow as tf
from contextlib import contextmanager
import time
from time import time as timer
import traceback
import six

from .base import Callback
from .hooks import CallbackToHook
from ..utils import logger
from ..utils.utils import humanize_time_delta

if six.PY3:
from time import perf_counter as timer # noqa

__all__ = ['Callbacks']


Expand All @@ -26,9 +30,9 @@ def add(self, name, time):

@contextmanager
def timed_callback(self, name):
s = time.time()
s = timer()
yield
self.add(name, time.time() - s)
self.add(name, timer() - s)

def log(self):

Expand Down
2 changes: 1 addition & 1 deletion tensorpack/train/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def launch_train_with_config(config, trainer):
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):
1. Setup the input with automatic prefetching,
1. Setup the input with automatic prefetching heuristics,
from `config.data` or `config.dataflow`.
2. Call `trainer.setup_graph` with the input as well as `config.model`.
3. Call `trainer.train` with rest of the attributes of config.
Expand Down
18 changes: 11 additions & 7 deletions tensorpack/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@


from contextlib import contextmanager
import time
from collections import defaultdict
import six
import atexit
from time import time as timer

from .stats import StatCounter
from . import logger

if six.PY3:
from time import perf_counter as timer # noqa


__all__ = ['total_timer', 'timed_operation',
'print_total_timer', 'IterSpeedCounter']

Expand Down Expand Up @@ -38,10 +42,10 @@ def timed_operation(msg, log_start=False):
"""
if log_start:
logger.info('Start {} ...'.format(msg))
start = time.time()
start = timer()
yield
logger.info('{} finished, time:{:.4f}sec.'.format(
msg, time.time() - start))
msg, timer() - start))


_TOTAL_TIMER_DATA = defaultdict(StatCounter)
Expand All @@ -50,9 +54,9 @@ def timed_operation(msg, log_start=False):
@contextmanager
def total_timer(msg):
""" A context which add the time spent inside to TotalTimer. """
start = time.time()
start = timer()
yield
t = time.time() - start
t = timer() - start
_TOTAL_TIMER_DATA[msg].feed(t)


Expand Down Expand Up @@ -96,14 +100,14 @@ def __init__(self, print_every, name=None):
self.name = name if name else 'IterSpeed'

def reset(self):
self.start = time.time()
self.start = timer()

def __call__(self):
if self.cnt == 0:
self.reset()
self.cnt += 1
if self.cnt % self.print_every != 0:
return
t = time.time() - self.start
t = timer() - self.start
logger.info("{}: {:.2f} sec, {} times, {:.3g} sec/time".format(
self.name, t, self.cnt, t / self.cnt))

0 comments on commit d2c5cc1

Please sign in to comment.