Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
url = https://github.com/Physical-Intelligence/aloha.git
[submodule "third_party/libero"]
path = third_party/libero
url = https://github.com/Lifelong-Robot-Learning/LIBERO.git
url = https://github.com/szhaovas/LIBERO.git
[submodule "third_party/SimplerEnv"]
path = third_party/SimplerEnv
url = https://github.com/simpler-env/SimplerEnv.git
201 changes: 18 additions & 183 deletions README.md

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions convert_google_robot_to_lerobot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import numpy as np
import json

from pathlib import Path

from lerobot.common.datasets.lerobot_dataset import HF_LEROBOT_HOME
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
import tensorflow_datasets as tfds
import tyro

google_demo_conversion_cfg = {
"repo_id": "hchen/google_robot",
"demo_dir": "./simpler_env_demos/demo_collection/collected_data"
}

def main(data_cfg):
demo_root_dir = Path(data_cfg["demo_dir"])
task_dirs = [d for d in demo_root_dir.iterdir() if d.is_dir()]
task_metadata_paths = [d / "metadata.json" for d in task_dirs]

task_metadata = [json.loads(p.read_text()) for p in task_metadata_paths]

dataset = LeRobotDataset.create(
repo_id=data_cfg["repo_id"],
robot_type="google_robot",
fps=10,
features={
"image": {
"dtype": "image",
"shape": (224, 224, 3),
"names": ["height", "width", "channel"]
},
"state": {
"dtype": "float32",
"shape": (8,),
"names": ["state"],
},
"actions": {
"dtype": "float32",
"shape": (7,),
"names": ["actions"],
}
},
image_writer_threads=10,
image_writer_processes=5
)

for single_task_ds in task_metadata:
success_episode_files = ["./simpler_env_demos/demo_collection/" + file for file in single_task_ds["success_episode_files"]]
for i, episode_file in enumerate(success_episode_files):
traj_data = np.load(episode_file)

traj_images = traj_data["images"]
traj_states = traj_data["states"]
traj_actions = traj_data["actions"]
traj_language = str(traj_data["language"])

episode_len = len(traj_images)

for t in range(episode_len):
dataset.add_frame(
{
"image": traj_images[t],
"state": traj_states[t],
"actions": traj_actions[t],
"task": traj_language
}
)

dataset.save_episode()
print(f"Saved trajectory {i} out of {single_task_ds['total_saved_episodes']} for {single_task_ds['environment_name']}")

if __name__ == "__main__":
main(data_cfg=google_demo_conversion_cfg)
106 changes: 106 additions & 0 deletions create_lerobot_ds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""
Minimal example script for converting a dataset to LeRobot format.

We use the Libero dataset (stored in RLDS) for this example, but it can be easily
modified for any other data you have saved in a custom format.

Usage:
uv run examples/libero/convert_libero_data_to_lerobot.py --data_dir /path/to/your/data

If you want to push your dataset to the Hugging Face Hub, you can use the following command:
uv run examples/libero/convert_libero_data_to_lerobot.py --data_dir /path/to/your/data --push_to_hub

Note: to run the script, you need to install tensorflow_datasets:
`uv pip install tensorflow tensorflow_datasets`

You can download the raw Libero datasets from https://huggingface.co/datasets/openvla/modified_libero_rlds
The resulting dataset will get saved to the $HF_LEROBOT_HOME directory.
Running this conversion script will take approximately 30 minutes.
"""

import shutil

from lerobot.common.datasets.lerobot_dataset import HF_LEROBOT_HOME
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
import tensorflow_datasets as tfds
import tyro

import numpy as np
import pickle

import os, struct

def main(scheduler_pkl_path="./test_logs/scheduler_00000010.pkl",
repo_name="hchen/libero"):
# Clean up any existing dataset in the output directory
output_path = HF_LEROBOT_HOME / repo_name
if output_path.exists():
shutil.rmtree(output_path)

# Create LeRobot dataset, define features to store
# OpenPi assumes that proprio is stored in `state` and actions in `action`
# LeRobot assumes that dtype of image data is `image`
dataset = LeRobotDataset.create(
repo_id=repo_name,
robot_type="panda",
fps=10,
features={
"image": {
"dtype": "image",
"shape": (256, 256, 3),
"names": ["height", "width", "channel"],
},
"wrist_image": {
"dtype": "image",
"shape": (256, 256, 3),
"names": ["height", "width", "channel"],
},
"state": {
"dtype": "float64",
"shape": (8,),
"names": ["state"],
},
"actions": {
"dtype": "float64",
"shape": (7,),
"names": ["actions"],
},
},
image_writer_threads=10,
image_writer_processes=5,
)

with open(scheduler_pkl_path, "rb") as f:
scheduler = pickle.load(f)

archive = scheduler.archive
all_trajectories = archive.data("trajectories")

include_failures = True

for elite_trajectories in all_trajectories:
for traj_id, traj in enumerate(elite_trajectories):
episode_len = np.array(traj["image"]).shape[0]

if not include_failures and not traj["success"]:
continue

for step in range(episode_len):
dataset.add_frame(
{
"image": traj["image"][step],
"wrist_image": traj["wrist_image"][step],
"state": traj["state"][step],
"actions": traj["action"][step],
"task": traj["prompt"]
}
)

dataset.save_episode()
print(f"Saved trajectory {traj_id}!")

print(dataset)

if __name__ == "__main__":
main(scheduler_pkl_path="./test_logs/scheduler_00000010.pkl",
repo_name="hchen/libero")
51 changes: 51 additions & 0 deletions eval_base_libero_logs/summary.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
env_num,success_rate
0,1.0
1,1.0
2,1.0
3,1.0
4,0.8
5,1.0
6,1.0
7,1.0
8,1.0
9,1.0
10,1.0
11,1.0
12,1.0
13,1.0
14,1.0
15,1.0
16,1.0
17,1.0
18,1.0
19,1.0
20,1.0
21,0.8
22,1.0
23,1.0
24,1.0
25,1.0
26,1.0
27,1.0
28,1.0
29,1.0
30,0.8
31,1.0
32,1.0
33,1.0
34,0.8
35,1.0
36,1.0
37,1.0
38,0.8
39,1.0
40,1.0
41,1.0
42,0.8
43,1.0
44,1.0
45,1.0
46,1.0
47,0.8
48,1.0
49,1.0
51 changes: 51 additions & 0 deletions eval_finetuned_libero_logs/summary.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
env_num,success_rate
0,1.0
1,1.0
2,1.0
3,1.0
4,1.0
5,1.0
6,1.0
7,0.8
8,1.0
9,0.8
10,1.0
11,1.0
12,1.0
13,0.8
14,1.0
15,1.0
16,0.8
17,1.0
18,1.0
19,0.8
20,1.0
21,0.8
22,1.0
23,0.8
24,1.0
25,1.0
26,1.0
27,1.0
28,1.0
29,1.0
30,1.0
31,1.0
32,0.8
33,1.0
34,1.0
35,1.0
36,1.0
37,1.0
38,1.0
39,1.0
40,1.0
41,0.8
42,0.8
43,1.0
44,1.0
45,1.0
46,1.0
47,1.0
48,0.8
49,1.0
Loading