forked from maxpumperla/betago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_demo.py
executable file
·38 lines (31 loc) · 1.27 KB
/
run_demo.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
#!/usr/bin/env python
from __future__ import print_function
import argparse
import yaml
import os
import webbrowser
import tensorflow as tf
from keras.models import model_from_yaml
from betago.model import HTTPFrontend, KerasBot
from betago.processor import SevenPlaneProcessor
processor = SevenPlaneProcessor()
bot_name = 'demo'
model_file = 'model_zoo/' + bot_name + '_bot.yml'
weight_file = 'model_zoo/' + bot_name + '_weights.hd5'
with open(model_file, 'r') as f:
yml = yaml.load(f)
model = model_from_yaml(yaml.dump(yml))
# Note that in Keras 1.0 we have to recompile the model explicitly
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
model.load_weights(weight_file)
graph = tf.get_default_graph()
parser = argparse.ArgumentParser()
parser.add_argument('--host', default='localhost', help='host to listen to')
parser.add_argument('--port', '-p', type=int, default=8080,
help='Port the web server should listen on (default 8080).')
args = parser.parse_args()
# Open web frontend and serve model
webbrowser.open('http://{}:{}/'.format(args.host, args.port), new=2)
go_model = KerasBot(model=model, processor=processor)
go_server = HTTPFrontend(bot=go_model, graph=graph, port=args.port)
go_server.run()