Add ndjson logging for training (#10970)
* Add ndjson logging for training This adds support for NDJSON (newline-delimited JSON) metrics logging, for both console (stdout) output and a file (like the current CSV file). NDJSON can be easily grepped from the output and/or parsed with e.g. `jq`. The feature is enabled with the `--ndjson-console` and `--ndjson-file` switches to `train.py`. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
43c43d8244
commit
52db52b927
2 files changed
+42
-3
No files matched your search
@@ -58,7 +58,7 @@ from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, ch
|
||||
get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
|
||||
labels_to_image_weights, methods, one_cycle, print_args, print_mutation, strip_optimizer,
|
||||
yaml_save)
|
||||
from utils.loggers import Loggers
|
||||
from utils.loggers import LOGGERS, Loggers
|
||||
from utils.loggers.comet.comet_utils import check_comet_resume
|
||||
from utils.loss import ComputeLoss
|
||||
from utils.metrics import fitness
|
||||
@@ -98,7 +98,20 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
|
||||
# Loggers
|
||||
data_dict = None
|
||||
if RANK in {-1, 0}:
|
||||
loggers = Loggers(save_dir, weights, opt, hyp, LOGGER) # loggers instance
|
||||
include_loggers = list(LOGGERS)
|
||||
if getattr(opt, 'ndjson_console', False):
|
||||
include_loggers.append('ndjson_console')
|
||||
if getattr(opt, 'ndjson_file', False):
|
||||
include_loggers.append('ndjson_file')
|
||||
|
||||
loggers = Loggers(
|
||||
save_dir=save_dir,
|
||||
weights=weights,
|
||||
opt=opt,
|
||||
hyp=hyp,
|
||||
logger=LOGGER,
|
||||
include=tuple(include_loggers),
|
||||
)
|
||||
|
||||
# Register actions
|
||||
for k in methods(loggers):
|
||||
@@ -482,6 +495,10 @@ def parse_opt(known=False):
|
||||
parser.add_argument('--bbox_interval', type=int, default=-1, help='Set bounding-box image logging interval')
|
||||
parser.add_argument('--artifact_alias', type=str, default='latest', help='Version of dataset artifact to use')
|
||||
|
||||
# NDJSON logging
|
||||
parser.add_argument('--ndjson-console', action='store_true', help='Log ndjson to console')
|
||||
parser.add_argument('--ndjson-file', action='store_true', help='Log ndjson to file')
|
||||
|
||||
return parser.parse_known_args()[0] if known else parser.parse_args()
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user