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.
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 takesbatch, 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.
- model¶
argus.Model
that usesargus.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
- 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
- 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
- stopped¶
Boolean indicates
argus.engine.Engine
is stopped or not.- Type
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 takesbatch, state
and returns step output.phase_states (dict, optional) – Dictionary with states for each training phase.
**kwargs – Initial attributes of the state.
- step_method¶
Method of
argus.model.Model
that takesbatch, 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 loaderend_epoch - start_epoch
times.