|
|
@ -27,14 +27,16 @@ def _log_debug_samples(files, title='Debug Samples'):
|
|
|
|
files (List(PosixPath)) a list of file paths in PosixPath format
|
|
|
|
files (List(PosixPath)) a list of file paths in PosixPath format
|
|
|
|
title (str) A title that groups together images with the same values
|
|
|
|
title (str) A title that groups together images with the same values
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
for f in files:
|
|
|
|
task = Task.current_task()
|
|
|
|
if f.exists():
|
|
|
|
if task:
|
|
|
|
it = re.search(r'_batch(\d+)', f.name)
|
|
|
|
for f in files:
|
|
|
|
iteration = int(it.groups()[0]) if it else 0
|
|
|
|
if f.exists():
|
|
|
|
Task.current_task().get_logger().report_image(title=title,
|
|
|
|
it = re.search(r'_batch(\d+)', f.name)
|
|
|
|
series=f.name.replace(it.group(), ''),
|
|
|
|
iteration = int(it.groups()[0]) if it else 0
|
|
|
|
local_path=str(f),
|
|
|
|
task.get_logger().report_image(title=title,
|
|
|
|
iteration=iteration)
|
|
|
|
series=f.name.replace(it.group(), ''),
|
|
|
|
|
|
|
|
local_path=str(f),
|
|
|
|
|
|
|
|
iteration=iteration)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _log_plot(title, plot_path):
|
|
|
|
def _log_plot(title, plot_path):
|
|
|
@ -54,11 +56,9 @@ def _log_plot(title, plot_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_pretrain_routine_start(trainer):
|
|
|
|
def on_pretrain_routine_start(trainer):
|
|
|
|
# TODO: reuse existing task
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if Task.current_task():
|
|
|
|
task = Task.current_task()
|
|
|
|
task = Task.current_task()
|
|
|
|
if task:
|
|
|
|
|
|
|
|
|
|
|
|
# Make sure the automatic pytorch and matplotlib bindings are disabled!
|
|
|
|
# Make sure the automatic pytorch and matplotlib bindings are disabled!
|
|
|
|
# We are logging these plots and model files manually in the integration
|
|
|
|
# We are logging these plots and model files manually in the integration
|
|
|
|
PatchPyTorchModelIO.update_current_task(None)
|
|
|
|
PatchPyTorchModelIO.update_current_task(None)
|
|
|
@ -80,43 +80,46 @@ def on_pretrain_routine_start(trainer):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_train_epoch_end(trainer):
|
|
|
|
def on_train_epoch_end(trainer):
|
|
|
|
if trainer.epoch == 1:
|
|
|
|
if trainer.epoch == 1 and Task.current_task():
|
|
|
|
_log_debug_samples(sorted(trainer.save_dir.glob('train_batch*.jpg')), 'Mosaic')
|
|
|
|
_log_debug_samples(sorted(trainer.save_dir.glob('train_batch*.jpg')), 'Mosaic')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_fit_epoch_end(trainer):
|
|
|
|
def on_fit_epoch_end(trainer):
|
|
|
|
# You should have access to the validation bboxes under jdict
|
|
|
|
task = Task.current_task()
|
|
|
|
Task.current_task().get_logger().report_scalar(title='Epoch Time',
|
|
|
|
if task:
|
|
|
|
series='Epoch Time',
|
|
|
|
# You should have access to the validation bboxes under jdict
|
|
|
|
value=trainer.epoch_time,
|
|
|
|
task.get_logger().report_scalar(title='Epoch Time',
|
|
|
|
iteration=trainer.epoch)
|
|
|
|
series='Epoch Time',
|
|
|
|
if trainer.epoch == 0:
|
|
|
|
value=trainer.epoch_time,
|
|
|
|
model_info = {
|
|
|
|
iteration=trainer.epoch)
|
|
|
|
'model/parameters': get_num_params(trainer.model),
|
|
|
|
if trainer.epoch == 0:
|
|
|
|
'model/GFLOPs': round(get_flops(trainer.model), 3),
|
|
|
|
model_info = {
|
|
|
|
'model/speed(ms)': round(trainer.validator.speed['inference'], 3)}
|
|
|
|
'model/parameters': get_num_params(trainer.model),
|
|
|
|
for k, v in model_info.items():
|
|
|
|
'model/GFLOPs': round(get_flops(trainer.model), 3),
|
|
|
|
Task.current_task().get_logger().report_single_value(k, v)
|
|
|
|
'model/speed(ms)': round(trainer.validator.speed['inference'], 3)}
|
|
|
|
|
|
|
|
for k, v in model_info.items():
|
|
|
|
|
|
|
|
task.get_logger().report_single_value(k, v)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_val_end(validator):
|
|
|
|
def on_val_end(validator):
|
|
|
|
# Log val_labels and val_pred
|
|
|
|
if Task.current_task():
|
|
|
|
_log_debug_samples(sorted(validator.save_dir.glob('val*.jpg')), 'Validation')
|
|
|
|
# Log val_labels and val_pred
|
|
|
|
|
|
|
|
_log_debug_samples(sorted(validator.save_dir.glob('val*.jpg')), 'Validation')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_train_end(trainer):
|
|
|
|
def on_train_end(trainer):
|
|
|
|
# Log final results, CM matrix + PR plots
|
|
|
|
task = Task.current_task()
|
|
|
|
files = ['results.png', 'confusion_matrix.png', *(f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R'))]
|
|
|
|
if task:
|
|
|
|
files = [(trainer.save_dir / f) for f in files if (trainer.save_dir / f).exists()] # filter
|
|
|
|
# Log final results, CM matrix + PR plots
|
|
|
|
for f in files:
|
|
|
|
files = ['results.png', 'confusion_matrix.png', *(f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R'))]
|
|
|
|
_log_plot(title=f.stem, plot_path=f)
|
|
|
|
files = [(trainer.save_dir / f) for f in files if (trainer.save_dir / f).exists()] # filter
|
|
|
|
# Report final metrics
|
|
|
|
for f in files:
|
|
|
|
for k, v in trainer.validator.metrics.results_dict.items():
|
|
|
|
_log_plot(title=f.stem, plot_path=f)
|
|
|
|
Task.current_task().get_logger().report_single_value(k, v)
|
|
|
|
# Report final metrics
|
|
|
|
# Log the final model
|
|
|
|
for k, v in trainer.validator.metrics.results_dict.items():
|
|
|
|
Task.current_task().update_output_model(model_path=str(trainer.best),
|
|
|
|
task.get_logger().report_single_value(k, v)
|
|
|
|
model_name=trainer.args.name,
|
|
|
|
# Log the final model
|
|
|
|
auto_delete_file=False)
|
|
|
|
task.update_output_model(model_path=str(trainer.best), model_name=trainer.args.name, auto_delete_file=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callbacks = {
|
|
|
|
callbacks = {
|
|
|
|