-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_nn_calc_time.py
80 lines (71 loc) · 2.56 KB
/
test_nn_calc_time.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
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test NN calculation time.
Using unittest.
"""
import time
import unittest
import chess
import numpy
import crocrodile.nn
LAYERS_COUNT = 32
class TestNNCalcTime(unittest.TestCase):
def test_nn_build(self):
start = time.time()
nn = crocrodile.nn.NeuralNetwork()
end = time.time()
print(f" (time: {end - start})")
def test_nn_load(self):
nn = crocrodile.nn.NeuralNetwork()
start = time.time()
for layer in range(LAYERS_COUNT):
nn.layers.append(
numpy.genfromtxt(f"nns/0-w{layer}.csv", delimiter=","))
nn.bias.append(
numpy.genfromtxt(f"nns/0-b{layer}.csv", delimiter=","))
nn.layers[-1] = nn.layers[-1].reshape(
1, nn.layers[-1].size
)
nn.bias[-1] = nn.bias[-1].reshape(
1, nn.bias[-1].size
)
nn.last_layer = numpy.genfromtxt("nns/0-wlast.csv",
delimiter=",")
nn.last_layer = nn.last_layer.reshape(
nn.last_layer.size, 1)
nn.last_bias = numpy.genfromtxt("nns/0-blast.csv",
delimiter=",")
nn.last_bias = nn.last_bias.reshape(
1, 1)
end = time.time()
print(f" (time: {end - start})")
def test_calc_time(self):
nn = crocrodile.nn.NeuralNetwork()
for layer in range(LAYERS_COUNT):
nn.layers.append(
numpy.genfromtxt(f"nns/0-w{layer}.csv", delimiter=","))
nn.bias.append(
numpy.genfromtxt(f"nns/0-b{layer}.csv", delimiter=","))
nn.layers[-1] = nn.layers[-1].reshape(
1, nn.layers[-1].size
)
nn.bias[-1] = nn.bias[-1].reshape(
1, nn.bias[-1].size
)
nn.last_layer = numpy.genfromtxt("nns/0-wlast.csv",
delimiter=",")
nn.last_layer = nn.last_layer.reshape(
nn.last_layer.size, 1)
nn.last_bias = numpy.genfromtxt("nns/0-blast.csv",
delimiter=",")
nn.last_bias = nn.last_bias.reshape(
1, 1)
start = time.time()
for i in range(100):
nn.check_move(chess.STARTING_FEN, "e2e4")
end = time.time()
print(f" (time: {end - start})")
self.assertLess(end - start, 0.1) # add assertion here
if __name__ == '__main__':
unittest.main()