twocan.ThresholdReachedCallback

class twocan.ThresholdReachedCallback(threshold: float, metric_name: str = 'iou', direction: str = 'maximize')[source]

Bases: object

Callback to stop optimization when a target metric threshold is reached.

This callback monitors a specified metric during optimization and raises optuna.TrialPruned to stop the study when the threshold is reached. Useful for stopping optimization early when satisfactory results are achieved.

Parameters:
  • threshold (float) – Target threshold value for the monitored metric.

  • metric_name (str, default='iou') – Name of the metric to monitor in trial.user_attrs. Must be a key present in the user attributes of trials.

  • direction (str, default='maximize') – Whether to stop when metric goes ‘above’ (‘maximize’) or ‘below’ (‘minimize’) the threshold.

threshold

Current threshold value.

Type:

float

metric_name

Current metric being monitored.

Type:

str

direction

Current direction (‘maximize’ or ‘minimize’).

Type:

str