Skip to content

Commit de60499

Browse files
Save video (#78)
* started save-video * update save-video * save video works * ran some checks * fixed checks? * ran checks again * fix checks * final touches * revert changes in planning * yapf --------- Co-authored-by: Nishanth Kumar <nishanth.kumar20@gmail.com>
1 parent 9945992 commit de60499

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ machines.txt
2525
*_vision_data
2626
tests/_fake_trajs
2727
tests/_fake_results
28+
*.mp4
29+
video_frames/
2830

2931
# Jetbrains IDEs
3032
.idea/

predicators/behavior_utils/option_model_fns.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,24 @@ def navigateToOptionModel(_init_state: State, env: "BehaviorEnv") -> None:
6969
f"params {sample_arr}")
7070

7171
if CFG.simulate_nav:
72+
# Run a closed-loop controller for navigation.
73+
curr_plan = plan[:]
7274
done_bit = False
7375
while not done_bit:
7476
# Get expected position and orientation from plan.
75-
expected_pos = np.array([plan[0][0], plan[0][1], robot_z])
77+
expected_pos = np.array(
78+
[curr_plan[0][0], curr_plan[0][1], robot_z])
7679
expected_orn = p.getQuaternionFromEuler(
77-
np.array([robot_orn[0], robot_orn[1], plan[0][2]]))
80+
np.array([robot_orn[0], robot_orn[1], curr_plan[0][2]]))
7881
# In this case, we're at the final position we wanted to reach.
79-
if len(plan) == 1:
82+
if len(curr_plan) == 1:
8083
done_bit = True
8184
logging.info(
8285
"PRIMITIVE: navigation policy completed execution!")
8386
env.robots[0].set_position_orientation(expected_pos,
8487
expected_orn)
8588
env.step(np.zeros(env.action_space.shape))
86-
plan.pop(0)
89+
curr_plan.pop(0)
8790
target_pos = np.array([desired_xpos, desired_ypos, robot_z])
8891
target_orn = p.getQuaternionFromEuler(
8992
np.array([robot_orn[0], robot_orn[1], desired_zrot]))

predicators/envs/behavior.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ def set_igibson_behavior_env(self, task_num: int, task_instance_id: int,
577577
"""Sets/resets the igibson_behavior_env."""
578578
np.random.seed(seed)
579579
env_creation_attempts = 0
580+
save_video = CFG.env == "behavior" and CFG.behavior_save_video
581+
if CFG.env == "behavior":
582+
task_name = str(CFG.behavior_task_list)[2:-2]
580583
# NOTE: this while loop is necessary because in some cases
581584
# when CFG.randomize_init_state is True, creating a new
582585
# iGibson env may fail and we need to keep trying until
@@ -593,8 +596,10 @@ def set_igibson_behavior_env(self, task_num: int, task_instance_id: int,
593596
instance_id=task_instance_id,
594597
rng=self._rng,
595598
)
596-
self.igibson_behavior_env.step(
597-
np.zeros(self.igibson_behavior_env.action_space.shape))
599+
self.igibson_behavior_env.step(np.zeros(
600+
self.igibson_behavior_env.action_space.shape),
601+
save_video=save_video,
602+
task_name=task_name)
598603
ig_objs_bddl_scope = [
599604
self._ig_object_name(obj) for obj in list(
600605
self.igibson_behavior_env.task.object_scope.values())

predicators/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from predicators.approaches.gnn_approach import GNNApproach
5353
from predicators.datasets import create_dataset
5454
from predicators.envs import BaseEnv, create_new_env
55+
from predicators.envs.behavior import BehaviorEnv
5556
from predicators.planning import _run_plan_with_option_model
5657
from predicators.settings import CFG
5758
from predicators.structs import Dataset, InteractionRequest, \
@@ -122,6 +123,11 @@ def main() -> None:
122123
# Run the full pipeline.
123124
_run_pipeline(env, approach, stripped_train_tasks, offline_dataset)
124125
script_time = time.perf_counter() - script_start
126+
if CFG.env == "behavior": # pragma: no cover
127+
assert isinstance(env, BehaviorEnv)
128+
task_name = str(CFG.behavior_task_list)[2:-2]
129+
env.igibson_behavior_env.simulator.viewer.make_video(
130+
task_name=task_name)
125131
logging.info(f"\n\nMain script terminated in {script_time:.5f} seconds")
126132

127133

predicators/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class GlobalSettings:
120120
"wbm3_modifiable_full_obs.yaml",
121121
)
122122
behavior_mode = "headless" # headless, pbgui, iggui
123+
behavior_save_video = False # True
123124
behavior_action_timestep = 1.0 / 10.0
124125
behavior_physics_timestep = 1.0 / 120.0
125126
behavior_task_list = ["re-shelving_library_books"]

0 commit comments

Comments
 (0)