Created
February 3, 2022 20:46
-
-
Save ViniTheSwan/09764158f4adfd0ae77c62a0f8a51766 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.common.env_util import make_atari_env | |
from stable_baselines3.common.vec_env import VecFrameStack | |
from stable_baselines3 import A2C | |
# There already exists an environment generator | |
# that will make and wrap atari environments correctly. | |
# Here we are also multi-worker training (n_envs=4 => 4 environments) | |
env = make_atari_env('BreakoutNoFrameskip-v4', n_envs=16) | |
# Frame-stacking with 4 frames | |
env = VecFrameStack(env, n_stack=4) | |
model = A2C("CnnPolicy", env, verbose=1) | |
model.learn(total_timesteps=int(5e6)) | |
obs = env.reset() | |
#model = A2C.load("A2C_breakout") #uncomment to load saved model | |
model.save("A2C_breakout") | |
while True: | |
action, _states = model.predict(obs) | |
obs, rewards, dones, info = env.step(action) | |
env.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment