Ejemplo n.º 1
0
def make_gtp_instance(load_file, cgos_mode=False, kgs_mode=False,
                      minigui_mode=False, verbosity=1):
    '''Takes a path to model files and set up a GTP engine instance.'''
    n = DualNetwork(load_file)
    if cgos_mode:
        player = CGOSPlayer(network=n, seconds_per_move=5, timed_match=True,
                            verbosity=verbosity, two_player_mode=True)
    else:
        player = MCTSPlayer(network=n, verbosity=verbosity, two_player_mode=True)

    name = "Minigo-" + os.path.basename(load_file)
    version = "0.2"

    engine = gtp_engine.Engine()
    engine.add_cmd_handler(
        gtp_engine.EngineCmdHandler(engine, name, version))

    if kgs_mode:
        engine.add_cmd_handler(KgsCmdHandler(player))
    engine.add_cmd_handler(RegressionsCmdHandler(player))
    engine.add_cmd_handler(GoGuiCmdHandler(player))
    if minigui_mode:
        engine.add_cmd_handler(MiniguiBasicCmdHandler(player, courtesy_pass=kgs_mode))
    else:
        engine.add_cmd_handler(BasicCmdHandler(player, courtesy_pass=kgs_mode))

    return engine
Ejemplo n.º 2
0
def make_gtp_instance(read_file, verbosity=1, cgos_mode=False, kgs_mode=False):
    n = DualNetwork(read_file)
    if cgos_mode:
        player = CGOSPlayer(network=n,
                            seconds_per_move=5,
                            timed_match=True,
                            verbosity=verbosity,
                            two_player_mode=True)
    else:
        readouts = flags.FLAGS.num_readouts  # defined in strategies.py
        player = MCTSPlayer(network=n,
                            num_readouts=readouts,
                            verbosity=verbosity,
                            two_player_mode=True)

    name = "Minigo-" + os.path.basename(read_file)
    version = "0.2"

    engine = gtp_engine.Engine()
    engine.add_cmd_handler(gtp_engine.EngineCmdHandler(engine, name, version))

    if kgs_mode:
        engine.add_cmd_handler(KgsCmdHandler(player))
    engine.add_cmd_handler(RegressionsCmdHandler(player))
    engine.add_cmd_handler(GoGuiCmdHandler(player))
    engine.add_cmd_handler(MiniguiCmdHandler(player, courtesy_pass=kgs_mode))

    return engine
Ejemplo n.º 3
0
def make_gtp_instance(load_file, cgos_mode=False, kgs_mode=False,
                      minigui_mode=False):
    """Takes a path to model files and set up a GTP engine instance."""
    # Here so we dont try load EdgeTPU python library unless we need to
    #if load_file.endswith(".tflite"):
        #from dual_net_edge_tpu import DualNetworkEdgeTpu
        #n = DualNetworkEdgeTpu(load_file)
    #else:
        #from dual_net import DualNetwork
        #n = DualNetwork(load_file)
    n = dual_net.DualNetwork(load_file)

    if cgos_mode:
        player = CGOSPlayer(network=n, seconds_per_move=5, timed_match=True,
                            two_player_mode=True)
    else:
        player = MCTSPlayer(network=n, two_player_mode=True)

    name = "Minigo-" + os.path.basename(load_file)
    version = "0.2"

    engine = gtp_engine.Engine()
    engine.add_cmd_handler(
        gtp_engine.EngineCmdHandler(engine, name, version))

    if kgs_mode:
        engine.add_cmd_handler(KgsCmdHandler(player))
    engine.add_cmd_handler(RegressionsCmdHandler(player))
    engine.add_cmd_handler(GoGuiCmdHandler(player))
    if minigui_mode:
        engine.add_cmd_handler(MiniguiBasicCmdHandler(player, courtesy_pass=kgs_mode))
    else:
        engine.add_cmd_handler(BasicCmdHandler(player, courtesy_pass=kgs_mode))

    return engine
Ejemplo n.º 4
0
def make_gtp_instance(save_dir,
                      name_scope,
                      cgos_mode=False,
                      kgs_mode=False,
                      minigui_mode=False):
    """Takes a path to model files and set up a GTP engine instance."""
    # Here so we dont try load EdgeTPU python library unless we need to

    load_file = os.path.join(save_dir, "variables", "variables")
    model_config_json = os.path.join(save_dir, "model.config.json")

    with open(model_config_json) as f:
        model_config = json.load(f)

    if load_file.endswith(".tflite"):
        from dual_net_edge_tpu import DualNetworkEdgeTpu
        n = DualNetworkEdgeTpu(load_file)
    else:
        from kata_net import Model
        with tf.compat.v1.variable_scope(name_scope):
            n = Model(load_file, model_config, 19, {})

    if cgos_mode:
        player = CGOSPlayer(network=n,
                            seconds_per_move=5,
                            timed_match=True,
                            two_player_mode=True)
    else:
        player = MCTSPlayer(network=n, two_player_mode=True)

    name = "Minigo-" + os.path.basename(load_file)
    version = "0.2"

    engine = gtp_engine.Engine()
    engine.add_cmd_handler(gtp_engine.EngineCmdHandler(engine, name, version))

    if kgs_mode:
        engine.add_cmd_handler(KgsCmdHandler(player))
    engine.add_cmd_handler(RegressionsCmdHandler(player))
    engine.add_cmd_handler(GoGuiCmdHandler(player))
    if minigui_mode:
        engine.add_cmd_handler(
            MiniguiBasicCmdHandler(player, courtesy_pass=kgs_mode))
    else:
        engine.add_cmd_handler(BasicCmdHandler(player, courtesy_pass=kgs_mode))

    return engine
Ejemplo n.º 5
0
def make_gtp_instance(model_path,
                      model_name,
                      cgos_mode=False,
                      kgs_mode=False,
                      minigui_mode=False):
    '''Takes a path to model files and set up a GTP engine instance.'''
    device = torch.device('cuda:0' if FLAGS.use_gpu else 'cpu')
    print(device)
    if FLAGS.model_name == 'model0_1':
        n = policy_value_net.PolicyValueNet(9, 9, model_path, model_name,
                                            FLAGS.use_gpu).to(device)
    else:
        n = residual_policy_value_net.PolicyValueNet(9, 9, model_path,
                                                     model_name,
                                                     FLAGS.use_gpu).to(device)
    if cgos_mode:
        player = CGOSPlayer(network=n,
                            seconds_per_move=5,
                            timed_match=True,
                            two_player_mode=True)
    else:
        player = MCTSPlayer(network=n, two_player_mode=True, device=device)

    name = "ECM_Minigo-" + os.path.basename(model_name)
    version = "0.2"

    engine = gtp_engine.Engine()
    engine.add_cmd_handler(gtp_engine.EngineCmdHandler(engine, name, version))

    if kgs_mode:
        engine.add_cmd_handler(KgsCmdHandler(player))
    engine.add_cmd_handler(RegressionsCmdHandler(player))
    engine.add_cmd_handler(GoGuiCmdHandler(player))
    if minigui_mode:
        engine.add_cmd_handler(
            MiniguiBasicCmdHandler(player, courtesy_pass=kgs_mode))
    else:
        engine.add_cmd_handler(BasicCmdHandler(player, courtesy_pass=kgs_mode))

    return engine