-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMinRt.py
54 lines (43 loc) · 1.74 KB
/
MinRt.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
import os
import numpy as np
class MinRt:
def __init__(self):
raise NotImplementedError("This is a static class")
@staticmethod
def do_ai(input_array: np.ndarray) -> int:
current = np.array(input_array)
# current = input_array.copy()
# Dense layer
if not os.path.exists('D1.npy'):
raise RuntimeError("D1.npy No exist")
weights = np.load('D1.npy')
current = np.dot(current.reshape(1, -1), weights).flatten()
# LeakyRelu layer
n = 20
if current.shape[0] != n:
raise RuntimeError(f"Wrong input size for LeakyRelu layer (expected {n}, got {current.shape[0]})")
# Apply LeakyReLU function
current = np.where(current > 0, current, current * 0.01)
# Dense layer
if not os.path.exists('D2.npy'):
raise RuntimeError("D2.npy No exist")
weights = np.load('D2.npy')
current = np.dot(current.reshape(1, -1), weights).flatten()
# LeakyRelu layer
n = 100
if current.shape[0] != n:
raise RuntimeError(f"Wrong input size for LeakyRelu layer (expected {n}, got {current.shape[0]})")
# Apply LeakyReLU function
current = np.where(current > 0, current, current * 0.01)
# Dense layer
if not os.path.exists('D3.npy'):
raise RuntimeError("D3.npy No exist")
weights = np.load('D3.npy')
current = np.dot(current.reshape(1, -1), weights).flatten()
# Judge layer
m = 2
if current.shape[0] != m:
raise RuntimeError(f"Wrong input size for Judge layer (expected {m}, got {current.shape[0]})")
# Find the index of the maximum value
idx = np.argmax(current)
return idx