-
Notifications
You must be signed in to change notification settings - Fork 13
/
fully_connected_network.py
42 lines (30 loc) · 1.13 KB
/
fully_connected_network.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
from layers.fully_connected import FullyConnected
from layers.flatten import Flatten
from layers.activation import Elu, Softmax
from utilities.filereader import get_data
from utilities.model import Model
from loss.losses import CategoricalCrossEntropy
import numpy as np
np.random.seed(0)
if __name__ == '__main__':
train_data, train_labels = get_data()
test_data, test_labels = get_data(num_samples=10000, dataset="testing")
train_data = train_data / 255
test_data = test_data / 255
train_labels = train_labels.T
test_labels = test_labels.T
print("Train data shape: {}, {}".format(train_data.shape, train_labels.shape))
print("Test data shape: {}, {}".format(test_data.shape, test_labels.shape))
model = Model(
Flatten(),
FullyConnected(units=200),
Elu(),
FullyConnected(units=200),
Elu(),
FullyConnected(units=10),
Softmax(),
name='fcn200'
)
model.set_loss(CategoricalCrossEntropy)
model.train(train_data, train_labels, batch_size=128, epochs=50)
print('Testing accuracy = {}'.format(model.evaluate(test_data, test_labels)))