"""Constants and the dataset-level selection rules shared by download.py and preprocess.py.""" from __future__ import annotations import json import os REPO = "HuggingFaceVLA/community_dataset_v2" # The revision this code was written and checked against (2026-11-18). Every step reads this revision. REVISION = "815dd11af21a488d2c8c6a87e550d6e890fbf558" DINO_URL = "https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_pretrain.pth" DINO_SHA256 = "b938bf1bc15cd2ec0feacfe3a1bb553fe8ea9ca46a7e1d8d00217f29aef60cd9" # SO-100 / SO-101 single arm, LeRobot order. Names may carry a prefix (main_, left_, right_). JOINTS = ("shoulder_pan", "shoulder_lift", "elbow_flex", "wrist_flex", "wrist_roll", "gripper") ARM = slice(0, 5) # the five arm joints; index 5 is the gripper ROBOTS = {"so100", "so101"} # Original camera names that mean "mounted on the gripper". Used only to drop single-camera datasets whose one # camera is a wrist camera and to report agreement with the motion test; roles are decided by motion. WRIST_WORDS = ("wrist", "gripper", "gipper", "hand", "endeffector", "end_rgb", "eef") def joint_names_ok(names) -> bool: if isinstance(names, dict): names = names.get("motors") if not isinstance(names, list) or len(names) != len(JOINTS): return False return all(str(n).split(".")[-1].endswith(j) for n, j in zip(names, JOINTS)) def slot_number(key: str) -> int: """observation.images.image -> 1, ...image2 -> 2, ...image3 -> 3.""" tail = key.split(".")[-1] digits = tail[len(tail.rstrip("0123456789")):] return int(digits) if digits else 1 def rgb_streams(info: dict) -> list[str]: """Video features with 3 channels, in slot order (image, image2, image3); info.json does not keep that order.""" keys = [k for k, f in info["features"].items() if f.get("dtype") == "video" and len(f.get("shape", [])) == 3 and f["shape"][-1] == 3] return sorted(keys, key=lambda k: (slot_number(k), k)) def dataset_check(info: dict | None, target_fps: int) -> str | None: """None if the dataset qualifies, else the reason it is dropped.""" if info is None: return "no_meta" if str(info.get("robot_type", "")).lower().replace("-", "").replace("_", "") not in ROBOTS: return "robot_type" f = info.get("features", {}) if "action" not in f or "observation.state" not in f: return "no_action_or_state" if f["action"].get("shape") != [6] or f["observation.state"].get("shape") != [6]: return "not_single_arm_6d" if not (joint_names_ok(f["action"].get("names")) and joint_names_ok(f["observation.state"].get("names"))): return "joint_names" if info.get("fps", 0) < target_fps: return "fps_below_target" if not rgb_streams(info): return "no_rgb_video" return None def original_camera_names(summary: dict | None, dataset: str) -> dict: """Slot (image, image2, image3) -> the contributor's original camera name, from PROCESSING_SUMMARY.json.""" if not summary or dataset not in summary.get("datasets", {}): return {} m = summary["datasets"][dataset]["preprocessing_applied"]["feature_remapping"].get("mapping_applied") or {} return {dst.split(".")[-1]: src.split(".")[-1] for src, dst in m.items() if dst} def is_wrist_name(name: str | None) -> bool: return bool(name) and any(w in name.lower() for w in WRIST_WORDS) def read_json(path: str): with open(path) as f: return json.load(f) def read_jsonl(path: str) -> list: with open(path) as f: return [json.loads(line) for line in f if line.strip()] def write_json(path: str, obj) -> None: tmp = path + ".tmp" with open(tmp, "w") as f: json.dump(obj, f, indent=1) os.replace(tmp, path) def work_dirs(work: str) -> dict: d = {"work": work, "raw": os.path.join(work, "raw"), "shards": os.path.join(work, "shards"), "weights": os.path.join(work, "weights"), "runs": os.path.join(work, "runs")} d["dino"] = os.path.join(d["weights"], "dinov2_vits14_pretrain.pth") d["selection"] = os.path.join(work, "selection.json") return d