Spaces:
Sleeping
Sleeping
Update callbacks.py
Browse files- callbacks.py +1 -5
callbacks.py
CHANGED
|
@@ -4,9 +4,7 @@ import imageio
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
class SaveFramesCallback(BaseCallback):
|
| 7 |
-
|
| 8 |
-
Callback for saving frames during training.
|
| 9 |
-
"""
|
| 10 |
def __init__(self, save_freq, save_path, verbose=0):
|
| 11 |
super(SaveFramesCallback, self).__init__(verbose)
|
| 12 |
self.save_freq = save_freq
|
|
@@ -16,7 +14,6 @@ class SaveFramesCallback(BaseCallback):
|
|
| 16 |
|
| 17 |
def _on_step(self) -> bool:
|
| 18 |
if self.num_timesteps % self.save_freq == 0:
|
| 19 |
-
# Render the environment and get the RGB array
|
| 20 |
frame = self.training_env.render(mode='rgb_array')
|
| 21 |
self.frames.append(frame)
|
| 22 |
if self.verbose > 0:
|
|
@@ -24,7 +21,6 @@ class SaveFramesCallback(BaseCallback):
|
|
| 24 |
return True
|
| 25 |
|
| 26 |
def _on_training_end(self) -> None:
|
| 27 |
-
# Save the frames as a GIF
|
| 28 |
if self.frames:
|
| 29 |
gif_path = os.path.join(self.save_path, "training.gif")
|
| 30 |
imageio.mimsave(gif_path, self.frames, fps=10)
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
class SaveFramesCallback(BaseCallback):
|
| 7 |
+
|
|
|
|
|
|
|
| 8 |
def __init__(self, save_freq, save_path, verbose=0):
|
| 9 |
super(SaveFramesCallback, self).__init__(verbose)
|
| 10 |
self.save_freq = save_freq
|
|
|
|
| 14 |
|
| 15 |
def _on_step(self) -> bool:
|
| 16 |
if self.num_timesteps % self.save_freq == 0:
|
|
|
|
| 17 |
frame = self.training_env.render(mode='rgb_array')
|
| 18 |
self.frames.append(frame)
|
| 19 |
if self.verbose > 0:
|
|
|
|
| 21 |
return True
|
| 22 |
|
| 23 |
def _on_training_end(self) -> None:
|
|
|
|
| 24 |
if self.frames:
|
| 25 |
gif_path = os.path.join(self.save_path, "training.gif")
|
| 26 |
imageio.mimsave(gif_path, self.frames, fps=10)
|