Expand data loading section with datasets and PyTorch examples
Browse files
README.md
CHANGED
|
@@ -329,19 +329,69 @@ This dataset is intended for embodied AI and egocentric robotics research.
|
|
| 329 |
- object tracks are only present when source frames include object detections
|
| 330 |
- this export is optimized for structured ML ingestion rather than human-readable storytelling
|
| 331 |
|
| 332 |
-
## Data Loading
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
```python
|
| 335 |
import json
|
| 336 |
from pathlib import Path
|
| 337 |
|
| 338 |
-
root = Path("RoboX-EgoTask")
|
| 339 |
clips = [json.loads(line) for line in (root / "metadata" / "clips.jsonl").read_text().splitlines()]
|
| 340 |
-
# Filter clips that have hand keypoints in this export tier
|
| 341 |
hand_clips = [c for c in clips if (c.get("exported_modalities") or {}).get("hand_keypoints_2d")]
|
| 342 |
print(clips[0]["clip_id"], clips[0]["labels"])
|
| 343 |
```
|
| 344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
## Citation
|
| 346 |
|
| 347 |
```bibtex
|
|
|
|
| 329 |
- object tracks are only present when source frames include object detections
|
| 330 |
- this export is optimized for structured ML ingestion rather than human-readable storytelling
|
| 331 |
|
| 332 |
+
## Data Loading
|
| 333 |
+
|
| 334 |
+
### Clip metadata with the datasets library
|
| 335 |
+
|
| 336 |
+
The clip-level metadata is exposed as a loadable config with `train`, `validation` and `test` splits. This dataset is gated, so authenticate first with `hf auth login` (or pass `token=True`).
|
| 337 |
+
|
| 338 |
+
```python
|
| 339 |
+
from datasets import load_dataset
|
| 340 |
+
|
| 341 |
+
ds = load_dataset("RoboXTechnologies/RoboX-EgoTask", "clips")
|
| 342 |
+
print(ds)
|
| 343 |
+
|
| 344 |
+
row = ds["train"][0]
|
| 345 |
+
print(row["clip_id"], row["task_category"], row["narration"])
|
| 346 |
+
print(row["video_url"]) # clean RGB clip
|
| 347 |
+
print(row["overlay_url"]) # same clip with hand landmarks rendered
|
| 348 |
+
```
|
| 349 |
+
|
| 350 |
+
### Full per-frame annotations from a local copy
|
| 351 |
+
|
| 352 |
+
The config above is a flat summary, one row per clip. The complete per-frame streams (hand keypoints, sensors, trajectory and more) ship as JSONL under `annotations/` and `metadata/`. Download or clone the repo, then read them directly:
|
| 353 |
|
| 354 |
```python
|
| 355 |
import json
|
| 356 |
from pathlib import Path
|
| 357 |
|
| 358 |
+
root = Path("RoboX-EgoTask") # path to the downloaded repo
|
| 359 |
clips = [json.loads(line) for line in (root / "metadata" / "clips.jsonl").read_text().splitlines()]
|
|
|
|
| 360 |
hand_clips = [c for c in clips if (c.get("exported_modalities") or {}).get("hand_keypoints_2d")]
|
| 361 |
print(clips[0]["clip_id"], clips[0]["labels"])
|
| 362 |
```
|
| 363 |
|
| 364 |
+
### Streaming clip videos into PyTorch
|
| 365 |
+
|
| 366 |
+
A minimal `Dataset` that pulls each clip's MP4 on demand (cached after the first fetch) and decodes it to a tensor. Clips vary in length, so this uses `batch_size=1`; add a `collate_fn` that pads or samples a fixed number of frames to batch them.
|
| 367 |
+
|
| 368 |
+
```python
|
| 369 |
+
import torch
|
| 370 |
+
from torch.utils.data import Dataset, DataLoader
|
| 371 |
+
from datasets import load_dataset
|
| 372 |
+
from huggingface_hub import hf_hub_download
|
| 373 |
+
import torchvision
|
| 374 |
+
|
| 375 |
+
REPO = "RoboXTechnologies/RoboX-EgoTask"
|
| 376 |
+
|
| 377 |
+
class EgoTaskClips(Dataset):
|
| 378 |
+
def __init__(self, split="train"):
|
| 379 |
+
self.rows = load_dataset(REPO, "clips", split=split)
|
| 380 |
+
|
| 381 |
+
def __len__(self):
|
| 382 |
+
return len(self.rows)
|
| 383 |
+
|
| 384 |
+
def __getitem__(self, idx):
|
| 385 |
+
row = self.rows[idx]
|
| 386 |
+
path = hf_hub_download(REPO, f"clips/{row['clip_id']}.mp4", repo_type="dataset")
|
| 387 |
+
video, _, _ = torchvision.io.read_video(path, output_format="TCHW") # (T, C, H, W)
|
| 388 |
+
return {"clip_id": row["clip_id"], "video": video, "label": row["task_category"]}
|
| 389 |
+
|
| 390 |
+
loader = DataLoader(EgoTaskClips("train"), batch_size=1, shuffle=True)
|
| 391 |
+
batch = next(iter(loader))
|
| 392 |
+
print(batch["clip_id"], batch["video"].shape)
|
| 393 |
+
```
|
| 394 |
+
|
| 395 |
## Citation
|
| 396 |
|
| 397 |
```bibtex
|