-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_atari_env.py
41 lines (31 loc) · 1.07 KB
/
test_atari_env.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
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import numpy as np
import matplotlib.pyplot as plt
import pickle
import gymnasium as gym
if __name__ == "__main__":
env_name = 'ALE/MontezumaRevenge-v5'
save_path = f'./results/visuals/atari/{env_name[4:-3]}/trajectories.npy'
obs_list = []
# Create environment
env = gym.make(
env_name,
render_mode="human",
)
# Generate observations
observation, info = env.reset()
obs_list = [observation]
for i in range(100):
action = env.action_space.sample() # agent policy that uses the observation and info
observation, reward, terminated, truncated, info = env.step(action)
obs_list.append(observation)
if terminated or truncated:
observation, info = env.reset()
obs_list.append(observation)
env.close()
# Create path if it does not exist
os.makedirs(os.path.dirname(os.path.abspath(save_path)), exist_ok=True)
# Save observations
with open(save_path, 'wb') as file:
observations = np.stack(obs_list, axis=0)
np.save(file, observations)