blob: d80a1e592f3092eafb9c17aa30f6b738486a03b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
"""Metaclass for callback functions."""
from abc import ABC
from typing import Callable, List, Type
class Callback(ABC):
"""Metaclass for callbacks used in training."""
def on_fit_begin(self) -> None:
"""Called when fit begins."""
pass
def on_fit_end(self) -> None:
"""Called when fit ends."""
pass
def on_train_epoch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_train_epoch_end(self) -> None:
"""Called at the end of an epoch."""
pass
def on_val_epoch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_val_epoch_end(self) -> None:
"""Called at the end of an epoch."""
pass
def on_train_batch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_train_batch_end(self) -> None:
"""Called at the end of an epoch."""
pass
def on_val_batch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_val_batch_end(self) -> None:
"""Called at the end of an epoch."""
pass
class CallbackList:
"""Container for abstracting away callback calls."""
def __init__(self, callbacks: List[Callable] = None) -> None:
"""TBC."""
self._callbacks = callbacks if callbacks is not None else []
def append(self, callback: Type[Callback]) -> None:
"""Append new callback to callback list."""
self.callbacks.append(callback)
def on_fit_begin(self) -> None:
"""Called when fit begins."""
for _ in self._callbacks:
pass
def on_fit_end(self) -> None:
"""Called when fit ends."""
pass
def on_train_epoch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_train_epoch_end(self) -> None:
"""Called at the end of an epoch."""
pass
def on_val_epoch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_val_epoch_end(self) -> None:
"""Called at the end of an epoch."""
pass
def on_train_batch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_train_batch_end(self) -> None:
"""Called at the end of an epoch."""
pass
def on_val_batch_begin(self) -> None:
"""Called at the beginning of an epoch."""
pass
def on_val_batch_end(self) -> None:
"""Called at the end of an epoch."""
pass
|