### Download Source Human Dataset Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/getting_started.md Download the source demonstrations for the Square task. ```shell $ python mimicgen/scripts/download_datasets.py --dataset_type source --tasks square ``` -------------------------------- ### Prepare Source Dataset Script Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/getting_started.md Command to prepare source demonstrations using the prepare_src_dataset.py script. ```bash scripts/prepare_src_dataset.py ``` -------------------------------- ### Generate Dataset Script Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/getting_started.md Command to launch data generation using the generate_dataset.py script. ```bash scripts/generate_dataset.py ``` -------------------------------- ### Prepare Source Dataset for MimicGen Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/getting_started.md Add extra information to the hdf5 file to make it compatible with MimicGen, specifying the environment interface. ```shell $ python mimicgen/scripts/prepare_src_dataset.py \ --dataset datasets/source/square.hdf5 \ --env_interface MG_Square \ --env_interface_type robosuite ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Install additional requirements for building documentation locally. ```shell pip install -r requirements-docs.txt ``` -------------------------------- ### Install robosuite_task_zoo Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Cloning and installing the robosuite_task_zoo dependency. Note: remove dependencies in setup.py before installation. ```shell cd git clone https://github.com/ARISE-Initiative/robosuite-task-zoo cd robosuite-task-zoo git checkout 74eab7f88214c21ca1ae8617c2b2f8d19718a9ed # NOTE: should remove dependencies in setup.py in the "install_requires" before the last step pip install -e . ``` -------------------------------- ### Install MimicGen from source Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Cloning the repository and installing MimicGen using pip. ```shell cd git clone https://github.com/NVlabs/mimicgen.git cd mimicgen pip install -e . ``` -------------------------------- ### Install robosuite Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Cloning and installing the robosuite dependency. ```shell cd git clone https://github.com/ARISE-Initiative/robosuite.git cd robosuite git checkout b9d8d3de5e3dfd1724f4a0e6555246c460407daa pip install -e . ``` -------------------------------- ### Install robomimic Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Cloning and installing the robomimic dependency. ```shell cd git clone https://github.com/ARISE-Initiative/robomimic.git cd robomimic git checkout d0b37cf214bd24fb590d182edb6384333f67b661 pip install -e . ``` -------------------------------- ### Build and View Documentation Locally Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Commands to generate and view the documentation locally in a web browser. ```shell cd /docs make clean make apidoc make html cp -r images _build/html/ ``` -------------------------------- ### Run Data Generation Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/getting_started.md Command to run the data generation script for the Square D1 task. ```shell python mimicgen/scripts/generate_dataset.py \ --config /tmp/core_configs/demo_src_square_task_D1.json \ --auto-remove-exp ``` -------------------------------- ### Annotate Subtasks Script Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/getting_started.md Command to manually segment source demonstrations into subtasks using the annotate_subtasks.py script. ```bash scripts/annotate_subtasks.py ``` -------------------------------- ### Create and activate conda environment Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Recommended way to install MimicGen is into a new conda environment. ```shell conda create -n mimicgen python=3.8 conda activate mimicgen ``` -------------------------------- ### Install pygame Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Install pygame if using the subtask annotation interface. ```shell pip install pygame ``` -------------------------------- ### Download Datasets Script Examples Source: https://github.com/nvlabs/mimicgen/blob/main/docs/datasets/mimicgen_corl_2023.md Examples of using the `download_datasets.py` script to download MimicGen datasets. ```bash python download_datasets.py python download_datasets.py --dataset_type core --tasks square_d0 square_d1 square_d2 coffee_d0 coffee_d1 coffee_d2 python download_datasets.py --dataset_type core --tasks all --dry_run python download_datasets.py --dataset_type source --tasks all ``` -------------------------------- ### Generate Training Configs Script Example Source: https://github.com/nvlabs/mimicgen/blob/main/docs/datasets/mimicgen_corl_2023.md Example of using the `generate_training_configs_for_public_datasets.py` script to generate training configuration files. ```bash # Assume datasets already exist in mimicgen/../datasets folder. Configs will be generated under mimicgen/exps/paper, and training results will be at mimicgen/../training_results after launching training runs. python generate_training_configs_for_public_datasets.py ``` -------------------------------- ### Task-Specific Environment Interface Example (Robosuite) Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md Example of subclassing RobosuiteInterface for a custom task. ```python class MG_StackThree(RobosuiteInterface): """ Corresponds to robosuite StackThree task and variants. """ pass ``` -------------------------------- ### Robosuite StackThree Task Subtask Segmentation Example Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/subtask_termination_signals.md Illustrates how subtask termination signals segment a source demonstration into subtask segments with start and end indices for the robosuite StackThree task. ```text 1. (signal: grasp_1) grasping cubeA (motion relative to cubeA) 2. (signal: place_1) placing cubeA on cubeB (motion relative to cubeB) 3. (signal: grasp_2) grasping cubeC (motion relative to cubeC) 4. (signal: None) placing cubeC on cubeA (motion relative to cubeA) ``` ```text 1. (signal: grasp_1) [0, 50] 2. (signal: place_1) [50, 94] 3. (signal: grasp_2) [94, 148] 4. (signal: None) [148, 210] ``` -------------------------------- ### Test Random Actions Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/installation.md Run a script to test random actions in a custom robosuite task. ```shell cd mimicgen/scripts python demo_random_action.py ``` -------------------------------- ### Example Invocations for annotate_subtasks.py Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/subtask_termination_signals.md Shows example command-line invocations for the scripts/annotate_subtasks.py script. ```sh python scripts/annotate_subtasks.py --demo_path /path/to/source/demos --output_path /path/to/output/annotations --env_name "Stack-v1" --num_demos 10 --demo_idx 0 ``` ```sh python scripts/annotate_subtasks.py --demo_path /path/to/source/demos --output_path /path/to/output/annotations --env_name "PickPlace-v1" --num_demos 5 --demo_idx 1 ``` -------------------------------- ### Robosuite Environment Wrapper Example Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md An example implementation of the `get_robot_eef_pose` method for a robosuite environment, which retrieves the pose of the robot's end effector site used by the Operational Space Controller. ```python def get_robot_eef_pose(self): """ Get current robot end effector pose. Should be the same frame as used by the robot end-effector controller. Returns: pose (np.array): 4x4 eef pose matrix """ # OSC control frame is a MuJoCo site - just retrieve its current pose return self.get_object_pose( obj_name=self.env.robots[0].controller.eef_name, obj_type="site", ) ``` -------------------------------- ### StackThree Config Implementation Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md An example implementation of a task-specific Config object for the StackThree task. ```python class StackThree_Config(MG_Config): """ Corresponds to robosuite StackThree task and variants. """ NAME = "stack_three" TYPE = "robosuite" def task_config(self): """ This function populates the `config.task` attribute of the config, which has settings for each object-centric subtask in a task. Each dictionary should have kwargs for the @add_subtask method in the @MG_TaskSpec object. """ self.task.task_spec.subtask_1 = dict( object_ref="cubeA", subtask_term_signal="grasp_1", subtask_term_offset_range=(10, 20), selection_strategy="nearest_neighbor_object", selection_strategy_kwargs=dict(nn_k=3), action_noise=0.05, num_interpolation_steps=5, num_fixed_steps=0, apply_noise_during_interpolation=False, ) self.task.task_spec.subtask_2 = dict( object_ref="cubeB", subtask_term_signal="stack_1", subtask_term_offset_range=(10, 20), selection_strategy="nearest_neighbor_object", selection_strategy_kwargs=dict(nn_k=3), action_noise=0.05, num_interpolation_steps=5, num_fixed_steps=0, apply_noise_during_interpolation=False, ) self.task.task_spec.subtask_3 = dict( object_ref="cubeC", subtask_term_signal="grasp_2", subtask_term_offset_range=(10, 20), selection_strategy="nearest_neighbor_object", selection_strategy_kwargs=dict(nn_k=3), action_noise=0.05, num_interpolation_steps=5, num_fixed_steps=0, apply_noise_during_interpolation=False, ) self.task.task_spec.subtask_4 = dict( object_ref="cubeA", subtask_term_signal=None, subtask_term_offset_range=None, selection_strategy="nearest_neighbor_object", selection_strategy_kwargs=dict(nn_k=3), action_noise=0.05, num_interpolation_steps=5, num_fixed_steps=0, apply_noise_during_interpolation=False, ) self.task.task_spec.do_not_lock_keys() ``` -------------------------------- ### Recommended PyTorch version for policy learning Source: https://github.com/nvlabs/mimicgen/blob/main/docs/miscellaneous/troubleshooting.md For image-based agents, using PyTorch 1.12.1 is recommended to avoid potential issues with newer versions. This command installs PyTorch 1.12.1 along with torchvision and torchaudio for CUDA 11.3. ```bash conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch ``` -------------------------------- ### Reproduce Image Training Results Source: https://github.com/nvlabs/mimicgen/blob/main/docs/datasets/mimicgen_corl_2023.md Example shell command to reproduce image training results on the Coffee D0 dataset using a specific configuration. ```bash # task: coffee_d0 # obs modality: image python /path/to/robomimic/scripts/train.py --config /path/to/mimicgen/exps/paper/core/coffee_d0/image/bc_rnn.json ``` -------------------------------- ### Fixing egl_probe installation error Source: https://github.com/nvlabs/mimicgen/blob/main/docs/miscellaneous/troubleshooting.md This error during robomimic installation can be resolved by installing cmake. ```bash pip install cmake ``` -------------------------------- ### Task-Specific Environment Interface Implementation Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md Example implementation of the `get_subtask_term_signals` function to define subtask termination signals. ```python signals["grasp_2"] = int(self.env._check_grasp(gripper=self.env.robots[0].gripper, object_geoms=self.env.cubeC)) # final subtask is placing cubeC on cubeA (motion relative to cubeA) - but final subtask signal is not needed return signals ``` -------------------------------- ### Get Source Dataset Information Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/debugging_datagen.md Use the get_source_info.py script to validate the structure of source demonstrations and their environment interfaces. ```sh $ python mimicgen/scripts/get_source_info.py --dataset datasets/source/square.hdf5 ``` -------------------------------- ### Download Source Human Datasets Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/reproducing_experiments.md Download all source demonstrations of interest. The --download_dir argument can be used to specify the download path. ```shell $ python mimicgen/scripts/download_datasets.py --dataset_type source --tasks all ``` -------------------------------- ### Prepare a Source Dataset for Data Generation Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/reproducing_experiments.md Prepare a specific source dataset (e.g., Coffee) for data generation by running the prepare_src_dataset.py script. ```shell $ python mimicgen/scripts/prepare_src_dataset.py --dataset datasets/source/coffee.hdf5 --env_interface MG_Coffee --env_interface_type robosuite ``` -------------------------------- ### Navigate to MimicGen Repository Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/reproducing_experiments.md Change the current directory to the base path of the MimicGen repository. ```shell $ cd {/path/to/mimicgen} ``` -------------------------------- ### Limit annotation to a range of demos Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/subtask_termination_signals.md This command limits the annotation to a specific range of demos, starting from a given index. ```bash python annotate_subtasks.py --dataset /path/to/demo.hdf5 --signals grasp_1 insert_1 grasp_2 \ --render_image_names agentview_image robot0_eye_in_hand_image --n 2 --start 1 ``` -------------------------------- ### Generate Training Configurations Source: https://github.com/nvlabs/mimicgen/blob/main/docs/datasets/mimicgen_corl_2023.md Command to generate training configurations for public datasets, specifying dataset and configuration directories. ```bash python generate_training_configs_for_public_datasets.py --config_dir /tmp/configs --dataset_dir /tmp/datasets --output_dir /tmp/experiment_results ``` -------------------------------- ### Generate Data Generation Configurations Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/reproducing_experiments.md Run the script to generate data generation configurations. Key parameters like NUM_TRAJ and GUARANTEE can be set in the script. ```shell $ python mimicgen/scripts/generate_core_configs.py ``` -------------------------------- ### Fixing ffmpeg not found error Source: https://github.com/nvlabs/mimicgen/blob/main/docs/miscellaneous/troubleshooting.md This error occurs when ffmpeg is not found on the system. Installing ffmpeg via conda can resolve this. ```bash conda install ffmpeg ``` -------------------------------- ### Recommended MuJoCo version Source: https://github.com/nvlabs/mimicgen/blob/main/docs/miscellaneous/troubleshooting.md To resolve rendering issues with the Sawyer robot arm and ensure reproducibility, use MuJoCo version 2.3.2. ```bash pip install mujoco==2.3.2 ``` -------------------------------- ### Implementing get_object_poses for StackThree Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md Implementation of the get_object_poses method to retrieve the poses of the three cubes in the StackThree task using a helper method. ```python def get_object_poses(self): """ Gets the pose of each object relevant to MimicGen data generation in the current scene. Returns: object_poses (dict): dictionary that maps object name (str) to object pose matrix (4x4 np.array) """ # three relevant objects - three cubes return dict( cubeA=self.get_object_pose(obj_name=self.env.cubeA.root_body, obj_type="body"), cubeB=self.get_object_pose(obj_name=self.env.cubeB.root_body, obj_type="body"), cubeC=self.get_object_pose(obj_name=self.env.cubeC.root_body, obj_type="body"), ) ``` -------------------------------- ### WaypointSequence.from_poses Class Method Source: https://github.com/nvlabs/mimicgen/blob/main/docs/modules/datagen.md Instantiate a WaypointSequence object given a sequence of poses, gripper actions, and action noise. ```python @classmethod def from_poses(cls, poses, gripper_actions, action_noise): """ Instantiate a WaypointSequence object given a sequence of poses, gripper actions, and action noise. Args: poses (np.array): sequence of pose matrices of shape (T, 4, 4) gripper_actions (np.array): sequence of gripper actions that should be applied at each timestep of shape (T, D). action_noise (float or np.array): sequence of action noise magnitudes that should be applied at each timestep. If a single float is provided, the noise magnitude will be constant over the trajectory. """ ``` -------------------------------- ### Convert action to target pose Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md Converts an action (compatible with env.step) to a target pose for the end-effector controller. This is the inverse of `target_pose_to_action` and is useful for inferring target controller poses from recorded actions. ```python def action_to_target_pose(self, action, relative=True): """ Converts action (compatible with env.step) to a target pose for the end effector controller. Inverse of @target_pose_to_action. Usually used to infer a sequence of target controller poses from a demonstration trajectory using the recorded actions. Args: action (np.array): environment action relative (bool): if True, use relative pose actions, else absolute pose actions Returns: target_pose (np.array): 4x4 target eef pose that @action corresponds to """ # version check for robosuite - must be v1.2+, so that we're using the correct controller convention assert (robosuite.__version__.split(".")[0] == "1") assert (robosuite.__version__.split(".")[1] >= "2") if (not relative): # convert absolute action to absolute pose target_pos = action[:3] target_quat = T.axisangle2quat(action[3:6]) target_rot = T.quat2mat(target_quat) else: # get maximum position and rotation action bounds max_dpos = self.env.robots[0].controller.output_max[0] max_drot = self.env.robots[0].controller.output_max[3] # unscale actions delta_position = action[:3] * max_dpos delta_rotation = action[3:6] * max_drot # current position and rotation curr_pose = self.get_robot_eef_pose() curr_pos, curr_rot = PoseUtils.unmake_pose(curr_pose) # get pose target target_pos = curr_pos + delta_position delta_quat = T.axisangle2quat(delta_rotation) delta_rot_mat = T.quat2mat(delta_quat) target_rot = delta_rot_mat.dot(curr_rot) target_pose = PoseUtils.make_pose(target_pos, target_rot) return target_pose ``` -------------------------------- ### MimicGen Citation Source: https://github.com/nvlabs/mimicgen/blob/main/docs/introduction/overview.md BibTeX entry for citing the MimicGen paper. ```bibtex @inproceedings{mandlekar2023mimicgen, title={MimicGen: A Data Generation System for Scalable Robot Learning using Human Demonstrations}, author={Mandlekar, Ajay and Nasiriany, Soroush and Wen, Bowen and Akinola, Iretiayo and Narang, Yashraj and Fan, Linxi and Zhu, Yuke and Fox, Dieter}, booktitle={7th Annual Conference on Robot Learning}, year={2023} } ``` -------------------------------- ### Base Config Class Methods Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md The three methods that must be implemented by a subclass of MG_Config: NAME, TYPE, and task_config. ```python @property @classmethod def NAME(cls): # must be specified by subclasses raise NotImplementedError @property @classmethod def TYPE(cls): # must be specified by subclasses raise NotImplementedError def task_config(self): """ This function populates the `config.task` attribute of the config, which has settings for each object-centric subtask in a task. """ raise NotImplementedError ``` -------------------------------- ### MG_EnvInterface Abstract Base Class Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md The abstract base class `MG_EnvInterface` outlines the methods that must be implemented for new simulator environment interfaces. These include `INTERFACE_TYPE`, `get_robot_eef_pose`, `target_pose_to_action`, `action_to_target_pose`, and `action_to_gripper_action`. ```python """ These should be filled out by simulator subclasses (e.g. robosuite). """ @property @classmethod def INTERFACE_TYPE(self): """ Returns string corresponding to interface type. This is used to group all subclasses together in the interface registry (for example, all robosuite interfaces) and helps avoid name conflicts. """ raise NotImplementedError @abc.abstractmethod def get_robot_eef_pose(self): """ Get current robot end effector pose. Should be the same frame as used by the robot end-effector controller. Returns: pose (np.array): 4x4 eef pose matrix """ raise NotImplementedError @abc.abstractmethod def target_pose_to_action(self, target_pose, relative=True): """ Takes a target pose for the end effector controller and returns an action (usually a normalized delta pose action) to try and achieve that target pose. Args: target_pose (np.array): 4x4 target eef pose relative (bool): if True, use relative pose actions, else absolute pose actions Returns: action (np.array): action compatible with env.step (minus gripper actuation) """ raise NotImplementedError @abc.abstractmethod def action_to_target_pose(self, action, relative=True): """ Converts action (compatible with env.step) to a target pose for the end effector controller. Inverse of @target_pose_to_action. Usually used to infer a sequence of target controller poses from a demonstration trajectory using the recorded actions. Args: action (np.array): environment action relative (bool): if True, use relative pose actions, else absolute pose actions Returns: target_pose (np.array): 4x4 target eef pose that @action corresponds to """ raise NotImplementedError @abc.abstractmethod def action_to_gripper_action(self, action): """ Extracts the gripper actuation part of an action (compatible with env.step). Args: action (np.array): environment action Returns: gripper_action (np.array): subset of environment action for gripper actuation """ raise NotImplementedError ``` -------------------------------- ### Extract gripper action Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md Extracts the gripper actuation part of an action that is compatible with the environment's step function. ```python def action_to_gripper_action(self, action): """ Extracts the gripper actuation part of an action (compatible with env.step). Args: action (np.array): environment action Returns: gripper_action (np.array): subset of environment action for gripper actuation """ # last dimension is gripper action return action[-1:] ``` -------------------------------- ### Convert target pose to action Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md Converts a target end-effector pose to an action compatible with the environment's step function. It handles both relative and absolute pose actions and includes version checks for robosuite. ```python def target_pose_to_action(self, target_pose, relative=True): """ Converts a target end-effector pose to an action compatible with env.step. (usually a normalized delta pose action) to try and achieve that target pose. Args: target_pose (np.array): 4x4 target eef pose relative (bool): if True, use relative pose actions, else absolute pose actions Returns: action (np.array): action compatible with env.step (minus gripper actuation) """ # version check for robosuite - must be v1.2+, so that we're using the correct controller convention assert (robosuite.__version__.split(".")[0] == "1") assert (robosuite.__version__.split(".")[1] >= "2") # target position and rotation target_pos, target_rot = PoseUtils.unmake_pose(target_pose) # current position and rotation curr_pose = self.get_robot_eef_pose() curr_pos, curr_rot = PoseUtils.unmake_pose(curr_pose) # get maximum position and rotation action bounds max_dpos = self.env.robots[0].controller.output_max[0] max_drot = self.env.robots[0].controller.output_max[3] if relative: # normalized delta position action delta_position = target_pos - curr_pos delta_position = np.clip(delta_position / max_dpos, -1., 1.) # normalized delta rotation action delta_rot_mat = target_rot.dot(curr_rot.T) delta_quat = T.mat2quat(delta_rot_mat) delta_rotation = T.quat2axisangle(delta_quat) delta_rotation = np.clip(delta_rotation / max_drot, -1., 1.) return np.concatenate([delta_position, delta_rotation]) # absolute position and rotation action target_quat = T.mat2quat(target_rot) abs_rotation = T.quat2axisangle(target_quat) return np.concatenate([target_pos, abs_rotation]) ``` -------------------------------- ### Pose to Action Translation Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md The `target_pose_to_action` method translates between target end effector poses and simulator actions, often involving scaling and rotation convention adjustments. ```python def target_pose_to_action(self, target_pose, relative=True): """ Takes a target pose for the end effector controller and returns an action ``` -------------------------------- ### Scale dataset images during rendering Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/subtask_termination_signals.md This command scales up the dataset images when rendering them to the screen by a specified factor. ```bash python annotate_subtasks.py --dataset /path/to/demo.hdf5 --signals grasp_1 insert_1 grasp_2 \ --render_image_names agentview_image robot0_eye_in_hand_image --image_scale 10 ``` -------------------------------- ### Visualize Subtasks in Source Dataset Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/debugging_datagen.md Visualize each subtask segment in a source demonstration using the visualize_subtasks.py script. Supports on-screen rendering or off-screen rendering to a video. ```sh # render on-screen $ python visualize_subtasks.py --dataset /path/to/demo.hdf5 --config /path/to/config.json --render # render to video $ python visualize_subtasks.py --dataset /path/to/demo.hdf5 --config /path/to/config.json --video_path /path/to/video.mp4 # specify subtask information manually instead of using a config $ python visualize_subtasks.py --dataset /path/to/demo.hdf5 --signals grasp_1 insert_1 grasp_2 --offsets 10 10 10 --render ``` -------------------------------- ### Nearest Neighbor Object Strategy Implementation Source: https://github.com/nvlabs/mimicgen/blob/main/docs/modules/datagen.md A concrete implementation of SelectionStrategy that selects the source demonstration with the closest object pose. ```python class NearestNeighborObjectStrategy(MG_SelectionStrategy): """ Pick source demonstration to be the one with the closest object pose to the object in the current scene. """ # name for registering this class into registry NAME = "nearest_neighbor_object" def select_source_demo( self, eef_pose, object_pose, src_subtask_datagen_infos, pos_weight=1., rot_weight=1., nn_k=3, ): """ Selects source demonstration index using the current robot pose, relevant object pose for the current subtask, and relevant information from the source demonstrations for the current subtask. Args: eef_pose (np.array): current 4x4 eef pose object_pose (np.array): current 4x4 object pose, for the object in this subtask src_subtask_datagen_infos (list): DatagenInfo instance for the relevant subtask segment in the source demonstrations pos_weight (float): weight on position for minimizing pose distance rot_weight (float): weight on rotation for minimizing pose distance nn_k (int): pick source demo index uniformly at randomly from the top @nn_k nearest neighbors ``` -------------------------------- ### Implementing get_subtask_term_signals for StackThree Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md Implementation of the get_subtask_term_signals method to define termination signals for the subtasks in the StackThree task. ```python def get_subtask_term_signals(self): """ Gets a dictionary of binary flags for each subtask in a task. The flag is 1 when the subtask has been completed and 0 otherwise. MimicGen only uses this when parsing source demonstrations at the start of data generation, and it only uses the first 0 -> 1 transition in this signal to detect the end of a subtask. Returns: subtask_term_signals (dict): dictionary that maps subtask name to termination flag (0 or 1) """ signals = dict() # first subtask is grasping cubeA (motion relative to cubeA) signals["grasp_1"] = int(self.env._check_grasp(gripper=self.env.robots[0].gripper, object_geoms=self.env.cubeA)) # second subtask is placing cubeA on cubeB (motion relative to cubeB) signals["stack_1"] = int(self.env._check_cubeA_stacked()) # third subtask is grasping cubeC (motion relative to cubeC) ``` -------------------------------- ### Abstract Base Class Methods for Task-Specific Subclasses Source: https://github.com/nvlabs/mimicgen/blob/main/docs/tutorials/datagen_custom.md The essential methods that task-specific subclasses must implement, as defined by the MG_EnvInterface abstract base class. ```python """ These should be filled out by each simulation domain (e.g. nut assembly, coffee). """ @abc.abstractmethod def get_object_poses(self): """ Gets the pose of each object relevant to MimicGen data generation in the current scene. Returns: object_poses (dict): dictionary that maps object name (str) to object pose matrix (4x4 np.array) """ raise NotImplementedError @abc.abstractmethod def get_subtask_term_signals(self): """ Gets a dictionary of binary flags for each subtask in a task. The flag is 1 when the subtask has been completed and 0 otherwise. MimicGen only uses this when parsing source demonstrations at the start of data generation, and it only uses the first 0 -> 1 transition in this signal to detect the end of a subtask. Returns: subtask_term_signals (dict): dictionary that maps subtask name to termination flag (0 or 1) """ raise NotImplementedError ``` -------------------------------- ### WaypointTrajectory.execute Method Source: https://github.com/nvlabs/mimicgen/blob/main/docs/modules/datagen.md Main function to execute the trajectory. Will use env_interface.target_pose_to_action to convert each target pose at each waypoint to an action command, and pass that along to env.step. ```python def execute( self, env, env_interface, render=False, video_writer=None, video_skip=5, camera_names=None, ): """ Main function to execute the trajectory. Will use env_interface.target_pose_to_action to convert each target pose at each waypoint to an action command, and pass that along to env.step. Args: ```