-
Notifications
You must be signed in to change notification settings - Fork 3
/
engine.py
64 lines (48 loc) · 1.12 KB
/
engine.py
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
from abc import abstractmethod
import numpy as np
class BaseModel(object):
def __init__(self):
super().__init__()
@abstractmethod
def call(self):
return NotImplementedError
@abstractmethod
def update(self):
return NotImplementedError
@abstractmethod
def fit(self, X, Y, epoch, lr):
return NotImplementedError
@abstractmethod
def predict(self, test_x):
return NotImplementedError
def show_anime(self, save_path: str):
self.save_path = save_path
pass
@abstractmethod
def on_train_begin(self):
pass
@abstractmethod
def on_train_batch_begin(self):
pass
@abstractmethod
def on_train_batch_end(self):
pass
@abstractmethod
def on_train_epoch_begin(self):
pass
@abstractmethod
def on_train_epoch_end(self):
pass
@abstractmethod
def on_train_begin(self):
pass
class Dict(dict):
""" warper for dict, support numpy getitem """
def __getitem__(self, key):
if isinstance(key, np.ndarray):
l = []
for k in key:
l.append(super().__getitem__(k))
return np.array(l)
else:
return super().__getitem__(key)