-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_train.py
107 lines (91 loc) · 2.92 KB
/
test_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 11 15:29:20 2020
@author: analoganddigital ( GitHub )
"""
import numpy as np
from grabscreen import grab_screen
import cv2
import time
import directkeys
from Alexnet import alexnet2
from getkeys import key_check
import random
WIDTH = 96
HEIGHT = 86
LR = 1e-3
EPOCHS = 20
MODEL_NAME = 'model_sekiro_1/py-sekiro-{}-{}-{}-epochs.model'.format(LR,'alexnetv2',EPOCHS)
#w j m k none
w = [1,0,0,0,0,0]
j = [0,1,0,0,0,0]
m = [0,0,1,0,0,0]
k = [0,0,0,1,0,0]
r = [0,0,0,0,1,0]
n_choise = [0,0,0,0,0,1]
model = alexnet2(WIDTH, HEIGHT, LR, output = 6)
model.load(MODEL_NAME)
window_size = (320,104,704,448)#384,224 192,112 96,86
def main():
last_time = time.time()
for i in list(range(5))[::-1]:
print(i+1)
time.sleep(1)
paused = False
while(True):
if not paused:
# 800x600 windowed mode
screen = grab_screen(region=(window_size))
print('loop took {} seconds'.format(time.time()-last_time))
last_time = time.time()
screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
screen = cv2.resize(screen, (WIDTH,HEIGHT))
prediction = model.predict([screen.reshape(WIDTH,HEIGHT,1)])[0]
print(prediction)
print("np后的预测:",np.argmax(prediction))
if np.argmax(prediction) == np.argmax(w):
print("前")
directkeys.go_forward()
elif np.argmax(prediction) == np.argmax(j):
print("攻击")
directkeys.attack()
elif np.argmax(prediction) == np.argmax(m):
print("防御")
directkeys.define()
elif np.argmax(prediction) == np.argmax(k):
print("跳")
directkeys.jump()
elif np.argmax(prediction) == np.argmax(r):
print("识破")
directkeys.dodge()
elif np.argmax(prediction) == np.argmax(n_choise):
print("不动")
keys = key_check()
# p pauses game and can get annoying.
if 'T' in keys:
if paused:
paused = False
time.sleep(1)
else:
paused = True
'''
ReleaseKey(A)
ReleaseKey(W)
ReleaseKey(D)
'''
time.sleep(1)
if 'Y' in keys:
if paused:
paused = False
time.sleep(1)
else:
paused = True
'''
directkeys.ReleaseKey(J)
directkeys.ReleaseKey(W)
directkeys.ReleaseKey(M)
directkeys.ReleaseKey(K)
'''
time.sleep(1)
break
main()