def load_model(self):
        """
        Loads the next generation model from the appropriate directory. If not found, loads
        the best known model.
        """
        model = ChessModel(self.config)
        rc = self.config.resource

        dirs = get_next_generation_model_dirs(rc)
        if not dirs:
            logger.debug("loading best model")
            if self.config.opts.new and not load_best_model_weight(model):
                model.build()
                save_as_best_model(model)
            elif not load_best_model_weight(model):
                raise RuntimeError("Best model can not loaded!")
        else:
            latest_dir = dirs[-1]
            logger.debug("loading latest model")
            config_path = os.path.join(
                latest_dir, rc.next_generation_model_config_filename)
            weight_path = os.path.join(
                latest_dir, rc.next_generation_model_weight_filename)
            model.load(config_path, weight_path)
        return model
Exemple #2
0
    def load_next_generation_model(self):
        rc = self.config.resource
        while True:
            dirs = get_next_generation_model_dirs(self.config.resource)

            i = -1
            if dirs is not None:
                i = len(dirs) - 1
            while i >= 0:
                if dirs[i] in self.history_list:
                    break
                i = i - 1
            if (dirs is not None) and (len(dirs) > i + 1):
                self.model_list.extend(dirs[i + 1:])
                self.history_list.extend(dirs[i + 1:])
            if len(self.model_list) > 0:
                break
            logger.info(
                "There is no next generation model to evaluate, waiting for 600s"
            )
            sleep(600)
        model_dir = self.model_list.pop()

        print('========================================================')
        print('eval against %s' % (model_dir))
        print('========================================================')

        config_path = os.path.join(model_dir,
                                   rc.next_generation_model_config_filename)
        weight_path = os.path.join(model_dir,
                                   rc.next_generation_model_weight_filename)
        self.ng_model.load(config_path, weight_path)
        return model_dir, config_path, weight_path
Exemple #3
0
 def load_next_generation_model(self):
     """
     Loads the next generation model from the standard directory
     :return (ChessModel, file): the model and the directory that it was in
     """
     rc = self.config.resource
     while True:
         dirs = get_next_generation_model_dirs(self.config.resource)
         if dirs:
             break
         logger.info("There is no next generation model to evaluate")
         sleep(60)
     model_dir = dirs[
         -1] if self.config.eval.evaluate_latest_first else dirs[0]
     i = -1
     while model_dir in self.evaluated_model_name:
         #while Counter(self.evaluated_model_name)[model_dir] >= 2:   # evaluate a model only once
         i -= 1
         model_dir = dirs[i]
     config_path = os.path.join(model_dir,
                                rc.next_generation_model_config_filename)
     weight_path = os.path.join(model_dir,
                                rc.next_generation_model_weight_filename)
     model = ChessModel(self.config)
     model.load(config_path, weight_path)
     self.evaluated_model_name.append(model_dir)
     return model, model_dir
Exemple #4
0
 def load_next_generation_model(self):
     rc = self.config.resource
     while True:
         dirs = get_next_generation_model_dirs(self.config.resource)
         if dirs:
             break
         logger.info(f"There is no next generation model to evaluate")
         sleep(60)
     model_dir = dirs[-1] if self.config.eval.evaluate_latest_first else dirs[0]
     config_path = os.path.join(model_dir, rc.next_generation_model_config_filename)
     weight_path = os.path.join(model_dir, rc.next_generation_model_weight_filename)
     model = ChessModel(self.config)
     model.load(config_path, weight_path)
     return model, model_dir
    def load_model(self):
        from chess_zero.agent.model_chess import ChessModel
        model = ChessModel(self.config)
        rc = self.config.resource

        dirs = get_next_generation_model_dirs(rc)
        if not dirs:
            logger.debug(f"loading best model")
            if not load_best_model_weight(model):
                raise RuntimeError(f"Best model can not loaded!")
        else:
            latest_dir = dirs[-1]
            logger.debug(f"loading latest model")
            config_path = os.path.join(latest_dir, rc.next_generation_model_config_filename)
            weight_path = os.path.join(latest_dir, rc.next_generation_model_weight_filename)
            model.load(config_path, weight_path)
        return model
Exemple #6
0
 def load_next_generation_model(self):
     """
     Loads the next generation model from the standard directory
     :return (ChessModel, file): the model and the directory that it was in
     """
     rc = self.config.resource
     while True:
         dirs = get_next_generation_model_dirs(self.config.resource)
         if dirs:
             break
         logger.info("There is no next generation model to evaluate")
         sleep(60)
     model_dir = dirs[-1] if self.config.eval.evaluate_latest_first else dirs[0]
     config_path = os.path.join(model_dir, rc.next_generation_model_config_filename)
     weight_path = os.path.join(model_dir, rc.next_generation_model_weight_filename)
     model = ChessModel(self.config)
     model.load(config_path, weight_path)
     return model, model_dir
Exemple #7
0
    def load_model(self):
        """
        Loads the next generation model from the appropriate directory. If not found, loads
        the best known model.
        """
        model = ChessModel(self.config)
        rc = self.config.resource

        dirs = get_next_generation_model_dirs(rc)
        if not dirs:
            logger.debug("loading best model")
            if not load_best_model_weight(model):
                raise RuntimeError("Best model can not loaded!")
        else:
            latest_dir = dirs[-1]
            logger.debug("loading latest model")
            config_path = os.path.join(latest_dir, rc.next_generation_model_config_filename)
            weight_path = os.path.join(latest_dir, rc.next_generation_model_weight_filename)
            model.load(config_path, weight_path)
        return model