-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
42 lines (32 loc) · 1.19 KB
/
test.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
import torch
from generator_training_test import generator
from rocket_deepl.module import *
from rocket_deepl.core.activations.relu import *
from rocket_deepl.core.activations.tanh import *
from rocket_deepl.core.layers import *
from rocket_deepl.sequential import *
from rocket_deepl.utils import *
# Generate training set with one-hot encoding
train_input, train_target = generator(1000)
# Generate test set with one-hot encoding
test_input, test_target = generator(1000)
# Model with 2 input units, 2 output units and 3 hidden layers as requested
model = Sequential([
Linear(2, 25), ReLU(),
Linear(25,25), ReLU(),
Linear(25,25), ReLU(),
Linear(25,25), ReLU(),
Linear(25, 2), tanH()
])
epochs = 250
mini_batch_size = 2
# train
train_model(model, train_input, train_target, epochs, mini_batch_size)
# plot accuracy and loss
# model.plot_accuracy_loss()
# compute miss prediction
number = compute_nb_errors(model, test_input, test_target, mini_batch_size)
number_of_misprediction = number
# compute accuray
accuracy = (1 - number/test_input.size(0)) * 100
print("accuracy after train for {} epochs: {}% \n number of miss-predictions : {}".format(epochs, accuracy, number_of_misprediction))