Skip to content

Commit

Permalink
fix demo script
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyguo11 committed Dec 8, 2023
1 parent 0d1e307 commit 22df12f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/examples/rl_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Config files used for this task are:

A variation of the Cartpole task showcases the usage of RGB image data as observations. This example
can be launched with command line argument `task=CartpoleCamera`. Note that to use camera data as
observations, `enable_cameras` must be set to `True` in the task config file. In addition, the example must be run with the `omni.isaac.sim.python.gym.camera.kit` app file provided under `apps`, which applies necessary settings to enable camera training. By default, this app file will be used automatically when `enable_cameras` is set to `True`.
observations, `enable_cameras` must be set to `True` in the task config file. In addition, the example must be run with the `omni.isaac.sim.python.gym.camera.kit` app file provided under `apps`, which applies necessary settings to enable camera training. By default, this app file will be used automatically when `enable_cameras` is set to `True`. Due to this limitation, this
example is currently not available in the extension workflow.

Config files used for this task are:

Expand Down
27 changes: 25 additions & 2 deletions omniisaacgymenvs/scripts/rlgames_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@

import datetime
import os

import gym
import hydra
import torch
from omegaconf import DictConfig
import omniisaacgymenvs
from omniisaacgymenvs.envs.vec_env_rlgames import VecEnvRLGames
from omniisaacgymenvs.scripts.rlgames_train import RLGTrainer
from omniisaacgymenvs.utils.config_utils.path_utils import retrieve_checkpoint_path
Expand All @@ -55,6 +56,28 @@ def parse_hydra_configs(cfg: DictConfig):
headless = cfg.headless
env = VecEnvRLGames(headless=headless, sim_device=cfg.device_id, enable_livestream=cfg.enable_livestream)

# parse experiment directory
module_path = os.path.abspath(os.path.join(os.path.dirname(omniisaacgymenvs.__file__)))
experiment_dir = os.path.join(module_path, "runs", cfg.train.params.config.name)

# use gym RecordVideo wrapper for viewport recording
if cfg.enable_recording:
if cfg.recording_dir == '':
videos_dir = os.path.join(experiment_dir, "videos")
else:
videos_dir = cfg.recording_dir
video_interval = lambda step: step % cfg.recording_interval == 0
video_length = cfg.recording_length
env.is_vector_env = True
if env.metadata is None:
env.metadata = {"render_modes": ["rgb_array"], "render_fps": cfg.recording_fps}
else:
env.metadata["render_modes"] = ["rgb_array"]
env.metadata["render_fps"] = cfg.recording_fps
env = gym.wrappers.RecordVideo(
env, video_folder=videos_dir, step_trigger=video_interval, video_length=video_length
)

# ensure checkpoints can be specified as relative paths
if cfg.checkpoint:
cfg.checkpoint = retrieve_checkpoint_path(cfg.checkpoint)
Expand Down Expand Up @@ -90,7 +113,7 @@ def parse_hydra_configs(cfg: DictConfig):

rlg_trainer = RLGDemo(cfg, cfg_dict)
rlg_trainer.launch_rlg_hydra(env)
rlg_trainer.run()
rlg_trainer.run(module_path, experiment_dir)
env.close()

if cfg.wandb_activate:
Expand Down

0 comments on commit 22df12f

Please sign in to comment.