-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
questionFurther information is requestedFurther information is requested
Description
🐛 Bug
I was training and used VecVideoRecorder to save some episodes. I saw that RAM usage kept increasing until crashing. I tried testing it to see what's happening with the following code:
from stable_baselines3.common.vec_env import SubprocVecEnv
from stable_baselines3.common.monitor import Monitor
from stable_baselines3.common.vec_env.vec_video_recorder import VecVideoRecorder
import gymnasium as gym
import numpy as np
def make_env(i):
def _init():
env = gym.make("LunarLander-v3", render_mode="rgb_array")
env = Monitor(env)
return env
return _init
if __name__ == "__main__":
n_envs = 1
env = SubprocVecEnv([make_env(i) for i in range(n_envs)])
env = VecVideoRecorder(
env,
r"videos",
record_video_trigger=lambda x: True,
)
num_episodes_to_watch = 50
lstm_state = None
episode_start = np.ones((n_envs,), dtype=bool)
obs = env.reset()
num_episodes = [0] * n_envs
from datetime import datetime
startTime = datetime.now()
counter = 0
while any(ep < num_episodes_to_watch for ep in num_episodes):
counter += 1
if counter % 100 == 0:
print(f"{counter} frames have passed, FPS: {counter/(datetime.now()-startTime).total_seconds()}")
actions = [env.action_space.sample() for _ in range(n_envs)]
next_obs, rewards, dones, infos = env.step(actions)
episode_start = dones.copy()
for idx, done in enumerate(dones):
if done:
num_episodes[idx] += 1
obs = next_obs
env.close()
Am I doing something wrong? I read and think maybe I should be closing the env and opening it again, but I want to use this on a custom env that is pretty heavy and I don't want to be oppening it and closing it constantly.
To Reproduce
from stable_baselines3 import ...
Relevant log output / Error message
System Info
No response
Checklist
- My issue does not relate to a custom gym environment. (Use the custom gym env template instead)
- I have checked that there is no similar issue in the repo
- I have read the documentation
- I have provided a minimal and working example to reproduce the bug
- I've used the markdown code blocks for both code and stack traces.
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested