timing

Provides CallbackTiming to configure when to call a callback.

The CallbackTiming class is used to configure when a callback should be called. This is useful for expensive callbacks that should not be called every step, such as image logging.

class CallbackTiming[source]

Base class for callback timings.

call_now(global_step: int) bool[source]

Returns True if the callback should be called now.

Parameters:

global_step – The current global step.

Returns:

True if the callback should be called now.

class EveryIncreasingInterval(initial_log_step=0, initial_interval: int = 10, slow_down_factor: float = 1.1)[source]

Callback timing with an exponentially increasing interval between calls.

__init__(initial_log_step=0, initial_interval: int = 10, slow_down_factor: float = 1.1) None[source]

Calls the callback every log_interval steps, increasing the interval by slow_down_factor every time. This results in exponentially increasing intervals between calls, and log files that grow logarithmically.

Parameters:
  • initial_log_step – The first step at which the callback should be called.

  • initial_interval – The initial number of steps between calls.

  • slow_down_factor – The factor by which the interval is increased after each call.

call_now(global_step: int) bool[source]

Returns True if the callback should be called now, which is the case if the global step is larger than self.next_log, the next scheduled call.

Note

If call_now is not called every step, the callback might not be called at all the scheduled steps at exponentially increasing intervals. This happens e.g. when using this at validation time.

Parameters:

global_step – The current global step.

Returns:

True if the callback should be called now.

class EveryNSteps(n_steps: int)[source]

Calls the callback every n_steps steps.

__init__(n_steps: int) None[source]

Initializes the EveryNSteps object.

Parameters:

n_steps – The number of steps between calls.

call_now(global_step: int) bool[source]

Returns True if the callback should be called now, which is the case if the global step is larger than self.next_log, the next scheduled call.

Note

If call_now is not called every step, the callback might not be called at all the scheduled steps at even intervals. This happens e.g. when using this at validation time.

Parameters:

global_step – The current global step.

Returns:

True if the callback should be called now.