Skip to content

Commit dd58ded

Browse files
Darijan Gudeljfacebook-github-bot
Darijan Gudelj
authored andcommitted
stats object counting time wrong
Summary: On each call of the stats.update the object calculates current average iteration time by getting time elapsed from the time_start and then dividing it by the current number of steps. It saves the result to AverageMeter object which when queried returns the average of things saved, so the time is averaged twice which biases it towards the start value (which is often larger). Reviewed By: kjchalup Differential Revision: D39206989 fbshipit-source-id: ccab5233d7aaca1ac4fd626fb329b83c7c0d6af9
1 parent 72c3a0e commit dd58ded

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pytorch3d/implicitron/tools/stats.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def __init__(
118118
self.plot_file = plot_file
119119
self.do_plot = do_plot
120120
self.hard_reset(epoch=epoch)
121+
self._t_last_update = None
121122

122123
@staticmethod
123124
def from_json_str(json_str):
@@ -215,7 +216,6 @@ def update(self, preds, time_start=None, freeze_iter=False, stat_set="train"):
215216
self.it[stat_set] += 1
216217

217218
epoch = self.epoch
218-
it = self.it[stat_set]
219219

220220
for stat in self.log_vars:
221221

@@ -224,10 +224,11 @@ def update(self, preds, time_start=None, freeze_iter=False, stat_set="train"):
224224

225225
if stat == "sec/it": # compute speed
226226
if time_start is None:
227-
elapsed = 0.0
227+
time_per_it = 0.0
228228
else:
229-
elapsed = time.time() - time_start
230-
time_per_it = float(elapsed) / float(it + 1)
229+
now = time.time()
230+
time_per_it = now - (self._t_last_update or time_start)
231+
self._t_last_update = now
231232
val = time_per_it
232233
else:
233234
if stat in preds:

0 commit comments

Comments
 (0)