Esempio n. 1
0
def load_keras_bot(bot_name):
    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)
    processor = SevenPlaneProcessor()
    return KerasBot(model=model, processor=processor)
Esempio n. 2
0
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)

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, port=args.port)
go_server.run()
Esempio n. 3
0
Y = np_utils.to_categorical(y, nb_classes)

# Specify a keras model with two convolutional layers and two dense layers,
# connecting the (num_samples, 7, 19, 19) input to the 19*19 output vector.
model = Sequential()
model.add(Convolution2D(nb_filters, nb_conv, nb_conv, border_mode='valid',
                        input_shape=(input_channels, go_board_rows, go_board_cols)))
model.add(Activation('relu'))
model.add(Convolution2D(nb_filters, nb_conv, nb_conv))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(256))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])

# Fit model to data
model.fit(X, Y, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1)

# Open web frontend
path = os.getcwd().replace('/examples', '')
webbrowser.open('file://' + path + '/ui/demoBot.html', new=2)

# Create a bot from processor and model, then serve it.
go_model = KerasBot(model=model, processor=processor)
go_model.run()
Esempio n. 4
0
args = argparser.parse_args()

processor = SevenPlaneProcessor()

bot_name = '100_epochs_cnn'
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)

bot = KerasBot(model=model, processor=processor)

gnugo_cmd = ["gnugo", "--mode", "gtp"]
p = subprocess.Popen(gnugo_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)


def send_command(gtpStream, cmd):
    gtpStream.stdin.write(cmd)
    print(cmd.strip())


def get_response(gtpStream):
    succeeded = False
    result = ''
    while succeeded == False:
        line = gtpStream.stdout.readline()
Esempio n. 5
0
from __future__ import print_function
import yaml
import os
import webbrowser

from keras.models import model_from_yaml
from betago.model import KerasBot
from betago.gtp import GTPFrontend
from betago.processor import SevenPlaneProcessor

processor = SevenPlaneProcessor()

bot_name = 'one_epoch_cnn'
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)

# Start GTP frontend and run model.
frontend = GTPFrontend(bot=KerasBot(model=model, processor=processor))
frontend.run()
Esempio n. 6
0
processor = SevenPlaneProcessor()

bot_name = '100_epochs_cnn'
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)

bot = KerasBot(model=model, processor=processor)

gnugo_cmd = ["gnugo", "--mode", "gtp"]
p = subprocess.Popen(gnugo_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)


def send_command(gtpStream, cmd):
    gtpStream.stdin.write(cmd)
    print(cmd.strip())


def get_response(gtpStream):
    succeeded = False
    result = ''
    while succeeded == False:
        line = gtpStream.stdout.readline()
Esempio n. 7
0
    Convolution2D(nb_filters,
                  nb_conv,
                  nb_conv,
                  border_mode='valid',
                  input_shape=(input_channels, go_board_rows, go_board_cols)))
model.add(Activation('relu'))
model.add(Convolution2D(nb_filters, nb_conv, nb_conv))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(256))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
              optimizer='adadelta',
              metrics=['accuracy'])

# Fit model to data
model.fit(X, Y, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1)

# Open web frontend
path = os.getcwd().replace('/examples', '')
webbrowser.open('file://' + path + '/ui/demoBot.html', new=2)

# Create a bot from processor and model, then serve it.
go_model = KerasBot(model=model, processor=processor)
go_model.run()