-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
57 lines (45 loc) · 1.57 KB
/
main.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
import argparse
import numpy as np
from nn.model import Model
from nn.layers import Dense
from nn.data import load_dataset
def parse_args():
parser = argparse.ArgumentParser(description='Training Configuration')
parser.add_argument('--epochs', type=int, default=10, dest='epochs',
help='Number of iterations for training')
parser.add_argument('--batch-size', type=int, default=64, dest='batch_size',
help='Batch size for one epoch in training')
parser.add_argument('--lr', type=float, default=0.001, dest='lr',
help='Initial learning rate')
return parser.parse_args()
def main():
args = parse_args()
# dataset
X_train, y_train, X_val, y_val, X_test, y_test = load_dataset(flatten=True)
# model layer dimensions
input_dim = X_train.shape[1]
num_classes = 10
# create model
model = Model()
model.add(Dense(input_dim, 100), activation='relu')
model.add(Dense(100, 200), activation='relu')
model.add(Dense(200, 200), activation='relu')
model.add(Dense(200, num_classes), activation='softmax')
# compile model
model.compile(optim='rmsprop', loss='categorical_crossentropy')
# train model
model.fit(
X_train, y_train,
val_data=(X_val, y_val),
lr=args.lr,
batch_size=args.batch_size,
epochs=args.epochs,
verbose=True,
)
# evaluate model
model.eval(X_test, y_test, verbose=True)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt as e:
print('EXIT')