2024-04-25 18:23:12 +08:00
|
|
|
import logging
|
2024-04-16 20:20:38 +08:00
|
|
|
import os
|
2024-03-15 20:44:52 +08:00
|
|
|
from pathlib import Path
|
2024-03-01 21:31:54 +08:00
|
|
|
|
2024-02-20 20:26:57 +08:00
|
|
|
import torch
|
2024-04-25 17:47:38 +08:00
|
|
|
from omegaconf import OmegaConf
|
2024-02-20 20:26:57 +08:00
|
|
|
|
2024-04-25 18:23:12 +08:00
|
|
|
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
|
|
|
|
|
2024-04-16 20:20:38 +08:00
|
|
|
DATA_DIR = Path(os.environ["DATA_DIR"]) if "DATA_DIR" in os.environ else None
|
|
|
|
|
2024-02-20 20:26:57 +08:00
|
|
|
|
2024-03-31 23:05:25 +08:00
|
|
|
def make_dataset(
|
2024-03-22 18:26:55 +08:00
|
|
|
cfg,
|
2024-04-16 20:20:38 +08:00
|
|
|
split="train",
|
2024-03-06 18:14:03 +08:00
|
|
|
):
|
2024-04-25 18:23:12 +08:00
|
|
|
if cfg.env.name not in cfg.dataset.repo_id:
|
|
|
|
logging.warning(
|
|
|
|
f"There might be a mismatch between your training dataset ({cfg.dataset.repo_id=}) and your environment ({cfg.env.name=})."
|
|
|
|
)
|
2024-02-20 20:26:57 +08:00
|
|
|
|
2024-04-08 00:01:22 +08:00
|
|
|
delta_timestamps = cfg.policy.get("delta_timestamps")
|
|
|
|
if delta_timestamps is not None:
|
|
|
|
for key in delta_timestamps:
|
|
|
|
if isinstance(delta_timestamps[key], str):
|
|
|
|
delta_timestamps[key] = eval(delta_timestamps[key])
|
2024-03-05 18:20:57 +08:00
|
|
|
|
2024-04-25 17:47:38 +08:00
|
|
|
# TODO(rcadene): add data augmentations
|
|
|
|
|
2024-04-25 18:23:12 +08:00
|
|
|
dataset = LeRobotDataset(
|
|
|
|
cfg.dataset.repo_id,
|
2024-04-16 20:20:38 +08:00
|
|
|
split=split,
|
|
|
|
root=DATA_DIR,
|
2024-03-31 23:05:25 +08:00
|
|
|
delta_timestamps=delta_timestamps,
|
|
|
|
)
|
2024-02-20 20:26:57 +08:00
|
|
|
|
2024-04-25 17:47:38 +08:00
|
|
|
if cfg.get("override_dataset_stats"):
|
|
|
|
for key, stats_dict in cfg.override_dataset_stats.items():
|
|
|
|
for stats_type, listconfig in stats_dict.items():
|
|
|
|
# example of stats_type: min, max, mean, std
|
|
|
|
stats = OmegaConf.to_container(listconfig, resolve=True)
|
|
|
|
dataset.stats[key][stats_type] = torch.tensor(stats, dtype=torch.float32)
|
|
|
|
|
2024-03-31 23:05:25 +08:00
|
|
|
return dataset
|