Spaces:
Runtime error
Runtime error
Commit ·
4d84f5b
1
Parent(s): 4b714e2
render example episode
Browse files- apple_retrieval.gif +0 -0
- apple_retrieval.mp4 +0 -0
- create_movie.py +42 -0
apple_retrieval.gif
ADDED
|
apple_retrieval.mp4
ADDED
|
Binary file (160 kB). View file
|
|
|
create_movie.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
from apple.envs.discrete_apple import get_apple_env
|
| 5 |
+
from apple.evaluation.render_episode import render_episode
|
| 6 |
+
from apple.models.categorical_policy import CategoricalPolicy
|
| 7 |
+
|
| 8 |
+
env_kwargs = dict(
|
| 9 |
+
start_x=0,
|
| 10 |
+
goal_x=8,
|
| 11 |
+
c=0.5,
|
| 12 |
+
time_limit=100,
|
| 13 |
+
bias_in_state=True,
|
| 14 |
+
position_in_state=False,
|
| 15 |
+
apple_in_state=True,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
env = get_apple_env("full", render_mode="rgb_array", **env_kwargs)
|
| 19 |
+
|
| 20 |
+
model = CategoricalPolicy(env.observation_space.shape[0], 1, 0, 10)
|
| 21 |
+
data = list(render_episode(env, model))
|
| 22 |
+
|
| 23 |
+
video_frames = np.stack([d["pixel_array"] for d in data], axis=0)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Define the output file name and location
|
| 27 |
+
output_file = "apple_retrieval.mp4"
|
| 28 |
+
|
| 29 |
+
# Define the video codec and parameters
|
| 30 |
+
fourcc = cv2.VideoWriter_fourcc(*"XVID")
|
| 31 |
+
fps = 1.0
|
| 32 |
+
|
| 33 |
+
# Create a VideoWriter object
|
| 34 |
+
writer = cv2.VideoWriter(output_file, fourcc, fps, (video_frames.shape[2], video_frames.shape[1]))
|
| 35 |
+
|
| 36 |
+
# Write the video frames to the output file
|
| 37 |
+
for frame in video_frames:
|
| 38 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 39 |
+
writer.write(frame)
|
| 40 |
+
|
| 41 |
+
# Release the VideoWriter object
|
| 42 |
+
writer.release()
|