DLR-RM / DLR-RM/stable-baselines3
[Bug]: VecVideoRecorder RAM USAGE
- Dominant language
- Python
- Stars
- 13.8k
- Forks
- 2.2k
- Avg merge
- 1h 35m
- Merged PRs (30d)
- 2
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:
```python
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
```python
from stable_baselines3 import ...
```
### Relevant log output / Error message
```shell
```
### System Info
_No response_
### Checklist
- [x] My issue does not relate to a custom gym environment. (Use the custom gym env template instead)
- [x] I have checked that there is no similar [issue](https://github.com/DLR-RM/stable-baselines3/issues) in the repo
- [x] I have read the [documentation](https://stable-baselines3.readthedocs.io/en/master/)
- [x] I have provided a [minimal and working](https://github.com/DLR-RM/stable-baselines3/issues/982#issuecomment-1197044014) example to reproduce the bug
- [x] I've used the [markdown code blocks](https://help.github.com/en/articles/creating-and-highlighting-code-blocks) for both code and stack traces.
Contributor guide
Assessment
This issue has not been assessed yet.