|
import tensorflow as tf |
|
|
|
from data.utils import clean_task_instruction |
|
|
|
def process_step(step: dict) -> dict: |
|
""" |
|
Unify the action format and clean the task instruction. |
|
|
|
DO NOT use python list, use tf.TensorArray instead. |
|
""" |
|
|
|
|
|
origin_action = step['action'] |
|
step['action']={} |
|
action=step['action'] |
|
|
|
eef_delta_pos=origin_action |
|
|
|
|
|
|
|
action['arm_concat'] = eef_delta_pos |
|
action['terminate'] = step['is_terminal'] |
|
|
|
|
|
action['format'] = tf.constant( |
|
"eef_delta_pos_x,eef_delta_pos_y") |
|
|
|
|
|
state = step['observation'] |
|
|
|
eef_pos=state['effector_translation'] |
|
state['arm_concat'] = eef_pos |
|
|
|
state['format'] = tf.constant( |
|
"eef_pos_x,eef_pos_y") |
|
|
|
|
|
|
|
replacements = { |
|
'_': ' ', |
|
'1f': ' ', |
|
'4f': ' ', |
|
'-': ' ', |
|
'50': ' ', |
|
'55': ' ', |
|
'56': ' ', |
|
|
|
} |
|
instr = step['observation']['instruction'] |
|
|
|
instr = tf.strings.unicode_encode(instr, 'UTF-8') |
|
|
|
instr = tf.strings.regex_replace(instr, '\x00', '') |
|
instr = clean_task_instruction(instr, replacements) |
|
step['observation']['natural_language_instruction'] = instr |
|
return step |
|
|
|
|
|
if __name__ == "__main__": |
|
import tensorflow_datasets as tfds |
|
from data.utils import dataset_to_path |
|
|
|
DATASET_DIR = 'data/datasets/openx_embod' |
|
DATASET_NAME = 'language_table' |
|
|
|
dataset = tfds.builder_from_directory( |
|
builder_dir=dataset_to_path( |
|
DATASET_NAME, DATASET_DIR)) |
|
dataset = dataset.as_dataset(split='all') |
|
|
|
|
|
for episode in dataset: |
|
for step in episode['steps']: |
|
print(step) |
|
|
|
|