-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
64 lines (54 loc) · 1.76 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
from sklearn.model_selection import train_test_split
from keras.models import Sequential
from keras.layers import Dense, Activation, Conv2D, Dropout, Flatten, MaxPooling2D
import numpy as np
dataset = "datasets/dataset_move_ai.npz"
test_size = 0.33
if __name__ == "__main__":
model = Sequential()
# model.add(Flatten(input_shape=(5,5)))
model.add(
Conv2D(
4,
kernel_size=5,
strides=(1, 1),
padding='same',
input_shape=(5, 5, 1)))
model.add(Flatten())
model.add(Dense(128, activation='relu', name='Dense_1'))
model.add(Dropout(0.4))
model.add(Dense(32, activation='relu', name='Dense_2'))
model.add(Dense(1, activation='sigmoid', name='Dense_Output'))
model.compile(
optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.summary()
data = np.load(dataset)
X = data['arr_0'] / 2
X = np.expand_dims(X, axis=-1)
Y = data['arr_1']
print(f"Dataset size : {len(X)}")
X_train, X_test, y_train, y_test = train_test_split(
X, Y, test_size=test_size)
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
del X
del Y
model.fit(X_train, y_train, epochs=8, batch_size=192)
model.save('value.h5')
test_loss, test_acc = model.evaluate(X_test, y_test)
print('Test accuracy:', test_acc)
for i in range(0, 5):
testCase = X_test[i]
print(testCase.reshape(5,5))
# testCase = np.expand_dims(testCase, axis=-1)
print(testCase.shape)
t = [testCase]
pred = model.predict(np.array(t))[0][0]
print(pred)
if (pred < 0.5):
print("Winner is O")
else:
print("Winner is X")
print()