-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_value.py
More file actions
39 lines (26 loc) · 954 Bytes
/
Copy patheval_value.py
File metadata and controls
39 lines (26 loc) · 954 Bytes
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
import numpy as np
import torch
from train_value import ValueNet, encode_value_states, predict_value
def load_value_model(path="value.pt"):
model = ValueNet()
state_dict = torch.load(path, map_location="cpu")
model.load_state_dict(state_dict)
model.eval()
return model
def main():
data = np.load("values_oracle.npz")
states = data["states"]
values = data["values"]
model = load_value_model()
x = encode_value_states(states)
targets = torch.from_numpy(values.astype(np.int64)) + 1
with torch.no_grad():
logits = model(x)
predicted_classes = logits.argmax(dim=1)
acc = (predicted_classes == targets).float().mean().item()
empty_state = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=np.int8)
print(f"examples: {len(states)}")
print(f"value accuracy: {acc:.1%}")
print("empty-board value:", predict_value(model, empty_state))
if __name__ == "__main__":
main()