Engine

Events

class argus.engine.Events(value)[source]

Events that are fired by the argus.engine.Engine during running.

Built-in events:

  • START: triggered when the engine’s run is started.

  • COMPLETE: triggered when the engine’s run is completed.

  • EPOCH_START: triggered when the epoch is started.

  • EPOCH_COMPLETE: triggered when the epoch is ended.

  • ITERATION_START: triggered when an iteration is started.

  • ITERATION_COMPLETE: triggered when the iteration is ended.

  • CATCH_EXCEPTION: triggered on catching of an exception.

class argus.engine.EventEnum(value)[source]

Base class for engine events. User defined custom events should also inherit this class. Example of creating custom events you can find here.

State

class argus.engine.State(step_method: Callable[[Any, argus.engine.engine.State], Any], engine: Optional[argus.engine.engine.Engine] = None, phase_states: Optional[Dict[str, argus.engine.engine.State]] = None, **kwargs)[source]

A state used to store internal and user-defined variables during a run of argus.engine.Engine. The class is highly inspired by the State from pytorch-ignite.

Parameters
  • step_method (Callable) – Method of argus.model.Model that takes batch, state and returns step output.

  • engine (Engine, optional) – argus.engine.Engine that uses this object as a state.

  • phase_states (dict, optional) – Dictionary with states for each training phase.

  • **kwargs – Initial attributes of the state.

By default, the state contains the following attributes.

iteration

Iteration, the first iteration is 0.

Type

int

epoch

Epoch, the first iteration is 0.

Type

int

model

argus.Model that uses argus.engine.State.engine and this object as a state.

Type

argus.Model

data_loader

A data passed to the argus.engine.Engine.

Type

Iterable, optional

logger

Logger.

Type

logging.Logger

exception

Catched exception.

Type

BaseException, optional

engine

argus.engine.Engine that uses this object as a state.

Type

Engine, optional

phase

A phase of training this state was created for. The value takes from the name of the method step_method. If the step_method name ends with _step, the postfix will be removed. For default steps of argus model values are ‘train’ and ‘val’.

Type

str

phase_states

Dictionary with states for each training phase.

Type

dict, optional

batch

Batch sample from a data loader on the current iteration.

Type

Any

step_output

Current output from step_method on current iteration.

Type

Any

metrics

Dictionary with metrics values.

Type

dict

stopped

Boolean indicates argus.engine.Engine is stopped or not.

Type

bool

update(**kwargs)[source]

Update state attributes.

Parameters

**kwargs – Update attributes using kwargs

Engine

class argus.engine.Engine(step_method: Callable[[Any, argus.engine.engine.State], Any], phase_states: Optional[Dict[str, argus.engine.engine.State]] = None, **kwargs)[source]

Runs step_method over each batch of a data loader with triggering event handlers. The class is highly inspired by the Engine from pytorch-ignite.

Parameters
  • step_method (Callable) – Method of argus.model.Model that takes batch, state and returns step output.

  • phase_states (dict, optional) – Dictionary with states for each training phase.

  • **kwargs – Initial attributes of the state.

state

Stores internal and user-defined variables during a run of the engine.

Type

State

step_method

Method of argus.model.Model that takes batch, state and returns step output.

Type

Callable

event_handlers (dict of EventEnum

list): Dictionary that stores event handlers.

add_event_handler(event: argus.engine.engine.EventEnum, handler: Callable, *args, **kwargs)[source]

Add an event handler to be executed when the event is triggered.

Parameters
  • event (EventEnum) – An event that will be associated with the handler.

  • handler (Callable) – A callable handler that will be executed on the event. The handler should take argus.engine.State as the first argument.

  • *args – optional args arguments to be passed to the handler.

  • **kwargs – optional kwargs arguments to be passed to the handler.

raise_event(event: argus.engine.engine.EventEnum)[source]

Execute all the handlers associated with the given event.

Parameters

event (EventEnum) – An event that will be triggered.

run(data_loader: Iterable, start_epoch: int = 0, end_epoch: int = 1) argus.engine.engine.State[source]

Run step_method on each batch from data loader end_epoch - start_epoch times.

Parameters
  • data_loader (Iterable) – An iterable collection that returns batches.

  • start_epoch (int) – The first epoch number.

  • end_epoch (int) – One above the largest epoch number.

Returns

An engine state.

Return type

State