| |
| """ |
| Fixed_Viewpoint_Tactile_Dataset 加载示例。 |
| |
| python example_usage.py # 从 HuggingFace 下载 |
| python example_usage.py --root <本地数据集路径> # 用本地副本,不下载 |
| |
| 需要 Python >= 3.10 且已安装 lerobot。 |
| """ |
| import argparse |
| import numpy as np |
|
|
| REPO = "Tachintech/Fixed_Viewpoint_Tactile_Dataset" |
|
|
|
|
| def main(): |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--root", default=None, help="本地数据集路径,给了就不从 HF 下载") |
| ap.add_argument("--save-img", default="sample_color.png") |
| args = ap.parse_args() |
|
|
| from lerobot.datasets.lerobot_dataset import LeRobotDataset |
| ds = LeRobotDataset(REPO, root=args.root) |
| print(f"frames={ds.num_frames} episodes={ds.num_episodes} fps={ds.fps}") |
|
|
| |
| print("\n[features]") |
| for name, spec in ds.meta.info["features"].items(): |
| print(f" {name:35s} {spec['dtype']:8s} {spec['shape']}") |
|
|
| shapes = ds.meta.info.get("tactile_2d_shapes", {}) |
|
|
| |
| s = ds[100] |
| print("\n[frame 100]") |
| for k in sorted(s.keys()): |
| v = s[k] |
| print(f" {k:35s} {tuple(v.shape) if hasattr(v, 'shape') else v}") |
|
|
| |
| pos20 = s["observation_motion_positions"].numpy().reshape(20, 3) |
| quat20 = s["observation_motion_quaternions"].numpy().reshape(20, 4) |
| print(f"\nmotion: pos {pos20.shape}, quat {quat20.shape}") |
|
|
| |
| for i in (0, 19): |
| flat = s[f"tactile_tactile_{i}"].numpy() |
| grid = flat.reshape(shapes[f"tactile_{i}"]) |
| print(f"tactile_{i}: {flat.shape} -> {grid.shape}") |
|
|
| |
| act = s["action"].numpy() |
| obs = np.concatenate([s["observation_motion_positions"].numpy(), |
| s["observation_motion_quaternions"].numpy()]) |
| print(f"action == motion(pos+quat): {np.allclose(act, obs)}") |
|
|
| |
| color = s["observation.images.color"] |
| print(f"color {tuple(color.shape)}, depth {tuple(s['observation.images.depth'].shape)}") |
| try: |
| from PIL import Image |
| img = (color.permute(1, 2, 0).numpy() * 255).astype(np.uint8) |
| Image.fromarray(img).save(args.save_img) |
| print(f"saved {args.save_img}") |
| except Exception as e: |
| print(f"skip save image: {e}") |
|
|
| |
| from torch.utils.data import DataLoader |
| batch = next(iter(DataLoader(ds, batch_size=8, shuffle=True, num_workers=0))) |
| print(f"\nbatch: action {tuple(batch['action'].shape)}, " |
| f"color {tuple(batch['observation.images.color'].shape)}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|