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.
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)
```
......
......@@ -80,7 +80,8 @@ MaskRCNN results contain both box and mask mAP.
<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
......
......@@ -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')
......@@ -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']
......@@ -26,9 +30,9 @@ class CallbackTimeLogger(object):
@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):
......
......@@ -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.
......
......@@ -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']
......@@ -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)
......@@ -50,9 +54,9 @@ _TOTAL_TIMER_DATA = defaultdict(StatCounter)
@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)
......@@ -96,7 +100,7 @@ class IterSpeedCounter(object):
self.name = name if name else 'IterSpeed'
def reset(self):
self.start = time.time()
self.start = timer()
def __call__(self):
if self.cnt == 0:
......@@ -104,6 +108,6 @@ class IterSpeedCounter(object):
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))
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