Skip to content

Instantly share code, notes, and snippets.

@ViniTheSwan
Created January 28, 2022 10:49
Show Gist options
  • Save ViniTheSwan/0de005954280e934675b29c94615e504 to your computer and use it in GitHub Desktop.
Save ViniTheSwan/0de005954280e934675b29c94615e504 to your computer and use it in GitHub Desktop.
from stable_baselines3 import PPO
import gym
env = gym.make("CartPole-v1")
model = PPO(policy = "MlpPolicy",env = env, verbose=1)
model.learn(total_timesteps=25000)
model.save("ppo_cartpole") # saving the model to ppo_cartpole.zip
model = PPO.load("ppo_cartpole") # loading the model from ppo_cartpole.zip
obs = env.reset()
for i in range(1000):
action, _state = model.predict(obs, deterministic=True)
obs, reward, done, info = env.step(action)
env.render()
if done:
obs = env.reset()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment