Skip to content

callback

zeus.callback

Infrastructure for calling callbacks.

Callback

Base class for callbacks.

Source code in zeus/callback.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Callback:
    """Base class for callbacks."""

    def on_train_begin(self) -> None:
        """Called at the beginning of training."""

    def on_train_end(self) -> None:
        """Called at the end of training."""

    def on_epoch_begin(self) -> None:
        """Called at the beginning of each epoch."""

    def on_epoch_end(self) -> None:
        """Called at the end of each epoch."""

    def on_step_begin(self) -> None:
        """Called at the beginning of each step."""

    def on_step_end(self) -> None:
        """Called at the end of each step."""

    def on_evaluate(self, metric: float) -> None:
        """Called after evaluating the model."""

on_train_begin

on_train_begin()

Called at the beginning of training.

Source code in zeus/callback.py
23
24
def on_train_begin(self) -> None:
    """Called at the beginning of training."""

on_train_end

on_train_end()

Called at the end of training.

Source code in zeus/callback.py
26
27
def on_train_end(self) -> None:
    """Called at the end of training."""

on_epoch_begin

on_epoch_begin()

Called at the beginning of each epoch.

Source code in zeus/callback.py
29
30
def on_epoch_begin(self) -> None:
    """Called at the beginning of each epoch."""

on_epoch_end

on_epoch_end()

Called at the end of each epoch.

Source code in zeus/callback.py
32
33
def on_epoch_end(self) -> None:
    """Called at the end of each epoch."""

on_step_begin

on_step_begin()

Called at the beginning of each step.

Source code in zeus/callback.py
35
36
def on_step_begin(self) -> None:
    """Called at the beginning of each step."""

on_step_end

on_step_end()

Called at the end of each step.

Source code in zeus/callback.py
38
39
def on_step_end(self) -> None:
    """Called at the end of each step."""

on_evaluate

on_evaluate(metric)

Called after evaluating the model.

Source code in zeus/callback.py
41
42
def on_evaluate(self, metric: float) -> None:
    """Called after evaluating the model."""

CallbackSet

Bases: Callback

A set of callbacks.

Source code in zeus/callback.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class CallbackSet(Callback):
    """A set of callbacks."""

    def __init__(self, callbacks: list[Callback]) -> None:
        """Initialize the callback set."""
        self.callbacks = callbacks

    def on_train_begin(self) -> None:
        """Called at the beginning of training."""
        for callback in self.callbacks:
            callback.on_train_begin()

    def on_train_end(self) -> None:
        """Called at the end of training."""
        for callback in self.callbacks:
            callback.on_train_end()

    def on_epoch_begin(self) -> None:
        """Called at the beginning of each epoch."""
        for callback in self.callbacks:
            callback.on_epoch_begin()

    def on_epoch_end(self) -> None:
        """Called at the end of each epoch."""
        for callback in self.callbacks:
            callback.on_epoch_end()

    def on_step_begin(self) -> None:
        """Called at the beginning of each step."""
        for callback in self.callbacks:
            callback.on_step_begin()

    def on_step_end(self) -> None:
        """Called at the end of each step."""
        for callback in self.callbacks:
            callback.on_step_end()

    def on_evaluate(self, metric: float) -> None:
        """Called after evaluating the model."""
        for callback in self.callbacks:
            callback.on_evaluate(metric)

__init__

__init__(callbacks)
Source code in zeus/callback.py
48
49
50
def __init__(self, callbacks: list[Callback]) -> None:
    """Initialize the callback set."""
    self.callbacks = callbacks

on_train_begin

on_train_begin()

Called at the beginning of training.

Source code in zeus/callback.py
52
53
54
55
def on_train_begin(self) -> None:
    """Called at the beginning of training."""
    for callback in self.callbacks:
        callback.on_train_begin()

on_train_end

on_train_end()

Called at the end of training.

Source code in zeus/callback.py
57
58
59
60
def on_train_end(self) -> None:
    """Called at the end of training."""
    for callback in self.callbacks:
        callback.on_train_end()

on_epoch_begin

on_epoch_begin()

Called at the beginning of each epoch.

Source code in zeus/callback.py
62
63
64
65
def on_epoch_begin(self) -> None:
    """Called at the beginning of each epoch."""
    for callback in self.callbacks:
        callback.on_epoch_begin()

on_epoch_end

on_epoch_end()

Called at the end of each epoch.

Source code in zeus/callback.py
67
68
69
70
def on_epoch_end(self) -> None:
    """Called at the end of each epoch."""
    for callback in self.callbacks:
        callback.on_epoch_end()

on_step_begin

on_step_begin()

Called at the beginning of each step.

Source code in zeus/callback.py
72
73
74
75
def on_step_begin(self) -> None:
    """Called at the beginning of each step."""
    for callback in self.callbacks:
        callback.on_step_begin()

on_step_end

on_step_end()

Called at the end of each step.

Source code in zeus/callback.py
77
78
79
80
def on_step_end(self) -> None:
    """Called at the end of each step."""
    for callback in self.callbacks:
        callback.on_step_end()

on_evaluate

on_evaluate(metric)

Called after evaluating the model.

Source code in zeus/callback.py
82
83
84
85
def on_evaluate(self, metric: float) -> None:
    """Called after evaluating the model."""
    for callback in self.callbacks:
        callback.on_evaluate(metric)