Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- data/preprocess_scripts/agilex.py +186 -0
- data/preprocess_scripts/aloha_box_into_pot.py +55 -0
- data/preprocess_scripts/aloha_dish_drainer.py +55 -0
- data/preprocess_scripts/aloha_handover_box.py +55 -0
- data/preprocess_scripts/aloha_lift_box.py +55 -0
- data/preprocess_scripts/aloha_mobile.py +183 -0
- data/preprocess_scripts/aloha_static.py +193 -0
- data/preprocess_scripts/asu_table_top_converted_externally_to_rlds.py +91 -0
- data/preprocess_scripts/austin_sailor_dataset_converted_externally_to_rlds.py +91 -0
- data/preprocess_scripts/austin_sirius_dataset_converted_externally_to_rlds.py +93 -0
- data/preprocess_scripts/bc_z.py +95 -0
- data/preprocess_scripts/berkeley_fanuc_manipulation.py +81 -0
- data/preprocess_scripts/berkeley_gnm_cory_hall.py +78 -0
- data/preprocess_scripts/berkeley_gnm_recon.py +78 -0
- data/preprocess_scripts/berkeley_mvp_converted_externally_to_rlds.py +90 -0
- data/preprocess_scripts/bridge.py +90 -0
- data/preprocess_scripts/bridgev2.py +179 -0
- data/preprocess_scripts/columbia_cairlab_pusht_real.py +84 -0
- data/preprocess_scripts/dlr_edan_shared_control_converted_externally_to_rlds.py +89 -0
- data/preprocess_scripts/dlr_sara_grid_clamp_converted_externally_to_rlds.py +78 -0
- data/preprocess_scripts/dlr_sara_pour_converted_externally_to_rlds.py +88 -0
- data/preprocess_scripts/dobbe.py +86 -0
- data/preprocess_scripts/eth_agent_affordances.py +77 -0
- data/preprocess_scripts/fmb.py +78 -0
- data/preprocess_scripts/furniture_bench_dataset_converted_externally_to_rlds.py +98 -0
- data/preprocess_scripts/imperialcollege_sawyer_wrist_cam.py +77 -0
- data/preprocess_scripts/jaco_play.py +91 -0
- data/preprocess_scripts/kaist_nonprehensile_converted_externally_to_rlds.py +91 -0
- data/preprocess_scripts/kuka.py +107 -0
- data/preprocess_scripts/language_table.py +75 -0
- data/preprocess_scripts/libero_10_no_noops.py +82 -0
- data/preprocess_scripts/libero_object_no_noops.py +82 -0
- data/preprocess_scripts/maniskill_dataset_converted_externally_to_rlds.py +106 -0
- data/preprocess_scripts/nyu_door_opening_surprising_effectiveness.py +77 -0
- data/preprocess_scripts/nyu_franka_play_dataset_converted_externally_to_rlds.py +87 -0
- data/preprocess_scripts/qut_dexterous_manpulation.py +68 -0
- data/preprocess_scripts/rh20t.py +214 -0
- data/preprocess_scripts/robomimic_can_ph.py +96 -0
- data/preprocess_scripts/robomimic_tool_hang_ph.py +97 -0
- data/preprocess_scripts/robomimic_transport_ph.py +114 -0
- data/preprocess_scripts/roboturk_real_laundrylayout.py +223 -0
- data/preprocess_scripts/singlevla_benchmark.py +82 -0
- data/preprocess_scripts/stanford_kuka_multimodal_dataset_converted_externally_to_rlds.py +84 -0
- data/preprocess_scripts/stanford_mask_vit_converted_externally_to_rlds.py +98 -0
- data/preprocess_scripts/stanford_robocook_converted_externally_to_rlds.py +89 -0
- data/preprocess_scripts/taco_play.py +98 -0
- data/preprocess_scripts/toto.py +82 -0
- data/preprocess_scripts/twinvla_benchmark.py +81 -0
- data/preprocess_scripts/ucsd_kitchen_dataset_converted_externally_to_rlds.py +91 -0
- data/preprocess_scripts/ucsd_pick_and_place_dataset_converted_externally_to_rlds.py +90 -0
data/preprocess_scripts/agilex.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import random
|
| 3 |
+
import os
|
| 4 |
+
import fnmatch
|
| 5 |
+
import random
|
| 6 |
+
|
| 7 |
+
import tensorflow as tf
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _parse_function(proto, precomputed_instr_embed_path):
|
| 11 |
+
keys_to_features = {
|
| 12 |
+
'action': tf.io.FixedLenFeature([], tf.string),
|
| 13 |
+
'base_action': tf.io.FixedLenFeature([], tf.string),
|
| 14 |
+
'qpos': tf.io.FixedLenFeature([], tf.string),
|
| 15 |
+
'qvel': tf.io.FixedLenFeature([], tf.string),
|
| 16 |
+
'cam_high': tf.io.FixedLenFeature([], tf.string),
|
| 17 |
+
'cam_left_wrist': tf.io.FixedLenFeature([], tf.string),
|
| 18 |
+
'cam_right_wrist': tf.io.FixedLenFeature([], tf.string),
|
| 19 |
+
'instruction': tf.io.FixedLenFeature([], tf.string),
|
| 20 |
+
'terminate_episode': tf.io.FixedLenFeature([], tf.int64)
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
parsed_features = tf.io.parse_single_example(proto, keys_to_features)
|
| 24 |
+
|
| 25 |
+
action = tf.io.parse_tensor(parsed_features['action'], out_type=tf.float32)
|
| 26 |
+
base_action = tf.io.parse_tensor(parsed_features['base_action'], out_type=tf.float32)
|
| 27 |
+
qpos = tf.io.parse_tensor(parsed_features['qpos'], out_type=tf.float32)
|
| 28 |
+
qvel = tf.io.parse_tensor(parsed_features['qvel'], out_type=tf.float32)
|
| 29 |
+
cam_high = tf.io.parse_tensor(parsed_features['cam_high'], out_type=tf.string)
|
| 30 |
+
cam_left_wrist = tf.io.parse_tensor(parsed_features['cam_left_wrist'], out_type=tf.string)
|
| 31 |
+
cam_right_wrist = tf.io.parse_tensor(parsed_features['cam_right_wrist'], out_type=tf.string)
|
| 32 |
+
# instruction = parsed_features['instruction']
|
| 33 |
+
terminate_episode = tf.cast(parsed_features['terminate_episode'], tf.int64)
|
| 34 |
+
|
| 35 |
+
cam_high = tf.image.decode_jpeg(cam_high, channels=3, dct_method='INTEGER_ACCURATE')
|
| 36 |
+
cam_left_wrist = tf.image.decode_jpeg(cam_left_wrist, channels=3, dct_method='INTEGER_ACCURATE')
|
| 37 |
+
cam_right_wrist = tf.image.decode_jpeg(cam_right_wrist, channels=3, dct_method='INTEGER_ACCURATE')
|
| 38 |
+
# BGR to RGB
|
| 39 |
+
cam_high = tf.reverse(cam_high, axis=[-1])
|
| 40 |
+
cam_left_wrist = tf.reverse(cam_left_wrist, axis=[-1])
|
| 41 |
+
cam_right_wrist = tf.reverse(cam_right_wrist, axis=[-1])
|
| 42 |
+
|
| 43 |
+
action = tf.reshape(action, [14])
|
| 44 |
+
base_action = tf.reshape(base_action, [2])
|
| 45 |
+
qpos = tf.reshape(qpos, [14])
|
| 46 |
+
qvel = tf.reshape(qvel, [14])
|
| 47 |
+
cam_high = tf.reshape(cam_high, [480, 640, 3])
|
| 48 |
+
cam_left_wrist = tf.reshape(cam_left_wrist, [480, 640, 3])
|
| 49 |
+
cam_right_wrist = tf.reshape(cam_right_wrist, [480, 640, 3])
|
| 50 |
+
|
| 51 |
+
return {
|
| 52 |
+
"action": action,
|
| 53 |
+
"base_action": base_action,
|
| 54 |
+
"qpos": qpos,
|
| 55 |
+
"qvel": qvel,
|
| 56 |
+
'observation':{
|
| 57 |
+
"cam_high": cam_high,
|
| 58 |
+
"cam_left_wrist": cam_left_wrist,
|
| 59 |
+
"cam_right_wrist": cam_right_wrist
|
| 60 |
+
},
|
| 61 |
+
"instruction": precomputed_instr_embed_path,
|
| 62 |
+
"terminate_episode": terminate_episode,
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def dataset_generator_from_tfrecords(seed):
|
| 67 |
+
tfrecord_path = './data/datasets/agilex/tfrecords/'
|
| 68 |
+
filepaths = []
|
| 69 |
+
for root, dirs, files in os.walk(tfrecord_path):
|
| 70 |
+
for filename in fnmatch.filter(files, '*.tfrecord'):
|
| 71 |
+
filepath = os.path.join(root, filename)
|
| 72 |
+
filepaths.append(filepath)
|
| 73 |
+
|
| 74 |
+
random.seed(seed)
|
| 75 |
+
random.shuffle(filepaths)
|
| 76 |
+
for filepath in filepaths:
|
| 77 |
+
raw_dataset = tf.data.TFRecordDataset(filepath)
|
| 78 |
+
dataset = raw_dataset.map(lambda x: _parse_function(x, os.path.dirname(filepath)))
|
| 79 |
+
yield {
|
| 80 |
+
'steps': dataset
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def load_dataset(seed):
|
| 85 |
+
dataset = tf.data.Dataset.from_generator(
|
| 86 |
+
lambda: dataset_generator_from_tfrecords(seed),
|
| 87 |
+
output_signature={
|
| 88 |
+
'steps': tf.data.DatasetSpec(
|
| 89 |
+
element_spec={
|
| 90 |
+
'action': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 91 |
+
'base_action': tf.TensorSpec(shape=(2), dtype=tf.float32),
|
| 92 |
+
'qpos': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 93 |
+
'qvel': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 94 |
+
'observation': {
|
| 95 |
+
'cam_high': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 96 |
+
'cam_left_wrist': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 97 |
+
'cam_right_wrist': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 98 |
+
},
|
| 99 |
+
'instruction': tf.TensorSpec(shape=(), dtype=tf.string),
|
| 100 |
+
'terminate_episode': tf.TensorSpec(shape=(), dtype=tf.int64),
|
| 101 |
+
}
|
| 102 |
+
)
|
| 103 |
+
}
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
return dataset
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 110 |
+
"""
|
| 111 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 112 |
+
"""
|
| 113 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 114 |
+
|
| 115 |
+
def process_step(step: dict) -> dict:
|
| 116 |
+
"""
|
| 117 |
+
Unify the action format and clean the task instruction.
|
| 118 |
+
|
| 119 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 120 |
+
"""
|
| 121 |
+
# Convert raw action to our action
|
| 122 |
+
old_action = step['action']
|
| 123 |
+
step['action'] = {}
|
| 124 |
+
action = step['action']
|
| 125 |
+
step['action']['terminate'] = step['terminate_episode']
|
| 126 |
+
# act-plus-plus/utils.py at main · MarkFzp/act-plus-plus
|
| 127 |
+
left_arm_pos = old_action[:6]
|
| 128 |
+
left_gripper_open = old_action[6:7] / 11.8997
|
| 129 |
+
right_arm_pos = old_action[7:13]
|
| 130 |
+
right_gripper_open = old_action[13:14] / 13.9231
|
| 131 |
+
|
| 132 |
+
# Base action is dummy (all zeros)
|
| 133 |
+
arm_action = tf.concat([left_arm_pos,left_gripper_open,right_arm_pos,right_gripper_open], axis=0)
|
| 134 |
+
action['arm_concat'] = arm_action
|
| 135 |
+
# Write the action format
|
| 136 |
+
action['format'] = tf.constant(
|
| 137 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_gripper_open")
|
| 138 |
+
|
| 139 |
+
state = step['observation']
|
| 140 |
+
left_qpos = step['qpos'][:6]
|
| 141 |
+
left_gripper_open = step['qpos'][6:7] / 4.7908 # rescale to [0, 1]
|
| 142 |
+
right_qpos = step['qpos'][7:13]
|
| 143 |
+
right_gripper_open = step['qpos'][13:14] / 4.7888 # rescale to [0, 1]
|
| 144 |
+
state['arm_concat'] = tf.concat([left_qpos, left_gripper_open,right_qpos, right_gripper_open], axis=0)
|
| 145 |
+
# # Write the state format
|
| 146 |
+
state['format'] = tf.constant(
|
| 147 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_gripper_open")
|
| 148 |
+
|
| 149 |
+
# We randomly sample [original,expanded,simplified] instructions. The ratio is 1:1:1
|
| 150 |
+
instr_type = tf.random.uniform(shape=(), minval=0, maxval=3, dtype=tf.int32)
|
| 151 |
+
# # NOTE bg : tf.random and tf.constant is buggy as it always return 0 (?)
|
| 152 |
+
# instr_type = tf.constant(instr_type)
|
| 153 |
+
# print(instr_type)
|
| 154 |
+
@tf.function
|
| 155 |
+
def f0():
|
| 156 |
+
return tf.strings.join([step['instruction'], tf.constant('/lang_embed_0.pt')])
|
| 157 |
+
@tf.function
|
| 158 |
+
def f1():
|
| 159 |
+
return tf.strings.join([step['instruction'], tf.constant('/lang_embed_1.pt')])
|
| 160 |
+
@tf.function
|
| 161 |
+
def f2():
|
| 162 |
+
index = tf.random.uniform(shape=(), minval=0, maxval=100, dtype=tf.int32)
|
| 163 |
+
return tf.strings.join([
|
| 164 |
+
step['instruction'], tf.constant('/lang_embed_'), tf.strings.as_string(index+2), tf.constant('.pt')])
|
| 165 |
+
|
| 166 |
+
instr = tf.case([
|
| 167 |
+
(tf.equal(instr_type, 0), f0),
|
| 168 |
+
(tf.equal(instr_type, 1), f1),
|
| 169 |
+
(tf.equal(instr_type, 2), f2)
|
| 170 |
+
], exclusive=True)
|
| 171 |
+
step['observation']['natural_language_instruction'] = instr
|
| 172 |
+
|
| 173 |
+
return step
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
if __name__ == "__main__":
|
| 177 |
+
import tensorflow_datasets as tfds
|
| 178 |
+
from data.utils import dataset_to_path
|
| 179 |
+
|
| 180 |
+
dataset = load_dataset(42)
|
| 181 |
+
|
| 182 |
+
for episode in dataset:
|
| 183 |
+
for step in episode['steps']:
|
| 184 |
+
step = process_step(step)
|
| 185 |
+
# save the images
|
| 186 |
+
print(step['observation']['natural_language_instruction'])
|
data/preprocess_scripts/aloha_box_into_pot.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
# Concatenate the action
|
| 15 |
+
step['action'] = {}
|
| 16 |
+
action = step['action']
|
| 17 |
+
action['arm_concat'] = action_dict['ee_6d_pos']
|
| 18 |
+
|
| 19 |
+
# Write the action format
|
| 20 |
+
action['format'] = tf.constant(
|
| 21 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Convert raw state to our state
|
| 25 |
+
# Robot state
|
| 26 |
+
state_dict = step['observation']['state']
|
| 27 |
+
state = {}
|
| 28 |
+
state['arm_concat'] = state_dict
|
| 29 |
+
|
| 30 |
+
# Write the state format
|
| 31 |
+
state['format'] = tf.constant(
|
| 32 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 33 |
+
)
|
| 34 |
+
# Clean the task instruction
|
| 35 |
+
# Define the replacements (old, new) as a dictionary
|
| 36 |
+
replacements = {
|
| 37 |
+
'_': ' ',
|
| 38 |
+
'1f': ' ',
|
| 39 |
+
'4f': ' ',
|
| 40 |
+
'-': ' ',
|
| 41 |
+
'50': ' ',
|
| 42 |
+
'55': ' ',
|
| 43 |
+
'56': ' ',
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
instr = step['language_instruction']
|
| 47 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 48 |
+
step['observation'] = state
|
| 49 |
+
step['observation']['natural_language_instruction'] = instr
|
| 50 |
+
|
| 51 |
+
return step
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
pass
|
data/preprocess_scripts/aloha_dish_drainer.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
# Concatenate the action
|
| 15 |
+
step['action'] = {}
|
| 16 |
+
action = step['action']
|
| 17 |
+
action['arm_concat'] = action_dict['ee_6d_pos']
|
| 18 |
+
|
| 19 |
+
# Write the action format
|
| 20 |
+
action['format'] = tf.constant(
|
| 21 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Convert raw state to our state
|
| 25 |
+
# Robot state
|
| 26 |
+
state_dict = step['observation']['state']
|
| 27 |
+
state = {}
|
| 28 |
+
state['arm_concat'] = state_dict
|
| 29 |
+
|
| 30 |
+
# Write the state format
|
| 31 |
+
state['format'] = tf.constant(
|
| 32 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 33 |
+
)
|
| 34 |
+
# Clean the task instruction
|
| 35 |
+
# Define the replacements (old, new) as a dictionary
|
| 36 |
+
replacements = {
|
| 37 |
+
'_': ' ',
|
| 38 |
+
'1f': ' ',
|
| 39 |
+
'4f': ' ',
|
| 40 |
+
'-': ' ',
|
| 41 |
+
'50': ' ',
|
| 42 |
+
'55': ' ',
|
| 43 |
+
'56': ' ',
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
instr = step['language_instruction']
|
| 47 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 48 |
+
step['observation'] = state
|
| 49 |
+
step['observation']['natural_language_instruction'] = instr
|
| 50 |
+
|
| 51 |
+
return step
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
pass
|
data/preprocess_scripts/aloha_handover_box.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
# Concatenate the action
|
| 15 |
+
step['action'] = {}
|
| 16 |
+
action = step['action']
|
| 17 |
+
action['arm_concat'] = action_dict['ee_6d_pos']
|
| 18 |
+
|
| 19 |
+
# Write the action format
|
| 20 |
+
action['format'] = tf.constant(
|
| 21 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Convert raw state to our state
|
| 25 |
+
# Robot state
|
| 26 |
+
state_dict = step['observation']['state']
|
| 27 |
+
state = {}
|
| 28 |
+
state['arm_concat'] = state_dict
|
| 29 |
+
|
| 30 |
+
# Write the state format
|
| 31 |
+
state['format'] = tf.constant(
|
| 32 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 33 |
+
)
|
| 34 |
+
# Clean the task instruction
|
| 35 |
+
# Define the replacements (old, new) as a dictionary
|
| 36 |
+
replacements = {
|
| 37 |
+
'_': ' ',
|
| 38 |
+
'1f': ' ',
|
| 39 |
+
'4f': ' ',
|
| 40 |
+
'-': ' ',
|
| 41 |
+
'50': ' ',
|
| 42 |
+
'55': ' ',
|
| 43 |
+
'56': ' ',
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
instr = step['language_instruction']
|
| 47 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 48 |
+
step['observation'] = state
|
| 49 |
+
step['observation']['natural_language_instruction'] = instr
|
| 50 |
+
|
| 51 |
+
return step
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
pass
|
data/preprocess_scripts/aloha_lift_box.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
# Concatenate the action
|
| 15 |
+
step['action'] = {}
|
| 16 |
+
action = step['action']
|
| 17 |
+
action['arm_concat'] = action_dict['ee_6d_pos']
|
| 18 |
+
|
| 19 |
+
# Write the action format
|
| 20 |
+
action['format'] = tf.constant(
|
| 21 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Convert raw state to our state
|
| 25 |
+
# Robot state
|
| 26 |
+
state_dict = step['observation']['state']
|
| 27 |
+
state = {}
|
| 28 |
+
state['arm_concat'] = state_dict
|
| 29 |
+
|
| 30 |
+
# Write the state format
|
| 31 |
+
state['format'] = tf.constant(
|
| 32 |
+
"left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_0,left_eef_angle_1,left_eef_angle_2,left_eef_angle_3,left_eef_angle_4,left_eef_angle_5,left_gripper_open,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_0,right_eef_angle_1,right_eef_angle_2,right_eef_angle_3,right_eef_angle_4,right_eef_angle_5,right_gripper_open"
|
| 33 |
+
)
|
| 34 |
+
# Clean the task instruction
|
| 35 |
+
# Define the replacements (old, new) as a dictionary
|
| 36 |
+
replacements = {
|
| 37 |
+
'_': ' ',
|
| 38 |
+
'1f': ' ',
|
| 39 |
+
'4f': ' ',
|
| 40 |
+
'-': ' ',
|
| 41 |
+
'50': ' ',
|
| 42 |
+
'55': ' ',
|
| 43 |
+
'56': ' ',
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
instr = step['language_instruction']
|
| 47 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 48 |
+
step['observation'] = state
|
| 49 |
+
step['observation']['natural_language_instruction'] = instr
|
| 50 |
+
|
| 51 |
+
return step
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
pass
|
data/preprocess_scripts/aloha_mobile.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import h5py
|
| 6 |
+
import numpy as np
|
| 7 |
+
from tqdm import tqdm
|
| 8 |
+
import os
|
| 9 |
+
import imageio
|
| 10 |
+
import concurrent.futures
|
| 11 |
+
import fnmatch
|
| 12 |
+
import cv2
|
| 13 |
+
import random
|
| 14 |
+
|
| 15 |
+
def _parse_function(proto):
|
| 16 |
+
keys_to_features = {
|
| 17 |
+
'action': tf.io.FixedLenFeature([], tf.string),
|
| 18 |
+
'base_action': tf.io.FixedLenFeature([], tf.string),
|
| 19 |
+
'qpos': tf.io.FixedLenFeature([], tf.string),
|
| 20 |
+
'qvel': tf.io.FixedLenFeature([], tf.string),
|
| 21 |
+
'cam_high': tf.io.FixedLenFeature([], tf.string),
|
| 22 |
+
'cam_left_wrist': tf.io.FixedLenFeature([], tf.string),
|
| 23 |
+
'cam_right_wrist': tf.io.FixedLenFeature([], tf.string),
|
| 24 |
+
'instruction': tf.io.FixedLenFeature([], tf.string),
|
| 25 |
+
'terminate_episode': tf.io.FixedLenFeature([], tf.int64)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
parsed_features = tf.io.parse_single_example(proto, keys_to_features)
|
| 29 |
+
|
| 30 |
+
action = tf.io.parse_tensor(parsed_features['action'], out_type=tf.float32)
|
| 31 |
+
base_action = tf.io.parse_tensor(parsed_features['base_action'], out_type=tf.float32)
|
| 32 |
+
qpos = tf.io.parse_tensor(parsed_features['qpos'], out_type=tf.float32)
|
| 33 |
+
qvel = tf.io.parse_tensor(parsed_features['qvel'], out_type=tf.float32)
|
| 34 |
+
cam_high = tf.io.parse_tensor(parsed_features['cam_high'], out_type=tf.uint8)
|
| 35 |
+
cam_left_wrist = tf.io.parse_tensor(parsed_features['cam_left_wrist'], out_type=tf.uint8)
|
| 36 |
+
cam_right_wrist = tf.io.parse_tensor(parsed_features['cam_right_wrist'], out_type=tf.uint8)
|
| 37 |
+
instruction = parsed_features['instruction']
|
| 38 |
+
terminate_episode = tf.cast(parsed_features['terminate_episode'], tf.int64)
|
| 39 |
+
action = tf.reshape(action, [14])
|
| 40 |
+
base_action = tf.reshape(base_action, [2])
|
| 41 |
+
qpos = tf.reshape(qpos, [14])
|
| 42 |
+
qvel = tf.reshape(qvel, [14])
|
| 43 |
+
cam_high = tf.reshape(cam_high, [480, 640, 3])
|
| 44 |
+
cam_left_wrist = tf.reshape(cam_left_wrist, [480, 640, 3])
|
| 45 |
+
cam_right_wrist = tf.reshape(cam_right_wrist, [480, 640, 3])
|
| 46 |
+
|
| 47 |
+
return {
|
| 48 |
+
"action": action,
|
| 49 |
+
"base_action": base_action,
|
| 50 |
+
"qpos": qpos,
|
| 51 |
+
"qvel": qvel,
|
| 52 |
+
'observation':{
|
| 53 |
+
"cam_high": cam_high,
|
| 54 |
+
"cam_left_wrist": cam_left_wrist,
|
| 55 |
+
"cam_right_wrist": cam_right_wrist
|
| 56 |
+
},
|
| 57 |
+
"instruction": instruction,
|
| 58 |
+
"terminate_episode": terminate_episode
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
def dataset_generator_from_tfrecords(seed):
|
| 62 |
+
tfrecord_path = './data/datasets/aloha/tfrecords/aloha_mobile/'
|
| 63 |
+
datasets = []
|
| 64 |
+
filepaths = []
|
| 65 |
+
for root, dirs, files in os.walk(tfrecord_path):
|
| 66 |
+
for filename in fnmatch.filter(files, '*.tfrecord'):
|
| 67 |
+
filepath = os.path.join(root, filename)
|
| 68 |
+
filepaths.append(filepath)
|
| 69 |
+
|
| 70 |
+
random.seed(seed)
|
| 71 |
+
random.shuffle(filepaths)
|
| 72 |
+
for filepath in filepaths:
|
| 73 |
+
raw_dataset = tf.data.TFRecordDataset(filepath)
|
| 74 |
+
dataset = raw_dataset.map(_parse_function)
|
| 75 |
+
yield {
|
| 76 |
+
'steps': dataset
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
def load_dataset(seed):
|
| 80 |
+
dataset = tf.data.Dataset.from_generator(
|
| 81 |
+
lambda: dataset_generator_from_tfrecords(seed),
|
| 82 |
+
output_signature={
|
| 83 |
+
'steps': tf.data.DatasetSpec(
|
| 84 |
+
element_spec={
|
| 85 |
+
'action': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 86 |
+
'base_action': tf.TensorSpec(shape=(2), dtype=tf.float32),
|
| 87 |
+
'qpos': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 88 |
+
'qvel': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 89 |
+
'observation': {
|
| 90 |
+
'cam_high': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 91 |
+
'cam_left_wrist': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 92 |
+
'cam_right_wrist': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 93 |
+
},
|
| 94 |
+
'instruction': tf.TensorSpec(shape=(), dtype=tf.string),
|
| 95 |
+
'terminate_episode': tf.TensorSpec(shape=(), dtype=tf.int64)
|
| 96 |
+
}
|
| 97 |
+
)
|
| 98 |
+
}
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
return dataset
|
| 102 |
+
|
| 103 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 104 |
+
"""
|
| 105 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 106 |
+
"""
|
| 107 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def process_step(step: dict) -> dict:
|
| 111 |
+
"""
|
| 112 |
+
Unify the action format and clean the task instruction.
|
| 113 |
+
|
| 114 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 115 |
+
"""
|
| 116 |
+
# Convert raw action to our action
|
| 117 |
+
old_action = step['action']
|
| 118 |
+
step['action'] = {}
|
| 119 |
+
action = step['action']
|
| 120 |
+
step['action']['terminate'] = step['terminate_episode']
|
| 121 |
+
# act-plus-plus/utils.py at main · MarkFzp/act-plus-plus
|
| 122 |
+
left_arm_pos = old_action[:6]
|
| 123 |
+
left_gripper_open = old_action[6:7]
|
| 124 |
+
right_arm_pos = old_action[7:13]
|
| 125 |
+
right_gripper_open = old_action[13:14]
|
| 126 |
+
|
| 127 |
+
base_vel_y = step['base_action'][:1]
|
| 128 |
+
base_delta_ang = step['base_action'][1:]
|
| 129 |
+
base_action = tf.concat([base_vel_y, base_delta_ang], axis=0)
|
| 130 |
+
# # No base found
|
| 131 |
+
arm_action = tf.concat([left_arm_pos,left_gripper_open,right_arm_pos,right_gripper_open], axis=0)
|
| 132 |
+
action['arm_concat'] = arm_action
|
| 133 |
+
action['base_concat'] = base_action
|
| 134 |
+
# # Write the action format
|
| 135 |
+
action['format'] = tf.constant(
|
| 136 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_gripper_open,base_vel_y,base_angular_vel")
|
| 137 |
+
|
| 138 |
+
state = step['observation']
|
| 139 |
+
left_qpos = step['qpos'][:6]
|
| 140 |
+
left_gripper_open = step['qpos'][6:7]
|
| 141 |
+
right_qpos = step['qpos'][7:13]
|
| 142 |
+
right_gripper_open = step['qpos'][13:14]
|
| 143 |
+
left_qvel = step['qvel'][:6]
|
| 144 |
+
# left_gripper_joint_vel = step['qvel'][6:7]
|
| 145 |
+
right_qvel = step['qvel'][7:13]
|
| 146 |
+
# right_gripper_joint_vel = step['qvel'][13:14]
|
| 147 |
+
|
| 148 |
+
state['arm_concat'] = tf.concat([left_qpos, left_qvel, left_gripper_open, right_qpos, right_qvel, right_gripper_open], axis=0)
|
| 149 |
+
# # Write the state format
|
| 150 |
+
state['format'] = tf.constant(
|
| 151 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_arm_joint_0_vel,left_arm_joint_1_vel,left_arm_joint_2_vel,left_arm_joint_3_vel,left_arm_joint_4_vel,left_arm_joint_5_vel,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_arm_joint_0_vel,right_arm_joint_1_vel,right_arm_joint_2_vel,right_arm_joint_3_vel,right_arm_joint_4_vel,right_arm_joint_5_vel,right_gripper_open")
|
| 152 |
+
|
| 153 |
+
# Clean the task instruction
|
| 154 |
+
# Define the replacements (old, new) as a dictionary
|
| 155 |
+
replacements = {
|
| 156 |
+
'_': ' ',
|
| 157 |
+
'1f': ' ',
|
| 158 |
+
'4f': ' ',
|
| 159 |
+
'-': ' ',
|
| 160 |
+
'50': ' ',
|
| 161 |
+
'55': ' ',
|
| 162 |
+
'56': ' ',
|
| 163 |
+
|
| 164 |
+
}
|
| 165 |
+
instr = step['instruction']
|
| 166 |
+
instr = clean_task_instruction(instr, replacements)
|
| 167 |
+
step['observation']['natural_language_instruction'] = instr
|
| 168 |
+
|
| 169 |
+
return step
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
if __name__ == "__main__":
|
| 173 |
+
import tensorflow_datasets as tfds
|
| 174 |
+
from data.utils import dataset_to_path
|
| 175 |
+
|
| 176 |
+
DATASET_DIR = '/mnt/d/aloha/'
|
| 177 |
+
DATASET_NAME = 'dataset'
|
| 178 |
+
# Load the dataset
|
| 179 |
+
dataset = load_dataset()
|
| 180 |
+
for data in dataset.take(1):
|
| 181 |
+
for step in data['steps'].take(1):
|
| 182 |
+
from IPython import embed; embed()
|
| 183 |
+
print(step)
|
data/preprocess_scripts/aloha_static.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import h5py
|
| 6 |
+
import numpy as np
|
| 7 |
+
from tqdm import tqdm
|
| 8 |
+
import os
|
| 9 |
+
import imageio
|
| 10 |
+
import concurrent.futures
|
| 11 |
+
import fnmatch
|
| 12 |
+
import cv2
|
| 13 |
+
import random
|
| 14 |
+
|
| 15 |
+
def get_all_hdf5s(root_dir):
|
| 16 |
+
num_files = 0
|
| 17 |
+
for root, dirs, files in os.walk(root_dir):
|
| 18 |
+
for filename in fnmatch.filter(files, '*.hdf5'):
|
| 19 |
+
num_files += 1
|
| 20 |
+
return num_files
|
| 21 |
+
|
| 22 |
+
def stash_image_into_observation(step):
|
| 23 |
+
step['observation'] = {'cam_high': [], 'cam_left_wrist': [], 'cam_right_wrist':[], 'cam_low':[] }
|
| 24 |
+
step['observation']['cam_high'] = step['cam_high']
|
| 25 |
+
step['observation']['cam_left_wrist'] = step['cam_left_wrist']
|
| 26 |
+
step['observation']['cam_right_wrist'] = step['cam_right_wrist']
|
| 27 |
+
step['observation']['cam_low'] = step['cam_low']
|
| 28 |
+
return step
|
| 29 |
+
|
| 30 |
+
def _parse_function(proto):
|
| 31 |
+
keys_to_features = {
|
| 32 |
+
'action': tf.io.FixedLenFeature([], tf.string),
|
| 33 |
+
'qpos': tf.io.FixedLenFeature([], tf.string),
|
| 34 |
+
'qvel': tf.io.FixedLenFeature([], tf.string),
|
| 35 |
+
'cam_high': tf.io.FixedLenFeature([], tf.string),
|
| 36 |
+
'cam_left_wrist': tf.io.FixedLenFeature([], tf.string),
|
| 37 |
+
'cam_right_wrist': tf.io.FixedLenFeature([], tf.string),
|
| 38 |
+
'cam_low': tf.io.FixedLenFeature([], tf.string),
|
| 39 |
+
'instruction': tf.io.FixedLenFeature([], tf.string),
|
| 40 |
+
'terminate_episode': tf.io.FixedLenFeature([], tf.int64)
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
parsed_features = tf.io.parse_single_example(proto, keys_to_features)
|
| 44 |
+
|
| 45 |
+
action = tf.io.parse_tensor(parsed_features['action'], out_type=tf.float32)
|
| 46 |
+
qpos = tf.io.parse_tensor(parsed_features['qpos'], out_type=tf.float32)
|
| 47 |
+
qvel = tf.io.parse_tensor(parsed_features['qvel'], out_type=tf.float32)
|
| 48 |
+
cam_high = tf.io.parse_tensor(parsed_features['cam_high'], out_type=tf.uint8)
|
| 49 |
+
cam_left_wrist = tf.io.parse_tensor(parsed_features['cam_left_wrist'], out_type=tf.uint8)
|
| 50 |
+
cam_right_wrist = tf.io.parse_tensor(parsed_features['cam_right_wrist'], out_type=tf.uint8)
|
| 51 |
+
cam_low = tf.io.parse_tensor(parsed_features['cam_low'], out_type=tf.uint8)
|
| 52 |
+
instruction = parsed_features['instruction']
|
| 53 |
+
terminate_episode = tf.cast(parsed_features['terminate_episode'], tf.int64)
|
| 54 |
+
action = tf.reshape(action, [14])
|
| 55 |
+
qpos = tf.reshape(qpos, [14])
|
| 56 |
+
qvel = tf.reshape(qvel, [14])
|
| 57 |
+
cam_high = tf.reshape(cam_high, [480, 640, 3])
|
| 58 |
+
cam_left_wrist = tf.reshape(cam_left_wrist, [480, 640, 3])
|
| 59 |
+
cam_right_wrist = tf.reshape(cam_right_wrist, [480, 640, 3])
|
| 60 |
+
cam_low = tf.reshape(cam_low, [480, 640, 3])
|
| 61 |
+
return {
|
| 62 |
+
"action": action,
|
| 63 |
+
"qpos": qpos,
|
| 64 |
+
"qvel": qvel,
|
| 65 |
+
'observation':{
|
| 66 |
+
"cam_high": cam_high,
|
| 67 |
+
"cam_left_wrist": cam_left_wrist,
|
| 68 |
+
"cam_right_wrist": cam_right_wrist,
|
| 69 |
+
"cam_low":cam_low
|
| 70 |
+
},
|
| 71 |
+
"instruction": instruction,
|
| 72 |
+
"terminate_episode": terminate_episode
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
def dataset_generator_from_tfrecords(seed):
|
| 76 |
+
tfrecord_path = './data/datasets/aloha/tfrecords/aloha_static_cotraining_datasets/'
|
| 77 |
+
datasets = []
|
| 78 |
+
filepaths = []
|
| 79 |
+
for root, dirs, files in os.walk(tfrecord_path):
|
| 80 |
+
for filename in fnmatch.filter(files, '*.tfrecord'):
|
| 81 |
+
filepath = os.path.join(root, filename)
|
| 82 |
+
filepaths.append(filepath)
|
| 83 |
+
|
| 84 |
+
random.seed(seed)
|
| 85 |
+
random.shuffle(filepaths)
|
| 86 |
+
for filepath in filepaths:
|
| 87 |
+
raw_dataset = tf.data.TFRecordDataset(filepath)
|
| 88 |
+
dataset = raw_dataset.map(_parse_function)
|
| 89 |
+
yield {
|
| 90 |
+
'steps': dataset
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
def load_dataset(seed):
|
| 94 |
+
dataset = tf.data.Dataset.from_generator(
|
| 95 |
+
lambda: dataset_generator_from_tfrecords(seed),
|
| 96 |
+
output_signature={
|
| 97 |
+
'steps': tf.data.DatasetSpec(
|
| 98 |
+
element_spec={
|
| 99 |
+
'action': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 100 |
+
'qpos': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 101 |
+
'qvel': tf.TensorSpec(shape=(14), dtype=tf.float32),
|
| 102 |
+
'observation': {
|
| 103 |
+
'cam_high': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 104 |
+
'cam_left_wrist': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 105 |
+
'cam_right_wrist': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 106 |
+
'cam_low': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 107 |
+
},
|
| 108 |
+
'instruction': tf.TensorSpec(shape=(), dtype=tf.string),
|
| 109 |
+
'terminate_episode': tf.TensorSpec(shape=(), dtype=tf.int64)
|
| 110 |
+
}
|
| 111 |
+
)
|
| 112 |
+
}
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
return dataset
|
| 116 |
+
|
| 117 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 118 |
+
"""
|
| 119 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 120 |
+
"""
|
| 121 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def process_step(step: dict) -> dict:
|
| 125 |
+
"""
|
| 126 |
+
Unify the action format and clean the task instruction.
|
| 127 |
+
|
| 128 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 129 |
+
"""
|
| 130 |
+
# Convert raw action to our action
|
| 131 |
+
old_action = step['action']
|
| 132 |
+
step['action'] = {}
|
| 133 |
+
action = step['action']
|
| 134 |
+
step['action']['terminate'] = step['terminate_episode']
|
| 135 |
+
# act-plus-plus/utils.py at main · MarkFzp/act-plus-plus
|
| 136 |
+
left_arm_pos = old_action[:6]
|
| 137 |
+
left_gripper_open = old_action[6:7]
|
| 138 |
+
right_arm_pos = old_action[7:13]
|
| 139 |
+
right_gripper_open = old_action[13:14]
|
| 140 |
+
|
| 141 |
+
arm_action = tf.concat([left_arm_pos,left_gripper_open,right_arm_pos,right_gripper_open], axis=0)
|
| 142 |
+
|
| 143 |
+
action['arm_concat'] = arm_action
|
| 144 |
+
# # Write the action format
|
| 145 |
+
action['format'] = tf.constant(
|
| 146 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_gripper_open")
|
| 147 |
+
|
| 148 |
+
state = step['observation']
|
| 149 |
+
left_qpos = step['qpos'][:6]
|
| 150 |
+
left_gripper_open = step['qpos'][6:7]
|
| 151 |
+
right_qpos = step['qpos'][7:13]
|
| 152 |
+
right_gripper_open = step['qpos'][13:14]
|
| 153 |
+
left_qvel = step['qvel'][:6]
|
| 154 |
+
# left_gripper_joint_vel = step['qvel'][6:7]
|
| 155 |
+
right_qvel = step['qvel'][7:13]
|
| 156 |
+
# right_gripper_joint_vel = step['qvel'][13:14]
|
| 157 |
+
|
| 158 |
+
state['arm_concat'] = tf.concat([left_qpos, left_qvel, left_gripper_open, right_qpos, right_qvel, right_gripper_open], axis=0)
|
| 159 |
+
# # Write the state format
|
| 160 |
+
state['format'] = tf.constant(
|
| 161 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_arm_joint_0_vel,left_arm_joint_1_vel,left_arm_joint_2_vel,left_arm_joint_3_vel,left_arm_joint_4_vel,left_arm_joint_5_vel,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_arm_joint_0_vel,right_arm_joint_1_vel,right_arm_joint_2_vel,right_arm_joint_3_vel,right_arm_joint_4_vel,right_arm_joint_5_vel,right_gripper_open")
|
| 162 |
+
|
| 163 |
+
# Clean the task instruction
|
| 164 |
+
# Define the replacements (old, new) as a dictionary
|
| 165 |
+
replacements = {
|
| 166 |
+
'_': ' ',
|
| 167 |
+
'1f': ' ',
|
| 168 |
+
'4f': ' ',
|
| 169 |
+
'-': ' ',
|
| 170 |
+
'50': ' ',
|
| 171 |
+
'55': ' ',
|
| 172 |
+
'56': ' ',
|
| 173 |
+
|
| 174 |
+
}
|
| 175 |
+
instr = step['instruction']
|
| 176 |
+
instr = clean_task_instruction(instr, replacements)
|
| 177 |
+
step['observation']['natural_language_instruction'] = instr
|
| 178 |
+
|
| 179 |
+
return step
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
if __name__ == "__main__":
|
| 183 |
+
import tensorflow_datasets as tfds
|
| 184 |
+
from data.utils import dataset_to_path
|
| 185 |
+
|
| 186 |
+
DATASET_DIR = '/mnt/d/aloha/'
|
| 187 |
+
DATASET_NAME = 'dataset'
|
| 188 |
+
# Load the dataset
|
| 189 |
+
dataset = load_dataset()
|
| 190 |
+
for data in dataset.take(1):
|
| 191 |
+
for step in data['steps'].take(1):
|
| 192 |
+
from IPython import embed; embed()
|
| 193 |
+
print(step)
|
data/preprocess_scripts/asu_table_top_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.float32)))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_step(step: dict) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Unify the action format and clean the task instruction.
|
| 16 |
+
|
| 17 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 18 |
+
"""
|
| 19 |
+
# Convert raw action to our action
|
| 20 |
+
action = step['action']
|
| 21 |
+
# Robot action, consists of [7x joint velocities, 2x gripper velocities, 1x terminate episode].
|
| 22 |
+
# NOTE the dimension of action is actually 7, so only 7x joint velocities exists
|
| 23 |
+
joint_vel = action[:7]
|
| 24 |
+
gripper_vel = action[7:9]
|
| 25 |
+
# there are extra action_delta information
|
| 26 |
+
# Robot delta action, consists of [7x joint velocities, 2x gripper velocities, 1x terminate episode].
|
| 27 |
+
# action_delta = step['action_delta']
|
| 28 |
+
|
| 29 |
+
# Concatenate the action
|
| 30 |
+
step['action'] = {}
|
| 31 |
+
action = step['action']
|
| 32 |
+
action['arm_concat'] = tf.concat([joint_vel, gripper_vel], axis=0)
|
| 33 |
+
action['terminate'] = step['is_terminal']
|
| 34 |
+
|
| 35 |
+
# Write the action format
|
| 36 |
+
action['format'] = tf.constant(
|
| 37 |
+
"arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,gripper_joint_0_vel,gripper_joint_1_vel")
|
| 38 |
+
|
| 39 |
+
# Convert raw state to our state
|
| 40 |
+
state = step['observation']
|
| 41 |
+
state_vec = state['state']
|
| 42 |
+
# Robot state, consists of [6x robot joint angles, 1x gripper position].
|
| 43 |
+
arm_joint_ang = state_vec[:6]
|
| 44 |
+
grip_pos = state_vec[6:7]
|
| 45 |
+
# Robot joint velocity, consists of [6x robot joint angles, 1x gripper position].
|
| 46 |
+
state_vel = state['state_vel']
|
| 47 |
+
arm_joint_vel = state_vel[:6]
|
| 48 |
+
grip_vel = state_vel[6:7]
|
| 49 |
+
|
| 50 |
+
# Concatenate the state
|
| 51 |
+
state['arm_concat'] = tf.concat([arm_joint_ang,arm_joint_vel,grip_pos,grip_vel], axis=0)
|
| 52 |
+
|
| 53 |
+
# Write the state format
|
| 54 |
+
state['format'] = tf.constant(
|
| 55 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,gripper_joint_0_pos,gripper_joint_0_vel")
|
| 56 |
+
|
| 57 |
+
# Clean the task instruction
|
| 58 |
+
# Define the replacements (old, new) as a dictionary
|
| 59 |
+
replacements = {
|
| 60 |
+
'_': ' ',
|
| 61 |
+
'1f': ' ',
|
| 62 |
+
'4f': ' ',
|
| 63 |
+
'-': ' ',
|
| 64 |
+
'50': ' ',
|
| 65 |
+
'55': ' ',
|
| 66 |
+
'56': ' ',
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
instr = step['language_instruction']
|
| 70 |
+
instr = clean_task_instruction(instr, replacements)
|
| 71 |
+
step['observation']['natural_language_instruction'] = instr
|
| 72 |
+
|
| 73 |
+
return step
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
import tensorflow_datasets as tfds
|
| 78 |
+
from data.utils import dataset_to_path
|
| 79 |
+
|
| 80 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 81 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 82 |
+
# Load the dataset
|
| 83 |
+
dataset = tfds.builder_from_directory(
|
| 84 |
+
builder_dir=dataset_to_path(
|
| 85 |
+
DATASET_NAME, DATASET_DIR))
|
| 86 |
+
dataset = dataset.as_dataset(split='all')
|
| 87 |
+
|
| 88 |
+
# Inspect the dataset
|
| 89 |
+
for episode in dataset:
|
| 90 |
+
for step in episode['steps']:
|
| 91 |
+
print(step)
|
data/preprocess_scripts/austin_sailor_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, \
|
| 4 |
+
quaternion_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.float32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
# Robot action, consists of [3x ee relative pos, 3x ee relative rotation, 1x gripper action].
|
| 22 |
+
action = step['action']
|
| 23 |
+
eef_delta_pos = action[:3]
|
| 24 |
+
eef_ang = action[3:6]
|
| 25 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 26 |
+
grip_open = tf.expand_dims(1 - action[6], axis=0)
|
| 27 |
+
|
| 28 |
+
# Concatenate the action
|
| 29 |
+
# action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 30 |
+
step['action'] = {}
|
| 31 |
+
action = step['action']
|
| 32 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 33 |
+
action['terminate'] = step['is_terminal']
|
| 34 |
+
|
| 35 |
+
# Write the action format
|
| 36 |
+
action['format'] = tf.constant(
|
| 37 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 38 |
+
|
| 39 |
+
# Convert raw state to our state
|
| 40 |
+
state = step['observation']['state']
|
| 41 |
+
joint_pos = step['observation']['state_joint']
|
| 42 |
+
# Default robot state, consists of [3x robot ee pos, 3x ee quat, 1x gripper state].
|
| 43 |
+
eef_pos = state[:3]
|
| 44 |
+
eef_quat = state[3:7]
|
| 45 |
+
eef_ang = quaternion_to_rotation_matrix(eef_quat)
|
| 46 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 47 |
+
gripper_joint_pos = state[7:8] * 12.85 # rescale to [0, 1]
|
| 48 |
+
|
| 49 |
+
# Concatenate the state
|
| 50 |
+
state = step['observation']
|
| 51 |
+
state['arm_concat'] = tf.concat([joint_pos,gripper_joint_pos,eef_pos,eef_ang], axis=0)
|
| 52 |
+
|
| 53 |
+
# Write the state format
|
| 54 |
+
state['format'] = tf.constant(
|
| 55 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,gripper_joint_0_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 56 |
+
|
| 57 |
+
# Clean the task instruction
|
| 58 |
+
# Define the replacements (old, new) as a dictionary
|
| 59 |
+
replacements = {
|
| 60 |
+
'_': ' ',
|
| 61 |
+
'1f': ' ',
|
| 62 |
+
'4f': ' ',
|
| 63 |
+
'-': ' ',
|
| 64 |
+
'50': ' ',
|
| 65 |
+
'55': ' ',
|
| 66 |
+
'56': ' ',
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
instr = step['language_instruction']
|
| 70 |
+
instr = clean_task_instruction(instr, replacements)
|
| 71 |
+
step['observation']['natural_language_instruction'] = instr
|
| 72 |
+
|
| 73 |
+
return step
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
import tensorflow_datasets as tfds
|
| 78 |
+
from data.utils import dataset_to_path
|
| 79 |
+
|
| 80 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 81 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 82 |
+
# Load the dataset
|
| 83 |
+
dataset = tfds.builder_from_directory(
|
| 84 |
+
builder_dir=dataset_to_path(
|
| 85 |
+
DATASET_NAME, DATASET_DIR))
|
| 86 |
+
dataset = dataset.as_dataset(split='all')
|
| 87 |
+
|
| 88 |
+
# Inspect the dataset
|
| 89 |
+
for episode in dataset:
|
| 90 |
+
for step in episode['steps']:
|
| 91 |
+
print(step)
|
data/preprocess_scripts/austin_sirius_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.float32)))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_step(step: dict) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Unify the action format and clean the task instruction.
|
| 16 |
+
|
| 17 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
# Robot action, consists of [3x ee relative pos, 3x ee relative rotation, 1x gripper action].
|
| 22 |
+
action = step['action']
|
| 23 |
+
eef_pos = action[:3]
|
| 24 |
+
eef_ang = action[3:6]
|
| 25 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 26 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 27 |
+
grip_open = tf.expand_dims(1 - action[6], axis=0)
|
| 28 |
+
|
| 29 |
+
# Concatenate the action
|
| 30 |
+
# action['arm_concat'] = tf.concat([eef_pos, eef_ang, grip_open], axis=0)
|
| 31 |
+
step['action'] = {}
|
| 32 |
+
action = step['action']
|
| 33 |
+
|
| 34 |
+
action['arm_concat'] = tf.concat([eef_pos, eef_ang, grip_open], axis=0)
|
| 35 |
+
action['terminate'] = step['is_terminal']
|
| 36 |
+
|
| 37 |
+
# Write the action format
|
| 38 |
+
action['format'] = tf.constant(
|
| 39 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 40 |
+
|
| 41 |
+
# Convert raw state to our state
|
| 42 |
+
joint_pos = step['observation']['state'][:7]
|
| 43 |
+
grip_open = step['observation']['state'][7:8] * 12.55
|
| 44 |
+
state_ee = step['observation']['state_ee']
|
| 45 |
+
# Tensor (16,) End-effector state, represented as 4x4 homogeneous transformation matrix of ee pose.
|
| 46 |
+
transform_matrix = tf.transpose(tf.reshape(state_ee, (4, 4)))
|
| 47 |
+
eef_pos = transform_matrix[:3, 3]
|
| 48 |
+
rotation_matrix = transform_matrix[:3, :3]
|
| 49 |
+
eef_ang = rotation_matrix_to_ortho6d(rotation_matrix)
|
| 50 |
+
# Concatenate the state
|
| 51 |
+
|
| 52 |
+
state = step['observation']
|
| 53 |
+
state['arm_concat'] = tf.concat([joint_pos,grip_open,eef_pos,eef_ang], axis=0)
|
| 54 |
+
|
| 55 |
+
# Write the state format
|
| 56 |
+
state['format'] = tf.constant(
|
| 57 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,gripper_joint_0_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 58 |
+
|
| 59 |
+
# Clean the task instruction
|
| 60 |
+
# Define the replacements (old, new) as a dictionary
|
| 61 |
+
replacements = {
|
| 62 |
+
'_': ' ',
|
| 63 |
+
'1f': ' ',
|
| 64 |
+
'4f': ' ',
|
| 65 |
+
'-': ' ',
|
| 66 |
+
'50': ' ',
|
| 67 |
+
'55': ' ',
|
| 68 |
+
'56': ' ',
|
| 69 |
+
|
| 70 |
+
}
|
| 71 |
+
instr = step['language_instruction']
|
| 72 |
+
instr = clean_task_instruction(instr, replacements)
|
| 73 |
+
step['observation']['natural_language_instruction'] = instr
|
| 74 |
+
|
| 75 |
+
return step
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
import tensorflow_datasets as tfds
|
| 80 |
+
from data.utils import dataset_to_path
|
| 81 |
+
|
| 82 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 83 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 84 |
+
# Load the dataset
|
| 85 |
+
dataset = tfds.builder_from_directory(
|
| 86 |
+
builder_dir=dataset_to_path(
|
| 87 |
+
DATASET_NAME, DATASET_DIR))
|
| 88 |
+
dataset = dataset.as_dataset(split='all')
|
| 89 |
+
|
| 90 |
+
# Inspect the dataset
|
| 91 |
+
for episode in dataset:
|
| 92 |
+
for step in episode['steps']:
|
| 93 |
+
print(step)
|
data/preprocess_scripts/bc_z.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, \
|
| 4 |
+
euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.float32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# Convert raw action to our action
|
| 22 |
+
action = step['action']
|
| 23 |
+
# The next 10 actions for the positions. Each action is a 3D delta to add to current position.
|
| 24 |
+
eef_delta_pos = action['future/xyz_residual'][:3]
|
| 25 |
+
# The next 10 actions for the rotation. Each action is a 3D delta to add to the current axis angle.
|
| 26 |
+
eef_ang = action['future/axis_angle_residual'][:3]
|
| 27 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 28 |
+
# The next 10 actions for the gripper. Each action is the value the gripper closure should be changed to (notably it is not a delta.)
|
| 29 |
+
grip_open = tf.cast(tf.expand_dims(1 - action['future/target_close'][0], axis=0), dtype=tf.float32)
|
| 30 |
+
|
| 31 |
+
# Concatenate the action
|
| 32 |
+
step['action'] = {}
|
| 33 |
+
action = step['action']
|
| 34 |
+
|
| 35 |
+
action['terminate'] = step['is_terminal']
|
| 36 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 37 |
+
|
| 38 |
+
# Write the action format
|
| 39 |
+
action['format'] = tf.constant(
|
| 40 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 41 |
+
|
| 42 |
+
# Convert raw state to our state
|
| 43 |
+
state = step['observation']
|
| 44 |
+
|
| 45 |
+
gripper_ang = state['present/axis_angle']
|
| 46 |
+
gripper_ang = euler_to_rotation_matrix(gripper_ang)
|
| 47 |
+
gripper_ang = rotation_matrix_to_ortho6d(gripper_ang)
|
| 48 |
+
gripper_pos = state['present/xyz']
|
| 49 |
+
# How much the gripper is currently closed. Scaled from 0 to 1, but not all values from 0 to 1 are reachable. The range in the data is about 0.2 to 1
|
| 50 |
+
gripper_open = 1- state['present/sensed_close']
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# Concatenate the state
|
| 54 |
+
state = step['observation']
|
| 55 |
+
state['arm_concat'] = tf.concat([gripper_pos, gripper_ang, gripper_open], axis=0)
|
| 56 |
+
|
| 57 |
+
# Write the state format
|
| 58 |
+
state['format'] = tf.constant(
|
| 59 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 60 |
+
|
| 61 |
+
# Clean the task instruction
|
| 62 |
+
# Define the replacements (old, new) as a dictionary
|
| 63 |
+
replacements = {
|
| 64 |
+
'_': ' ',
|
| 65 |
+
'1f': ' ',
|
| 66 |
+
'4f': ' ',
|
| 67 |
+
'-': ' ',
|
| 68 |
+
'50': ' ',
|
| 69 |
+
'55': ' ',
|
| 70 |
+
'56': ' ',
|
| 71 |
+
|
| 72 |
+
}
|
| 73 |
+
instr = step['observation']['natural_language_instruction']
|
| 74 |
+
instr = clean_task_instruction(instr, replacements)
|
| 75 |
+
step['observation']['natural_language_instruction'] = instr
|
| 76 |
+
|
| 77 |
+
return step
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
import tensorflow_datasets as tfds
|
| 82 |
+
from data.utils import dataset_to_path
|
| 83 |
+
|
| 84 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 85 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 86 |
+
# Load the dataset
|
| 87 |
+
dataset = tfds.builder_from_directory(
|
| 88 |
+
builder_dir=dataset_to_path(
|
| 89 |
+
DATASET_NAME, DATASET_DIR))
|
| 90 |
+
dataset = dataset.as_dataset(split='all')
|
| 91 |
+
|
| 92 |
+
# Inspect the dataset
|
| 93 |
+
for episode in dataset:
|
| 94 |
+
for step in episode['steps']:
|
| 95 |
+
print(step)
|
data/preprocess_scripts/berkeley_fanuc_manipulation.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, \
|
| 4 |
+
quaternion_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
|
| 14 |
+
origin_action = step['action']
|
| 15 |
+
step['action']={}
|
| 16 |
+
action=step['action']
|
| 17 |
+
action['terminate'] = step['is_terminal']
|
| 18 |
+
# 6x end effector delta pose, 1x gripper position
|
| 19 |
+
eef_delta_pos = origin_action[:3]
|
| 20 |
+
eef_ang=origin_action[3:6]
|
| 21 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 22 |
+
# No base found
|
| 23 |
+
|
| 24 |
+
# Concatenate the action
|
| 25 |
+
action['arm_concat'] = tf.concat([eef_delta_pos,eef_ang],axis=0)
|
| 26 |
+
|
| 27 |
+
# Write the action format
|
| 28 |
+
action['format'] = tf.constant(
|
| 29 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w")
|
| 30 |
+
|
| 31 |
+
# Convert raw state to our state
|
| 32 |
+
state = step['observation']
|
| 33 |
+
# Concatenate the state
|
| 34 |
+
# [6x robot joint angles, 1x gripper open status, 6x robot joint velocities].
|
| 35 |
+
arm_joint_ang=state['state'][:6]
|
| 36 |
+
grip_open=1-state['state'][6:7]
|
| 37 |
+
# arm_joint_vel=state['state'][7:13] # all zeros
|
| 38 |
+
eef_pos = state['end_effector_state'][:3]
|
| 39 |
+
eef_ang = quaternion_to_rotation_matrix(state['end_effector_state'][3:])
|
| 40 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 41 |
+
state['arm_concat'] = tf.concat([arm_joint_ang,grip_open,eef_pos,eef_ang],axis=0)
|
| 42 |
+
|
| 43 |
+
# Write the state format
|
| 44 |
+
state['format'] = tf.constant(
|
| 45 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,gripper_open,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 46 |
+
|
| 47 |
+
# Clean the task instruction
|
| 48 |
+
# Define the replacements (old, new) as a dictionary
|
| 49 |
+
replacements = {
|
| 50 |
+
'_': ' ',
|
| 51 |
+
'1f': ' ',
|
| 52 |
+
'4f': ' ',
|
| 53 |
+
'-': ' ',
|
| 54 |
+
'50': ' ',
|
| 55 |
+
'55': ' ',
|
| 56 |
+
'56': ' ',
|
| 57 |
+
|
| 58 |
+
}
|
| 59 |
+
instr = step['language_instruction']
|
| 60 |
+
instr = clean_task_instruction(instr, replacements)
|
| 61 |
+
step['observation']['natural_language_instruction'] = instr
|
| 62 |
+
|
| 63 |
+
return step
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
import tensorflow_datasets as tfds
|
| 68 |
+
from data.utils import dataset_to_path
|
| 69 |
+
|
| 70 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 71 |
+
DATASET_NAME = 'berkeley_fanuc_manipulation'
|
| 72 |
+
# Load the dataset
|
| 73 |
+
dataset = tfds.builder_from_directory(
|
| 74 |
+
builder_dir=dataset_to_path(
|
| 75 |
+
DATASET_NAME, DATASET_DIR))
|
| 76 |
+
dataset = dataset.as_dataset(split='all')
|
| 77 |
+
|
| 78 |
+
# Inspect the dataset
|
| 79 |
+
for episode in dataset:
|
| 80 |
+
for step in episode['steps']:
|
| 81 |
+
print(step)
|
data/preprocess_scripts/berkeley_gnm_cory_hall.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix,\
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
|
| 14 |
+
origin_action = step['action']
|
| 15 |
+
step['action']={}
|
| 16 |
+
action=step['action']
|
| 17 |
+
action['terminate'] = step['is_terminal']
|
| 18 |
+
|
| 19 |
+
eef_pos=tf.cast(origin_action,dtype=tf.float32)
|
| 20 |
+
eef_ang=tf.cast(step['action_angle'][2:3],dtype=tf.float32)
|
| 21 |
+
eef_ang = euler_to_quaternion(tf.stack([0,0,eef_ang[0]],axis=0))
|
| 22 |
+
# No base found
|
| 23 |
+
|
| 24 |
+
# Concatenate the action
|
| 25 |
+
action['arm_concat'] = tf.concat([eef_pos,eef_ang],axis=0)
|
| 26 |
+
|
| 27 |
+
# Write the action format
|
| 28 |
+
action['format'] = tf.constant(
|
| 29 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w")
|
| 30 |
+
|
| 31 |
+
# Convert raw state to our state
|
| 32 |
+
state = step['observation']
|
| 33 |
+
# Concatenate the state
|
| 34 |
+
eef_pos=tf.cast(state['position'],dtype=tf.float32)
|
| 35 |
+
eef_ang=tf.cast(state['yaw'],dtype=tf.float32)
|
| 36 |
+
eef_ang = euler_to_rotation_matrix(tf.stack([0,0,eef_ang[0]],axis=0))
|
| 37 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 38 |
+
state['arm_concat'] = tf.concat([eef_pos,eef_ang],axis=0)
|
| 39 |
+
# Write the state format
|
| 40 |
+
state['format'] = tf.constant(
|
| 41 |
+
"eef_pos_x,eef_pos_y,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 42 |
+
|
| 43 |
+
# Clean the task instruction
|
| 44 |
+
# Define the replacements (old, new) as a dictionary
|
| 45 |
+
replacements = {
|
| 46 |
+
'_': ' ',
|
| 47 |
+
'1f': ' ',
|
| 48 |
+
'4f': ' ',
|
| 49 |
+
'-': ' ',
|
| 50 |
+
'50': ' ',
|
| 51 |
+
'55': ' ',
|
| 52 |
+
'56': ' ',
|
| 53 |
+
|
| 54 |
+
}
|
| 55 |
+
instr = step['language_instruction']
|
| 56 |
+
instr = clean_task_instruction(instr, replacements)
|
| 57 |
+
step['observation']['natural_language_instruction'] = instr
|
| 58 |
+
|
| 59 |
+
return step
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
import tensorflow_datasets as tfds
|
| 64 |
+
from data.utils import dataset_to_path
|
| 65 |
+
|
| 66 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 67 |
+
DATASET_NAME = 'berkeley_gnm_cory_hall'
|
| 68 |
+
# Load the dataset
|
| 69 |
+
dataset = tfds.builder_from_directory(
|
| 70 |
+
builder_dir=dataset_to_path(
|
| 71 |
+
DATASET_NAME, DATASET_DIR))
|
| 72 |
+
dataset = dataset.as_dataset(split='all')
|
| 73 |
+
|
| 74 |
+
# Inspect the dataset
|
| 75 |
+
for episode in dataset:
|
| 76 |
+
for step in episode['steps']:
|
| 77 |
+
print(step['action'][6:7])
|
| 78 |
+
|
data/preprocess_scripts/berkeley_gnm_recon.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix,\
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
|
| 14 |
+
origin_action = step['action']
|
| 15 |
+
step['action']={}
|
| 16 |
+
action=step['action']
|
| 17 |
+
action['terminate'] = step['is_terminal']
|
| 18 |
+
|
| 19 |
+
eef_pos=tf.cast(origin_action,dtype=tf.float32)
|
| 20 |
+
eef_ang=tf.cast(step['action_angle'][2:3],dtype=tf.float32)
|
| 21 |
+
eef_ang = euler_to_quaternion(tf.stack([0,0,eef_ang[0]],axis=0))
|
| 22 |
+
# No base found
|
| 23 |
+
|
| 24 |
+
# Concatenate the action
|
| 25 |
+
action['arm_concat'] = tf.concat([eef_pos,eef_ang],axis=0)
|
| 26 |
+
|
| 27 |
+
# Write the action format
|
| 28 |
+
action['format'] = tf.constant(
|
| 29 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w")
|
| 30 |
+
|
| 31 |
+
# Convert raw state to our state
|
| 32 |
+
state = step['observation']
|
| 33 |
+
# Concatenate the state
|
| 34 |
+
eef_pos=tf.cast(state['position'],dtype=tf.float32)
|
| 35 |
+
eef_ang=tf.cast(state['yaw'],dtype=tf.float32)
|
| 36 |
+
eef_ang = euler_to_rotation_matrix(tf.stack([0,0,eef_ang[0]],axis=0))
|
| 37 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 38 |
+
state['arm_concat'] = tf.concat([eef_pos/100,eef_ang],axis=0)
|
| 39 |
+
# Write the state format
|
| 40 |
+
state['format'] = tf.constant(
|
| 41 |
+
"eef_pos_x,eef_pos_y,eef_angle_x,eef_angle_y,eef_angle_z,eef_angle_w")
|
| 42 |
+
|
| 43 |
+
# Clean the task instruction
|
| 44 |
+
# Define the replacements (old, new) as a dictionary
|
| 45 |
+
replacements = {
|
| 46 |
+
'_': ' ',
|
| 47 |
+
'1f': ' ',
|
| 48 |
+
'4f': ' ',
|
| 49 |
+
'-': ' ',
|
| 50 |
+
'50': ' ',
|
| 51 |
+
'55': ' ',
|
| 52 |
+
'56': ' ',
|
| 53 |
+
|
| 54 |
+
}
|
| 55 |
+
instr = step['language_instruction']
|
| 56 |
+
instr = clean_task_instruction(instr, replacements)
|
| 57 |
+
step['observation']['natural_language_instruction'] = instr
|
| 58 |
+
|
| 59 |
+
return step
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
import tensorflow_datasets as tfds
|
| 64 |
+
from data.utils import dataset_to_path
|
| 65 |
+
|
| 66 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 67 |
+
DATASET_NAME = 'berkeley_gnm_recon'
|
| 68 |
+
# Load the dataset
|
| 69 |
+
dataset = tfds.builder_from_directory(
|
| 70 |
+
builder_dir=dataset_to_path(
|
| 71 |
+
DATASET_NAME, DATASET_DIR))
|
| 72 |
+
dataset = dataset.as_dataset(split='all')
|
| 73 |
+
|
| 74 |
+
# Inspect the dataset
|
| 75 |
+
for episode in dataset:
|
| 76 |
+
for step in episode['steps']:
|
| 77 |
+
print(step['action'][6:7])
|
| 78 |
+
|
data/preprocess_scripts/berkeley_mvp_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
# Robot action, consists of [7 delta joint pos,1x gripper binary state].
|
| 23 |
+
delta_joint_pos = action[:7]
|
| 24 |
+
grip_open = tf.expand_dims(1 - action[7], axis=0)
|
| 25 |
+
|
| 26 |
+
# Concatenate the action
|
| 27 |
+
# action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 28 |
+
step['action'] = {}
|
| 29 |
+
action = step['action']
|
| 30 |
+
action['arm_concat'] = tf.concat([delta_joint_pos, grip_open], axis=0)
|
| 31 |
+
action['terminate'] = step['is_terminal']
|
| 32 |
+
|
| 33 |
+
# Write the action format
|
| 34 |
+
action['format'] = tf.constant(
|
| 35 |
+
"arm_joint_0_delta_pos,arm_joint_1_delta_pos,arm_joint_2_delta_pos,arm_joint_3_delta_pos,arm_joint_4_delta_pos,arm_joint_5_delta_pos,arm_joint_6_delta_pos,gripper_open")
|
| 36 |
+
|
| 37 |
+
# Convert raw state to our state
|
| 38 |
+
state = step['observation']
|
| 39 |
+
# xArm joint positions (7 DoF).
|
| 40 |
+
arm_joint_pos = state['joint_pos']
|
| 41 |
+
# Binary gripper state (1 - closed, 0 - open)
|
| 42 |
+
grip_open = tf.expand_dims(1 - tf.cast(state['gripper'],dtype=tf.float32), axis=0)
|
| 43 |
+
# Gripper pose, robot frame, [3 position, 4 rotation]
|
| 44 |
+
gripper_pose = state['pose'][:3]
|
| 45 |
+
# gripper_ang = quaternion_to_euler(state['pose'][3:7])
|
| 46 |
+
gripper_ang = quaternion_to_rotation_matrix(state['pose'][3:7])
|
| 47 |
+
gripper_ang = rotation_matrix_to_ortho6d(gripper_ang)
|
| 48 |
+
|
| 49 |
+
# Concatenate the state
|
| 50 |
+
state['arm_concat'] = tf.concat([arm_joint_pos, gripper_pose,gripper_ang, grip_open], axis=0)
|
| 51 |
+
|
| 52 |
+
# Write the state format
|
| 53 |
+
state['format'] = tf.constant(
|
| 54 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 55 |
+
|
| 56 |
+
# Clean the task instruction
|
| 57 |
+
# Define the replacements (old, new) as a dictionary
|
| 58 |
+
replacements = {
|
| 59 |
+
'_': ' ',
|
| 60 |
+
'1f': ' ',
|
| 61 |
+
'4f': ' ',
|
| 62 |
+
'-': ' ',
|
| 63 |
+
'50': ' ',
|
| 64 |
+
'55': ' ',
|
| 65 |
+
'56': ' ',
|
| 66 |
+
|
| 67 |
+
}
|
| 68 |
+
instr = step['language_instruction']
|
| 69 |
+
instr = clean_task_instruction(instr, replacements)
|
| 70 |
+
step['observation']['natural_language_instruction'] = instr
|
| 71 |
+
|
| 72 |
+
return step
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
import tensorflow_datasets as tfds
|
| 77 |
+
from data.utils import dataset_to_path
|
| 78 |
+
|
| 79 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 80 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 81 |
+
# Load the dataset
|
| 82 |
+
dataset = tfds.builder_from_directory(
|
| 83 |
+
builder_dir=dataset_to_path(
|
| 84 |
+
DATASET_NAME, DATASET_DIR))
|
| 85 |
+
dataset = dataset.as_dataset(split='all')
|
| 86 |
+
|
| 87 |
+
# Inspect the dataset
|
| 88 |
+
for episode in dataset:
|
| 89 |
+
for step in episode['steps']:
|
| 90 |
+
print(step)
|
data/preprocess_scripts/bridge.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.equal(terminate_act, tf.constant(1.0, dtype=tf.float32))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
action['terminate'] = terminate_act_to_bool(action['terminate_episode'])
|
| 23 |
+
|
| 24 |
+
eef_delta_pos = action['world_vector']
|
| 25 |
+
eef_ang=action['rotation_delta']
|
| 26 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 27 |
+
grip_open=tf.reshape(tf.where(action['open_gripper'],1.0, 0.0),(1,))
|
| 28 |
+
# grip_open:tensor
|
| 29 |
+
|
| 30 |
+
# No base found
|
| 31 |
+
|
| 32 |
+
# Concatenate the action
|
| 33 |
+
arm_action=tf.concat([eef_delta_pos,eef_ang,grip_open],axis=0)
|
| 34 |
+
action['arm_concat']=arm_action
|
| 35 |
+
#base_action = tf.concat([base_delta_pos, base_delta_ang], axis=0)
|
| 36 |
+
#action['base_concat'] = base_action
|
| 37 |
+
|
| 38 |
+
# Write the action format
|
| 39 |
+
action['format']=tf.constant("eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 40 |
+
|
| 41 |
+
# Convert raw state to our state
|
| 42 |
+
state= step['observation']
|
| 43 |
+
eef_pos=state['state'][:3]
|
| 44 |
+
eef_ang=state['state'][3:6]
|
| 45 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 46 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 47 |
+
gripper_action=state['state'][6:]
|
| 48 |
+
|
| 49 |
+
# Concatenate the state
|
| 50 |
+
state['arm_concat']=tf.concat([eef_pos,eef_ang,gripper_action],axis=0)
|
| 51 |
+
|
| 52 |
+
# Write the state format
|
| 53 |
+
state['format'] = tf.constant(
|
| 54 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 55 |
+
|
| 56 |
+
# Clean the task instruction
|
| 57 |
+
# Define the replacements (old, new) as a dictionary
|
| 58 |
+
replacements = {
|
| 59 |
+
'_': ' ',
|
| 60 |
+
'1f': ' ',
|
| 61 |
+
'4f': ' ',
|
| 62 |
+
'-': ' ',
|
| 63 |
+
'50': ' ',
|
| 64 |
+
'55': ' ',
|
| 65 |
+
'56': ' ',
|
| 66 |
+
|
| 67 |
+
}
|
| 68 |
+
instr = step['observation']['natural_language_instruction']
|
| 69 |
+
instr = clean_task_instruction(instr, replacements)
|
| 70 |
+
step['observation']['natural_language_instruction'] = instr
|
| 71 |
+
|
| 72 |
+
return step
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
import tensorflow_datasets as tfds
|
| 77 |
+
from data.utils import dataset_to_path
|
| 78 |
+
|
| 79 |
+
DATASET_DIR = 'data/datasets/openx_embod/'
|
| 80 |
+
DATASET_NAME = 'bridge'
|
| 81 |
+
# Load the dataset
|
| 82 |
+
dataset = tfds.builder_from_directory(
|
| 83 |
+
builder_dir=dataset_to_path(
|
| 84 |
+
DATASET_NAME, DATASET_DIR))
|
| 85 |
+
dataset = dataset.as_dataset(split='all')
|
| 86 |
+
|
| 87 |
+
# Inspect the dataset
|
| 88 |
+
for episode in dataset:
|
| 89 |
+
for step in episode['steps']:
|
| 90 |
+
print(step)
|
data/preprocess_scripts/bridgev2.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler, euler_to_quaternion, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import h5py
|
| 6 |
+
import numpy as np
|
| 7 |
+
from tqdm import tqdm
|
| 8 |
+
import os
|
| 9 |
+
import imageio
|
| 10 |
+
import concurrent.futures
|
| 11 |
+
import fnmatch
|
| 12 |
+
import random
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _parse_function(proto):
|
| 16 |
+
keys_to_features = {
|
| 17 |
+
'observations/images0': tf.io.FixedLenFeature([], tf.string),
|
| 18 |
+
'observations/state': tf.io.FixedLenFeature([], tf.string),
|
| 19 |
+
'observations/qpos': tf.io.FixedLenFeature([], tf.string),
|
| 20 |
+
'observations/eef_transform': tf.io.FixedLenFeature([], tf.string),
|
| 21 |
+
'language': tf.io.FixedLenFeature([], tf.string),
|
| 22 |
+
'actions': tf.io.FixedLenFeature([], tf.string),
|
| 23 |
+
'truncates': tf.io.FixedLenFeature([], tf.int64),
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
parsed_features = tf.io.parse_single_example(proto, keys_to_features)
|
| 27 |
+
|
| 28 |
+
observations_images0 = tf.io.parse_tensor(parsed_features['observations/images0'], out_type=tf.uint8)
|
| 29 |
+
observations_state = tf.io.parse_tensor(parsed_features['observations/state'], out_type=tf.float32)
|
| 30 |
+
observations_qpos = tf.io.parse_tensor(parsed_features['observations/qpos'], out_type=tf.float32)
|
| 31 |
+
# observations_eef_transform = tf.io.parse_tensor(parsed_features['observations/eef_transform'], out_type=tf.float32)
|
| 32 |
+
language = parsed_features['language']
|
| 33 |
+
actions = tf.io.parse_tensor(parsed_features['actions'], out_type=tf.float32)
|
| 34 |
+
truncates = parsed_features['truncates']
|
| 35 |
+
|
| 36 |
+
actions = tf.reshape(actions, [7])
|
| 37 |
+
observations_images0 = tf.reshape(observations_images0, [480, 640, 3])
|
| 38 |
+
# observations_eef_transform = tf.reshape(observations_eef_transform, [4,4])
|
| 39 |
+
# observations_eef_transform = extract_angles_and_translation(observations_eef_transform)
|
| 40 |
+
# observations_eef_transform = tf.reshape(observations_eef_transform, [6])
|
| 41 |
+
observations_qpos = tf.reshape(observations_qpos, [6])
|
| 42 |
+
observations_state = tf.reshape(observations_state, [7])
|
| 43 |
+
|
| 44 |
+
return {
|
| 45 |
+
'observation': {
|
| 46 |
+
'images0': observations_images0,
|
| 47 |
+
'state': observations_state,
|
| 48 |
+
'qpos': observations_qpos,
|
| 49 |
+
},
|
| 50 |
+
'language': language,
|
| 51 |
+
'actions': actions,
|
| 52 |
+
'truncates': truncates
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def dataset_generator_from_tfrecords(seed):
|
| 57 |
+
tfrecord_path = './data/datasets/bridgev2/tfrecords'
|
| 58 |
+
filepaths = []
|
| 59 |
+
for root, dirs, files in os.walk(tfrecord_path):
|
| 60 |
+
for filename in fnmatch.filter(files, '*.tfrecord'):
|
| 61 |
+
filepath = os.path.join(root, filename)
|
| 62 |
+
filepaths.append(filepath)
|
| 63 |
+
|
| 64 |
+
random.seed(seed)
|
| 65 |
+
random.shuffle(filepaths)
|
| 66 |
+
for filepath in filepaths:
|
| 67 |
+
raw_dataset = tf.data.TFRecordDataset(filepath)
|
| 68 |
+
dataset = raw_dataset.map(_parse_function)
|
| 69 |
+
yield {
|
| 70 |
+
'steps': dataset
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
def load_dataset(seed):
|
| 74 |
+
dataset = tf.data.Dataset.from_generator(
|
| 75 |
+
lambda: dataset_generator_from_tfrecords(seed),
|
| 76 |
+
output_signature={
|
| 77 |
+
'steps': tf.data.DatasetSpec(
|
| 78 |
+
element_spec={
|
| 79 |
+
'observation': {
|
| 80 |
+
'images0': tf.TensorSpec(shape=(480, 640, 3), dtype=tf.uint8),
|
| 81 |
+
'state': tf.TensorSpec(shape=(7,), dtype=tf.float32),
|
| 82 |
+
'qpos': tf.TensorSpec(shape=(6,), dtype=tf.float32),
|
| 83 |
+
},
|
| 84 |
+
'language': tf.TensorSpec(shape=(), dtype=tf.string),
|
| 85 |
+
'actions': tf.TensorSpec(shape=(7,), dtype=tf.float32),
|
| 86 |
+
'truncates': tf.TensorSpec(shape=(), dtype=tf.int64)
|
| 87 |
+
}
|
| 88 |
+
)
|
| 89 |
+
}
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
return dataset
|
| 93 |
+
|
| 94 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 95 |
+
"""
|
| 96 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 97 |
+
"""
|
| 98 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def process_step(step: dict) -> dict:
|
| 102 |
+
"""
|
| 103 |
+
Unify the action format and clean the task instruction.
|
| 104 |
+
|
| 105 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 106 |
+
"""
|
| 107 |
+
# Convert raw action to our action
|
| 108 |
+
old_action = step['actions']
|
| 109 |
+
step['action'] = {}
|
| 110 |
+
action = step['action']
|
| 111 |
+
step['action']['terminate'] = step['truncates']
|
| 112 |
+
# https://github.com/rail-berkeley/bridge_data_robot/blob/main/widowx_envs/widowx_envs/utils/transformation_utils.py line 154
|
| 113 |
+
eef_delta_pos = old_action[:3]
|
| 114 |
+
eef_ang = old_action[3:6]
|
| 115 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 116 |
+
gripper_state = old_action[6]
|
| 117 |
+
# https://github.com/rail-berkeley/bridge_data_robot/blob/main/widowx_envs/widowx_envs/base/robot_base_env.py line 231
|
| 118 |
+
# gripper_open = tf.constant(0.0,dtype=tf.float32) if gripper_state < 0.5 else tf.constant(1.0,dtype=tf.float32)
|
| 119 |
+
gripper_open = tf.cond(tf.less(gripper_state, 0.5), lambda: tf.constant(0.0, dtype=tf.float32), lambda: tf.constant(1.0, dtype=tf.float32))
|
| 120 |
+
gripper_open = tf.expand_dims(gripper_open,axis=0)
|
| 121 |
+
|
| 122 |
+
# # No base found
|
| 123 |
+
# # Concatenate the action
|
| 124 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang,gripper_open], axis=0)
|
| 125 |
+
action['arm_concat'] = arm_action
|
| 126 |
+
# # Write the action format
|
| 127 |
+
action['format'] = tf.constant(
|
| 128 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z, eef_delta_angle_x, eef_delta_angle_y, eef_delta_angle_z, eef_delta_angle_w, gripper_open")
|
| 129 |
+
|
| 130 |
+
old_state = step['observation']['state']
|
| 131 |
+
qpos = step['observation']['qpos']
|
| 132 |
+
state = step['observation']
|
| 133 |
+
|
| 134 |
+
# https://github.com/rail-berkeley/bridge_data_robot/blob/main/widowx_envs/widowx_envs/base/robot_base_env.py line 292
|
| 135 |
+
eef_pos = old_state[:3]
|
| 136 |
+
eef_ang = old_state[3:6]
|
| 137 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 138 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 139 |
+
gripper_open = old_state[6:]
|
| 140 |
+
# gripper_open = tf.cond(tf.less(gripper_state, 0.5), lambda: tf.constant(0.0, dtype=tf.float32), lambda: tf.constant(1.0, dtype=tf.float32))
|
| 141 |
+
# gripper_open = tf.expand_dims(gripper_open,axis=0)
|
| 142 |
+
|
| 143 |
+
state['arm_concat'] = tf.concat([qpos,gripper_open,eef_pos,eef_ang], axis=0)
|
| 144 |
+
# # Write the state format
|
| 145 |
+
state['format'] = tf.constant(
|
| 146 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,gripper_joint_0_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 147 |
+
|
| 148 |
+
# Clean the task instruction
|
| 149 |
+
# Define the replacements (old, new) as a dictionary
|
| 150 |
+
replacements = {
|
| 151 |
+
'_': ' ',
|
| 152 |
+
'1f': ' ',
|
| 153 |
+
'4f': ' ',
|
| 154 |
+
'-': ' ',
|
| 155 |
+
'50': ' ',
|
| 156 |
+
'55': ' ',
|
| 157 |
+
'56': ' ',
|
| 158 |
+
|
| 159 |
+
}
|
| 160 |
+
# copied from openxembod
|
| 161 |
+
instr = step['language']
|
| 162 |
+
instr = clean_task_instruction(instr, replacements)
|
| 163 |
+
step['observation']['natural_language_instruction'] = instr
|
| 164 |
+
|
| 165 |
+
return step
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
if __name__ == "__main__":
|
| 169 |
+
import tensorflow_datasets as tfds
|
| 170 |
+
from data.utils import dataset_to_path
|
| 171 |
+
|
| 172 |
+
# Load the dataset
|
| 173 |
+
dataset = load_dataset(0)
|
| 174 |
+
for episode in dataset.take(1):
|
| 175 |
+
for step in episode['steps']:
|
| 176 |
+
step = process_step(step)
|
| 177 |
+
print(step)
|
| 178 |
+
break
|
| 179 |
+
|
data/preprocess_scripts/columbia_cairlab_pusht_real.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler, euler_to_quaternion
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_step(step: dict) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Unify the action format and clean the task instruction.
|
| 16 |
+
|
| 17 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 18 |
+
"""
|
| 19 |
+
# Convert raw action to our action
|
| 20 |
+
action = step['action']
|
| 21 |
+
action['terminate'] = terminate_act_to_bool(action['terminate_episode'])
|
| 22 |
+
|
| 23 |
+
eef_delta_pos = action['world_vector']
|
| 24 |
+
eef_ang = action['rotation_delta']
|
| 25 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 26 |
+
|
| 27 |
+
# Ignore action['gripper_open']: 1 if close gripper, -1 if open gripper, 0 if no change.
|
| 28 |
+
|
| 29 |
+
# No base found
|
| 30 |
+
|
| 31 |
+
# Concatenate the action
|
| 32 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang], axis=0)
|
| 33 |
+
action['arm_concat'] = arm_action
|
| 34 |
+
|
| 35 |
+
# Write the action format
|
| 36 |
+
action['format'] = tf.constant(
|
| 37 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w")
|
| 38 |
+
|
| 39 |
+
# Convert raw state to our state
|
| 40 |
+
state = step['observation']
|
| 41 |
+
eef_pos = state['robot_state']
|
| 42 |
+
|
| 43 |
+
# Concatenate the state
|
| 44 |
+
state['arm_concat'] = eef_pos
|
| 45 |
+
|
| 46 |
+
# Write the state format
|
| 47 |
+
state['format'] = tf.constant(
|
| 48 |
+
"eef_pos_x,eef_pos_y")
|
| 49 |
+
|
| 50 |
+
# Clean the task instruction
|
| 51 |
+
# Define the replacements (old, new) as a dictionary
|
| 52 |
+
replacements = {
|
| 53 |
+
'_': ' ',
|
| 54 |
+
'1f': ' ',
|
| 55 |
+
'4f': ' ',
|
| 56 |
+
'-': ' ',
|
| 57 |
+
'50': ' ',
|
| 58 |
+
'55': ' ',
|
| 59 |
+
'56': ' ',
|
| 60 |
+
|
| 61 |
+
}
|
| 62 |
+
instr = step['observation']['natural_language_instruction']
|
| 63 |
+
instr = clean_task_instruction(instr, replacements)
|
| 64 |
+
step['observation']['natural_language_instruction'] = instr
|
| 65 |
+
|
| 66 |
+
return step
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
if __name__ == "__main__":
|
| 70 |
+
import tensorflow_datasets as tfds
|
| 71 |
+
from data.utils import dataset_to_path
|
| 72 |
+
|
| 73 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 74 |
+
DATASET_NAME = 'columbia_cairlab_pusht_real'
|
| 75 |
+
# Load the dataset
|
| 76 |
+
dataset = tfds.builder_from_directory(
|
| 77 |
+
builder_dir=dataset_to_path(
|
| 78 |
+
DATASET_NAME, DATASET_DIR))
|
| 79 |
+
dataset = dataset.as_dataset(split='all')
|
| 80 |
+
|
| 81 |
+
# Inspect the dataset
|
| 82 |
+
for episode in dataset:
|
| 83 |
+
for step in episode['steps']:
|
| 84 |
+
print(step)
|
data/preprocess_scripts/dlr_edan_shared_control_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix,\
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
# Robot action, consists of [3x robot EEF position, 3x robot EEF orientation yaw/pitch/roll calculated with scipy Rotation.as_euler(="zxy") Class].
|
| 23 |
+
eef_delta_pos = action[:3]
|
| 24 |
+
eef_ang = tf.gather(action[3:6], [1, 2, 0]) # To Rotation.as_euler("xyz")
|
| 25 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 26 |
+
# After watching the episode, I found that the last action is the gripper open/close action, where 0 means open and 1 means close.
|
| 27 |
+
grip_open = tf.expand_dims(1 - action[6], axis=0)
|
| 28 |
+
|
| 29 |
+
# Concatenate the action
|
| 30 |
+
step['action'] = {}
|
| 31 |
+
action = step['action']
|
| 32 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang,grip_open], axis=0)
|
| 33 |
+
action['terminate'] = step['is_terminal']
|
| 34 |
+
|
| 35 |
+
# Write the action format
|
| 36 |
+
action['format'] = tf.constant(
|
| 37 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 38 |
+
|
| 39 |
+
# Convert raw state to our state
|
| 40 |
+
state = step['observation']
|
| 41 |
+
state_vec = state['state']
|
| 42 |
+
# Robot state, consists of [3x robot EEF position, 3x robot EEF orientation yaw/pitch/roll calculated with scipy Rotation.as_euler("zxy") Class, 6x robot EEF wrench].
|
| 43 |
+
eef_pos = state_vec[:3]
|
| 44 |
+
eef_ang = tf.gather(state_vec[3:6], [1, 2, 0]) # To Rotation.as_euler("xyz")
|
| 45 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 46 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 47 |
+
grip_open = tf.expand_dims(1 - state_vec[6], axis=0)
|
| 48 |
+
# Concatenate the state
|
| 49 |
+
state['arm_concat'] = tf.concat([eef_pos, eef_ang,grip_open], axis=0)
|
| 50 |
+
|
| 51 |
+
# Write the state format
|
| 52 |
+
state['format'] = tf.constant(
|
| 53 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 54 |
+
|
| 55 |
+
# Clean the task instruction
|
| 56 |
+
# Define the replacements (old, new) as a dictionary
|
| 57 |
+
replacements = {
|
| 58 |
+
'_': ' ',
|
| 59 |
+
'1f': ' ',
|
| 60 |
+
'4f': ' ',
|
| 61 |
+
'-': ' ',
|
| 62 |
+
'50': ' ',
|
| 63 |
+
'55': ' ',
|
| 64 |
+
'56': ' ',
|
| 65 |
+
|
| 66 |
+
}
|
| 67 |
+
instr = step['language_instruction']
|
| 68 |
+
instr = clean_task_instruction(instr, replacements)
|
| 69 |
+
step['observation']['natural_language_instruction'] = instr
|
| 70 |
+
|
| 71 |
+
return step
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
import tensorflow_datasets as tfds
|
| 76 |
+
from data.utils import dataset_to_path
|
| 77 |
+
|
| 78 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 79 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 80 |
+
# Load the dataset
|
| 81 |
+
dataset = tfds.builder_from_directory(
|
| 82 |
+
builder_dir=dataset_to_path(
|
| 83 |
+
DATASET_NAME, DATASET_DIR))
|
| 84 |
+
dataset = dataset.as_dataset(split='all')
|
| 85 |
+
|
| 86 |
+
# Inspect the dataset
|
| 87 |
+
for episode in dataset:
|
| 88 |
+
for step in episode['steps']:
|
| 89 |
+
print(step)
|
data/preprocess_scripts/dlr_sara_grid_clamp_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix,\
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
# Robot action, consists of [3x robot EEF position, 3x robot EEF orientation yaw/pitch/roll calculated with scipy Rotation.as_euler(="zxy") Class].
|
| 23 |
+
eef_delta_pos = action[:3]
|
| 24 |
+
eef_ang = tf.gather(action[3:6], [1, 2, 0]) # To Rotation.as_euler("xyz")
|
| 25 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 26 |
+
# After watching the episode, I found that the last action is the gripper open/close action, where 0 means open and 1 means close.
|
| 27 |
+
grip_open = tf.expand_dims(1 - action[6], axis=0)
|
| 28 |
+
|
| 29 |
+
# Concatenate the action
|
| 30 |
+
step['action'] = {}
|
| 31 |
+
action = step['action']
|
| 32 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang,grip_open], axis=0)
|
| 33 |
+
action['terminate'] = step['is_terminal']
|
| 34 |
+
|
| 35 |
+
# Write the action format
|
| 36 |
+
action['format'] = tf.constant(
|
| 37 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 38 |
+
|
| 39 |
+
# Convert raw state to our state
|
| 40 |
+
state = step['observation']
|
| 41 |
+
state_vec = state['state']
|
| 42 |
+
# Robot state, consists of [3x robot EEF position, 3x robot EEF orientation yaw/pitch/roll calculated with scipy Rotation.as_euler("zxy") Class, 6x robot EEF wrench].
|
| 43 |
+
eef_pos = state_vec[:3]
|
| 44 |
+
eef_ang = tf.gather(state_vec[3:6], [1, 2, 0]) # To Rotation.as_euler("xyz")
|
| 45 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 46 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 47 |
+
# joint_pos = state_vec[6:12] # EEF wrench is not the joint posit
|
| 48 |
+
# Concatenate the state
|
| 49 |
+
# state['arm_concat'] = tf.concat([joint_pos,eef_pos, eef_ang], axis=0)
|
| 50 |
+
state['arm_concat'] = tf.concat([eef_pos, eef_ang], axis=0)
|
| 51 |
+
|
| 52 |
+
# Write the state format
|
| 53 |
+
state['format'] = tf.constant(
|
| 54 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 55 |
+
|
| 56 |
+
# Define the task instruction
|
| 57 |
+
step['observation']['natural_language_instruction'] = tf.constant(
|
| 58 |
+
"Place the grid clamp on the table, aligning the protrusion on its bottom with the slots on the table.")
|
| 59 |
+
|
| 60 |
+
return step
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
import tensorflow_datasets as tfds
|
| 65 |
+
from data.utils import dataset_to_path
|
| 66 |
+
|
| 67 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 68 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 69 |
+
# Load the dataset
|
| 70 |
+
dataset = tfds.builder_from_directory(
|
| 71 |
+
builder_dir=dataset_to_path(
|
| 72 |
+
DATASET_NAME, DATASET_DIR))
|
| 73 |
+
dataset = dataset.as_dataset(split='all')
|
| 74 |
+
|
| 75 |
+
# Inspect the dataset
|
| 76 |
+
for episode in dataset:
|
| 77 |
+
for step in episode['steps']:
|
| 78 |
+
print(step)
|
data/preprocess_scripts/dlr_sara_pour_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix,\
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
# Robot action, consists of [3x robot EEF position, 3x robot EEF orientation yaw/pitch/roll calculated with scipy Rotation.as_euler(="zxy") Class].
|
| 23 |
+
eef_delta_pos = action[:3]
|
| 24 |
+
eef_ang = tf.gather(action[3:6], [1, 2, 0]) # To Rotation.as_euler("xyz")
|
| 25 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 26 |
+
# After watching the episode, I found that the last action is the gripper open/close action, where 0 means open and 1 means close.
|
| 27 |
+
grip_open = tf.expand_dims(1 - action[6], axis=0)
|
| 28 |
+
# Concatenate the action
|
| 29 |
+
step['action'] = {}
|
| 30 |
+
action = step['action']
|
| 31 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang,grip_open], axis=0)
|
| 32 |
+
action['terminate'] = step['is_terminal']
|
| 33 |
+
|
| 34 |
+
# Write the action format
|
| 35 |
+
action['format'] = tf.constant(
|
| 36 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 37 |
+
|
| 38 |
+
# Convert raw state to our state
|
| 39 |
+
state = step['observation']
|
| 40 |
+
state_vec = state['state']
|
| 41 |
+
# Robot state, consists of [3x robot EEF position, 3x robot EEF orientation yaw/pitch/roll calculated with scipy Rotation.as_euler(="zxy") Class].
|
| 42 |
+
eef_pos = state_vec[:3]
|
| 43 |
+
eef_ang = tf.gather(state_vec[3:6], [1, 2, 0]) # To Rotation.as_euler("xyz")
|
| 44 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 45 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 46 |
+
|
| 47 |
+
# Concatenate the state
|
| 48 |
+
state['arm_concat'] = tf.concat([ eef_pos, eef_ang], axis=0)
|
| 49 |
+
|
| 50 |
+
# Write the state format
|
| 51 |
+
state['format'] = tf.constant(
|
| 52 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 53 |
+
|
| 54 |
+
# Clean the task instruction
|
| 55 |
+
# Define the replacements (old, new) as a dictionary
|
| 56 |
+
replacements = {
|
| 57 |
+
'_': ' ',
|
| 58 |
+
'1f': ' ',
|
| 59 |
+
'4f': ' ',
|
| 60 |
+
'-': ' ',
|
| 61 |
+
'50': ' ',
|
| 62 |
+
'55': ' ',
|
| 63 |
+
'56': ' ',
|
| 64 |
+
|
| 65 |
+
}
|
| 66 |
+
instr = step['language_instruction']
|
| 67 |
+
instr = clean_task_instruction(instr, replacements)
|
| 68 |
+
step['observation']['natural_language_instruction'] = instr
|
| 69 |
+
|
| 70 |
+
return step
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
import tensorflow_datasets as tfds
|
| 75 |
+
from data.utils import dataset_to_path
|
| 76 |
+
|
| 77 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 78 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 79 |
+
# Load the dataset
|
| 80 |
+
dataset = tfds.builder_from_directory(
|
| 81 |
+
builder_dir=dataset_to_path(
|
| 82 |
+
DATASET_NAME, DATASET_DIR))
|
| 83 |
+
dataset = dataset.as_dataset(split='all')
|
| 84 |
+
|
| 85 |
+
# Inspect the dataset
|
| 86 |
+
for episode in dataset:
|
| 87 |
+
for step in episode['steps']:
|
| 88 |
+
print(step)
|
data/preprocess_scripts/dobbe.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
arm_action = step['action']
|
| 14 |
+
|
| 15 |
+
# Concatenate the action
|
| 16 |
+
step['action'] = {}
|
| 17 |
+
action = step['action']
|
| 18 |
+
action['arm_concat'] = arm_action
|
| 19 |
+
# Write the action format
|
| 20 |
+
action['format'] = tf.constant(
|
| 21 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw,gripper_open")
|
| 22 |
+
action['terminate'] = step['is_terminal']
|
| 23 |
+
|
| 24 |
+
# The state has any problem?
|
| 25 |
+
state = step['observation']
|
| 26 |
+
eef_pos = state['xyz']
|
| 27 |
+
# Clip eef_pos to be [-10, 10] for stability
|
| 28 |
+
eef_pos = tf.clip_by_value(eef_pos, -10, 10)
|
| 29 |
+
eef_ang = state['rot']
|
| 30 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 31 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 32 |
+
grip_pos = state['gripper']
|
| 33 |
+
|
| 34 |
+
# Concatenate the state
|
| 35 |
+
state['arm_concat'] = tf.concat([
|
| 36 |
+
grip_pos,eef_pos,eef_ang], axis=0)
|
| 37 |
+
|
| 38 |
+
# Write the state format
|
| 39 |
+
state['format'] = tf.constant(
|
| 40 |
+
"gripper_open,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 41 |
+
|
| 42 |
+
# Clean the task instruction
|
| 43 |
+
# Define the replacements (old, new) as a dictionary
|
| 44 |
+
replacements = {
|
| 45 |
+
'_': ' ',
|
| 46 |
+
'1f': ' ',
|
| 47 |
+
'4f': ' ',
|
| 48 |
+
'-': ' ',
|
| 49 |
+
'50': ' ',
|
| 50 |
+
'55': ' ',
|
| 51 |
+
'56': ' ',
|
| 52 |
+
}
|
| 53 |
+
instr = step['language_instruction']
|
| 54 |
+
instr = clean_task_instruction(instr, replacements)
|
| 55 |
+
step['observation']['natural_language_instruction'] = instr
|
| 56 |
+
|
| 57 |
+
return step
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
import tensorflow_datasets as tfds
|
| 62 |
+
from data.utils import dataset_to_path
|
| 63 |
+
from tqdm import tqdm
|
| 64 |
+
import numpy as np
|
| 65 |
+
|
| 66 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 67 |
+
DATASET_NAME = 'dobbe'
|
| 68 |
+
# Load the dataset
|
| 69 |
+
dataset = tfds.builder_from_directory(
|
| 70 |
+
builder_dir=dataset_to_path(
|
| 71 |
+
DATASET_NAME, DATASET_DIR))
|
| 72 |
+
dataset = dataset.as_dataset(split='all')
|
| 73 |
+
# dataset = dataset.filter(
|
| 74 |
+
# lambda x: tf.math.less(
|
| 75 |
+
# tf.math.reduce_max(tf.math.abs(
|
| 76 |
+
# tf.convert_to_tensor(
|
| 77 |
+
# [step['observation']['xyz'] for step in x['steps']]))), 3))
|
| 78 |
+
|
| 79 |
+
# Inspect the dataset
|
| 80 |
+
for i, episode in tqdm(enumerate(dataset), total=5208):
|
| 81 |
+
res = []
|
| 82 |
+
for step in episode['steps']:
|
| 83 |
+
res.append(step['observation']['xyz'].numpy())
|
| 84 |
+
max_val = np.max(np.abs(res))
|
| 85 |
+
if max_val > 2:
|
| 86 |
+
print(f"Episode {i} has a max value of {max_val}")
|
data/preprocess_scripts/eth_agent_affordances.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
def process_step(step: dict) -> dict:
|
| 6 |
+
"""
|
| 7 |
+
Unify the action format and clean the task instruction.
|
| 8 |
+
|
| 9 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 10 |
+
"""
|
| 11 |
+
# Convert raw action to our action
|
| 12 |
+
|
| 13 |
+
origin_action = step['action']
|
| 14 |
+
step['action']={}
|
| 15 |
+
action=step['action']
|
| 16 |
+
action['terminate'] = step['is_terminal']
|
| 17 |
+
|
| 18 |
+
eef_vel = origin_action[:3]
|
| 19 |
+
eef_ang_vel=origin_action[3:6]
|
| 20 |
+
# No base found
|
| 21 |
+
|
| 22 |
+
# Concatenate the action
|
| 23 |
+
action['arm_concat'] = tf.concat([eef_vel,eef_ang_vel],axis=0)
|
| 24 |
+
|
| 25 |
+
# Write the action format
|
| 26 |
+
action['format'] = tf.constant(
|
| 27 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw")
|
| 28 |
+
|
| 29 |
+
# Convert raw state to our state
|
| 30 |
+
state = step['observation']
|
| 31 |
+
# Concatenate the state
|
| 32 |
+
eef_pos = state['state'][:3]
|
| 33 |
+
eef_ang = tf.gather(state['state'][3:6], [2, 1, 0])
|
| 34 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 35 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 36 |
+
grip_open=state['state'][6:7]
|
| 37 |
+
# state['state'][8]:door opening angle
|
| 38 |
+
state['arm_concat'] = tf.concat([eef_pos,eef_ang,grip_open],axis=0)
|
| 39 |
+
|
| 40 |
+
# Write the state format
|
| 41 |
+
state['format'] = tf.constant(
|
| 42 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 43 |
+
# Clean the task instruction
|
| 44 |
+
# Define the replacements (old, new) as a dictionary
|
| 45 |
+
replacements = {
|
| 46 |
+
'_': ' ',
|
| 47 |
+
'1f': ' ',
|
| 48 |
+
'4f': ' ',
|
| 49 |
+
'-': ' ',
|
| 50 |
+
'50': ' ',
|
| 51 |
+
'55': ' ',
|
| 52 |
+
'56': ' ',
|
| 53 |
+
|
| 54 |
+
}
|
| 55 |
+
instr = step['language_instruction']
|
| 56 |
+
instr = clean_task_instruction(instr, replacements)
|
| 57 |
+
step['observation']['natural_language_instruction'] = instr
|
| 58 |
+
|
| 59 |
+
return step
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
import tensorflow_datasets as tfds
|
| 64 |
+
from data.utils import dataset_to_path
|
| 65 |
+
|
| 66 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 67 |
+
DATASET_NAME = 'eth_agent_affordances'
|
| 68 |
+
# Load the dataset
|
| 69 |
+
dataset = tfds.builder_from_directory(
|
| 70 |
+
builder_dir=dataset_to_path(
|
| 71 |
+
DATASET_NAME, DATASET_DIR))
|
| 72 |
+
dataset = dataset.as_dataset(split='all')
|
| 73 |
+
|
| 74 |
+
# Inspect the dataset
|
| 75 |
+
for episode in dataset:
|
| 76 |
+
for step in episode['steps']:
|
| 77 |
+
print(step)
|
data/preprocess_scripts/fmb.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d, \
|
| 4 |
+
quaternion_to_rotation_matrix
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def process_step(step: dict) -> dict:
|
| 8 |
+
"""
|
| 9 |
+
Unify the action format and clean the task instruction.
|
| 10 |
+
|
| 11 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 12 |
+
"""
|
| 13 |
+
# Convert raw action to our action
|
| 14 |
+
action = step['action']
|
| 15 |
+
|
| 16 |
+
# Robot action
|
| 17 |
+
eef_pos = action[:3]
|
| 18 |
+
eef_ang = action[3:6]
|
| 19 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 20 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 21 |
+
gripper_open = action[6:7]
|
| 22 |
+
|
| 23 |
+
# Concatenate the action
|
| 24 |
+
step['action'] = {}
|
| 25 |
+
action = step['action']
|
| 26 |
+
|
| 27 |
+
arm_action = tf.concat([eef_pos, eef_ang, gripper_open], axis=0)
|
| 28 |
+
action['arm_concat'] = arm_action
|
| 29 |
+
action['terminate'] = step['is_terminal']
|
| 30 |
+
|
| 31 |
+
# Write the action format
|
| 32 |
+
action['format'] = tf.constant(
|
| 33 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 34 |
+
|
| 35 |
+
# Convert raw state to our state
|
| 36 |
+
# Robot state
|
| 37 |
+
state = step['observation']
|
| 38 |
+
eef_pos = state['eef_pose'][:3]
|
| 39 |
+
eef_ang = state['eef_pose'][3:]
|
| 40 |
+
eef_ang = quaternion_to_rotation_matrix(eef_ang)
|
| 41 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 42 |
+
eef_pos_vel = state['eef_vel'][:3]
|
| 43 |
+
eef_ang_vel = state['eef_vel'][3:]
|
| 44 |
+
joint_pos = state['joint_pos']
|
| 45 |
+
joint_vel = state['joint_vel']
|
| 46 |
+
grip_pos = 1 - state['state_gripper_pose']
|
| 47 |
+
grip_pos = tf.expand_dims(grip_pos, axis=0)
|
| 48 |
+
|
| 49 |
+
# Concatenate the state
|
| 50 |
+
state['arm_concat'] = tf.concat([
|
| 51 |
+
joint_pos,joint_vel,grip_pos,eef_pos,eef_ang,eef_pos_vel,eef_ang_vel], axis=0)
|
| 52 |
+
|
| 53 |
+
# Write the state format
|
| 54 |
+
state['format'] = tf.constant(
|
| 55 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,gripper_open,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw")
|
| 56 |
+
|
| 57 |
+
# Clean the task instruction
|
| 58 |
+
# Define the replacements (old, new) as a dictionary
|
| 59 |
+
replacements = {
|
| 60 |
+
'_': ' ',
|
| 61 |
+
'1f': ' ',
|
| 62 |
+
'4f': ' ',
|
| 63 |
+
'-': ' ',
|
| 64 |
+
'50': ' ',
|
| 65 |
+
'55': ' ',
|
| 66 |
+
'56': ' ',
|
| 67 |
+
# Refine language instruction:
|
| 68 |
+
'object': 'brick and insert it into the slot of the matching shape'
|
| 69 |
+
}
|
| 70 |
+
instr = step['language_instruction']
|
| 71 |
+
instr = clean_task_instruction(instr, replacements)
|
| 72 |
+
step['observation']['natural_language_instruction'] = instr
|
| 73 |
+
|
| 74 |
+
return step
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
pass
|
data/preprocess_scripts/furniture_bench_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
|
| 14 |
+
origin_action = step['action']
|
| 15 |
+
step['action']={}
|
| 16 |
+
action=step['action']
|
| 17 |
+
|
| 18 |
+
# No base found
|
| 19 |
+
eef_pos_delta=origin_action[:3]
|
| 20 |
+
eef_quat_delta=origin_action[3:7]
|
| 21 |
+
eef_ang = eef_quat_delta
|
| 22 |
+
# eef_ang=quaternion_to_euler(eef_quat_delta)
|
| 23 |
+
grip_open=-origin_action[7:8]
|
| 24 |
+
|
| 25 |
+
action["arm_concat"]=tf.concat([eef_pos_delta,eef_ang,grip_open],axis=0)
|
| 26 |
+
action['format']=tf.constant("eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 27 |
+
# Ignore action
|
| 28 |
+
action['terminate'] = step['is_terminal']
|
| 29 |
+
|
| 30 |
+
# Convert raw state to our state
|
| 31 |
+
state = step['observation']
|
| 32 |
+
# Concatenate the state
|
| 33 |
+
|
| 34 |
+
''' 'state':
|
| 35 |
+
{
|
| 36 |
+
'ee_pos': EEF position (3,)
|
| 37 |
+
'ee_quat': EEF orientation (4,)
|
| 38 |
+
'ee_pos_vel': EEF linear velocity (3,)
|
| 39 |
+
'ee_ori_vel': EEF angular velocity (3,)
|
| 40 |
+
'joint_positions': Joint positions (7,)
|
| 41 |
+
'joint_velocities': Joint velocities (7,)
|
| 42 |
+
'joint_torques': Joint torques (7,)
|
| 43 |
+
'gripper_width': Gripper width (1,)
|
| 44 |
+
}'''
|
| 45 |
+
eef_pos=state['state'][:3]
|
| 46 |
+
# eef_ang=quaternion_to_euler(state['state'][3:7])
|
| 47 |
+
eef_ang = quaternion_to_rotation_matrix(state['state'][3:7])
|
| 48 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 49 |
+
eef_pos_vel=state['state'][7:10]
|
| 50 |
+
eef_ang_vel=state['state'][10:13]
|
| 51 |
+
arm_joint_pos=state['state'][13:20]
|
| 52 |
+
arm_joint_vel=state['state'][20:27]
|
| 53 |
+
arm_joint_tor=state['state'][27:34]
|
| 54 |
+
# gripper_width?
|
| 55 |
+
grip_open=state['state'][34:35] * 12.507 # rescale to [0, 1]
|
| 56 |
+
|
| 57 |
+
state['arm_concat'] = tf.concat([arm_joint_pos,grip_open,arm_joint_vel,\
|
| 58 |
+
eef_pos,eef_ang,eef_pos_vel,eef_ang_vel],axis=0)
|
| 59 |
+
|
| 60 |
+
# Write the state format
|
| 61 |
+
state['format'] = tf.constant(
|
| 62 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,gripper_open,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw")
|
| 63 |
+
|
| 64 |
+
# Clean the task instruction
|
| 65 |
+
# Define the replacements (old, new) as a dictionary
|
| 66 |
+
replacements = {
|
| 67 |
+
'_': ' ',
|
| 68 |
+
'1f': ' ',
|
| 69 |
+
'4f': ' ',
|
| 70 |
+
'-': ' ',
|
| 71 |
+
'50': ' ',
|
| 72 |
+
'55': ' ',
|
| 73 |
+
'56': ' ',
|
| 74 |
+
|
| 75 |
+
}
|
| 76 |
+
instr = step['language_instruction']
|
| 77 |
+
instr = clean_task_instruction(instr, replacements)
|
| 78 |
+
step['observation']['natural_language_instruction'] = instr
|
| 79 |
+
|
| 80 |
+
return step
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
import tensorflow_datasets as tfds
|
| 85 |
+
from data.utils import dataset_to_path
|
| 86 |
+
|
| 87 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 88 |
+
DATASET_NAME = 'furniture_bench_dataset_converted_externally_to_rlds'
|
| 89 |
+
# Load the dataset
|
| 90 |
+
dataset = tfds.builder_from_directory(
|
| 91 |
+
builder_dir=dataset_to_path(
|
| 92 |
+
DATASET_NAME, DATASET_DIR))
|
| 93 |
+
dataset = dataset.as_dataset(split='all')
|
| 94 |
+
|
| 95 |
+
# Inspect the dataset
|
| 96 |
+
for episode in dataset:
|
| 97 |
+
for step in episode['steps']:
|
| 98 |
+
print(step)
|
data/preprocess_scripts/imperialcollege_sawyer_wrist_cam.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
|
| 14 |
+
origin_action = step['action']
|
| 15 |
+
step['action'] = {}
|
| 16 |
+
action = step['action']
|
| 17 |
+
|
| 18 |
+
# Multiplied by 10 Hz to get units m/s and rad/s
|
| 19 |
+
eef_delta_pos = origin_action[:3] * 10
|
| 20 |
+
# delta ZYX euler angles == roll/pitch/yaw velocities
|
| 21 |
+
eef_ang = origin_action[3:6] * 10
|
| 22 |
+
grip_open = 1 - origin_action[6:7]
|
| 23 |
+
|
| 24 |
+
# No base found
|
| 25 |
+
|
| 26 |
+
# Concatenate the action
|
| 27 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open],axis=0)
|
| 28 |
+
|
| 29 |
+
# Write the action format
|
| 30 |
+
action['format'] = tf.constant(
|
| 31 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw,gripper_open")
|
| 32 |
+
|
| 33 |
+
# Convert raw state to our state
|
| 34 |
+
# state = step['observation']
|
| 35 |
+
# # Concatenate the state
|
| 36 |
+
# grip_open=state['state']
|
| 37 |
+
# state['arm_concat'] = grip_open
|
| 38 |
+
|
| 39 |
+
# Write the state format
|
| 40 |
+
# state['format'] = tf.constant(
|
| 41 |
+
# "gripper_open")
|
| 42 |
+
|
| 43 |
+
# Clean the task instruction
|
| 44 |
+
# Define the replacements (old, new) as a dictionary
|
| 45 |
+
replacements = {
|
| 46 |
+
'_': ' ',
|
| 47 |
+
'1f': ' ',
|
| 48 |
+
'4f': ' ',
|
| 49 |
+
'-': ' ',
|
| 50 |
+
'50': ' ',
|
| 51 |
+
'55': ' ',
|
| 52 |
+
'56': ' ',
|
| 53 |
+
|
| 54 |
+
}
|
| 55 |
+
instr = step['language_instruction']
|
| 56 |
+
instr = clean_task_instruction(instr, replacements)
|
| 57 |
+
step['observation']['natural_language_instruction'] = instr
|
| 58 |
+
|
| 59 |
+
return step
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
import tensorflow_datasets as tfds
|
| 64 |
+
from data.utils import dataset_to_path
|
| 65 |
+
|
| 66 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 67 |
+
DATASET_NAME = 'imperialcollege_sawyer_wrist_cam'
|
| 68 |
+
# Load the dataset
|
| 69 |
+
dataset = tfds.builder_from_directory(
|
| 70 |
+
builder_dir=dataset_to_path(
|
| 71 |
+
DATASET_NAME, DATASET_DIR))
|
| 72 |
+
dataset = dataset.as_dataset(split='all')
|
| 73 |
+
|
| 74 |
+
# Inspect the dataset
|
| 75 |
+
for episode in dataset:
|
| 76 |
+
for step in episode['steps']:
|
| 77 |
+
print(step)
|
data/preprocess_scripts/jaco_play.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
action['terminate'] = terminate_act_to_bool(action['terminate_episode'])
|
| 23 |
+
eef_delta_pos = action['world_vector']
|
| 24 |
+
# eef_ang = action['rotation_delta']
|
| 25 |
+
# (NOTE) due to the formality problem, grip_open is not used
|
| 26 |
+
# grip_open = 1 - (action['gripper_closedness_action'] ) / 2
|
| 27 |
+
# base_delta_pos = action['base_displacement_vector']
|
| 28 |
+
# base_delta_ang = action['base_displacement_vertical_rotation']
|
| 29 |
+
|
| 30 |
+
# Concatenate the action
|
| 31 |
+
arm_action = eef_delta_pos
|
| 32 |
+
action['arm_concat'] = arm_action
|
| 33 |
+
# base_action = tf.constant([0, 0, 0, 0], dtype=tf.float32)
|
| 34 |
+
# action['base_concat'] = None
|
| 35 |
+
|
| 36 |
+
# Write the action format
|
| 37 |
+
action['format'] = tf.constant(
|
| 38 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z")
|
| 39 |
+
|
| 40 |
+
# Convert raw state to our state
|
| 41 |
+
state = step['observation']
|
| 42 |
+
joint_pos = state['joint_pos']
|
| 43 |
+
eef_pos = state['end_effector_cartesian_pos'][:3]
|
| 44 |
+
eef_quat = state['end_effector_cartesian_pos'][3:]
|
| 45 |
+
eef_ang = quaternion_to_rotation_matrix(eef_quat)
|
| 46 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 47 |
+
eef_vel = state['end_effector_cartesian_velocity'][:3]
|
| 48 |
+
# We do not use angular velocity since it is very inaccurate in this environment
|
| 49 |
+
# eef_angular_vel = state['end_effector_cartesian_velocity'][3:]
|
| 50 |
+
# Concatenate the state
|
| 51 |
+
state['arm_concat'] = tf.concat([joint_pos, eef_pos, eef_ang, eef_vel], axis=0)
|
| 52 |
+
|
| 53 |
+
# Write the state format
|
| 54 |
+
state['format'] = tf.constant(
|
| 55 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,gripper_joint_0_pos,gripper_joint_1_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,eef_vel_x,eef_vel_y,eef_vel_z")
|
| 56 |
+
|
| 57 |
+
# Clean the task instruction
|
| 58 |
+
# Define the replacements (old, new) as a dictionary
|
| 59 |
+
replacements = {
|
| 60 |
+
'_': ' ',
|
| 61 |
+
'1f': ' ',
|
| 62 |
+
'4f': ' ',
|
| 63 |
+
'-': ' ',
|
| 64 |
+
'50': ' ',
|
| 65 |
+
'55': ' ',
|
| 66 |
+
'56': ' ',
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
instr = step['observation']['natural_language_instruction']
|
| 70 |
+
instr = clean_task_instruction(instr, replacements)
|
| 71 |
+
step['observation']['natural_language_instruction'] = instr
|
| 72 |
+
|
| 73 |
+
return step
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
import tensorflow_datasets as tfds
|
| 78 |
+
from data.utils import dataset_to_path
|
| 79 |
+
|
| 80 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 81 |
+
DATASET_NAME = 'jaco_play'
|
| 82 |
+
# Load the dataset
|
| 83 |
+
dataset = tfds.builder_from_directory(
|
| 84 |
+
builder_dir=dataset_to_path(
|
| 85 |
+
DATASET_NAME, DATASET_DIR))
|
| 86 |
+
dataset = dataset.as_dataset(split='all')
|
| 87 |
+
|
| 88 |
+
# Inspect the dataset
|
| 89 |
+
for episode in dataset:
|
| 90 |
+
for step in episode['steps']:
|
| 91 |
+
print(step)
|
data/preprocess_scripts/kaist_nonprehensile_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, quaternion_to_rotation_matrix,\
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
# Robot action, consists of [3x end-effector position residual, 3x end-effector axis-angle residual,
|
| 23 |
+
# 7x robot joint k_p gain coefficient, 7x robot joint damping ratio coefficient].
|
| 24 |
+
# The action residuals are global, i.e. multiplied on theleft-hand side of the current end-effector state.
|
| 25 |
+
eef_delta_pos = action[:3]
|
| 26 |
+
eef_ang = action[3:6]
|
| 27 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 28 |
+
|
| 29 |
+
# Concatenate the action
|
| 30 |
+
step['action'] = {}
|
| 31 |
+
action = step['action']
|
| 32 |
+
action['terminate'] = step['is_terminal']
|
| 33 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang,], axis=0)
|
| 34 |
+
|
| 35 |
+
# Write the action format
|
| 36 |
+
action['format'] = tf.constant(
|
| 37 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w")
|
| 38 |
+
|
| 39 |
+
# Convert raw state to our state
|
| 40 |
+
state = step['observation']
|
| 41 |
+
# Robot state, consists of [joint_states, end_effector_pose].Joint states are 14-dimensional, formatted in the order of [q_0, w_0, q_1, w_0, ...].
|
| 42 |
+
# In other words, joint positions and velocities are interleaved.The end-effector pose is 7-dimensional, formatted in the order of [position, quaternion].The quaternion is formatted in (x,y,z,w) order. The end-effector pose references the tool frame, in the center of the two fingers of the gripper.
|
| 43 |
+
joint_states = state['state'][:14]
|
| 44 |
+
arm_joint_pos = joint_states[::2]
|
| 45 |
+
arm_joint_vel = joint_states[1::2]
|
| 46 |
+
eef_pos = state['state'][14:17]
|
| 47 |
+
# eef_ang = quaternion_to_euler(state['state'][17:21])
|
| 48 |
+
eef_ang = quaternion_to_rotation_matrix(state['state'][17:21])
|
| 49 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 50 |
+
# Concatenate the state
|
| 51 |
+
state['arm_concat'] = tf.concat([arm_joint_pos, arm_joint_vel, eef_pos, eef_ang], axis=0)
|
| 52 |
+
|
| 53 |
+
# Write the state format
|
| 54 |
+
state['format'] = tf.constant(
|
| 55 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 56 |
+
|
| 57 |
+
# Clean the task instruction
|
| 58 |
+
# Define the replacements (old, new) as a dictionary
|
| 59 |
+
replacements = {
|
| 60 |
+
'_': ' ',
|
| 61 |
+
'1f': ' ',
|
| 62 |
+
'4f': ' ',
|
| 63 |
+
'-': ' ',
|
| 64 |
+
'50': ' ',
|
| 65 |
+
'55': ' ',
|
| 66 |
+
'56': ' ',
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
instr = step['language_instruction']
|
| 70 |
+
instr = clean_task_instruction(instr, replacements)
|
| 71 |
+
step['observation']['natural_language_instruction'] = instr
|
| 72 |
+
|
| 73 |
+
return step
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
import tensorflow_datasets as tfds
|
| 78 |
+
from data.utils import dataset_to_path
|
| 79 |
+
|
| 80 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 81 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 82 |
+
# Load the dataset
|
| 83 |
+
dataset = tfds.builder_from_directory(
|
| 84 |
+
builder_dir=dataset_to_path(
|
| 85 |
+
DATASET_NAME, DATASET_DIR))
|
| 86 |
+
dataset = dataset.as_dataset(split='all')
|
| 87 |
+
|
| 88 |
+
# Inspect the dataset
|
| 89 |
+
for episode in dataset:
|
| 90 |
+
for step in episode['steps']:
|
| 91 |
+
print(step)
|
data/preprocess_scripts/kuka.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, quaternion_to_rotation_matrix,\
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# keys_view = step.keys()
|
| 21 |
+
# print("step")
|
| 22 |
+
# print(list(keys_view))
|
| 23 |
+
# Convert raw action to our action
|
| 24 |
+
action: dict = step['action']
|
| 25 |
+
# print("action")
|
| 26 |
+
# print(list(action.keys()))
|
| 27 |
+
action['terminate'] = terminate_act_to_bool(action['terminate_episode'])
|
| 28 |
+
|
| 29 |
+
eef_delta_pos = action['world_vector']
|
| 30 |
+
eef_ang = action['rotation_delta']
|
| 31 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 32 |
+
grip_open = 1 - (action['gripper_closedness_action'] + 1) / 2
|
| 33 |
+
base_delta_pos = action['base_displacement_vector']
|
| 34 |
+
base_delta_ang = action['base_displacement_vertical_rotation']
|
| 35 |
+
|
| 36 |
+
# Concatenate the action
|
| 37 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 38 |
+
action['arm_concat'] = arm_action
|
| 39 |
+
base_action = tf.concat([base_delta_pos, base_delta_ang], axis=0)
|
| 40 |
+
action['base_concat'] = base_action
|
| 41 |
+
|
| 42 |
+
# print("action len:", len(action['arm_concat']) + len(action['base_concat']))
|
| 43 |
+
|
| 44 |
+
# Write the action format
|
| 45 |
+
action['format'] = tf.constant(
|
| 46 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open,base_vel_x,base_vel_y,base_angular_vel")
|
| 47 |
+
|
| 48 |
+
# action good for kuka same as example
|
| 49 |
+
|
| 50 |
+
# Convert raw state to our state
|
| 51 |
+
state = step['observation']
|
| 52 |
+
# print("state")
|
| 53 |
+
# print(list(state.keys()))
|
| 54 |
+
eef_pos = state['clip_function_input/base_pose_tool_reached'][:3]
|
| 55 |
+
eef_ang = quaternion_to_rotation_matrix(state['clip_function_input/base_pose_tool_reached'][3:])
|
| 56 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 57 |
+
grip_open = 1 - state['gripper_closed']
|
| 58 |
+
|
| 59 |
+
# Concatenate the state
|
| 60 |
+
state['arm_concat'] = tf.concat([eef_pos, eef_ang, grip_open], axis=0)
|
| 61 |
+
# print("state len:", len(state['arm_concat']))
|
| 62 |
+
|
| 63 |
+
# Write the state format
|
| 64 |
+
state['format'] = tf.constant(
|
| 65 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 66 |
+
|
| 67 |
+
# Clean the task instruction
|
| 68 |
+
# Define the replacements (old, new) as a dictionary
|
| 69 |
+
replacements = {
|
| 70 |
+
'_': ' ',
|
| 71 |
+
'1f': ' ',
|
| 72 |
+
'4f': ' ',
|
| 73 |
+
'-': ' ',
|
| 74 |
+
'50': ' ',
|
| 75 |
+
'55': ' ',
|
| 76 |
+
'56': ' ',
|
| 77 |
+
|
| 78 |
+
}
|
| 79 |
+
instr = step['observation']['natural_language_instruction']
|
| 80 |
+
instr = clean_task_instruction(instr, replacements)
|
| 81 |
+
step['observation']['natural_language_instruction'] = instr
|
| 82 |
+
|
| 83 |
+
return step
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
import tensorflow_datasets as tfds
|
| 88 |
+
from data.utils import dataset_to_path
|
| 89 |
+
|
| 90 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 91 |
+
DATASET_NAME = 'kuka'
|
| 92 |
+
# Load the dataset
|
| 93 |
+
dataset = tfds.builder_from_directory(
|
| 94 |
+
builder_dir=dataset_to_path(
|
| 95 |
+
DATASET_NAME, DATASET_DIR))
|
| 96 |
+
dataset = dataset.as_dataset(split='all')
|
| 97 |
+
|
| 98 |
+
# with open('example.txt', 'w') as file:
|
| 99 |
+
# Inspect the dataset
|
| 100 |
+
episode_num = len(dataset)
|
| 101 |
+
for episode in dataset:
|
| 102 |
+
# print("episode")
|
| 103 |
+
# print(list(episode.keys()))
|
| 104 |
+
for step in episode['steps']:
|
| 105 |
+
process_step(step)
|
| 106 |
+
# break
|
| 107 |
+
print(f"episode_num: {episode_num}")
|
data/preprocess_scripts/language_table.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction
|
| 4 |
+
|
| 5 |
+
def process_step(step: dict) -> dict:
|
| 6 |
+
"""
|
| 7 |
+
Unify the action format and clean the task instruction.
|
| 8 |
+
|
| 9 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 10 |
+
"""
|
| 11 |
+
# Convert raw action to our action
|
| 12 |
+
|
| 13 |
+
origin_action = step['action']
|
| 14 |
+
step['action']={}
|
| 15 |
+
action=step['action']
|
| 16 |
+
|
| 17 |
+
eef_delta_pos=origin_action
|
| 18 |
+
# No base found
|
| 19 |
+
|
| 20 |
+
# Concatenate the action
|
| 21 |
+
action['arm_concat'] = eef_delta_pos
|
| 22 |
+
action['terminate'] = step['is_terminal']
|
| 23 |
+
|
| 24 |
+
# Write the action format
|
| 25 |
+
action['format'] = tf.constant(
|
| 26 |
+
"eef_delta_pos_x,eef_delta_pos_y")
|
| 27 |
+
|
| 28 |
+
# Convert raw state to our state
|
| 29 |
+
state = step['observation']
|
| 30 |
+
# Concatenate the state
|
| 31 |
+
eef_pos=state['effector_translation']
|
| 32 |
+
state['arm_concat'] = eef_pos
|
| 33 |
+
# Write the state format
|
| 34 |
+
state['format'] = tf.constant(
|
| 35 |
+
"eef_pos_x,eef_pos_y")
|
| 36 |
+
|
| 37 |
+
# Clean the task instruction
|
| 38 |
+
# Define the replacements (old, new) as a dictionary
|
| 39 |
+
replacements = {
|
| 40 |
+
'_': ' ',
|
| 41 |
+
'1f': ' ',
|
| 42 |
+
'4f': ' ',
|
| 43 |
+
'-': ' ',
|
| 44 |
+
'50': ' ',
|
| 45 |
+
'55': ' ',
|
| 46 |
+
'56': ' ',
|
| 47 |
+
|
| 48 |
+
}
|
| 49 |
+
instr = step['observation']['instruction']
|
| 50 |
+
# Convert bytes to tf.string
|
| 51 |
+
instr = tf.strings.unicode_encode(instr, 'UTF-8')
|
| 52 |
+
# Remove '\x00'
|
| 53 |
+
instr = tf.strings.regex_replace(instr, '\x00', '')
|
| 54 |
+
instr = clean_task_instruction(instr, replacements)
|
| 55 |
+
step['observation']['natural_language_instruction'] = instr
|
| 56 |
+
return step
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
import tensorflow_datasets as tfds
|
| 61 |
+
from data.utils import dataset_to_path
|
| 62 |
+
|
| 63 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 64 |
+
DATASET_NAME = 'language_table'
|
| 65 |
+
# Load the dataset
|
| 66 |
+
dataset = tfds.builder_from_directory(
|
| 67 |
+
builder_dir=dataset_to_path(
|
| 68 |
+
DATASET_NAME, DATASET_DIR))
|
| 69 |
+
dataset = dataset.as_dataset(split='all')
|
| 70 |
+
|
| 71 |
+
# Inspect the dataset
|
| 72 |
+
for episode in dataset:
|
| 73 |
+
for step in episode['steps']:
|
| 74 |
+
print(step)
|
| 75 |
+
|
data/preprocess_scripts/libero_10_no_noops.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
|
| 15 |
+
# Robot action
|
| 16 |
+
# eef_pos = action_dict['ee_pos'][:3]
|
| 17 |
+
# eef_ang = action_dict['ee_pos'][3:6]
|
| 18 |
+
# eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 19 |
+
# eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 20 |
+
eef_pos_vel = action_dict[:3]
|
| 21 |
+
eef_ang_vel = action_dict[3:6]
|
| 22 |
+
# joint_pos = action_dict['joint_pos'][:-1]
|
| 23 |
+
# joint_vel = action_dict['delta_joint'][:-1]
|
| 24 |
+
grip_pos = 1 - tf.clip_by_value(action_dict[-1:], 0, 1)
|
| 25 |
+
|
| 26 |
+
# grip_vel = action_dict['gripper_velocity']
|
| 27 |
+
|
| 28 |
+
# Concatenate the action
|
| 29 |
+
step['action'] = {}
|
| 30 |
+
action = step['action']
|
| 31 |
+
|
| 32 |
+
arm_action = tf.concat([eef_pos_vel, eef_ang_vel, grip_pos], axis=0)
|
| 33 |
+
action['arm_concat'] = arm_action
|
| 34 |
+
# action['terminate'] = step['is_terminal']
|
| 35 |
+
|
| 36 |
+
# Write the action format
|
| 37 |
+
action['format'] = tf.constant(
|
| 38 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw,gripper_joint_0_pos")
|
| 39 |
+
|
| 40 |
+
# Convert raw state to our state
|
| 41 |
+
# Robot state
|
| 42 |
+
state = step['observation']
|
| 43 |
+
# print(state.keys())
|
| 44 |
+
# image = step['observation']['image']
|
| 45 |
+
eef_pos = state['state'][:3]
|
| 46 |
+
eef_ang = state['state'][3:6]
|
| 47 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 48 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 49 |
+
# joint_pos = state['joint_pos'][:-1]
|
| 50 |
+
grip_pos = state['state'][-2:]
|
| 51 |
+
|
| 52 |
+
# Concatenate the state
|
| 53 |
+
state['arm_concat'] = tf.concat([
|
| 54 |
+
grip_pos,eef_pos,eef_ang], axis=0)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Write the state format
|
| 58 |
+
state['format'] = tf.constant(
|
| 59 |
+
"gripper_joint_0_pos,gripper_joint_1_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 60 |
+
|
| 61 |
+
# Clean the task instruction
|
| 62 |
+
# Define the replacements (old, new) as a dictionary
|
| 63 |
+
replacements = {
|
| 64 |
+
'_': ' ',
|
| 65 |
+
'1f': ' ',
|
| 66 |
+
'4f': ' ',
|
| 67 |
+
'-': ' ',
|
| 68 |
+
'50': ' ',
|
| 69 |
+
'55': ' ',
|
| 70 |
+
'56': ' ',
|
| 71 |
+
|
| 72 |
+
}
|
| 73 |
+
instr = step['language_instruction']
|
| 74 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 75 |
+
step['observation'] = state
|
| 76 |
+
step['observation']['natural_language_instruction'] = instr
|
| 77 |
+
|
| 78 |
+
return step
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
pass
|
data/preprocess_scripts/libero_object_no_noops.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
|
| 15 |
+
# Robot action
|
| 16 |
+
# eef_pos = action_dict['ee_pos'][:3]
|
| 17 |
+
# eef_ang = action_dict['ee_pos'][3:6]
|
| 18 |
+
# eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 19 |
+
# eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 20 |
+
eef_pos_vel = action_dict[:3]
|
| 21 |
+
eef_ang_vel = action_dict[3:6]
|
| 22 |
+
# joint_pos = action_dict['joint_pos'][:-1]
|
| 23 |
+
# joint_vel = action_dict['delta_joint'][:-1]
|
| 24 |
+
grip_pos = 1 - tf.clip_by_value(action_dict[-1:], 0, 1)
|
| 25 |
+
|
| 26 |
+
# grip_vel = action_dict['gripper_velocity']
|
| 27 |
+
|
| 28 |
+
# Concatenate the action
|
| 29 |
+
step['action'] = {}
|
| 30 |
+
action = step['action']
|
| 31 |
+
|
| 32 |
+
arm_action = tf.concat([eef_pos_vel, eef_ang_vel, grip_pos], axis=0)
|
| 33 |
+
action['arm_concat'] = arm_action
|
| 34 |
+
# action['terminate'] = step['is_terminal']
|
| 35 |
+
|
| 36 |
+
# Write the action format
|
| 37 |
+
action['format'] = tf.constant(
|
| 38 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw,gripper_joint_0_pos")
|
| 39 |
+
|
| 40 |
+
# Convert raw state to our state
|
| 41 |
+
# Robot state
|
| 42 |
+
state = step['observation']
|
| 43 |
+
# print(state.keys())
|
| 44 |
+
# image = step['observation']['image']
|
| 45 |
+
eef_pos = state['state'][:3]
|
| 46 |
+
eef_ang = state['state'][3:6]
|
| 47 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 48 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 49 |
+
# joint_pos = state['joint_pos'][:-1]
|
| 50 |
+
grip_pos = state['state'][-2:]
|
| 51 |
+
|
| 52 |
+
# Concatenate the state
|
| 53 |
+
state['arm_concat'] = tf.concat([
|
| 54 |
+
grip_pos,eef_pos,eef_ang], axis=0)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Write the state format
|
| 58 |
+
state['format'] = tf.constant(
|
| 59 |
+
"gripper_joint_0_pos,gripper_joint_1_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 60 |
+
|
| 61 |
+
# Clean the task instruction
|
| 62 |
+
# Define the replacements (old, new) as a dictionary
|
| 63 |
+
replacements = {
|
| 64 |
+
'_': ' ',
|
| 65 |
+
'1f': ' ',
|
| 66 |
+
'4f': ' ',
|
| 67 |
+
'-': ' ',
|
| 68 |
+
'50': ' ',
|
| 69 |
+
'55': ' ',
|
| 70 |
+
'56': ' ',
|
| 71 |
+
|
| 72 |
+
}
|
| 73 |
+
instr = step['language_instruction']
|
| 74 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 75 |
+
step['observation'] = state
|
| 76 |
+
step['observation']['natural_language_instruction'] = instr
|
| 77 |
+
|
| 78 |
+
return step
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
pass
|
data/preprocess_scripts/maniskill_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler, euler_to_quaternion
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_step(step: dict) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Unify the action format and clean the task instruction.
|
| 16 |
+
|
| 17 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
|
| 23 |
+
# Robot action, consists of [3x end effector delta target position, 3x end effector delta target orientation in axis-angle format, 1x gripper target position (mimic for two fingers)].
|
| 24 |
+
# For delta target position, an action of -1 maps to a robot movement of -0.1m, and action of 1 maps to a movement of 0.1m.
|
| 25 |
+
# For delta target orientation, its encoded angle is mapped to a range of [-0.1rad, 0.1rad] for robot execution. For example, an action of [1, 0, 0] means rotating along the x-axis by 0.1 rad.
|
| 26 |
+
# For gripper target position, an action of -1 means close, and an action of 1 means open.
|
| 27 |
+
eef_delta_pos = action[:3] * 0.1
|
| 28 |
+
eef_ang = action[3:6] * 0.1
|
| 29 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 30 |
+
grip_open = tf.expand_dims((action[6] + 1) / 2, axis=0)
|
| 31 |
+
|
| 32 |
+
# Concatenate the action
|
| 33 |
+
step['action'] = {}
|
| 34 |
+
action = step['action']
|
| 35 |
+
|
| 36 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 37 |
+
action['arm_concat'] = arm_action
|
| 38 |
+
action['terminate'] = step['is_terminal']
|
| 39 |
+
|
| 40 |
+
# Write the action format
|
| 41 |
+
action['format'] = tf.constant(
|
| 42 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 43 |
+
|
| 44 |
+
# Convert raw state to our state
|
| 45 |
+
# Robot state, consists of [7x robot joint angles, 2x gripper position, 7x robot joint angle velocity, 2x gripper velocity]. Angle in radians, position in meters.
|
| 46 |
+
state = step['observation']['state']
|
| 47 |
+
arm_joint_pos = state[:7]
|
| 48 |
+
gripper_pos = state[7:9] * 25 # rescale to [0, 1]
|
| 49 |
+
# We do not use velocity since it is very inaccurate in this environment
|
| 50 |
+
# arm_joint_vel = state[9:16]
|
| 51 |
+
# gripper_vel = state[16:18]
|
| 52 |
+
|
| 53 |
+
# Concatenate the state
|
| 54 |
+
|
| 55 |
+
state = step['observation']
|
| 56 |
+
state['arm_concat'] = tf.concat([
|
| 57 |
+
arm_joint_pos, gripper_pos], axis=0)
|
| 58 |
+
|
| 59 |
+
# Robot base pose in the world frame, consists of [x, y, z, qw, qx, qy, qz].
|
| 60 |
+
# The first three dimensions represent xyz positions in meters. The last four dimensions are the quaternion representation of rotation
|
| 61 |
+
# base_pose = step['observation']['base_pose']
|
| 62 |
+
# base_pose_xyz = base_pose[:3]
|
| 63 |
+
# base_pose_ang = quaternion_to_euler(base_pose[3:])
|
| 64 |
+
# processed_base_pose = tf.concat([base_pose_xyz, base_pose_ang], axis=0)
|
| 65 |
+
|
| 66 |
+
# state['arm_concat'] = tf.concat([state['arm_concat'], processed_base_pose], axis=0)
|
| 67 |
+
|
| 68 |
+
# Write the state format
|
| 69 |
+
state['format'] = tf.constant(
|
| 70 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,gripper_joint_0_pos,gripper_joint_1_pos")
|
| 71 |
+
|
| 72 |
+
# Clean the task instruction
|
| 73 |
+
# Define the replacements (old, new) as a dictionary
|
| 74 |
+
replacements = {
|
| 75 |
+
'_': ' ',
|
| 76 |
+
'1f': ' ',
|
| 77 |
+
'4f': ' ',
|
| 78 |
+
'-': ' ',
|
| 79 |
+
'50': ' ',
|
| 80 |
+
'55': ' ',
|
| 81 |
+
'56': ' ',
|
| 82 |
+
|
| 83 |
+
}
|
| 84 |
+
instr = step['language_instruction']
|
| 85 |
+
instr = clean_task_instruction(instr, replacements)
|
| 86 |
+
step['observation']['natural_language_instruction'] = instr
|
| 87 |
+
|
| 88 |
+
return step
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
import tensorflow_datasets as tfds
|
| 93 |
+
from data.utils import dataset_to_path
|
| 94 |
+
|
| 95 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 96 |
+
DATASET_NAME = 'maniskill_dataset_converted_externally_to_rlds'
|
| 97 |
+
# Load the dataset
|
| 98 |
+
dataset = tfds.builder_from_directory(
|
| 99 |
+
builder_dir=dataset_to_path(
|
| 100 |
+
DATASET_NAME, DATASET_DIR))
|
| 101 |
+
dataset = dataset.as_dataset(split='all')
|
| 102 |
+
|
| 103 |
+
# Inspect the dataset
|
| 104 |
+
for episode in dataset.take(1):
|
| 105 |
+
for step in episode['steps']:
|
| 106 |
+
print(step['is_last'])
|
data/preprocess_scripts/nyu_door_opening_surprising_effectiveness.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.equal(terminate_act, tf.constant(1.0, dtype=tf.float32))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_step(step: dict) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Unify the action format and clean the task instruction.
|
| 16 |
+
|
| 17 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 18 |
+
"""
|
| 19 |
+
# Convert raw action to our action
|
| 20 |
+
action = step['action']
|
| 21 |
+
action['terminate'] = terminate_act_to_bool(action['terminate_episode'])
|
| 22 |
+
|
| 23 |
+
# Multiplied by 3 Hz to get units m/s and rad/s
|
| 24 |
+
eef_delta_pos = action['world_vector'] * 3
|
| 25 |
+
eef_ang = action['rotation_delta'] * 3
|
| 26 |
+
# Origin: [-0.28, 0.96]: open, close
|
| 27 |
+
# 1-Origin: [0.04, 1.28]: close, open
|
| 28 |
+
grip_open = 1 - action['gripper_closedness_action']
|
| 29 |
+
# base_delta_pos = action['base_displacement_vector']
|
| 30 |
+
# base_delta_ang = action['base_displacement_vertical_rotation']
|
| 31 |
+
|
| 32 |
+
# Concatenate the action
|
| 33 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 34 |
+
action['arm_concat'] = arm_action
|
| 35 |
+
# base_action = tf.concat([base_delta_pos, base_delta_ang], axis=0)
|
| 36 |
+
# action['base_concat'] = base_action
|
| 37 |
+
|
| 38 |
+
# Write the action format
|
| 39 |
+
action['format'] = tf.constant(
|
| 40 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw,gripper_open")
|
| 41 |
+
|
| 42 |
+
# Convert raw state to our state
|
| 43 |
+
# state = step['observation']
|
| 44 |
+
# eef_pos = state['base_pose_tool_reached'][:3]
|
| 45 |
+
# eef_ang = quaternion_to_euler(state['base_pose_tool_reached'][3:])
|
| 46 |
+
# grip_open = 1 - state['gripper_closed']
|
| 47 |
+
|
| 48 |
+
# create empty tensor
|
| 49 |
+
# state['arm_concat'] = tf.constant([0, 0, 0, 0, 0, 0], dtype=tf.float32)
|
| 50 |
+
|
| 51 |
+
# Write the state format
|
| 52 |
+
# state['format'] = tf.constant(
|
| 53 |
+
# "")
|
| 54 |
+
|
| 55 |
+
# Define the task instruction
|
| 56 |
+
step['observation']['natural_language_instruction'] = tf.constant(
|
| 57 |
+
"Open the cabinet door.")
|
| 58 |
+
|
| 59 |
+
return step
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
import tensorflow_datasets as tfds
|
| 64 |
+
from data.utils import dataset_to_path
|
| 65 |
+
|
| 66 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 67 |
+
DATASET_NAME = 'nyu_door_opening_surprising_effectiveness'
|
| 68 |
+
# Load the dataset
|
| 69 |
+
dataset = tfds.builder_from_directory(
|
| 70 |
+
builder_dir=dataset_to_path(
|
| 71 |
+
DATASET_NAME, DATASET_DIR))
|
| 72 |
+
dataset = dataset.as_dataset(split='all')
|
| 73 |
+
|
| 74 |
+
# Inspect the dataset
|
| 75 |
+
for episode in dataset.take(1):
|
| 76 |
+
for step in episode['steps']:
|
| 77 |
+
print(step)
|
data/preprocess_scripts/nyu_franka_play_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 11 |
+
|
| 12 |
+
def process_step(step: dict) -> dict:
|
| 13 |
+
"""
|
| 14 |
+
Unify the action format and clean the task instruction.
|
| 15 |
+
|
| 16 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 17 |
+
"""
|
| 18 |
+
# Convert raw action to our action
|
| 19 |
+
|
| 20 |
+
origin_action = step['action']
|
| 21 |
+
step['action']={}
|
| 22 |
+
action=step['action']
|
| 23 |
+
action['terminate']=terminate_act_to_bool(origin_action[14])
|
| 24 |
+
joint_vel=origin_action[:7]
|
| 25 |
+
# gripper_open: 1-open, -1-closed
|
| 26 |
+
|
| 27 |
+
grip_open=tf.where(tf.equal(origin_action[13:14],tf.constant(1.0)),tf.constant(1.0),tf.constant(0.0))
|
| 28 |
+
eef_pos=origin_action[7:10]
|
| 29 |
+
eef_ang=origin_action[10:13]
|
| 30 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 31 |
+
# No base found
|
| 32 |
+
|
| 33 |
+
# Concatenate the action
|
| 34 |
+
action['arm_concat'] = tf.concat([joint_vel,grip_open,eef_pos,eef_ang],axis=0)
|
| 35 |
+
|
| 36 |
+
# Write the action format
|
| 37 |
+
action['format'] = tf.constant(
|
| 38 |
+
"arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,gripper_joint_0_pos,eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w")
|
| 39 |
+
|
| 40 |
+
# Convert raw state to our state
|
| 41 |
+
state = step['observation']
|
| 42 |
+
# Concatenate the state
|
| 43 |
+
state_arm_joint = state['state'][:7]
|
| 44 |
+
eef_pos = state['state'][7:10]
|
| 45 |
+
eef_ang = euler_to_rotation_matrix(state['state'][10:13])
|
| 46 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 47 |
+
state['arm_concat'] = tf.concat([state_arm_joint,eef_pos,eef_ang],axis=0)
|
| 48 |
+
|
| 49 |
+
# Write the state format
|
| 50 |
+
state['format'] = tf.constant(
|
| 51 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 52 |
+
|
| 53 |
+
# Clean the task instruction
|
| 54 |
+
# Define the replacements (old, new) as a dictionary
|
| 55 |
+
replacements = {
|
| 56 |
+
'_': ' ',
|
| 57 |
+
'1f': ' ',
|
| 58 |
+
'4f': ' ',
|
| 59 |
+
'-': ' ',
|
| 60 |
+
'50': ' ',
|
| 61 |
+
'55': ' ',
|
| 62 |
+
'56': ' ',
|
| 63 |
+
|
| 64 |
+
}
|
| 65 |
+
instr = step['language_instruction']
|
| 66 |
+
instr = clean_task_instruction(instr, replacements)
|
| 67 |
+
step['observation']['natural_language_instruction'] = instr
|
| 68 |
+
|
| 69 |
+
return step
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
import tensorflow_datasets as tfds
|
| 74 |
+
from data.utils import dataset_to_path
|
| 75 |
+
|
| 76 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 77 |
+
DATASET_NAME = 'nyu_franka_play_dataset_converted_externally_to_rlds'
|
| 78 |
+
# Load the dataset
|
| 79 |
+
dataset = tfds.builder_from_directory(
|
| 80 |
+
builder_dir=dataset_to_path(
|
| 81 |
+
DATASET_NAME, DATASET_DIR))
|
| 82 |
+
dataset = dataset.as_dataset(split='all')
|
| 83 |
+
|
| 84 |
+
# Inspect the dataset
|
| 85 |
+
for episode in dataset:
|
| 86 |
+
for step in episode['steps']:
|
| 87 |
+
print(step)
|
data/preprocess_scripts/qut_dexterous_manpulation.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action = step['action']
|
| 14 |
+
eef_pos = action[:3]
|
| 15 |
+
eef_quat = action[3:7]
|
| 16 |
+
eef_ang = quaternion_to_rotation_matrix(eef_quat)
|
| 17 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 18 |
+
grip_pos = action[7:]
|
| 19 |
+
|
| 20 |
+
# Concatenate the action
|
| 21 |
+
step['action'] = {}
|
| 22 |
+
action = step['action']
|
| 23 |
+
action['arm_concat'] = tf.concat([
|
| 24 |
+
grip_pos,eef_pos,eef_ang], axis=0)
|
| 25 |
+
# Write the action format
|
| 26 |
+
action['format'] = tf.constant(
|
| 27 |
+
"gripper_open,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 28 |
+
action['terminate'] = step['is_terminal']
|
| 29 |
+
|
| 30 |
+
# Convert raw state to our state
|
| 31 |
+
state = step['observation']
|
| 32 |
+
robot_state = state['state']
|
| 33 |
+
eef_pos = robot_state[:3]
|
| 34 |
+
eef_quat = robot_state[3:7]
|
| 35 |
+
eef_ang = quaternion_to_rotation_matrix(eef_quat)
|
| 36 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 37 |
+
joint_pos = robot_state[7:14]
|
| 38 |
+
grip_pos = robot_state[14:16] * 24.707 # rescale to [0, 1]
|
| 39 |
+
joint_vel = robot_state[16:23]
|
| 40 |
+
|
| 41 |
+
# Concatenate the state
|
| 42 |
+
state['arm_concat'] = tf.concat([
|
| 43 |
+
grip_pos,eef_pos,eef_ang,joint_pos,joint_vel], axis=0)
|
| 44 |
+
|
| 45 |
+
# Write the state format
|
| 46 |
+
state['format'] = tf.constant(
|
| 47 |
+
"gripper_joint_0_pos,gripper_joint_1_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel")
|
| 48 |
+
|
| 49 |
+
# Clean the task instruction
|
| 50 |
+
# Define the replacements (old, new) as a dictionary
|
| 51 |
+
replacements = {
|
| 52 |
+
'_': ' ',
|
| 53 |
+
'1f': ' ',
|
| 54 |
+
'4f': ' ',
|
| 55 |
+
'-': ' ',
|
| 56 |
+
'50': ' ',
|
| 57 |
+
'55': ' ',
|
| 58 |
+
'56': ' ',
|
| 59 |
+
}
|
| 60 |
+
instr = step['language_instruction']
|
| 61 |
+
instr = clean_task_instruction(instr, replacements)
|
| 62 |
+
step['observation']['natural_language_instruction'] = instr
|
| 63 |
+
|
| 64 |
+
return step
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
pass
|
data/preprocess_scripts/rh20t.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_rotation_matrix_wo_static_check, \
|
| 4 |
+
rotation_matrix_to_ortho6d_1d
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import h5py
|
| 7 |
+
import numpy as np
|
| 8 |
+
from tqdm import tqdm
|
| 9 |
+
import os
|
| 10 |
+
import imageio
|
| 11 |
+
import concurrent.futures
|
| 12 |
+
import fnmatch
|
| 13 |
+
import cv2
|
| 14 |
+
import random
|
| 15 |
+
|
| 16 |
+
def decode_image(image_data):
|
| 17 |
+
image_data = np.frombuffer(image_data, dtype=np.uint8)
|
| 18 |
+
image = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
|
| 19 |
+
return image
|
| 20 |
+
|
| 21 |
+
def _parse_function(proto):
|
| 22 |
+
feature_description = {
|
| 23 |
+
'joint': tf.io.FixedLenFeature([], tf.string),
|
| 24 |
+
'image': tf.io.FixedLenFeature([], tf.string),
|
| 25 |
+
'instruction': tf.io.FixedLenFeature([], tf.string),
|
| 26 |
+
'terminate_episode': tf.io.FixedLenFeature([], tf.int64),
|
| 27 |
+
'gripper': tf.io.FixedLenFeature([], tf.string, default_value=""),
|
| 28 |
+
'tcp': tf.io.FixedLenFeature([], tf.string, default_value=""),
|
| 29 |
+
'tcp_base': tf.io.FixedLenFeature([], tf.string, default_value="")
|
| 30 |
+
}
|
| 31 |
+
parsed_features = tf.io.parse_single_example(proto, feature_description)
|
| 32 |
+
|
| 33 |
+
parsed_features['joint'] = tf.io.parse_tensor(parsed_features['joint'], out_type=tf.float64)
|
| 34 |
+
parsed_features['image'] = tf.io.parse_tensor(parsed_features['image'], out_type=tf.string)
|
| 35 |
+
parsed_features['instruction'] = tf.io.parse_tensor(parsed_features['instruction'], out_type=tf.string)
|
| 36 |
+
parsed_features['gripper'] = tf.cond(
|
| 37 |
+
tf.math.equal(parsed_features['gripper'], ""),
|
| 38 |
+
lambda: tf.constant([], dtype=tf.float64),
|
| 39 |
+
lambda: tf.reshape(tf.io.parse_tensor(parsed_features['gripper'], out_type=tf.float64), [3])
|
| 40 |
+
)
|
| 41 |
+
parsed_features['tcp_base'] = tf.cond(
|
| 42 |
+
tf.math.equal(parsed_features['tcp_base'], ""),
|
| 43 |
+
lambda: tf.constant([], dtype=tf.float64),
|
| 44 |
+
lambda: tf.reshape(tf.io.parse_tensor(parsed_features['tcp_base'], out_type=tf.float64),[7])
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
image = tf.image.decode_jpeg(parsed_features['image'],channels=3)
|
| 48 |
+
joint = parsed_features['joint']
|
| 49 |
+
shape = tf.shape(joint)[0]
|
| 50 |
+
joint = tf.reshape(joint, [shape])
|
| 51 |
+
|
| 52 |
+
instruction = parsed_features['instruction']
|
| 53 |
+
terminate_episode = tf.cast(parsed_features['terminate_episode'],tf.int64)
|
| 54 |
+
gripper = parsed_features['gripper']
|
| 55 |
+
tcp_base = parsed_features['tcp_base']
|
| 56 |
+
return {
|
| 57 |
+
'joint': joint,
|
| 58 |
+
'observation':{
|
| 59 |
+
'image': image,
|
| 60 |
+
},
|
| 61 |
+
'instruction': instruction,
|
| 62 |
+
'terminate_episode': terminate_episode,
|
| 63 |
+
'gripper': gripper,
|
| 64 |
+
'tcp_base': tcp_base,
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
def dataset_generator_from_tfrecords(seed):
|
| 68 |
+
tfrecord_path = './data/datasets/rh20t/tfrecords/'
|
| 69 |
+
datasets = []
|
| 70 |
+
filepaths = []
|
| 71 |
+
for root, dirs, files in os.walk(tfrecord_path):
|
| 72 |
+
for filename in fnmatch.filter(files, '*.tfrecord'):
|
| 73 |
+
filepath = os.path.join(root, filename)
|
| 74 |
+
filepaths.append(filepath)
|
| 75 |
+
|
| 76 |
+
random.seed(seed)
|
| 77 |
+
random.shuffle(filepaths)
|
| 78 |
+
for filepath in filepaths:
|
| 79 |
+
raw_dataset = tf.data.TFRecordDataset(filepath)
|
| 80 |
+
dataset = raw_dataset.map(_parse_function)
|
| 81 |
+
num = 0
|
| 82 |
+
for data in dataset:
|
| 83 |
+
num = num + 1
|
| 84 |
+
if data['joint'].shape != tf.TensorShape((6,)) and data['joint'].shape != tf.TensorShape((7,)):
|
| 85 |
+
num = 0
|
| 86 |
+
break
|
| 87 |
+
if num <= 1: # discard dataset
|
| 88 |
+
continue
|
| 89 |
+
yield {
|
| 90 |
+
'steps': dataset
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 94 |
+
"""
|
| 95 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 96 |
+
"""
|
| 97 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.int64)),tf.constant(False),tf.constant(True))
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def load_dataset(seed):
|
| 101 |
+
dataset = tf.data.Dataset.from_generator(
|
| 102 |
+
lambda: dataset_generator_from_tfrecords(seed),
|
| 103 |
+
output_signature={
|
| 104 |
+
'steps': tf.data.DatasetSpec(
|
| 105 |
+
element_spec={
|
| 106 |
+
'joint': tf.TensorSpec(shape=(None), dtype=tf.float64),
|
| 107 |
+
'observation':{
|
| 108 |
+
'image': tf.TensorSpec(shape=(None), dtype=tf.uint8),
|
| 109 |
+
},
|
| 110 |
+
'instruction': tf.TensorSpec(shape=(), dtype=tf.string),
|
| 111 |
+
'terminate_episode': tf.TensorSpec(shape=(), dtype=tf.int64),
|
| 112 |
+
'gripper': tf.TensorSpec(shape=(None), dtype=tf.float64),
|
| 113 |
+
'tcp_base': tf.TensorSpec(shape=(None), dtype=tf.float64),
|
| 114 |
+
}
|
| 115 |
+
)
|
| 116 |
+
}
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
return dataset
|
| 120 |
+
|
| 121 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 122 |
+
"""
|
| 123 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 124 |
+
"""
|
| 125 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0, dtype=tf.int64)),tf.constant(False),tf.constant(True))
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def process_step(step: dict) -> dict:
|
| 129 |
+
"""
|
| 130 |
+
Unify the action format and clean the task instruction.
|
| 131 |
+
|
| 132 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 133 |
+
"""
|
| 134 |
+
# Clean the task instruction
|
| 135 |
+
# Define the replacements (old, new) as a dictionary
|
| 136 |
+
replacements = {
|
| 137 |
+
'_': ' ',
|
| 138 |
+
'1f': ' ',
|
| 139 |
+
'4f': ' ',
|
| 140 |
+
'-': ' ',
|
| 141 |
+
'50': ' ',
|
| 142 |
+
'55': ' ',
|
| 143 |
+
'56': ' ',
|
| 144 |
+
|
| 145 |
+
}
|
| 146 |
+
instr = step['instruction']
|
| 147 |
+
instr = clean_task_instruction(instr, replacements)
|
| 148 |
+
step['observation']['natural_language_instruction'] = instr
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# Convert raw action to our action
|
| 152 |
+
step['action'] = {}
|
| 153 |
+
step['action']['terminate'] = terminate_act_to_bool(step['terminate_episode'])
|
| 154 |
+
|
| 155 |
+
state = step['observation']
|
| 156 |
+
joint_pos = step['joint']
|
| 157 |
+
state['arm_concat'] = joint_pos
|
| 158 |
+
|
| 159 |
+
state_format = ""
|
| 160 |
+
state_format = tf.cond(
|
| 161 |
+
tf.equal(tf.shape(joint_pos), tf.shape(tf.zeros((7,), dtype=tf.float64))),
|
| 162 |
+
lambda: tf.constant("arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos"),
|
| 163 |
+
lambda: state_format
|
| 164 |
+
)
|
| 165 |
+
state_format = tf.cond(
|
| 166 |
+
tf.equal(tf.shape(joint_pos), tf.shape(tf.zeros((6,), dtype=tf.float64))),
|
| 167 |
+
lambda: tf.constant("arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos"),
|
| 168 |
+
lambda: state_format
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
# eef
|
| 172 |
+
eef = step['tcp_base']
|
| 173 |
+
state['arm_concat'] = tf.cond(
|
| 174 |
+
tf.equal(tf.shape(eef), tf.shape(tf.zeros((7,), dtype=tf.float64))),
|
| 175 |
+
lambda: tf.concat([
|
| 176 |
+
state['arm_concat'],
|
| 177 |
+
tf.concat([
|
| 178 |
+
eef[:3], rotation_matrix_to_ortho6d_1d(
|
| 179 |
+
quaternion_to_rotation_matrix_wo_static_check(eef[3:]))], axis=0)], axis=0),
|
| 180 |
+
lambda: state['arm_concat']
|
| 181 |
+
)
|
| 182 |
+
state_format = tf.cond(
|
| 183 |
+
tf.equal(tf.shape(eef), tf.shape(tf.zeros((7,), dtype=tf.float64))),
|
| 184 |
+
lambda: tf.strings.join([state_format, tf.constant("eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")],separator = ','),
|
| 185 |
+
lambda: state_format
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
# gripper
|
| 189 |
+
state['arm_concat'] = tf.cond(
|
| 190 |
+
tf.equal(tf.shape(step['gripper']), tf.shape(tf.zeros((3,), dtype=tf.float64))),
|
| 191 |
+
lambda: tf.concat([state['arm_concat'], step['gripper'][0:1] / 110], axis=0),
|
| 192 |
+
lambda: state['arm_concat']
|
| 193 |
+
)
|
| 194 |
+
state_format = tf.cond(
|
| 195 |
+
tf.equal(tf.shape(step['gripper']), tf.shape(tf.zeros((3,), dtype=tf.float64))),
|
| 196 |
+
lambda: tf.strings.join([state_format, tf.constant("gripper_joint_0_pos")],separator = ','),
|
| 197 |
+
lambda: state_format
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
state['arm_concat'] = tf.cast(state['arm_concat'], tf.float32)
|
| 201 |
+
state['format'] = state_format
|
| 202 |
+
|
| 203 |
+
return step
|
| 204 |
+
|
| 205 |
+
if __name__ == "__main__":
|
| 206 |
+
import tensorflow_datasets as tfds
|
| 207 |
+
from data.utils import dataset_to_path
|
| 208 |
+
|
| 209 |
+
# Load the dataset
|
| 210 |
+
dataset = load_dataset(0)
|
| 211 |
+
for data in dataset:
|
| 212 |
+
for step in data['steps']:
|
| 213 |
+
step = process_step(step)
|
| 214 |
+
print(step['observation']['format'])
|
data/preprocess_scripts/robomimic_can_ph.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler
|
| 4 |
+
|
| 5 |
+
def load_dataset():
|
| 6 |
+
builder = tfds.builder('robomimic_ph/can_ph_image')
|
| 7 |
+
builder.download_and_prepare()
|
| 8 |
+
ds = builder.as_dataset(split='train', shuffle_files=True)
|
| 9 |
+
return ds
|
| 10 |
+
|
| 11 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 12 |
+
"""
|
| 13 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 14 |
+
"""
|
| 15 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 16 |
+
|
| 17 |
+
def process_step(step: dict) -> dict:
|
| 18 |
+
"""
|
| 19 |
+
Unify the action format and clean the task instruction.
|
| 20 |
+
|
| 21 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 22 |
+
"""
|
| 23 |
+
# format refers to https://www.tensorflow.org/datasets/catalog/robomimic_mg
|
| 24 |
+
# Convert raw action to our action
|
| 25 |
+
eef = step['action']
|
| 26 |
+
step['action'] = {}
|
| 27 |
+
action = step['action']
|
| 28 |
+
action['terminate'] = step['is_terminal']
|
| 29 |
+
|
| 30 |
+
eef_delta_pos = eef[:3]
|
| 31 |
+
eef_ang = eef[3:6]
|
| 32 |
+
# No base found
|
| 33 |
+
|
| 34 |
+
# Concatenate the action
|
| 35 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang], axis=0)
|
| 36 |
+
action['arm_concat'] = arm_action
|
| 37 |
+
|
| 38 |
+
# Write the action format
|
| 39 |
+
action['format'] = tf.constant(
|
| 40 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_roll,eef_delta_angle_pitch,eef_delta_angle_yaw")
|
| 41 |
+
|
| 42 |
+
# Convert raw state to our state
|
| 43 |
+
state = step['observation']
|
| 44 |
+
|
| 45 |
+
arm_joint_pos = state['robot0_joint_pos']
|
| 46 |
+
arm_joint_vel = state['robot0_joint_vel']
|
| 47 |
+
gripper_pos = state['robot0_gripper_qpos']
|
| 48 |
+
gripper_vel = state['robot0_gripper_qvel']
|
| 49 |
+
eef_pos = state['robot0_eef_pos']
|
| 50 |
+
eef_ang = quaternion_to_euler(state['robot0_eef_quat'])
|
| 51 |
+
|
| 52 |
+
state['arm_concat'] = tf.concat([arm_joint_pos, arm_joint_vel, gripper_pos,gripper_vel,eef_pos,eef_ang], axis=0)
|
| 53 |
+
# convert to tf32
|
| 54 |
+
state['arm_concat'] = tf.cast(state['arm_concat'], tf.float32)
|
| 55 |
+
# Write the state format
|
| 56 |
+
state['format'] = tf.constant(
|
| 57 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,gripper_joint_0_pos,gripper_joint_1_pos,gripper_joint_0_vel,gripper_joint_1_vel,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_roll,eef_angle_pitch,eef_angle_yaw")
|
| 58 |
+
|
| 59 |
+
# Clean the task instruction
|
| 60 |
+
# Define the replacements (old, new) as a dictionary
|
| 61 |
+
replacements = {
|
| 62 |
+
'_': ' ',
|
| 63 |
+
'1f': ' ',
|
| 64 |
+
'4f': ' ',
|
| 65 |
+
'-': ' ',
|
| 66 |
+
'50': ' ',
|
| 67 |
+
'55': ' ',
|
| 68 |
+
'56': ' ',
|
| 69 |
+
|
| 70 |
+
}
|
| 71 |
+
# manual added by lbg
|
| 72 |
+
instr = "lift the can into the the box"
|
| 73 |
+
instr = clean_task_instruction(instr, replacements)
|
| 74 |
+
step['observation']['natural_language_instruction'] = instr
|
| 75 |
+
|
| 76 |
+
return step
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
import tensorflow_datasets as tfds
|
| 81 |
+
from data.utils import dataset_to_path
|
| 82 |
+
|
| 83 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 84 |
+
DATASET_NAME = 'roboturk'
|
| 85 |
+
# Load the dataset
|
| 86 |
+
dataset = tfds.builder_from_directory(
|
| 87 |
+
builder_dir=dataset_to_path(
|
| 88 |
+
DATASET_NAME, DATASET_DIR))
|
| 89 |
+
dataset = dataset.as_dataset(split='all').take(1)
|
| 90 |
+
|
| 91 |
+
# Inspect the dataset
|
| 92 |
+
ze=tf.constant(0.0)
|
| 93 |
+
for episode in dataset:
|
| 94 |
+
for step in episode['steps']:
|
| 95 |
+
print(step)
|
| 96 |
+
break
|
data/preprocess_scripts/robomimic_tool_hang_ph.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def load_dataset():
|
| 7 |
+
builder = tfds.builder('robomimic_ph/tool_hang_ph_image')
|
| 8 |
+
builder.download_and_prepare()
|
| 9 |
+
ds = builder.as_dataset(split='train', shuffle_files=True)
|
| 10 |
+
return ds
|
| 11 |
+
|
| 12 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 13 |
+
"""
|
| 14 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 15 |
+
"""
|
| 16 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 17 |
+
|
| 18 |
+
def process_step(step: dict) -> dict:
|
| 19 |
+
"""
|
| 20 |
+
Unify the action format and clean the task instruction.
|
| 21 |
+
|
| 22 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 23 |
+
"""
|
| 24 |
+
# format refers to https://www.tensorflow.org/datasets/catalog/robomimic_mg
|
| 25 |
+
# Convert raw action to our action
|
| 26 |
+
eef = step['action']
|
| 27 |
+
step['action'] = {}
|
| 28 |
+
action = step['action']
|
| 29 |
+
action['terminate'] = step['is_terminal']
|
| 30 |
+
|
| 31 |
+
eef_delta_pos = eef[:3]
|
| 32 |
+
eef_ang = quaternion_to_euler(eef[3:])
|
| 33 |
+
|
| 34 |
+
# No base found
|
| 35 |
+
|
| 36 |
+
# Concatenate the action
|
| 37 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang], axis=0)
|
| 38 |
+
action['arm_concat'] = arm_action
|
| 39 |
+
|
| 40 |
+
# Write the action format
|
| 41 |
+
action['format'] = tf.constant(
|
| 42 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_roll,eef_delta_angle_pitch,eef_delta_angle_yaw")
|
| 43 |
+
|
| 44 |
+
# Convert raw state to our state
|
| 45 |
+
state = step['observation']
|
| 46 |
+
arm_joint_pos = state['robot0_joint_pos']
|
| 47 |
+
arm_joint_vel = state['robot0_joint_vel']
|
| 48 |
+
gripper_pos = state['robot0_gripper_qpos']
|
| 49 |
+
gripper_vel = state['robot0_gripper_qvel']
|
| 50 |
+
eef_pos = state['robot0_eef_pos']
|
| 51 |
+
eef_ang = quaternion_to_euler(state['robot0_eef_quat'])
|
| 52 |
+
|
| 53 |
+
state['arm_concat'] = tf.concat([arm_joint_pos, arm_joint_vel, gripper_pos,gripper_vel,eef_pos,eef_ang], axis=0)
|
| 54 |
+
# convert to tf32
|
| 55 |
+
state['arm_concat'] = tf.cast(state['arm_concat'], tf.float32)
|
| 56 |
+
# Write the state format
|
| 57 |
+
state['format'] = tf.constant(
|
| 58 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,gripper_joint_0_pos,gripper_joint_1_pos,gripper_joint_0_vel,gripper_joint_1_vel,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_roll,eef_angle_pitch,eef_angle_yaw")
|
| 59 |
+
|
| 60 |
+
# Clean the task instruction
|
| 61 |
+
# Define the replacements (old, new) as a dictionary
|
| 62 |
+
replacements = {
|
| 63 |
+
'_': ' ',
|
| 64 |
+
'1f': ' ',
|
| 65 |
+
'4f': ' ',
|
| 66 |
+
'-': ' ',
|
| 67 |
+
'50': ' ',
|
| 68 |
+
'55': ' ',
|
| 69 |
+
'56': ' ',
|
| 70 |
+
|
| 71 |
+
}
|
| 72 |
+
# manual added by lbg
|
| 73 |
+
instr = "hang the tool and place into the hole"
|
| 74 |
+
instr = clean_task_instruction(instr, replacements)
|
| 75 |
+
step['observation']['natural_language_instruction'] = instr
|
| 76 |
+
|
| 77 |
+
return step
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
import tensorflow_datasets as tfds
|
| 82 |
+
from data.utils import dataset_to_path
|
| 83 |
+
|
| 84 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 85 |
+
DATASET_NAME = 'roboturk'
|
| 86 |
+
# Load the dataset
|
| 87 |
+
dataset = tfds.builder_from_directory(
|
| 88 |
+
builder_dir=dataset_to_path(
|
| 89 |
+
DATASET_NAME, DATASET_DIR))
|
| 90 |
+
dataset = dataset.as_dataset(split='all').take(1)
|
| 91 |
+
|
| 92 |
+
# Inspect the dataset
|
| 93 |
+
ze=tf.constant(0.0)
|
| 94 |
+
for episode in dataset:
|
| 95 |
+
for step in episode['steps']:
|
| 96 |
+
print(step)
|
| 97 |
+
break
|
data/preprocess_scripts/robomimic_transport_ph.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def load_dataset():
|
| 7 |
+
builder = tfds.builder('robomimic_ph/transport_ph_image')
|
| 8 |
+
builder.download_and_prepare()
|
| 9 |
+
ds = builder.as_dataset(split='train', shuffle_files=True)
|
| 10 |
+
return ds
|
| 11 |
+
|
| 12 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 13 |
+
"""
|
| 14 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 15 |
+
"""
|
| 16 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 17 |
+
|
| 18 |
+
def process_step(step: dict) -> dict:
|
| 19 |
+
"""
|
| 20 |
+
Unify the action format and clean the task instruction.
|
| 21 |
+
|
| 22 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 23 |
+
"""
|
| 24 |
+
# format refers to https://www.tensorflow.org/datasets/catalog/robomimic_mg
|
| 25 |
+
# Convert raw action to our action
|
| 26 |
+
eef = step['action']
|
| 27 |
+
step['action'] = {}
|
| 28 |
+
action = step['action']
|
| 29 |
+
action['terminate'] = step['is_terminal']
|
| 30 |
+
|
| 31 |
+
left_eef_delta_pos = eef[:3]
|
| 32 |
+
left_eef_ang = quaternion_to_euler(eef[3:7])
|
| 33 |
+
|
| 34 |
+
right_eef_delta_pos = eef[7:10]
|
| 35 |
+
right_eef_ang = quaternion_to_euler(eef[10:])
|
| 36 |
+
|
| 37 |
+
# No base found
|
| 38 |
+
|
| 39 |
+
# Concatenate the action
|
| 40 |
+
arm_action = tf.concat([left_eef_delta_pos,left_eef_ang,right_eef_delta_pos,right_eef_ang], axis=0)
|
| 41 |
+
action['arm_concat'] = arm_action
|
| 42 |
+
|
| 43 |
+
# Write the action format
|
| 44 |
+
action['format'] = tf.constant(
|
| 45 |
+
"left_eef_delta_pos_x,left_eef_delta_pos_y,left_eef_delta_pos_z,left_eef_delta_angle_roll,left_eef_delta_angle_pitch,left_eef_delta_angle_yaw,right_eef_delta_pos_x,right_eef_delta_pos_y,right_eef_delta_pos_z,right_eef_delta_angle_roll,right_eef_delta_angle_pitch,right_eef_delta_angle_yaw")
|
| 46 |
+
|
| 47 |
+
# Convert raw state to our state
|
| 48 |
+
state = step['observation']
|
| 49 |
+
left_arm_joint_pos = state['robot0_joint_pos']
|
| 50 |
+
left_arm_joint_vel = state['robot0_joint_vel']
|
| 51 |
+
left_gripper_pos = state['robot0_gripper_qpos']
|
| 52 |
+
left_gripper_vel = state['robot0_gripper_qvel']
|
| 53 |
+
left_eef_pos = state['robot0_eef_pos']
|
| 54 |
+
left_eef_ang = quaternion_to_euler(state['robot0_eef_quat'])
|
| 55 |
+
|
| 56 |
+
right_arm_joint_pos = state['robot1_joint_pos']
|
| 57 |
+
right_arm_joint_vel = state['robot1_joint_vel']
|
| 58 |
+
right_gripper_pos = state['robot1_gripper_qpos']
|
| 59 |
+
right_gripper_vel = state['robot1_gripper_qvel']
|
| 60 |
+
right_eef_pos = state['robot1_eef_pos']
|
| 61 |
+
right_eef_ang = quaternion_to_euler(state['robot1_eef_quat'])
|
| 62 |
+
|
| 63 |
+
arm_joint_pos = tf.concat([left_arm_joint_pos, right_arm_joint_pos], axis=0)
|
| 64 |
+
arm_joint_vel = tf.concat([left_arm_joint_vel, right_arm_joint_vel], axis=0)
|
| 65 |
+
gripper_pos = tf.concat([left_gripper_pos, right_gripper_pos], axis=0)
|
| 66 |
+
gripper_vel = tf.concat([left_gripper_vel, right_gripper_vel], axis=0)
|
| 67 |
+
eef_pos = tf.concat([left_eef_pos, right_eef_pos], axis=0)
|
| 68 |
+
eef_ang = tf.concat([left_eef_ang, right_eef_ang], axis=0)
|
| 69 |
+
|
| 70 |
+
state['arm_concat'] = tf.concat([arm_joint_pos, arm_joint_vel, gripper_pos,gripper_vel,eef_pos,eef_ang], axis=0)
|
| 71 |
+
# convert to tf32
|
| 72 |
+
state['arm_concat'] = tf.cast(state['arm_concat'], tf.float32)
|
| 73 |
+
# Write the state format
|
| 74 |
+
state['format'] = tf.constant(
|
| 75 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_arm_joint_6_pos,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_arm_joint_6_pos,left_gripper_joint_0_pos,left_gripper_joint_1_pos,right_gripper_joint_0_pos,right_gripper_joint_1_pos,left_arm_joint_0_vel,left_arm_joint_1_vel,left_arm_joint_2_vel,left_arm_joint_3_vel,left_arm_joint_4_vel,left_arm_joint_5_vel,left_arm_joint_6_vel,right_arm_joint_0_vel,right_arm_joint_1_vel,right_arm_joint_2_vel,right_arm_joint_3_vel,right_arm_joint_4_vel,right_arm_joint_5_vel,right_arm_joint_6_vel,left_gripper_joint_0_vel,left_gripper_joint_1_vel,right_gripper_joint_0_vel,right_gripper_joint_1_vel,left_eef_pos_x,left_eef_pos_y,left_eef_pos_z,left_eef_angle_roll,left_eef_angle_pitch,left_eef_angle_yaw,right_eef_pos_x,right_eef_pos_y,right_eef_pos_z,right_eef_angle_roll,right_eef_angle_pitch,right_eef_angle_yaw")
|
| 76 |
+
|
| 77 |
+
# Clean the task instruction
|
| 78 |
+
# Define the replacements (old, new) as a dictionary
|
| 79 |
+
replacements = {
|
| 80 |
+
'_': ' ',
|
| 81 |
+
'1f': ' ',
|
| 82 |
+
'4f': ' ',
|
| 83 |
+
'-': ' ',
|
| 84 |
+
'50': ' ',
|
| 85 |
+
'55': ' ',
|
| 86 |
+
'56': ' ',
|
| 87 |
+
|
| 88 |
+
}
|
| 89 |
+
# manual added by lbg
|
| 90 |
+
instr = "transport the object from left hand to right hand"
|
| 91 |
+
instr = clean_task_instruction(instr, replacements)
|
| 92 |
+
step['observation']['natural_language_instruction'] = instr
|
| 93 |
+
|
| 94 |
+
return step
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
import tensorflow_datasets as tfds
|
| 99 |
+
from data.utils import dataset_to_path
|
| 100 |
+
|
| 101 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 102 |
+
DATASET_NAME = 'roboturk'
|
| 103 |
+
# Load the dataset
|
| 104 |
+
dataset = tfds.builder_from_directory(
|
| 105 |
+
builder_dir=dataset_to_path(
|
| 106 |
+
DATASET_NAME, DATASET_DIR))
|
| 107 |
+
dataset = dataset.as_dataset(split='all').take(1)
|
| 108 |
+
|
| 109 |
+
# Inspect the dataset
|
| 110 |
+
ze=tf.constant(0.0)
|
| 111 |
+
for episode in dataset:
|
| 112 |
+
for step in episode['steps']:
|
| 113 |
+
print(step)
|
| 114 |
+
break
|
data/preprocess_scripts/roboturk_real_laundrylayout.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_datasets as tfds
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import h5py
|
| 6 |
+
import numpy as np
|
| 7 |
+
from tqdm import tqdm
|
| 8 |
+
import os
|
| 9 |
+
import imageio
|
| 10 |
+
import concurrent.futures
|
| 11 |
+
|
| 12 |
+
def get_frames(file_path):
|
| 13 |
+
if not os.path.exists(file_path) or not os.path.isfile(file_path) or not file_path.endswith('.mp4'):
|
| 14 |
+
return []
|
| 15 |
+
frames = []
|
| 16 |
+
with imageio.get_reader(file_path, 'ffmpeg') as reader:
|
| 17 |
+
for frame in reader:
|
| 18 |
+
frame = np.array(frame, dtype=np.uint8)
|
| 19 |
+
frames.append(frame)
|
| 20 |
+
return frames
|
| 21 |
+
|
| 22 |
+
def parallel_get_frames(paths):
|
| 23 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 24 |
+
future_to_path = {executor.submit(get_frames, path): path for path in paths}
|
| 25 |
+
return [future.result() for future in concurrent.futures.as_completed(future_to_path)]
|
| 26 |
+
|
| 27 |
+
def count_total_samples(filename):
|
| 28 |
+
total_samples = 0
|
| 29 |
+
with h5py.File(filename, 'r') as f:
|
| 30 |
+
data = f['data']
|
| 31 |
+
for user_key in data.keys():
|
| 32 |
+
user = data[user_key]
|
| 33 |
+
for demo_key in user.keys():
|
| 34 |
+
total_samples += 1
|
| 35 |
+
return total_samples
|
| 36 |
+
|
| 37 |
+
def dataset_generator(filename, total_samples):
|
| 38 |
+
with h5py.File(filename, 'r') as f:
|
| 39 |
+
data = f['data']
|
| 40 |
+
for user_key in data.keys():
|
| 41 |
+
user = data[user_key]
|
| 42 |
+
for demo_key in user.keys():
|
| 43 |
+
demo = user[demo_key]
|
| 44 |
+
robot_observation = demo['robot_observation']
|
| 45 |
+
user_control = demo['user_control']
|
| 46 |
+
|
| 47 |
+
eef_poses = robot_observation['eef_poses']
|
| 48 |
+
joint_states_arm = robot_observation['joint_states_arm']
|
| 49 |
+
joint_states_gripper = robot_observation['joint_states_gripper']
|
| 50 |
+
user_control_data = user_control['user_control']
|
| 51 |
+
|
| 52 |
+
attrs = dict(demo.attrs)
|
| 53 |
+
top_depth_video_file = attrs['top_depth_video_file']
|
| 54 |
+
top_rgb_video_file = attrs['top_rgb_video_file']
|
| 55 |
+
front_rgb_video_file = attrs['front_rgb_video_file']
|
| 56 |
+
|
| 57 |
+
video_root_path = './data/datasets/roboturk'
|
| 58 |
+
top_depth_frames = get_frames(os.path.join(video_root_path, top_depth_video_file))
|
| 59 |
+
top_rgb_frames = get_frames(os.path.join(video_root_path, top_rgb_video_file))
|
| 60 |
+
front_rgb_frames = get_frames(os.path.join(video_root_path, front_rgb_video_file))
|
| 61 |
+
|
| 62 |
+
if len(top_depth_frames) == 0 or len(top_rgb_frames) == 0 or len(front_rgb_frames) == 0:
|
| 63 |
+
continue
|
| 64 |
+
# video_root_path = '/cephfs-thu/gsm_data/robotruck'
|
| 65 |
+
# video_paths = [
|
| 66 |
+
# os.path.join(video_root_path, attrs['top_depth_video_file']),
|
| 67 |
+
# os.path.join(video_root_path, attrs['top_rgb_video_file']),
|
| 68 |
+
# os.path.join(video_root_path, attrs['front_rgb_video_file'])
|
| 69 |
+
# ]
|
| 70 |
+
# top_depth_frames, top_rgb_frames, front_rgb_frames = parallel_get_frames(video_paths)
|
| 71 |
+
|
| 72 |
+
steps = []
|
| 73 |
+
for i in range(len(eef_poses)):
|
| 74 |
+
task_demo_id = f"SawyerTowerCreation_{demo_key}_{i}"
|
| 75 |
+
step = {
|
| 76 |
+
'task_demo_id': task_demo_id,
|
| 77 |
+
'eef_poses': eef_poses[i],
|
| 78 |
+
'joint_states_arm': joint_states_arm[i],
|
| 79 |
+
'joint_states_gripper': joint_states_gripper[i],
|
| 80 |
+
'user_control': user_control_data[i] if user_control_data.shape[0] > 0 else np.zeros(22),
|
| 81 |
+
'observation':{
|
| 82 |
+
'top_depth_frame': top_depth_frames[i] if i < len(top_depth_frames) else np.zeros((0,0, 3), dtype=np.uint8),
|
| 83 |
+
'top_rgb_frame': top_rgb_frames[i] if i < len(top_rgb_frames) else np.zeros((0, 0, 3), dtype=np.uint8),
|
| 84 |
+
'front_rgb_frame': front_rgb_frames[i] if i < len(front_rgb_frames) else np.zeros((0, 0, 3), dtype=np.uint8),
|
| 85 |
+
},
|
| 86 |
+
'terminate_episode': i == len(eef_poses) - 1
|
| 87 |
+
}
|
| 88 |
+
steps.append(step)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
steps_dataset = tf.data.Dataset.from_generator(
|
| 92 |
+
lambda: iter(steps),
|
| 93 |
+
output_signature={
|
| 94 |
+
'task_demo_id': tf.TensorSpec(shape=(), dtype=tf.string),
|
| 95 |
+
'eef_poses': tf.TensorSpec(shape=(7,), dtype=tf.float32),
|
| 96 |
+
'joint_states_arm': tf.TensorSpec(shape=(27,), dtype=tf.float32),
|
| 97 |
+
'joint_states_gripper': tf.TensorSpec(shape=(3,), dtype=tf.float32),
|
| 98 |
+
'user_control': tf.TensorSpec(shape=(22,), dtype=tf.float32),
|
| 99 |
+
'observation':{
|
| 100 |
+
'top_depth_frame': tf.TensorSpec(shape=(None, None, 3), dtype=tf.uint8),
|
| 101 |
+
'top_rgb_frame': tf.TensorSpec(shape=(None, None, 3), dtype=tf.uint8),
|
| 102 |
+
'front_rgb_frame': tf.TensorSpec(shape=(None, None, 3), dtype=tf.uint8),
|
| 103 |
+
},
|
| 104 |
+
'terminate_episode': tf.TensorSpec(shape=(), dtype=tf.bool),
|
| 105 |
+
}
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
yield {'steps': steps_dataset}
|
| 109 |
+
|
| 110 |
+
def load_dataset():
|
| 111 |
+
filename = './data/datasets/roboturk/SawyerLaundryLayout_aligned_dataset.hdf5'
|
| 112 |
+
total_samples = count_total_samples(filename)
|
| 113 |
+
dataset = tf.data.Dataset.from_generator(
|
| 114 |
+
lambda: dataset_generator(filename, total_samples),
|
| 115 |
+
output_signature={
|
| 116 |
+
'steps': tf.data.DatasetSpec(
|
| 117 |
+
element_spec={
|
| 118 |
+
'task_demo_id': tf.TensorSpec(shape=(), dtype=tf.string),
|
| 119 |
+
'eef_poses': tf.TensorSpec(shape=(7,), dtype=tf.float32),
|
| 120 |
+
'joint_states_arm': tf.TensorSpec(shape=(27,), dtype=tf.float32),
|
| 121 |
+
'joint_states_gripper': tf.TensorSpec(shape=(3,), dtype=tf.float32),
|
| 122 |
+
'user_control': tf.TensorSpec(shape=(22,), dtype=tf.float32),
|
| 123 |
+
'observation':{
|
| 124 |
+
'top_depth_frame': tf.TensorSpec(shape=(None, None, 3), dtype=tf.uint8),
|
| 125 |
+
'top_rgb_frame': tf.TensorSpec(shape=(None, None, 3), dtype=tf.uint8),
|
| 126 |
+
'front_rgb_frame': tf.TensorSpec(shape=(None, None, 3), dtype=tf.uint8),
|
| 127 |
+
},
|
| 128 |
+
'terminate_episode': tf.TensorSpec(shape=(), dtype = tf.bool),
|
| 129 |
+
}
|
| 130 |
+
)
|
| 131 |
+
}
|
| 132 |
+
)
|
| 133 |
+
return dataset
|
| 134 |
+
|
| 135 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 136 |
+
"""
|
| 137 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 138 |
+
"""
|
| 139 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def process_step(step: dict) -> dict:
|
| 143 |
+
"""
|
| 144 |
+
Unify the action format and clean the task instruction.
|
| 145 |
+
|
| 146 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 147 |
+
"""
|
| 148 |
+
# Convert raw action to our action
|
| 149 |
+
step['action'] = {}
|
| 150 |
+
action = step['action']
|
| 151 |
+
action['terminate'] = step['terminate_episode']
|
| 152 |
+
|
| 153 |
+
eef_delta_pos = step['eef_poses'][:3]
|
| 154 |
+
eef_ang = step['eef_poses'][3:]
|
| 155 |
+
|
| 156 |
+
# No base found
|
| 157 |
+
# Concatenate the action
|
| 158 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang], axis=0)
|
| 159 |
+
action['arm_concat'] = arm_action
|
| 160 |
+
|
| 161 |
+
# Write the action format
|
| 162 |
+
action['format'] = tf.constant(
|
| 163 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_roll,eef_delta_angle_pitch,eef_delta_angle_yaw")
|
| 164 |
+
|
| 165 |
+
# No state found
|
| 166 |
+
state = step['observation']
|
| 167 |
+
# joint_states_arm: dataset of (num_timestamps, 27) shape where each of the 9 joints is represented by the JointState message
|
| 168 |
+
# (the nine joints are in order by their ROSBAG names: ['head_pan', 'right_j0', 'right_j1', 'right_j2', 'right_j3', 'right_j4', 'right_j5', 'right_j6', 'torso_t0']. For the most part, head_pan and torso should be zeros)
|
| 169 |
+
# [0] the position of the first joint (rad or m)
|
| 170 |
+
# [1] the velocity of the first joint (rad/s or m/s)
|
| 171 |
+
# [2] the effort that is applied in the first joint
|
| 172 |
+
# [3] the position of the second joint...
|
| 173 |
+
joint_states_arm = step['joint_states_arm']
|
| 174 |
+
joint_pos = joint_states_arm[3:24:3]
|
| 175 |
+
joint_vel = joint_states_arm[4:25:3]
|
| 176 |
+
# joint_states_gripper: dataset of (num_timestamps, 3) shape
|
| 177 |
+
# [0] the position of the gripper (rad or m)
|
| 178 |
+
# [1] the velocity of the gripper (rad/s or m/s)
|
| 179 |
+
# [2] the effort that is applied in the gripper
|
| 180 |
+
joint_states_gripper = step['joint_states_gripper']
|
| 181 |
+
gripper_pos = joint_states_gripper[:1]
|
| 182 |
+
# remove gripper_vel due to they are all zeros
|
| 183 |
+
# gripper_vel = joint_states_gripper[1:2]
|
| 184 |
+
# Concatenate the state
|
| 185 |
+
# state['arm_concat'] = tf.concat([joint_pos,joint_vel,gripper_pos,gripper_vel], axis=0)
|
| 186 |
+
state['arm_concat'] = tf.concat([joint_pos,joint_vel,gripper_pos], axis=0)
|
| 187 |
+
# Write the state format
|
| 188 |
+
state['format'] = tf.constant(
|
| 189 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,gripper_joint_0_pos")
|
| 190 |
+
|
| 191 |
+
# Clean the task instruction
|
| 192 |
+
# Define the replacements (old, new) as a dictionary
|
| 193 |
+
replacements = {
|
| 194 |
+
'_': ' ',
|
| 195 |
+
'1f': ' ',
|
| 196 |
+
'4f': ' ',
|
| 197 |
+
'-': ' ',
|
| 198 |
+
'50': ' ',
|
| 199 |
+
'55': ' ',
|
| 200 |
+
'56': ' ',
|
| 201 |
+
|
| 202 |
+
}
|
| 203 |
+
# copied from openxembod
|
| 204 |
+
instr = b'create tower'
|
| 205 |
+
instr = clean_task_instruction(instr, replacements)
|
| 206 |
+
step['observation']['natural_language_instruction'] = instr
|
| 207 |
+
|
| 208 |
+
return step
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
if __name__ == "__main__":
|
| 212 |
+
import tensorflow_datasets as tfds
|
| 213 |
+
from data.utils import dataset_to_path
|
| 214 |
+
|
| 215 |
+
DATASET_DIR = '/cephfs-thu/gsm_data/openx_embod'
|
| 216 |
+
DATASET_NAME = 'roboturk_real_laundrylayout'
|
| 217 |
+
# Load the dataset
|
| 218 |
+
dataset = load_dataset()
|
| 219 |
+
|
| 220 |
+
# save_dir = os.path.join(DATASET_DIR, DATASET_NAME)
|
| 221 |
+
# if not os.path.exists(save_dir):
|
| 222 |
+
# os.makedirs(save_dir)
|
| 223 |
+
# tf.data.experimental.save(dataset, save_dir)
|
data/preprocess_scripts/singlevla_benchmark.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
|
| 15 |
+
# Robot action
|
| 16 |
+
# eef_pos = action_dict['ee_pos'][:3]
|
| 17 |
+
# eef_ang = action_dict['ee_pos'][3:6]
|
| 18 |
+
# eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 19 |
+
# eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 20 |
+
# eef_pos_vel = action_dict['delta_ee'][:3]
|
| 21 |
+
# eef_ang_vel = action_dict['delta_ee'][3:6]
|
| 22 |
+
joint_pos = action_dict['joint_pos']
|
| 23 |
+
# joint_vel = action_dict['delta_joint'][:-1]
|
| 24 |
+
# grip_pos = action_dict['delta_ee'][-1:]
|
| 25 |
+
# grip_vel = action_dict['gripper_velocity']
|
| 26 |
+
|
| 27 |
+
# Concatenate the action
|
| 28 |
+
step['action'] = {}
|
| 29 |
+
action = step['action']
|
| 30 |
+
|
| 31 |
+
# arm_action = tf.concat([joint_pos, eef_pos, eef_ang, eef_pos_vel, eef_ang_vel, grip_pos], axis=0)
|
| 32 |
+
action['arm_concat'] = joint_pos
|
| 33 |
+
# action['terminate'] = step['is_terminal']
|
| 34 |
+
|
| 35 |
+
# Write the action format
|
| 36 |
+
action['format'] = tf.constant(
|
| 37 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos, gripper_joint_0_pos")
|
| 38 |
+
|
| 39 |
+
# Convert raw state to our state
|
| 40 |
+
# Robot state
|
| 41 |
+
state = step['observation']['state']
|
| 42 |
+
# image = step['observation']['image']
|
| 43 |
+
# eef_pos = state['ee_pos'][:3]
|
| 44 |
+
# eef_ang = state['ee_pos'][3:6]
|
| 45 |
+
# eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 46 |
+
# eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 47 |
+
joint_pos = state['joint_pos']
|
| 48 |
+
# grip_pos = state['joint_pos'][-1:]
|
| 49 |
+
|
| 50 |
+
# # Concatenate the state
|
| 51 |
+
# state['arm_concat'] = tf.concat([
|
| 52 |
+
# joint_pos, grip_pos,eef_pos,eef_ang], axis=0)
|
| 53 |
+
|
| 54 |
+
state['arm_concat'] = joint_pos
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Write the state format
|
| 58 |
+
state['format'] = tf.constant(
|
| 59 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,gripper_joint_0_pos")
|
| 60 |
+
|
| 61 |
+
# Clean the task instruction
|
| 62 |
+
# Define the replacements (old, new) as a dictionary
|
| 63 |
+
replacements = {
|
| 64 |
+
'_': ' ',
|
| 65 |
+
'1f': ' ',
|
| 66 |
+
'4f': ' ',
|
| 67 |
+
'-': ' ',
|
| 68 |
+
'50': ' ',
|
| 69 |
+
'55': ' ',
|
| 70 |
+
'56': ' ',
|
| 71 |
+
|
| 72 |
+
}
|
| 73 |
+
instr = step['language_instruction']
|
| 74 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 75 |
+
step['observation'] = state
|
| 76 |
+
step['observation']['natural_language_instruction'] = instr
|
| 77 |
+
|
| 78 |
+
return step
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
pass
|
data/preprocess_scripts/stanford_kuka_multimodal_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
def process_step(step: dict) -> dict:
|
| 6 |
+
"""
|
| 7 |
+
Unify the action format and clean the task instruction.
|
| 8 |
+
|
| 9 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 10 |
+
"""
|
| 11 |
+
# Convert raw action to our action
|
| 12 |
+
|
| 13 |
+
origin_action = step['action']
|
| 14 |
+
step['action']={}
|
| 15 |
+
action=step['action']
|
| 16 |
+
action['terminate'] = step['is_terminal']
|
| 17 |
+
|
| 18 |
+
eef_delta_pos = origin_action[:3]
|
| 19 |
+
|
| 20 |
+
# Ignore grip_open: -0.15~0.15
|
| 21 |
+
|
| 22 |
+
# No base found
|
| 23 |
+
|
| 24 |
+
# Concatenate the action
|
| 25 |
+
action['arm_concat'] = eef_delta_pos
|
| 26 |
+
|
| 27 |
+
# Write the action format
|
| 28 |
+
action['format'] = tf.constant(
|
| 29 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z")
|
| 30 |
+
|
| 31 |
+
# Convert raw state to our state
|
| 32 |
+
state = step['observation']
|
| 33 |
+
eef_quat = state['ee_orientation']
|
| 34 |
+
eef_ang = quaternion_to_rotation_matrix(eef_quat)
|
| 35 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 36 |
+
eef_ang_vel = state['ee_orientation_vel']
|
| 37 |
+
eef_pos = state['ee_position']
|
| 38 |
+
eef_vel = state['ee_vel']
|
| 39 |
+
joint_pos = state['joint_pos']
|
| 40 |
+
joint_vel = state['joint_vel']
|
| 41 |
+
gripper_open = state['state'][7:8]
|
| 42 |
+
|
| 43 |
+
# Concatenate the state
|
| 44 |
+
state['arm_concat'] = tf.concat([joint_pos,gripper_open,joint_vel,eef_pos,eef_ang,eef_vel,eef_ang_vel],axis=0)
|
| 45 |
+
|
| 46 |
+
# Write the state format
|
| 47 |
+
state['format'] = tf.constant(
|
| 48 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,gripper_open,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw")
|
| 49 |
+
|
| 50 |
+
# Clean the task instruction
|
| 51 |
+
# Define the replacements (old, new) as a dictionary
|
| 52 |
+
replacements = {
|
| 53 |
+
'_': ' ',
|
| 54 |
+
'1f': ' ',
|
| 55 |
+
'4f': ' ',
|
| 56 |
+
'-': ' ',
|
| 57 |
+
'50': ' ',
|
| 58 |
+
'55': ' ',
|
| 59 |
+
'56': ' ',
|
| 60 |
+
|
| 61 |
+
}
|
| 62 |
+
instr = step['language_instruction']
|
| 63 |
+
instr = clean_task_instruction(instr, replacements)
|
| 64 |
+
step['observation']['natural_language_instruction'] = instr
|
| 65 |
+
|
| 66 |
+
return step
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
if __name__ == "__main__":
|
| 70 |
+
import tensorflow_datasets as tfds
|
| 71 |
+
from data.utils import dataset_to_path
|
| 72 |
+
|
| 73 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 74 |
+
DATASET_NAME = 'stanford_kuka_multimodal_dataset_converted_externally_to_rlds'
|
| 75 |
+
# Load the dataset
|
| 76 |
+
dataset = tfds.builder_from_directory(
|
| 77 |
+
builder_dir=dataset_to_path(
|
| 78 |
+
DATASET_NAME, DATASET_DIR))
|
| 79 |
+
dataset = dataset.as_dataset(split='all')
|
| 80 |
+
|
| 81 |
+
# Inspect the dataset
|
| 82 |
+
for episode in dataset:
|
| 83 |
+
for step in episode['steps']:
|
| 84 |
+
print(step)
|
data/preprocess_scripts/stanford_mask_vit_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.float32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# Convert raw action to our action
|
| 22 |
+
action = step['action']
|
| 23 |
+
# Robot action, consists of [3x change in end effector position, 1x gripper yaw, 1x open/close gripper (-1 means to open the gripper, 1 means close)].
|
| 24 |
+
eef_delta_pos = action[:3]
|
| 25 |
+
eef_yaw = action[3:4]
|
| 26 |
+
eef_ang = tf.stack([0,0,eef_yaw[0]],axis=0)
|
| 27 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 28 |
+
grip_open = tf.expand_dims((1 - action[4]) / 2, axis=0)
|
| 29 |
+
|
| 30 |
+
# Concatenate the action
|
| 31 |
+
step['action'] = {}
|
| 32 |
+
action = step['action']
|
| 33 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 34 |
+
|
| 35 |
+
action['terminate'] = step['is_terminal']
|
| 36 |
+
# Write the action format
|
| 37 |
+
action['format'] = tf.constant(
|
| 38 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Convert raw state to our state
|
| 42 |
+
state = step['observation']['state']
|
| 43 |
+
# Robot state, consists of [7x robot joint angles, 7x robot joint velocities,1x gripper position].
|
| 44 |
+
arm_joint_pos = state[:7]
|
| 45 |
+
arm_joint_vel = state[7:14]
|
| 46 |
+
gripper_pos = state[14:15]
|
| 47 |
+
# Robot end effector pose, consists of [3x Cartesian position, 1x gripper yaw, 1x gripper position]. This is the state used in the MaskViT paper.
|
| 48 |
+
eef = step['observation']['end_effector_pose']
|
| 49 |
+
eef_pos = eef[:3]
|
| 50 |
+
gripper_yaw = eef[3:4]
|
| 51 |
+
eef_ang = tf.stack([0.0,0.0,gripper_yaw[0]],axis=0)
|
| 52 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 53 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 54 |
+
# gripper_pos = eef[4:5]
|
| 55 |
+
|
| 56 |
+
# Concatenate the state
|
| 57 |
+
state = step['observation']
|
| 58 |
+
state['arm_concat'] = tf.concat([arm_joint_pos,arm_joint_vel,gripper_pos,eef_pos,eef_ang], axis=0)
|
| 59 |
+
|
| 60 |
+
# Write the state format
|
| 61 |
+
state['format'] = tf.constant(
|
| 62 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel,gripper_joint_0_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 63 |
+
|
| 64 |
+
# Clean the task instruction
|
| 65 |
+
# Define the replacements (old, new) as a dictionary
|
| 66 |
+
replacements = {
|
| 67 |
+
'_': ' ',
|
| 68 |
+
'1f': ' ',
|
| 69 |
+
'4f': ' ',
|
| 70 |
+
'-': ' ',
|
| 71 |
+
'50': ' ',
|
| 72 |
+
'55': ' ',
|
| 73 |
+
'56': ' ',
|
| 74 |
+
|
| 75 |
+
}
|
| 76 |
+
instr = step['language_instruction']
|
| 77 |
+
instr = clean_task_instruction(instr, replacements)
|
| 78 |
+
step['observation']['natural_language_instruction'] = instr
|
| 79 |
+
|
| 80 |
+
return step
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
import tensorflow_datasets as tfds
|
| 85 |
+
from data.utils import dataset_to_path
|
| 86 |
+
|
| 87 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 88 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 89 |
+
# Load the dataset
|
| 90 |
+
dataset = tfds.builder_from_directory(
|
| 91 |
+
builder_dir=dataset_to_path(
|
| 92 |
+
DATASET_NAME, DATASET_DIR))
|
| 93 |
+
dataset = dataset.as_dataset(split='all')
|
| 94 |
+
|
| 95 |
+
# Inspect the dataset
|
| 96 |
+
for episode in dataset:
|
| 97 |
+
for step in episode['steps']:
|
| 98 |
+
print(step)
|
data/preprocess_scripts/stanford_robocook_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.int32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
# Robot action, consists of [3x robot end-effector velocities, 3x robot end-effector angular velocities, 1x gripper velocity].
|
| 23 |
+
eef_delta_pos = action[:3]
|
| 24 |
+
eef_ang = action[3:6]
|
| 25 |
+
grip_vel = tf.expand_dims(action[6], axis=0)
|
| 26 |
+
|
| 27 |
+
# Concatenate the action
|
| 28 |
+
# action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 29 |
+
step['action'] = {}
|
| 30 |
+
action = step['action']
|
| 31 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_vel], axis=0)
|
| 32 |
+
action['terminate'] = step['is_terminal']
|
| 33 |
+
|
| 34 |
+
# Write the action format
|
| 35 |
+
action['format'] = tf.constant(
|
| 36 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw,gripper_joint_0_vel")
|
| 37 |
+
|
| 38 |
+
# Convert raw state to our state
|
| 39 |
+
state = step['observation']
|
| 40 |
+
state_vec = state['state']
|
| 41 |
+
# Robot state, consists of [3x robot end-effector position, 3x robot end-effector euler angles, 1x gripper position].
|
| 42 |
+
eef_pos = state_vec[:3]
|
| 43 |
+
eef_ang = state_vec[3:6]
|
| 44 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 45 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 46 |
+
grip_joint_pos = state_vec[6:7] * 13.03 # rescale to [0, 1]
|
| 47 |
+
|
| 48 |
+
# Concatenate the state
|
| 49 |
+
state['arm_concat'] = tf.concat([grip_joint_pos,eef_pos, eef_ang], axis=0)
|
| 50 |
+
|
| 51 |
+
# Write the state format
|
| 52 |
+
state['format'] = tf.constant(
|
| 53 |
+
"gripper_joint_0_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 54 |
+
|
| 55 |
+
# Clean the task instruction
|
| 56 |
+
# Define the replacements (old, new) as a dictionary
|
| 57 |
+
replacements = {
|
| 58 |
+
'_': ' ',
|
| 59 |
+
'1f': ' ',
|
| 60 |
+
'4f': ' ',
|
| 61 |
+
'-': ' ',
|
| 62 |
+
'50': ' ',
|
| 63 |
+
'55': ' ',
|
| 64 |
+
'56': ' ',
|
| 65 |
+
|
| 66 |
+
}
|
| 67 |
+
instr = step['language_instruction']
|
| 68 |
+
instr = clean_task_instruction(instr, replacements)
|
| 69 |
+
step['observation']['natural_language_instruction'] = instr
|
| 70 |
+
|
| 71 |
+
return step
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
import tensorflow_datasets as tfds
|
| 76 |
+
from data.utils import dataset_to_path
|
| 77 |
+
|
| 78 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 79 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 80 |
+
# Load the dataset
|
| 81 |
+
dataset = tfds.builder_from_directory(
|
| 82 |
+
builder_dir=dataset_to_path(
|
| 83 |
+
DATASET_NAME, DATASET_DIR))
|
| 84 |
+
dataset = dataset.as_dataset(split='all')
|
| 85 |
+
|
| 86 |
+
# Inspect the dataset
|
| 87 |
+
for episode in dataset:
|
| 88 |
+
for step in episode['steps']:
|
| 89 |
+
print(step)
|
data/preprocess_scripts/taco_play.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.equal(terminate_act, tf.constant(1.0, dtype=tf.float32))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
action = step['action']
|
| 22 |
+
action['terminate'] = terminate_act_to_bool(action['terminate_episode'])
|
| 23 |
+
|
| 24 |
+
# action['actions']: absolute desired values for gripper pose
|
| 25 |
+
the_actions=action['actions']
|
| 26 |
+
# First 6 dimensions are x, y, z, yaw, pitch, roll
|
| 27 |
+
eef_pos=the_actions[:3]
|
| 28 |
+
eef_ang = tf.concat([the_actions[5:6],the_actions[4:5],the_actions[3:4]],axis=0)
|
| 29 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 30 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 31 |
+
open_gripper=the_actions[6:]
|
| 32 |
+
# Last dimension is open_gripper (-1 is open gripper, 1 is close)
|
| 33 |
+
grip_open=tf.reshape(tf.where(open_gripper<0,1.0,0.0),(1,))
|
| 34 |
+
# -1 -> 1.0, 1->0.0
|
| 35 |
+
|
| 36 |
+
# No base found
|
| 37 |
+
|
| 38 |
+
# Concatenate the action
|
| 39 |
+
arm_action = tf.concat([eef_pos, eef_ang, grip_open], axis=0)
|
| 40 |
+
action['arm_concat'] = arm_action
|
| 41 |
+
|
| 42 |
+
# Write the action format
|
| 43 |
+
action['format'] = tf.constant(
|
| 44 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 45 |
+
|
| 46 |
+
# Convert raw state to our state
|
| 47 |
+
state = step['observation']
|
| 48 |
+
robot_obs=state['robot_obs']
|
| 49 |
+
# robot_obs: EE position (3), EE orientation in euler angles (3), gripper width (1), joint positions (7), gripper action (1)
|
| 50 |
+
eef_pos=robot_obs[:3]
|
| 51 |
+
eef_ang=robot_obs[3:6]
|
| 52 |
+
eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 53 |
+
eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 54 |
+
gripper_open=robot_obs[6:7] * 12.3843 # rescale to [0, 1]
|
| 55 |
+
joint_pos=robot_obs[7:14]
|
| 56 |
+
|
| 57 |
+
# Concatenate the state
|
| 58 |
+
state['arm_concat'] = tf.concat([joint_pos,gripper_open,eef_pos,eef_ang],axis=0)
|
| 59 |
+
|
| 60 |
+
# Write the state format
|
| 61 |
+
state['format'] = tf.constant(
|
| 62 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,gripper_open,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5")
|
| 63 |
+
|
| 64 |
+
# Clean the task instruction
|
| 65 |
+
# Define the replacements (old, new) as a dictionary
|
| 66 |
+
replacements = {
|
| 67 |
+
'_': ' ',
|
| 68 |
+
'1f': ' ',
|
| 69 |
+
'4f': ' ',
|
| 70 |
+
'-': ' ',
|
| 71 |
+
'50': ' ',
|
| 72 |
+
'55': ' ',
|
| 73 |
+
'56': ' ',
|
| 74 |
+
|
| 75 |
+
}
|
| 76 |
+
instr = step['observation']['natural_language_instruction']
|
| 77 |
+
instr = clean_task_instruction(instr, replacements)
|
| 78 |
+
step['observation']['natural_language_instruction'] = instr
|
| 79 |
+
|
| 80 |
+
return step
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
import tensorflow_datasets as tfds
|
| 85 |
+
from data.utils import dataset_to_path
|
| 86 |
+
|
| 87 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 88 |
+
DATASET_NAME = 'taco_play'
|
| 89 |
+
# Load the dataset
|
| 90 |
+
dataset = tfds.builder_from_directory(
|
| 91 |
+
builder_dir=dataset_to_path(
|
| 92 |
+
DATASET_NAME, DATASET_DIR))
|
| 93 |
+
dataset = dataset.as_dataset(split='all')
|
| 94 |
+
|
| 95 |
+
# Inspect the dataset
|
| 96 |
+
for episode in dataset:
|
| 97 |
+
for step in episode['steps']:
|
| 98 |
+
print(step)
|
data/preprocess_scripts/toto.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler, euler_to_quaternion
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.where(tf.equal(terminate_act, tf.constant(0.0, dtype=tf.float32)),tf.constant(False),tf.constant(True))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_step(step: dict) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Unify the action format and clean the task instruction.
|
| 16 |
+
|
| 17 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 18 |
+
"""
|
| 19 |
+
# Convert raw action to our action
|
| 20 |
+
action = step['action']
|
| 21 |
+
action['terminate'] = terminate_act_to_bool(action['terminate_episode'])
|
| 22 |
+
eef_delta_pos = action['world_vector']
|
| 23 |
+
eef_ang = action['rotation_delta']
|
| 24 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 25 |
+
grip_open = tf.reshape(tf.where(action['open_gripper'],tf.constant(1.0),tf.constant(0.0)),(1,))
|
| 26 |
+
|
| 27 |
+
# No base found
|
| 28 |
+
|
| 29 |
+
# Concatenate the action
|
| 30 |
+
arm_action = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 31 |
+
action['arm_concat'] = arm_action
|
| 32 |
+
|
| 33 |
+
# Write the action format
|
| 34 |
+
action['format'] = tf.constant(
|
| 35 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 36 |
+
|
| 37 |
+
# Convert raw state to our state
|
| 38 |
+
state = step['observation']
|
| 39 |
+
joint_pos=state['state']
|
| 40 |
+
|
| 41 |
+
# Concatenate the state
|
| 42 |
+
state['arm_concat'] = joint_pos
|
| 43 |
+
|
| 44 |
+
# Write the state format
|
| 45 |
+
state['format'] = tf.constant(
|
| 46 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos")
|
| 47 |
+
|
| 48 |
+
# Clean the task instruction
|
| 49 |
+
# Define the replacements (old, new) as a dictionary
|
| 50 |
+
replacements = {
|
| 51 |
+
'_': ' ',
|
| 52 |
+
'1f': ' ',
|
| 53 |
+
'4f': ' ',
|
| 54 |
+
'-': ' ',
|
| 55 |
+
'50': ' ',
|
| 56 |
+
'55': ' ',
|
| 57 |
+
'56': ' ',
|
| 58 |
+
|
| 59 |
+
}
|
| 60 |
+
instr = step['observation']['natural_language_instruction']
|
| 61 |
+
instr = clean_task_instruction(instr, replacements)
|
| 62 |
+
step['observation']['natural_language_instruction'] = instr
|
| 63 |
+
|
| 64 |
+
return step
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
import tensorflow_datasets as tfds
|
| 69 |
+
from data.utils import dataset_to_path
|
| 70 |
+
|
| 71 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 72 |
+
DATASET_NAME = 'toto'
|
| 73 |
+
# Load the dataset
|
| 74 |
+
dataset = tfds.builder_from_directory(
|
| 75 |
+
builder_dir=dataset_to_path(
|
| 76 |
+
DATASET_NAME, DATASET_DIR))
|
| 77 |
+
dataset = dataset.as_dataset(split='all')
|
| 78 |
+
|
| 79 |
+
# Inspect the dataset
|
| 80 |
+
for episode in dataset:
|
| 81 |
+
for step in episode['steps']:
|
| 82 |
+
print(step)
|
data/preprocess_scripts/twinvla_benchmark.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def process_step(step: dict) -> dict:
|
| 7 |
+
"""
|
| 8 |
+
Unify the action format and clean the task instruction.
|
| 9 |
+
|
| 10 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 11 |
+
"""
|
| 12 |
+
# Convert raw action to our action
|
| 13 |
+
action_dict = step['action']
|
| 14 |
+
|
| 15 |
+
# Robot action
|
| 16 |
+
# eef_pos = action_dict['ee_pos'][:3]
|
| 17 |
+
# eef_ang = action_dict['ee_pos'][3:6]
|
| 18 |
+
# eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 19 |
+
# eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 20 |
+
# eef_pos_vel = action_dict['delta_ee'][:3]
|
| 21 |
+
# eef_ang_vel = action_dict['delta_ee'][3:6]
|
| 22 |
+
left_joint_pos = action_dict['joint_pos'][:7]
|
| 23 |
+
right_joint_pos = action_dict['joint_pos'][7:]
|
| 24 |
+
# joint_vel = action_dict['delta_joint'][:-1]
|
| 25 |
+
# grip_pos = action_dict['delta_ee'][-1:]
|
| 26 |
+
# grip_vel = action_dict['gripper_velocity']
|
| 27 |
+
|
| 28 |
+
# Concatenate the action
|
| 29 |
+
step['action'] = {}
|
| 30 |
+
action = step['action']
|
| 31 |
+
|
| 32 |
+
arm_action = tf.concat([left_joint_pos, right_joint_pos], axis=0)
|
| 33 |
+
action['arm_concat'] = arm_action
|
| 34 |
+
# action['terminate'] = step['is_terminal']
|
| 35 |
+
|
| 36 |
+
# Write the action format
|
| 37 |
+
action['format'] = tf.constant(
|
| 38 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_gripper_open")
|
| 39 |
+
|
| 40 |
+
# Convert raw state to our state
|
| 41 |
+
# Robot state
|
| 42 |
+
state = step['observation']['state']
|
| 43 |
+
# image = step['observation']['image']
|
| 44 |
+
# eef_pos = state['ee_pos'][:3]
|
| 45 |
+
# eef_ang = state['ee_pos'][3:6]
|
| 46 |
+
# eef_ang = euler_to_rotation_matrix(eef_ang)
|
| 47 |
+
# eef_ang = rotation_matrix_to_ortho6d(eef_ang)
|
| 48 |
+
left_joint_pos = state['joint_pos'][:7]
|
| 49 |
+
right_joint_pos = state['joint_pos'][7:]
|
| 50 |
+
# grip_pos = state['joint_pos'][-1:]
|
| 51 |
+
|
| 52 |
+
# Concatenate the state
|
| 53 |
+
state['arm_concat'] = tf.concat([left_joint_pos, right_joint_pos], axis=0)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# Write the state format
|
| 57 |
+
state['format'] = tf.constant(
|
| 58 |
+
"left_arm_joint_0_pos,left_arm_joint_1_pos,left_arm_joint_2_pos,left_arm_joint_3_pos,left_arm_joint_4_pos,left_arm_joint_5_pos,left_gripper_open,right_arm_joint_0_pos,right_arm_joint_1_pos,right_arm_joint_2_pos,right_arm_joint_3_pos,right_arm_joint_4_pos,right_arm_joint_5_pos,right_gripper_open")
|
| 59 |
+
|
| 60 |
+
# Clean the task instruction
|
| 61 |
+
# Define the replacements (old, new) as a dictionary
|
| 62 |
+
replacements = {
|
| 63 |
+
'_': ' ',
|
| 64 |
+
'1f': ' ',
|
| 65 |
+
'4f': ' ',
|
| 66 |
+
'-': ' ',
|
| 67 |
+
'50': ' ',
|
| 68 |
+
'55': ' ',
|
| 69 |
+
'56': ' ',
|
| 70 |
+
|
| 71 |
+
}
|
| 72 |
+
instr = step['language_instruction']
|
| 73 |
+
# instr = clean_task_instruction(instr, replacements)
|
| 74 |
+
step['observation'] = state
|
| 75 |
+
step['observation']['natural_language_instruction'] = instr
|
| 76 |
+
|
| 77 |
+
return step
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
pass
|
data/preprocess_scripts/ucsd_kitchen_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, quaternion_to_euler, euler_to_quaternion
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 7 |
+
"""
|
| 8 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 9 |
+
"""
|
| 10 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.float32)))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_step(step: dict) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Unify the action format and clean the task instruction.
|
| 16 |
+
|
| 17 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
# Convert raw action to our action
|
| 21 |
+
|
| 22 |
+
# 8-dimensional action, consisting of end-effector position and orientation, gripper open/close and a episode termination action.
|
| 23 |
+
action = step['action']
|
| 24 |
+
eef_delta_pos = action[:3]
|
| 25 |
+
eef_ang = action[3:6]
|
| 26 |
+
eef_ang = euler_to_quaternion(eef_ang)
|
| 27 |
+
grip_open = tf.expand_dims(1 - action[6], axis=0)
|
| 28 |
+
|
| 29 |
+
# Concatenate the action
|
| 30 |
+
# action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 31 |
+
step['action'] = {}
|
| 32 |
+
action = step['action']
|
| 33 |
+
|
| 34 |
+
action['terminate'] = step['is_terminal']
|
| 35 |
+
action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 36 |
+
|
| 37 |
+
# Write the action format
|
| 38 |
+
action['format'] = tf.constant(
|
| 39 |
+
"eef_delta_pos_x,eef_delta_pos_y,eef_delta_pos_z,eef_delta_angle_x,eef_delta_angle_y,eef_delta_angle_z,eef_delta_angle_w,gripper_open")
|
| 40 |
+
|
| 41 |
+
# Convert raw state to our state
|
| 42 |
+
state = step['observation']['state']
|
| 43 |
+
# 21-dimensional joint states, consists of robot joint angles, joint velocity and joint torque.
|
| 44 |
+
arm_joint_pos = state[:7]
|
| 45 |
+
arm_joint_vel = state[7:14]
|
| 46 |
+
# arm_joint_torque = state[14:21]
|
| 47 |
+
|
| 48 |
+
# Concatenate the state
|
| 49 |
+
|
| 50 |
+
state = step['observation']
|
| 51 |
+
state['arm_concat'] = tf.concat([arm_joint_pos, arm_joint_vel], axis=0)
|
| 52 |
+
|
| 53 |
+
# Write the state format
|
| 54 |
+
state['format'] = tf.constant(
|
| 55 |
+
"arm_joint_0_pos,arm_joint_1_pos,arm_joint_2_pos,arm_joint_3_pos,arm_joint_4_pos,arm_joint_5_pos,arm_joint_6_pos,arm_joint_0_vel,arm_joint_1_vel,arm_joint_2_vel,arm_joint_3_vel,arm_joint_4_vel,arm_joint_5_vel,arm_joint_6_vel")
|
| 56 |
+
|
| 57 |
+
# Clean the task instruction
|
| 58 |
+
# Define the replacements (old, new) as a dictionary
|
| 59 |
+
replacements = {
|
| 60 |
+
'_': ' ',
|
| 61 |
+
'1f': ' ',
|
| 62 |
+
'4f': ' ',
|
| 63 |
+
'-': ' ',
|
| 64 |
+
'50': ' ',
|
| 65 |
+
'55': ' ',
|
| 66 |
+
'56': ' ',
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
instr = step['language_instruction']
|
| 70 |
+
instr = clean_task_instruction(instr, replacements)
|
| 71 |
+
step['observation']['natural_language_instruction'] = instr
|
| 72 |
+
|
| 73 |
+
return step
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
import tensorflow_datasets as tfds
|
| 78 |
+
from data.utils import dataset_to_path
|
| 79 |
+
|
| 80 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 81 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 82 |
+
# Load the dataset
|
| 83 |
+
dataset = tfds.builder_from_directory(
|
| 84 |
+
builder_dir=dataset_to_path(
|
| 85 |
+
DATASET_NAME, DATASET_DIR))
|
| 86 |
+
dataset = dataset.as_dataset(split='all')
|
| 87 |
+
|
| 88 |
+
# Inspect the dataset
|
| 89 |
+
for episode in dataset:
|
| 90 |
+
for step in episode['steps']:
|
| 91 |
+
print(step)
|
data/preprocess_scripts/ucsd_pick_and_place_dataset_converted_externally_to_rlds.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
|
| 3 |
+
from data.utils import clean_task_instruction, euler_to_quaternion, euler_to_rotation_matrix, \
|
| 4 |
+
rotation_matrix_to_ortho6d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def terminate_act_to_bool(terminate_act: tf.Tensor) -> tf.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Convert terminate action to a boolean, where True means terminate.
|
| 10 |
+
"""
|
| 11 |
+
return tf.reduce_all(tf.equal(terminate_act, tf.constant([1, 0, 0], dtype=tf.float32)))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def process_step(step: dict) -> dict:
|
| 15 |
+
"""
|
| 16 |
+
Unify the action format and clean the task instruction.
|
| 17 |
+
|
| 18 |
+
DO NOT use python list, use tf.TensorArray instead.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# Convert raw action to our action
|
| 22 |
+
action = step['action']
|
| 23 |
+
# Robot action, consists of [3x gripper velocities,1x gripper open/close torque].
|
| 24 |
+
eef_vel = action[:3]
|
| 25 |
+
grip_open = tf.expand_dims(1 - action[3], axis=0)
|
| 26 |
+
|
| 27 |
+
# Concatenate the action
|
| 28 |
+
# action['arm_concat'] = tf.concat([eef_delta_pos, eef_ang, grip_open], axis=0)
|
| 29 |
+
step['action'] = {}
|
| 30 |
+
action = step['action']
|
| 31 |
+
|
| 32 |
+
action['terminate'] = step['is_terminal']
|
| 33 |
+
action['arm_concat'] = tf.concat([eef_vel,grip_open], axis=0)
|
| 34 |
+
# Write the action format
|
| 35 |
+
action['format'] = tf.constant(
|
| 36 |
+
"eef_vel_x,eef_vel_y,eef_vel_z,gripper_open")
|
| 37 |
+
|
| 38 |
+
# Convert raw state to our state
|
| 39 |
+
state = step['observation']['state']
|
| 40 |
+
# Robot state, consists of [3x gripper position,3x gripper orientation, 1x finger distance].
|
| 41 |
+
gripper_pos = state[:3]/10 # dm -> m
|
| 42 |
+
gripper_ang = state[3:6]
|
| 43 |
+
gripper_ang = euler_to_rotation_matrix(gripper_ang)
|
| 44 |
+
gripper_ang = rotation_matrix_to_ortho6d(gripper_ang)
|
| 45 |
+
gripper_open = state[6:7]/6.03 # 1 for open
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Concatenate the state
|
| 49 |
+
state = step['observation']
|
| 50 |
+
state['arm_concat'] = tf.concat([gripper_pos, gripper_ang, gripper_open], axis=0)
|
| 51 |
+
|
| 52 |
+
# Write the state format
|
| 53 |
+
state['format'] = tf.constant(
|
| 54 |
+
"eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5,gripper_open")
|
| 55 |
+
|
| 56 |
+
# Clean the task instruction
|
| 57 |
+
# Define the replacements (old, new) as a dictionary
|
| 58 |
+
replacements = {
|
| 59 |
+
'_': ' ',
|
| 60 |
+
'1f': ' ',
|
| 61 |
+
'4f': ' ',
|
| 62 |
+
'-': ' ',
|
| 63 |
+
'50': ' ',
|
| 64 |
+
'55': ' ',
|
| 65 |
+
'56': ' ',
|
| 66 |
+
|
| 67 |
+
}
|
| 68 |
+
instr = step['language_instruction']
|
| 69 |
+
instr = clean_task_instruction(instr, replacements)
|
| 70 |
+
step['observation']['natural_language_instruction'] = instr
|
| 71 |
+
|
| 72 |
+
return step
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
import tensorflow_datasets as tfds
|
| 77 |
+
from data.utils import dataset_to_path
|
| 78 |
+
|
| 79 |
+
DATASET_DIR = 'data/datasets/openx_embod'
|
| 80 |
+
DATASET_NAME = 'fractal20220817_data'
|
| 81 |
+
# Load the dataset
|
| 82 |
+
dataset = tfds.builder_from_directory(
|
| 83 |
+
builder_dir=dataset_to_path(
|
| 84 |
+
DATASET_NAME, DATASET_DIR))
|
| 85 |
+
dataset = dataset.as_dataset(split='all')
|
| 86 |
+
|
| 87 |
+
# Inspect the dataset
|
| 88 |
+
for episode in dataset:
|
| 89 |
+
for step in episode['steps']:
|
| 90 |
+
print(step)
|