-
Notifications
You must be signed in to change notification settings - Fork 5
/
train.py
68 lines (36 loc) · 1.21 KB
/
train.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
65
66
67
68
''' The training Module to train the SpatioTemporal AutoEncoder
Run:
>>python3 train.py n_epochs(enter integer) to begin training.
Author: Harsh Tiku
'''
from keras.callbacks import ModelCheckpoint, EarlyStopping
from model import load_model
import numpy as np
import argparse
# parser=argparse.ArgumentParser()
# parser.add_argument('n_epochs',type=int)
# parser.add_argument(3)
# args=parser.parse_args()
X_train=np.load('training.npy')
frames=X_train.shape[2]
#Need to make number of frames divisible by 10
frames=frames-frames%10
X_train=X_train[:,:,:frames]
X_train=X_train.reshape(-1,227,227,10)
X_train=np.expand_dims(X_train,axis=4)
Y_train=X_train.copy()
epochs=2
batch_size=1
if __name__=="__main__":
model=load_model()
# callback_save = ModelCheckpoint("AnomalyDetector.h5",
# monitor="mean_squared_error", save_best_only=True)
callback_save = ModelCheckpoint("model.h5",
monitor="mean_squared_error", save_best_only=True)
callback_early_stopping = EarlyStopping(monitor='val_loss', patience=3)
print('Model has been loaded')
model.fit(X_train,Y_train,
batch_size=batch_size,
epochs=epochs,
callbacks = [callback_save,callback_early_stopping]
)