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

Fix graph metric order and label issues #2356

Merged
Merged
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
25 changes: 24 additions & 1 deletion src/otx/algorithms/common/adapters/mmcv/hooks/logger_hook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Logger hooks."""

# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from collections import defaultdict
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -29,6 +33,19 @@ def __repr__(self):
points.append(f"({x},{y})")
return "curve[" + ",".join(points) + "]"

_TAGS_TO_SKIP = (
"accuracy_top-1",
"current_iters",
"decode.acc_seg",
"decode.loss_ce_ignore",
)

_TAGS_TO_RENAME = {
"train/time": "train/time (sec/iter)",
"train/data_time": "train/data_time (sec/iter)",
"val/accuracy": "val/accuracy (%)",
}

def __init__(
self,
curves: Optional[Dict[Any, Curve]] = None,
Expand All @@ -43,12 +60,13 @@ def __init__(
@master_only
def log(self, runner: BaseRunner):
"""Log function for OTXLoggerHook."""
tags = self.get_loggable_tags(runner, allow_text=False, tags_to_skip=())
tags = self.get_loggable_tags(runner, allow_text=False, tags_to_skip=self._TAGS_TO_SKIP)
if runner.max_epochs is not None:
normalized_iter = self.get_iter(runner) / runner.max_iters * runner.max_epochs
else:
normalized_iter = self.get_iter(runner)
for tag, value in tags.items():
tag = self._TAGS_TO_RENAME.get(tag, tag)
curve = self.curves[tag]
# Remove duplicates.
if len(curve.x) > 0 and curve.x[-1] == normalized_iter:
Expand All @@ -57,6 +75,11 @@ def log(self, runner: BaseRunner):
curve.x.append(normalized_iter)
curve.y.append(value)

def before_run(self, runner: BaseRunner):
"""Called before_run in OTXLoggerHook."""
super().before_run(runner)
self.curves.clear()

def after_train_epoch(self, runner: BaseRunner):
"""Called after_train_epoch in OTXLoggerHook."""
# Iteration counter is increased right after the last iteration in the epoch,
Expand Down