-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Train difusion policy using lerobot with custom dataset #63
Comments
(this is personal note, not actual question to anybody) training phaseQ: However, when we use custom dataset, we need to specifcy? dataset.stats by myself otherwise deployment phaseQ: in training phase batch image shape is like [64, 2, 3, 112, 112] but in the execution phase [1, 3, 112, 112]. Due to the lack of dimension of "2", error occured => |
@HiroIshida
if you are not using latest ffmpeg, you need to modify lerobot's this line to use libx264 or libx265 for video codec, not libsvtav1 and |
@ojh6404 I forgot to compute the stats value myself, so I just had to call Anyway, thank you for your instructions! Having the actual data you provided definitely helps a lot. |
Further to this topic, I was able to create a custom dataset fairly easily by following the following steps. Unfortunately, it feels like a workaround rather than a proper method:
import h5py
lr_ds = {}
for episode_id, t in enumerate(trajectories):
lr_ds["/action"] = t["action"]
lr_ds["/observations/qpos"] = t["obs"]["agent_pos"]
# Note LeRobot Alpha format expects uint8 images with channels in the last dimension.
lr_ds["/observations/images/cam1"] =(t["obs"]["rgb"].transpose(0,2,3,1) * 255).astype(np.uint8)
# Aloha LeRobot also accepts /observations/qvel and /observations/effort
# It does not support point clouds or depth images yet.
# Note sim has to be the name of the last folder because currently
# from_raw_to_lerobot_format treats image arrays as 4 dimensional only
# if sim is in the name...
savepath = f"/tmp/<ENV NAME>/sim/episode_{episode_id}.hdf5"
os.makedirs(os.path.dirname(savepath), exist_ok=True)
with h5py.File(savepath, "w") as f:
for key, value in lr_ds.items():
f.create_dataset(key, data=value)
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
from lerobot.common.datasets.push_dataset_to_hub.aloha_hdf5_format import from_raw_to_lerobot_format
from pathlib import Path
from lerobot.common.datasets.compute_stats import compute_stats
raw_dir = Path("/tmp/<ENV NAME>/sim/")
dataset, episode_data_index, info = from_raw_to_lerobot_format(raw_dir, videos_dir=None, video=False)
stats = compute_stats(dataset, batch_size=32, num_workers=16, max_num_samples=None)
dataset = LeRobotDataset.from_preloaded(
root = raw_dir,
hf_dataset = dataset,
episode_data_index = episode_data_index,
stats = stats,
delta_timestamps = None,
info = info,
) Then I can safely visualize it as normal. Ideally, in the future, the stats will be automatically parsed from the data. I have not tried training with it yet. Edit 1: python lerobot/scripts/train.py policy=act_custom env=real_world env.task=StackCube-v1 All I had to do is modify the dataset factory to load real_world datasets from raw as step 2) above, and change act_custom policy configuration to my config. |
@dennisushi thanks for the info! |
Resources
The lerobot repository does not provide detained explanation to how to create custom dataset, but @ojh6404 succeeded (tried?) to created by himself
https://github.com/ojh6404/imitator/tree/lerobot
Also, I'm posting issue here
huggingface/lerobot#304
Creation of dummy lerobot dataset (just a random dataset)
Referencing his source code, I'm trying to create custom dataset. The following script is the minimum working example to at least run the training pipeline (but on random data, so meaning less though).
https://github.com/HiroIshida/snippets/blob/master/python/ext_examples/lerobot/build_data.py
Creation of more realistic lerobot datase (IK-reaching task using pybullet)
Also, plug the data created by https://github.com/HiroIshida/mohou/blob/master/example/kuka_reaching.py into lerobot in the same manner (see https://github.com/HiroIshida/snippets/blob/master/python/ext_examples/lerobot/from_mohou.py ), and confirmed that at least the loss is decreasing
Of course after some tweak of config
Demonstration example
Execution example
The text was updated successfully, but these errors were encountered: