コード例 #1
0
def main():
    # tag::e2e_processor[]
    go_board_rows, go_board_cols = 19, 19
    nb_classes = go_board_rows * go_board_cols
    encoder = SevenPlaneEncoder((go_board_rows, go_board_cols))
    processor = GoDataProcessor(encoder=encoder.name())

    X, y = processor.load_go_data(num_samples=100)
    # end::e2e_processor[]

    # tag::e2e_model[]
    input_shape = (encoder.num_planes, go_board_rows, go_board_cols)
    model = Sequential()
    network_layers = large.layers(input_shape)
    for layer in network_layers:
        model.add(layer)
    model.add(Dense(nb_classes, activation='softmax'))
    model.compile(loss='categorical_crossentropy',
                  optimizer='adadelta',
                  metrics=['accuracy'])

    model.fit(X, y, batch_size=128, epochs=20, verbose=1)
    # end::e2e_model[]

    # tag::e2e_agent[]
    deep_learning_bot = DeepLearningAgent(model, encoder)
    model_file = h5py.File("../agents/deep_bot.h5", "w")
    deep_learning_bot.serialize(model_file)
    model_file.close()
コード例 #2
0
def main():
	parser = argparse.ArgumentParser()
	parser.add_argument('--epochs', '-e', default=20, type=int,
		help="Training epochs. Default is 20")

	args = parser.parse_args()
	# tag::e2e_processor[]
	go_board_rows, go_board_cols = 19, 19
	nb_classes = go_board_rows * go_board_cols
	encoder = SevenPlaneEncoder((go_board_rows, go_board_cols))
	processor = GoDataProcessor(encoder=encoder.name())

	X, y = processor.load_go_data(num_samples=100)
	# end::e2e_processor[]

	# tag::e2e_model[]
	input_shape = (go_board_rows, go_board_cols, encoder.num_planes)
	model = Sequential()
	network_layers = drew_example.layers(input_shape)
	for layer in network_layers:
		model.add(layer)
	model.add(Dense(nb_classes, activation='softmax'))
	model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])

	model.fit(X, y, batch_size=128, epochs=args.epochs, verbose=1)
	# end::e2e_model[]

	# tag::e2e_agent[]
	deep_learning_bot = DeepLearningAgent(model, encoder)
	fpath = os.path.join(CODE_ROOT_DIR, "agents/deep_bot.h5")
	model_file = h5py.File(fpath, "w")
	deep_learning_bot.serialize(model_file)
	model_file.close()
コード例 #3
0
ファイル: end_to_end.py プロジェクト: Go-Brainer/v0.3
def main():
    samp = 1000
    epo = 1

    # tag::e2e_processor[]
    timestr = time.strftime("%Y%m%d-%H%M%S")
    model_h5filename = "./agents/deep_bot_" + timestr + "_s" + str(
        samp) + "e" + str(epo) + ".h5"

    go_board_rows, go_board_cols = 19, 19
    nb_classes = go_board_rows * go_board_cols
    encoder = XPlaneEncoder((go_board_rows, go_board_cols))
    data_dir = "data/" + str(encoder.num_planes) + "-planes"
    processor = GoDataProcessor(encoder=encoder.name(),
                                data_directory=data_dir)

    X, y = processor.load_go_data(num_samples=samp)
    # end::e2e_processor[]

    # tag::e2e_model[]
    input_shape = (encoder.num_planes, go_board_rows, go_board_cols)
    model = Sequential()
    network_layers = large.layers(input_shape)
    for layer in network_layers:
        model.add(layer)
    try:
        with tf.device('/device:GPU:0'):
            model.add(Dense(nb_classes, activation='softmax'))
            model.compile(loss='categorical_crossentropy',
                          optimizer='adadelta',
                          metrics=['accuracy'])

            model.fit(X, y, batch_size=128, epochs=epo, verbose=1)
            # end::e2e_model[]

            # tag::e2e_agent[]
            deep_learning_bot = DeepLearningAgent(model, encoder)
            deep_learning_bot.serialize(h5py.File(model_h5filename, "w"))
            # end::e2e_agent[]

            # tag::e2e_load_agent[]
            model_file = h5py.File(model_h5filename, "r")
            bot_from_file = load_prediction_agent(model_file)

            web_app = get_web_app({'predict': bot_from_file})
            web_app.run()
            # end::e2e_load_agent[]
    except RuntimeError as e:
        print(e)
コード例 #4
0
from dlgo.networks import large
from keras.models import Sequential
from keras.layers.core import Dense
from keras.callbacks import ModelCheckpoint

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

go_board_rows, go_board_cols = 19, 19
num_classes = go_board_rows * go_board_cols
num_games = 100

encoder = SevenPlaneEncoder((go_board_rows, go_board_cols))

processor = GoDataProcessor(encoder=encoder.name())

if __name__ == '__main__':
    generator = processor.load_go_data('train', num_games, use_generator=True)
    test_generator = processor.load_go_data('test',
                                            num_games,
                                            use_generator=True)

    input_shape = (encoder.num_planes, go_board_rows, go_board_cols)
    network_layers = large.layers(input_shape)
    model = Sequential()
    for layer in network_layers:
        model.add(layer)
    model.add(Dense(num_classes, activation='softmax'))
    model.compile(loss='categorical_crossentropy',
                  optimizer='adagrad',