Ejemplo n.º 1
0
 def __init__(self,
              print_gametick=False,
              print_on_receive=False,
              create_server=True):
     self.network = Network(create_server)
     self.print_gametick = print_gametick
     self.print_on_receive = print_on_receive
     self.game_states = []
     self.player_states = {}
Ejemplo n.º 2
0
 def __init__(self,
              model_path: Optional[str] = None,
              min_wait_time: float = 0.0,
              max_wait_time: float = 0.0,
              verbose: bool = False,
              gpus: Union[int, List[int]] = 0,
              max_gpu_mem_fraction: float = 1.0):
     super().__init__("LazyBug-Policy")
     self.max_wait_time = max_wait_time
     self.min_wait_time = min_wait_time
     self.__network = Network(model_path=model_path,
                              gpus=gpus,
                              max_gpu_mem_fraction=max_gpu_mem_fraction)
     # Perform first prediction to force keras to load the model
     self.__network.evaluate_positions(Positions.create_empty(1))
     self.verbose = verbose
Ejemplo n.º 3
0
 def __init__(self,
              model_path: str,
              max_gpu_mem_fraction: Optional[float] = None):
     self.__network = Network(model_path=model_path,
                              max_gpu_mem_fraction=max_gpu_mem_fraction)
Ejemplo n.º 4
0
handler.setFormatter(formatter)
LOGGER = logging.getLogger(__name__)

is_atty = os.isatty(sys.stdout.fileno())
if not is_atty:
    root = logging.getLogger()
    root.setLevel(logging.DEBUG)
    root.handlers = []
    root.addHandler(handler)
else:
    LOGGER.addHandler(handler)

network = Network(nr_of_boards=2,
                  num_residual_blocks=args.residual_blocks,
                  optimizer=SGD(lr=0.001),
                  gpus=args.gpus,
                  verbose=is_atty,
                  value_weight=0.1,
                  policy_weight=0.9)
network.compile_model()
print(network.model.summary())

name_prefix = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
rel_model_dir = name_prefix
model_dir = os.path.join(args.model_path, rel_model_dir)
base_name = os.path.join(name_prefix + "_{:02d}_{:03d}.h5py")
os.makedirs(model_dir, exist_ok=False)
for e in range(10):
    LOGGER.info("Main epoch {}".format(e))
    if args.database_dir is not None:
        data_generator = read_database(PositionDatabase(args.database_dir))
Ejemplo n.º 5
0
    root.addHandler(handler)
else:
    LOGGER.addHandler(handler)

name_prefix, model_dir, epoch, config = args.setup(args)

base_name = os.path.join(name_prefix + "_{:04d}.h5py")

tensorboard_dir = os.path.join(model_dir, "tensorboard")
os.makedirs(tensorboard_dir, exist_ok=True)
create_link(name_prefix, os.path.join(args.output_path, "latest"))

if epoch >= 1:
    model_name = base_name.format(epoch - 1)
    model_path = os.path.join(model_dir, model_name)
    network = Network(model_path=model_path)
else:
    network = Network(nr_of_boards=2,
                      num_residual_blocks=config["residual_blocks"],
                      optimizer=SGD(lr=0.001),
                      gpus=args.gpus,
                      verbose=is_atty,
                      value_weight=0.01,
                      policy_weight=0.99,
                      use_batch_normalization=True)
    network.compile_model()
print(network.model.summary())

training_database = PositionDatabase(args.training_database_dir)
validation_database = PositionDatabase(args.validation_database_dir)
extra_databases = {
Ejemplo n.º 6
0
import numpy as np

from chess.variant import BughouseBoards
from engine.data import read_batches, transform_move_id_to_chessmove, PositionDatabase
from engine.data.position_sequence import PositionSequence
from engine.network import Network

MODEL_PATH = "../models/current"

network = Network(model_path=MODEL_PATH)
network.compile_model()

# TODO: this is inaccurate
dummy_boards = BughouseBoards()
database = PositionDatabase(
    "/mnt/linux_data_slow/bughouse_data/databases/validation_full")
position_sequence = PositionSequence(database, batch_size=256 * 4)
out_list = []
for i, (x_data, y_data) in enumerate(position_sequence):
    print("")
    print("Batch {}".format(i))
    num = len(x_data)
    output = network.model.test_on_batch(x_data, y_data)
    out_list.append(output)
    for n, o in zip(network.model.metrics_names, output):
        print("{}: {}".format(n, o))

    probs, value = network.model.predict([x[0:1] for x in x_data])
    probs = probs[0]
    value = value[0][0]
    print("Example: ")