-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (46 loc) · 1.63 KB
/
main.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
from belabot.engine.belot import Belot
from belabot.engine.player import AiPlayer, BigBrain, RandomPlayer
from belabot.engine.util import get_logger
import time
import torch
import argparse
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--from-checkpoint', type=argparse.FileType('rb'), dest='checkpoint')
parser.add_argument('--save-as', type=str, default=None, dest='model_filename')
parser.add_argument('--no-save', action='store_false', dest='do_save')
parser.add_argument('--epochs', type=int, default=100)
parser.add_argument('--test', action='store_false', dest='train')
return parser.parse_args()
def main(args):
log = get_logger(__name__)
big_brain = BigBrain(args.checkpoint)
if args.train:
players = [
AiPlayer("0", big_brain),
AiPlayer("1", big_brain),#RandomPlayer("1"),
AiPlayer("2", big_brain),
AiPlayer("3", big_brain),#RandomPlayer("3"),
]
grad = torch.enable_grad()
else:
players = [
AiPlayer("0", big_brain),
RandomPlayer("1"),
AiPlayer("2", big_brain),
RandomPlayer("3")
]
grad = torch.no_grad()
#log.info("Grad: {}".format(grad))
with grad:
belot = Belot(players, do_train=args.train)
#belot.play()
for i in range(args.epochs):
metrics = belot.round(i % 4)
metrics.type = 'Train' if args.train else 'Test'
log.info(metrics)
if args.do_save:
big_brain.save(args.model_filename)
if __name__ == '__main__':
args = get_args()
main(args)