Exemple #1
0
    def test_model_saving_after_training(self):
        init_directories()
        model_name = "model_1"
        model = build_model(model_name)
        self.assertEqual(model.name, 'model_1')
        board, player = game_init()
        policies, values = model.predict(board)
        try:
            os.remove('test.h5')
        except:
            pass
        model.save('test.h5')
        self_play(model, n_games=2, mcts_simulations=32)
        train(model, game_model_name=model.name, epochs=2)
        self.assertEqual(model.name, 'model_2')
        policies2, values2 = model.predict(board)
        self.assertFalse(np.array_equal(values, values2))
        self.assertFalse(np.array_equal(policies, policies2))

        model3 = load_model('test.h5', custom_objects={'loss': loss})
        policies3, values3 = model3.predict(board)

        self.assertTrue(np.array_equal(values, values3))
        self.assertTrue(np.array_equal(policies, policies3))
        os.remove('test.h5')
Exemple #2
0
 def setUp(self):
     init_directories()
     model_name = "model_1"
     model = create_initial_model(name=model_name)
     best_model = load_best_model()
     if best_model.name == model.name:
         train(model, game_model_name=best_model.name)
         evaluate(best_model, model)
         # We save wether or not it was a better model
         full_filename = os.path.join(conf['MODEL_DIR'], conf['BEST_MODEL'])
         model.save(full_filename)
     else:
         model = best_model
     self.model = model
Exemple #3
0
    def test_model_saving(self):
        init_directories()
        model_name = "model_1"
        model = build_model(model_name)

        board, player = game_init()
        policies, values = model.predict(board)
        try:
            os.remove('test.h5')
        except:
            pass
        model.save('test.h5')
        model2 = load_model('test.h5', custom_objects={'loss': loss})
        policies2, values2 = model2.predict(board)

        self.assertTrue(np.array_equal(values, values2))
        self.assertTrue(np.array_equal(policies, policies2))
        os.remove('test.h5')
Exemple #4
0
 def setUp(self):
     init_directories()
     model_name = "model_1"
     best_model = load_best_model()
     self.model = best_model
     self.board, player = game_init()