ledmands commited on
Commit
6aec4d8
1 Parent(s): e3b737c

Modified the record_video.py file, still not functional.

Browse files
Files changed (1) hide show
  1. agents/dqn_v2/record_video.py +24 -8
agents/dqn_v2/record_video.py CHANGED
@@ -1,22 +1,38 @@
1
  import gymnasium as gym
2
- from stable_baselines3.common.vec_env import VecVideoRecorder, DummyVecEnv
 
 
3
 
4
  env_id = "ALE/Pacman-v5"
5
- video_folder = "./"
6
  video_length = 100 #steps
7
 
8
  vec_env = DummyVecEnv([lambda: gym.make(env_id, render_mode="rgb_array")])
 
 
9
 
 
 
 
 
 
 
 
10
  obs = vec_env.reset()
11
 
12
- # Record the video starting at the first step
13
- vec_env = VecVideoRecorder(vec_env, video_folder,
14
- record_video_trigger=lambda x: x == 0, video_length=video_length,
15
- name_prefix=f"{env_id}")
16
 
 
 
 
 
 
 
 
 
17
  vec_env.reset()
 
18
  for _ in range(video_length + 1):
19
- action = [vec_env.action_space.sample()]
20
  obs, _, _, _ = vec_env.step(action)
21
- # Save the video
22
  vec_env.close()
 
1
  import gymnasium as gym
2
+ from stable_baselines3 import DQN
3
+ from stable_baselines3.common.monitor import Monitor
4
+ from stable_baselines3.common.vec_env import VecVideoRecorder, DummyVecEnv, VecEnv
5
 
6
  env_id = "ALE/Pacman-v5"
7
+ video_folder = "videos/"
8
  video_length = 100 #steps
9
 
10
  vec_env = DummyVecEnv([lambda: gym.make(env_id, render_mode="rgb_array")])
11
+ model = DQN.load("ALE-Pacman-v5")
12
+ # output: <stable_baselines3.common.vec_env.dummy_vec_env.DummyVecEnv object at 0x0000029974DC6550>
13
 
14
+ # vec_env = gym.make(env_id, render_mode="rgb_array")
15
+ # output <OrderEnforcing<PassiveEnvChecker<AtariEnv<ALE/Pacman-v5>>>>
16
+
17
+ # vec_env = Monitor(gym.make(env_id, render_mode="rgb_array"))
18
+
19
+
20
+ # print(vec_env)
21
  obs = vec_env.reset()
22
 
 
 
 
 
23
 
24
+ # Record the video starting at the first step
25
+ vec_env = VecVideoRecorder(vec_env,
26
+ video_folder,
27
+ record_video_trigger=lambda x: x == 0,
28
+ video_length=video_length,
29
+ name_prefix=f"video-{env_id}")
30
+ # Once I make the environment, now I need to walk through it...???
31
+ # I want to act according to the policy that has been trained
32
  vec_env.reset()
33
+ print(vec_env)
34
  for _ in range(video_length + 1):
35
+ action, states = model.predict(obs)
36
  obs, _, _, _ = vec_env.step(action)
37
+ # # Save the video
38
  vec_env.close()