Exemplo n.º 1
0
def test_load_and_save():
    env = gym.make('CartPole-v0')
    M = Model(env, build_graph, build_update_feed_dict)
    M.update([0, 0, 0, 0], 2)
    weights = M.G._session.run(M['vars'])
    M.save('test_load_and_save_model')
    M.update([0, 0, 0, 0], 2)
    del M
    M = Model.load(path='test_load_and_save_model')
    weights2 = M.G._session.run(M['vars'])
    M.build_update_feed([0, 1, 0, 1], 2)
    M.update([0, 0, 0, 0], 2)
    shutil.rmtree('test_load_and_save_model')
    assert np.allclose(weights, weights2)
Exemplo n.º 2
0
def test_gradient_ops():
    env = gym.make('CartPole-v0')
    M = Model(env, build_graph, build_update_feed_dict)
    feed_dict = M.build_update_feed([0, 1, 0, 1], 2)

    weights_before = M.get_weights()[0]
    M.apply_gradient_ops(M.get_loss().name, feed_dict)
    weights_after = M.get_weights()[0]

    assert weights_after[0] == pytest.approx(weights_before[0], 1e-7)
    assert weights_after[2] == pytest.approx(weights_before[2], 1e-7)
    assert weights_after[1] != weights_before[1]
    assert weights_after[3] != weights_before[3]