Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ List of Contributors
* [Pedro Larroy](https://github.com/larroy)
* [Jun Wu](https://github.com/reminisce)
* [Dom Divakaruni](https://github.com/domdivakaruni)
* [David Salinas](https://github.com/geoalgo)
8 changes: 6 additions & 2 deletions python/mxnet/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ class Speedometer(object):
frequent: int
How many batches between calculations.
Defaults to calculating & logging every 50 batches.
auto_reset : bool
Reset the metric after each log.
"""
def __init__(self, batch_size, frequent=50):
def __init__(self, batch_size, frequent=50, auto_reset=True):
self.batch_size = batch_size
self.frequent = frequent
self.init = False
self.tic = 0
self.last_count = 0
self.auto_reset = auto_reset

def __call__(self, param):
"""Callback to Show speed."""
Expand All @@ -116,7 +119,8 @@ def __call__(self, param):
speed = self.frequent * self.batch_size / (time.time() - self.tic)
if param.eval_metric is not None:
name_value = param.eval_metric.get_name_value()
param.eval_metric.reset()
if self.auto_reset:
param.eval_metric.reset()
for name, value in name_value:
logging.info('Epoch[%d] Batch [%d]\tSpeed: %.2f samples/sec\tTrain-%s=%f',
param.epoch, count, speed, name, value)
Expand Down