Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved logging time taken message showing milliseconds #2650

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/contrib/cifar10/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def initialize(config):

def log_metrics(logger, epoch, elapsed, tag, metrics):
metrics_output = "\n".join([f"\t{k}: {v}" for k, v in metrics.items()])
logger.info(f"\nEpoch {epoch} - Evaluation time (seconds): {elapsed:.2f} - {tag} metrics:\n {metrics_output}")
logger.info(f"Epoch[{epoch}] - Evaluation time (seconds): {elapsed:.3f}\n - {tag} metrics:\n {metrics_output}")
vfdev-5 marked this conversation as resolved.
Show resolved Hide resolved


def log_basic_info(logger, config):
Expand Down Expand Up @@ -380,9 +380,6 @@ def evaluate_step(engine: Engine, batch):
for name, metric in metrics.items():
metric.attach(evaluator, name)

if idist.get_rank() == 0 and (not config["with_clearml"]):
vfdev-5 marked this conversation as resolved.
Show resolved Hide resolved
common.ProgressBar(desc=f"Evaluation ({tag})", persist=False).attach(evaluator)

return evaluator


Expand Down
4 changes: 2 additions & 2 deletions ignite/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def _internal_run(self) -> State:
# update time wrt handlers
self.state.times[Events.EPOCH_COMPLETED.name] = time_taken
hours, mins, secs = _to_hours_mins_secs(time_taken)
self.logger.info(f"Epoch[{self.state.epoch}] Complete. Time taken: {hours:02d}:{mins:02d}:{secs:02d}")
self.logger.info(f"Epoch[{self.state.epoch}] Complete. Time taken: {hours:02d}:{mins:02d}:{secs:06.3f}")
if self.should_terminate:
break

Expand All @@ -776,7 +776,7 @@ def _internal_run(self) -> State:
# update time wrt handlers
self.state.times[Events.COMPLETED.name] = time_taken
hours, mins, secs = _to_hours_mins_secs(time_taken)
self.logger.info(f"Engine run complete. Time taken: {hours:02d}:{mins:02d}:{secs:02d}")
self.logger.info(f"Engine run complete. Time taken: {hours:02d}:{mins:02d}:{secs:06.3f}")
vfdev-5 marked this conversation as resolved.
Show resolved Hide resolved

except BaseException as e:
self._dataloader_iter = None
Expand Down
6 changes: 3 additions & 3 deletions ignite/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def _check_signature(fn: Callable, fn_description: str, *args: Any, **kwargs: An
)


def _to_hours_mins_secs(time_taken: Union[float, int]) -> Tuple[int, int, int]:
"""Convert seconds to hours, mins, and seconds."""
def _to_hours_mins_secs(time_taken: Union[float, int]) -> Tuple[int, int, float]:
"""Convert seconds to hours, mins, seconds and milliseconds."""
mins, secs = divmod(time_taken, 60)
hours, mins = divmod(mins, 60)
return round(hours), round(mins), round(secs)
return round(hours), round(mins), secs