-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkEnv.py
28 lines (24 loc) · 933 Bytes
/
checkEnv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gym
import numpy as np
import imageio
from stable_baselines3 import PPO
from stable_baselines3.common.env_checker import check_env
from custEnvsCombined import HeirarchyEnvAnt
baseEnv = gym.make("Ant-v3")
env = HeirarchyEnvAnt(baseEnv,numModels=40)
# check_env(env)
model = PPO("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=10000)
frames = []
obs = baseEnv.reset()
img = baseEnv.render(mode="rgb_array")
for _ in range(200):
# obs = env.render(mode='rgb_array', width=width, height=height)
modelNo, _states = model.predict(obs)
for _ in range(1):
action, __states = env.model[modelNo].predict(obs)
obs, rewards, dones, info = baseEnv.step(action)
frames.append(baseEnv.render(mode="rgb_array"))
# img = model.env.render(mode="rgb_array")
# # env.render()
imageio.mimsave(f"ant_heirarchy_test.gif", [np.array(img) for i, img in enumerate(frames) if i%2 == 0], fps=10)