scores_monitor

class fgvc.core.training.scores_monitor.LossMonitor(num_batches: int)

Helper class for monitoring loss(es) during training.

Parameters:

num_batches – Number of batches in dataloader.

property avg_loss: float

Get average loss.

property other_avg_losses: dict

Get other average losses.

reset()

Reset internal variable average loss.

update(loss: float | dict)

Update average loss.

class fgvc.core.training.scores_monitor.ScoresMonitor(scores_fn: Callable, num_samples: int, *, eval_batches: bool = True, store_preds_targs: bool = False)

Helper class for monitoring scores during training.

Parameters:
  • scores_fn – Callable function for evaluating training scores. The function should accept preds and targs and return a dictionary with scores.

  • num_samples – Number of samples in the dataset.

  • eval_batches – If true the method evaluates scores on each mini-batch during training. Otherwise, it stores predictions and targets (preds, targs) and evaluates scores on full dataset. Set eval_batches=False in cases where all data points are needed to compute a score, e.g. F1 score in classification.

  • store_preds_targs – If true the method stores predictions and targets (preds, targs) for later use.

property avg_scores: dict

Get average scores.

property preds_all: ndarray

Get stored predictions from the full dataset.

reset()

Reset internal variables including average scores and stored predictions and targets.

property targs_all: ndarray

Get stored predictions from the full dataset.

update(preds: ndarray | dict, targs: ndarray | dict)

Evaluate scores based on the given predictions and targets and update average scores.

Parameters:
  • preds – Numpy array or dictionary of numpy arrays with predictions.

  • targs – Numpy array or dictionary of numpy arrays with ground-truth targets.