示例#1
0
def run(architecture_file, model_file, num_batches=10, pattern="centralModel-*"):
    print "evaluating Q values..."
    redisInstance = Redis(host='localhost', port=6379, db=0)
    model_keys = redisInstance.keys(pattern)
    results = {}

    net = BaristaNet(architecture_file, model_file, None)
    replay_dataset = ReplayDataset("temp-q-converge-dset.hdf5",
                                   net.state[0].shape,
                                   dset_size=1000,
                                   overwrite=True)
    net.add_dataset(replay_dataset)

    game = SnakeGame()
    preprocessor = generate_preprocessor(net.state.shape[2:], gray_scale)
    exp_gain = ExpGain(net, ['w', 'a', 's', 'd'], preprocessor, game.cpu_play,
                       replay_dataset, game.encode_state())

    print "Generating new experiences..."
    for _ in xrange(100):
        exp_gain.generate_experience(1e5)
    print "Done"

    for key in model_keys:
        print "Evaluating model:", key
        model = dict(redisC.Dict(key=key, redis=redisInstance))
        q_avg = evaluate_model(net, model, num_batches)
        results[key] = q_avg

    for key in sorted(results.keys()):
        print key.ljust(25) + "%0.4f" % results[key]
示例#2
0
def main():
    args = get_args()

    caffe.set_phase_test()
    if args.mode == "cpu":
        caffe.set_mode_cpu()
    else:
        caffe.set_mode_gpu()

    if not os.path.isfile(args.model):
        if not args.solver:
            print "Error: Model does not exist. No solver specified."
            sys.exit(1)

        print "Warning: model %s does not exist. Creating..."
        solver = SGDSolver(args.solver)
        solver.net.save(args.model)

    # Initialize objects
    net = BaristaNet(args.architecture, args.model, args.driver,
                     reset_log=True)

    replay_dataset = ReplayDataset(args.dataset, net.state[0].shape,
                                   dset_size=args.dset_size,
                                   overwrite=args.overwrite)
    net.add_dataset(replay_dataset)

    game = SnakeGame()
    preprocessor = generate_preprocessor(net.state.shape[2:], gray_scale)
    exp_gain = ExpGain(net, ['w', 'a', 's', 'd'], preprocessor, game.cpu_play,
                       replay_dataset, game.encode_state())

    if(args.overwrite):
        for _ in xrange(min(args.initial_replay, args.dset_size)):
            exp_gain.generate_experience(0)

    # Start server loop
    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    serversocket.bind(('127.0.0.1', args.port))
    serversocket.listen(5)

    print
    print "*"*80
    print "* Starting BARISTA server: listening on port %d." % args.port
    print "*"*80
    # Signal Spark Executor that Barista is ready to receive connections
    issue_ready_signal(args.port)
    while True:
        (clientsocket, address) = serversocket.accept()
        if args.debug:
            handler = debug_process_connection
        else:
            handler = process_connection

        client_thread = threading.Thread(
                            target=handler,
                            args=(clientsocket, net, exp_gain))
        client_thread.run()
示例#3
0
def main():
    args = get_args()

    caffe.set_phase_test()
    if args.mode == "cpu":
        caffe.set_mode_cpu()
    else:
        caffe.set_mode_gpu()

    if not os.path.isfile(args.model):
        if not args.solver:
            print "Error: Model does not exist. No solver specified."
            sys.exit(1)

        print "Warning: model %s does not exist. Creating..."
        solver = SGDSolver(args.solver)
        solver.net.save(args.model)

    # Initialize objects
    net = BaristaNet(args.architecture,
                     args.model,
                     args.driver,
                     reset_log=True)

    replay_dataset = ReplayDataset(args.dataset,
                                   net.state[0].shape,
                                   dset_size=args.dset_size,
                                   overwrite=args.overwrite)
    net.add_dataset(replay_dataset)

    game = SnakeGame()
    preprocessor = generate_preprocessor(net.state.shape[2:], gray_scale)
    exp_gain = ExpGain(net, ['w', 'a', 's', 'd'], preprocessor, game.cpu_play,
                       replay_dataset, game.encode_state())

    if (args.overwrite):
        for _ in xrange(min(args.initial_replay, args.dset_size)):
            exp_gain.generate_experience(0)

    # Start server loop
    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    serversocket.bind(('127.0.0.1', args.port))
    serversocket.listen(5)

    print
    print "*" * 80
    print "* Starting BARISTA server: listening on port %d." % args.port
    print "*" * 80
    # Signal Spark Executor that Barista is ready to receive connections
    issue_ready_signal(args.port)
    while True:
        (clientsocket, address) = serversocket.accept()
        if args.debug:
            handler = debug_process_connection
        else:
            handler = process_connection

        client_thread = threading.Thread(target=handler,
                                         args=(clientsocket, net, exp_gain))
        client_thread.run()