def load_network_fixme(self, game): import glob import datetime p = os.path.join(self.data_path, game, "models") os.chdir(p) gens = glob.glob("%s_*" % game) for g in gens: print "doing", game, g generation = os.path.splitext(g)[0] new_style_gen = generation.replace(game + "_", "") print generation, new_style_gen # dummy generation_descr generation_descr = templates.default_generation_desc(game) json_str = open(self.model_path(game, generation)).read() keras_model = keras_models.model_from_json(json_str) keras_model.load_weights(self.weights_path(game, generation)) transformer = self.get_transformer(game, generation_descr) print transformer, keras_model, generation_descr nn = NeuralNetwork(transformer, keras_model, generation_descr) generation_descr.name = new_style_gen generation_descr.trained_losses = "unknown" generation_descr.trained_validation_losses = "unknown" generation_descr.trained_policy_accuracy = "unknown" generation_descr.trained_value_accuracy = "unknown" ctime = os.stat(self.model_path(game, generation)).st_ctime generation_descr.date_created = datetime.datetime.fromtimestamp( ctime).strftime("%Y/%m/%d %H:%M") print generation_descr self.save_network(nn)
def load_network(self, game, generation_name): json_str = open(self.generation_path(game, generation_name)).read() generation_descr = attrutil.json_to_attr(json_str) json_str = open(self.model_path(game, generation_name)).read() keras_model = keras_models.model_from_json(json_str) keras_model.load_weights(self.weights_path(game, generation_name)) transformer = self.get_transformer(game, generation_descr) return NeuralNetwork(transformer, keras_model, generation_descr)
def test_nn_model_config_template(): game = "breakthrough" gen_prefix = "x1" prev_states = 1 gen_desc = templates.default_generation_desc( game, gen_prefix, multiple_policy_heads=True, num_previous_states=prev_states) transformer = man.get_transformer(game, gen_desc) model = templates.nn_model_config_template("breakthrough", "small", transformer) attrutil.pprint(model) keras_model = get_network_model(model, gen_desc) network = NeuralNetwork(transformer, keras_model, gen_desc) print network network.summary()
def create_new_network(self, game, nn_model_conf=None, generation_descr=None): if generation_descr is None: generation_descr = templates.default_generation_desc(game) transformer = self.get_transformer(game, generation_descr) if isinstance(nn_model_conf, str): nn_model_conf = templates.nn_model_config_template(game, network_size_hint=nn_model_conf, transformer=transformer) elif nn_model_conf is None: nn_model_conf = templates.nn_model_config_template(game, network_size_hint="small", transformer=transformer) assert isinstance(nn_model_conf, confs.NNModelConfig) assert isinstance(generation_descr, datadesc.GenerationDescription) keras_model = get_network_model(nn_model_conf, generation_descr) return NeuralNetwork(transformer, keras_model, generation_descr)