Created
August 3, 2022 02:05
-
-
Save liketheflower/8c2884aa6cf8e3a9470d0922a4829bda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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