robodata-workbench 0.18.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robodata/__init__.py +2 -0
- robodata/__main__.py +3 -0
- robodata/adapters/__init__.py +12 -0
- robodata/adapters/builtin/__init__.py +1 -0
- robodata/adapters/builtin/aloha.py +129 -0
- robodata/adapters/builtin/hdf5.py +112 -0
- robodata/adapters/builtin/lerobot_v21.py +170 -0
- robodata/adapters/builtin/matching_cable.py +157 -0
- robodata/adapters/builtin/mcap.py +143 -0
- robodata/adapters/builtin/so100.py +173 -0
- robodata/adapters/contract.py +161 -0
- robodata/adapters/registry.py +143 -0
- robodata/adapters/schema/adapter.schema.json +63 -0
- robodata/adapters/support.py +88 -0
- robodata/aloha.py +208 -0
- robodata/business/__init__.py +115 -0
- robodata/business/__main__.py +8 -0
- robodata/business/constants.py +162 -0
- robodata/business/coordinator.py +585 -0
- robodata/business/requests.py +173 -0
- robodata/business/validation.py +534 -0
- robodata/ci_output.py +129 -0
- robodata/cli.py +504 -0
- robodata/config.py +66 -0
- robodata/contract.py +140 -0
- robodata/conversion.py +269 -0
- robodata/dataset.py +369 -0
- robodata/dataset_card.py +140 -0
- robodata/delivery.py +286 -0
- robodata/demo.py +177 -0
- robodata/doctor.py +119 -0
- robodata/errors.py +75 -0
- robodata/fixture_check.py +83 -0
- robodata/gc.py +138 -0
- robodata/importing.py +246 -0
- robodata/jobs.py +404 -0
- robodata/journal.py +131 -0
- robodata/layout.py +50 -0
- robodata/matching.py +223 -0
- robodata/models.py +43 -0
- robodata/process_plan.py +453 -0
- robodata/profiles/so100_hashes.json +20 -0
- robodata/quality.py +498 -0
- robodata/registry.py +151 -0
- robodata/reports.py +166 -0
- robodata/runtime.py +808 -0
- robodata/source.py +330 -0
- robodata/sources.py +60 -0
- robodata/status.py +55 -0
- robodata/ui_runs.py +102 -0
- robodata/video.py +121 -0
- robodata/web.py +625 -0
- robodata/worker.py +193 -0
- robodata/workflow.py +483 -0
- robodata_business/__init__.py +5 -0
- robodata_business/store.py +486 -0
- robodata_workbench-0.18.0.dist-info/METADATA +158 -0
- robodata_workbench-0.18.0.dist-info/RECORD +61 -0
- robodata_workbench-0.18.0.dist-info/WHEEL +4 -0
- robodata_workbench-0.18.0.dist-info/entry_points.txt +2 -0
- robodata_workbench-0.18.0.dist-info/licenses/LICENSE +21 -0
robodata/__init__.py
ADDED
robodata/__main__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Pluggable source adapters (contract v1)."""
|
|
2
|
+
|
|
3
|
+
from .contract import (ADAPTER_CONTRACT_VERSION, AdapterDescriptor, AdapterError, Detection,
|
|
4
|
+
Preflight, PreparedInput, SourceAdapter, SourceChanged,
|
|
5
|
+
UnsupportedSource, UnsupportedVersion, rejected, supported)
|
|
6
|
+
from .registry import (AdapterRegistry, REGISTRY, adapter_ids, adapters, best, descriptors,
|
|
7
|
+
detect, get_adapter, register, unregister)
|
|
8
|
+
|
|
9
|
+
__all__ = ["ADAPTER_CONTRACT_VERSION", "AdapterDescriptor", "AdapterError", "AdapterRegistry",
|
|
10
|
+
"Detection", "Preflight", "PreparedInput", "REGISTRY", "SourceAdapter", "SourceChanged",
|
|
11
|
+
"UnsupportedSource", "UnsupportedVersion", "adapter_ids", "adapters", "best",
|
|
12
|
+
"descriptors", "detect", "get_adapter", "register", "rejected", "supported", "unregister"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Built-in adapters shipped with RoboData."""
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Pinned ALOHA Coffee LeRobot v3.0 adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from ...aloha import (ALOHA_CAMERAS, ALOHA_EPISODES, ALOHA_FILES, ALOHA_MANIFEST_NAME,
|
|
9
|
+
ALOHA_REPO_ID, ALOHA_REVISION, fetch_aloha_sample)
|
|
10
|
+
from ..contract import (INPUT_DIRECTORY, AdapterDescriptor, Detection, Preflight, PreparedInput,
|
|
11
|
+
SourceAdapter, rejected, supported)
|
|
12
|
+
from ..support import read_json
|
|
13
|
+
|
|
14
|
+
ADAPTER_ID = "aloha"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AlohaAdapter(SourceAdapter):
|
|
18
|
+
descriptor = AdapterDescriptor(
|
|
19
|
+
adapter_id=ADAPTER_ID,
|
|
20
|
+
label="ALOHA Coffee(固定 revision 的四相机 v3.0 样本)",
|
|
21
|
+
source_kind="aloha",
|
|
22
|
+
input_kind=INPUT_DIRECTORY,
|
|
23
|
+
supported_versions=("lerobot-v3.0-aloha-coffee-pinned",),
|
|
24
|
+
pinned=True,
|
|
25
|
+
supports_test_label=False,
|
|
26
|
+
description="固定 repo_id/revision/相机/帧率的 ALOHA Coffee 目录;导入时只读下载并校验固定清单。",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def detect(self, path: Path, *, test_label: str | None = None) -> Detection:
|
|
30
|
+
path = Path(path)
|
|
31
|
+
if not path.is_dir():
|
|
32
|
+
return rejected(ADAPTER_ID, "输入不是目录", reasons=["ALOHA Coffee 需要本地 LeRobot 目录"])
|
|
33
|
+
info_path = path / "meta/info.json"
|
|
34
|
+
if not info_path.is_file():
|
|
35
|
+
return rejected(ADAPTER_ID, "缺少 meta/info.json,不是 LeRobot 目录", confidence=0.1)
|
|
36
|
+
try:
|
|
37
|
+
info = read_json(info_path)
|
|
38
|
+
except (ValueError, OSError) as exc:
|
|
39
|
+
return rejected(ADAPTER_ID, f"meta/info.json 无法读取:{exc}", confidence=0.2)
|
|
40
|
+
version = info.get("codebase_version")
|
|
41
|
+
if version != "v3.0":
|
|
42
|
+
return rejected(ADAPTER_ID, f"ALOHA Coffee 固定来源只支持 LeRobot v3.0,检测到 {version!r}",
|
|
43
|
+
confidence=0.4, version=str(version), reasons=["版本不在支持矩阵内"])
|
|
44
|
+
if not any((path / "data").rglob("*.parquet")):
|
|
45
|
+
return rejected(ADAPTER_ID, "LeRobot 目录没有 data/*.parquet", confidence=0.5,
|
|
46
|
+
version=version, reasons=["缺少数据表"])
|
|
47
|
+
if not any((path / "videos").rglob("*.mp4")):
|
|
48
|
+
return rejected(ADAPTER_ID, "LeRobot 目录没有 videos/*.mp4", confidence=0.5,
|
|
49
|
+
version=version, reasons=["缺少视频文件"])
|
|
50
|
+
manifest_path = path / ALOHA_MANIFEST_NAME
|
|
51
|
+
if not manifest_path.is_file():
|
|
52
|
+
return rejected(ADAPTER_ID, "缺少固定来源清单 source_manifest.json,无法证明 ALOHA Coffee 来源",
|
|
53
|
+
confidence=0.6, version=version)
|
|
54
|
+
declared = read_json(manifest_path).get("source", {})
|
|
55
|
+
if declared.get("repo_id") != ALOHA_REPO_ID:
|
|
56
|
+
return rejected(ADAPTER_ID, f"来源清单不是 ALOHA Coffee:{declared.get('repo_id')!r}",
|
|
57
|
+
confidence=0.2, version=version)
|
|
58
|
+
if declared.get("revision") != ALOHA_REVISION:
|
|
59
|
+
return rejected(ADAPTER_ID, "ALOHA Coffee revision 不符合已固定版本",
|
|
60
|
+
confidence=0.5, version=version,
|
|
61
|
+
reasons=[f"清单 revision:{declared.get('revision')}"])
|
|
62
|
+
cameras = sorted(key for key, feature in info.get("features", {}).items()
|
|
63
|
+
if isinstance(feature, dict) and feature.get("dtype") == "video")
|
|
64
|
+
if set(cameras) != set(ALOHA_CAMERAS):
|
|
65
|
+
return rejected(ADAPTER_ID, "ALOHA Coffee 相机特征不符合固定四相机配置",
|
|
66
|
+
confidence=0.5, version=version, reasons=[f"实际相机:{cameras}"])
|
|
67
|
+
if float(info.get("fps", 0)) != 50.0:
|
|
68
|
+
return rejected(ADAPTER_ID, "ALOHA Coffee 帧率不是固定 50 FPS",
|
|
69
|
+
confidence=0.5, version=version)
|
|
70
|
+
return supported(ADAPTER_ID, "lerobot-v3.0-aloha-coffee-pinned", 0.98,
|
|
71
|
+
["LeRobot v3.0", "repo_id/revision/相机/帧率均匹配固定来源"],
|
|
72
|
+
{"repo_id": ALOHA_REPO_ID, "revision": ALOHA_REVISION,
|
|
73
|
+
"cameras": cameras, "fps": info.get("fps")})
|
|
74
|
+
|
|
75
|
+
def preflight(self, path: Path, *, test_label: str | None = None) -> Preflight:
|
|
76
|
+
detection = self.detect(path, test_label=test_label)
|
|
77
|
+
summary: dict = {}
|
|
78
|
+
if Path(path, "meta/info.json").is_file():
|
|
79
|
+
info = read_json(Path(path) / "meta/info.json")
|
|
80
|
+
summary = {"codebase_version": info.get("codebase_version"), "fps": info.get("fps"),
|
|
81
|
+
"cameras": [key for key, feature in info.get("features", {}).items()
|
|
82
|
+
if isinstance(feature, dict) and feature.get("dtype") == "video"],
|
|
83
|
+
"data_files": len(list((Path(path) / "data").rglob("*.parquet")))}
|
|
84
|
+
return Preflight(adapter_id=ADAPTER_ID, supported=detection.supported,
|
|
85
|
+
detected_version=detection.detected_version, summary=summary,
|
|
86
|
+
warnings=[detection.unsupported_reason] if detection.unsupported_reason else [],
|
|
87
|
+
unsupported_reason=detection.unsupported_reason)
|
|
88
|
+
|
|
89
|
+
def prepare(self, request: dict, raw: Path, managed: Path) -> PreparedInput:
|
|
90
|
+
if request.get("test_label"):
|
|
91
|
+
raise ValueError("固定 ALOHA Coffee 来源不能使用故障副本标记;故障测试必须使用独立合成夹具")
|
|
92
|
+
source_manifest = fetch_aloha_sample(
|
|
93
|
+
raw, proxy=os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy"))
|
|
94
|
+
names = [*ALOHA_FILES, ALOHA_MANIFEST_NAME]
|
|
95
|
+
interpretation = {
|
|
96
|
+
"profile_version": "0.6.0", "kind": "aloha",
|
|
97
|
+
"repo_id": source_manifest["source"]["repo_id"], "revision": ALOHA_REVISION,
|
|
98
|
+
"episodes": list(ALOHA_EPISODES), "test_label": None,
|
|
99
|
+
"batch_label": str(request.get("label") or "").strip(),
|
|
100
|
+
}
|
|
101
|
+
from ..support import file_records
|
|
102
|
+
return PreparedInput(files=file_records(raw, names), interpretation=interpretation)
|
|
103
|
+
|
|
104
|
+
def preview(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
105
|
+
from ...dataset import load_metadata
|
|
106
|
+
meta = load_metadata(managed / "source")
|
|
107
|
+
return {"data_root": str(managed / "source"), "episode_indices": meta["episode_indices"]}
|
|
108
|
+
|
|
109
|
+
def inventory(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
110
|
+
from ...dataset import load_metadata
|
|
111
|
+
from ...quality import RULES
|
|
112
|
+
metadata = load_metadata(managed / "source")
|
|
113
|
+
indices = [index for index in ALOHA_EPISODES if index in metadata["episodes"]]
|
|
114
|
+
if tuple(indices) != ALOHA_EPISODES:
|
|
115
|
+
raise ValueError("固定 ALOHA Coffee Episode 0–4 不完整,拒绝创建批次")
|
|
116
|
+
manifest = read_json(managed / "input_manifest.json")
|
|
117
|
+
source = {
|
|
118
|
+
"kind": "aloha", "managed_path": str(managed),
|
|
119
|
+
"input_fingerprint": manifest["input_fingerprint"],
|
|
120
|
+
"manifest_path": str(managed / "input_manifest.json"),
|
|
121
|
+
"import_run_id": run_dir.name, "test_label": request.get("test_label"),
|
|
122
|
+
}
|
|
123
|
+
source.update(metadata["source"], data_root=str(managed / "source"), required_rules=list(RULES))
|
|
124
|
+
episodes = [{"episode_index": index, "row_count": int(metadata["episodes"][index]["length"])}
|
|
125
|
+
for index in indices]
|
|
126
|
+
return {"label": request.get("label", "本地导入批次"), "source": source, "episodes": episodes}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
adapter = AlohaAdapter()
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Pinned robomimic HDF5 adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import shutil
|
|
7
|
+
|
|
8
|
+
from ...sources import HDF5_SHA256, HDF5_SIZE, HDF5_SOURCE
|
|
9
|
+
from ...source import file_sha256
|
|
10
|
+
from ..contract import (INPUT_FILE, AdapterDescriptor, Detection, Preflight, PreparedInput,
|
|
11
|
+
SourceAdapter, rejected, supported)
|
|
12
|
+
from ..support import (HDF5_RULES, PROFILE, file_records, preview_worker, read_json)
|
|
13
|
+
|
|
14
|
+
ADAPTER_ID = "hdf5"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Hdf5Adapter(SourceAdapter):
|
|
18
|
+
descriptor = AdapterDescriptor(
|
|
19
|
+
adapter_id=ADAPTER_ID,
|
|
20
|
+
label="Robomimic HDF5(固定公开版本或明确标注的故障副本)",
|
|
21
|
+
source_kind="hdf5",
|
|
22
|
+
input_kind=INPUT_FILE,
|
|
23
|
+
supported_versions=("robomimic-hdf5-pinned", "hdf5-test-copy"),
|
|
24
|
+
pinned=True,
|
|
25
|
+
supports_test_label=True,
|
|
26
|
+
description="单个 .hdf5 文件;默认只接受固定 SHA-256,故障副本必须填写测试标记。",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def detect(self, path: Path, *, test_label: str | None = None) -> Detection:
|
|
30
|
+
path = Path(path)
|
|
31
|
+
if not path.is_file():
|
|
32
|
+
return rejected(ADAPTER_ID, "输入不是文件;HDF5 适配器只接受单个 .hdf5/.h5 文件",
|
|
33
|
+
reasons=["输入路径不存在或不是文件"])
|
|
34
|
+
if path.suffix.lower() not in {".hdf5", ".h5"}:
|
|
35
|
+
return rejected(ADAPTER_ID, f"文件扩展名不是 .hdf5/.h5:{path.suffix or '(无)'}",
|
|
36
|
+
confidence=0.1, reasons=["扩展名不匹配"])
|
|
37
|
+
size = path.stat().st_size
|
|
38
|
+
if test_label:
|
|
39
|
+
return supported(ADAPTER_ID, "hdf5-test-copy", 0.8,
|
|
40
|
+
[f"文件大小 {size} 字节", f"故障副本测试标记:{test_label}"],
|
|
41
|
+
{"size": size, "test_label": test_label})
|
|
42
|
+
if size != HDF5_SIZE:
|
|
43
|
+
return rejected(ADAPTER_ID, "HDF5 大小与固定公开版本不一致;若为故障副本,必须填写独立测试标记",
|
|
44
|
+
confidence=0.5, version="hdf5-local",
|
|
45
|
+
reasons=[f"实际 {size} 字节,固定版本 {HDF5_SIZE} 字节"], evidence={"size": size})
|
|
46
|
+
actual = file_sha256(path)
|
|
47
|
+
if actual != HDF5_SHA256:
|
|
48
|
+
return rejected(ADAPTER_ID, "HDF5 SHA-256 与固定公开版本不一致;若为故障副本,必须填写独立测试标记",
|
|
49
|
+
confidence=0.5, version="hdf5-local",
|
|
50
|
+
reasons=["内容哈希不匹配"], evidence={"size": size, "sha256": actual})
|
|
51
|
+
return supported(ADAPTER_ID, "robomimic-hdf5-pinned", 0.99,
|
|
52
|
+
["文件大小与 SHA-256 均匹配固定公开版本"],
|
|
53
|
+
{"size": size, "sha256": actual})
|
|
54
|
+
|
|
55
|
+
def preflight(self, path: Path, *, test_label: str | None = None) -> Preflight:
|
|
56
|
+
detection = self.detect(path, test_label=test_label)
|
|
57
|
+
path = Path(path)
|
|
58
|
+
summary = {"format": "hdf5", "size": path.stat().st_size if path.is_file() else None,
|
|
59
|
+
"pinned_sha256": detection.detected_version == "robomimic-hdf5-pinned"}
|
|
60
|
+
warnings = [] if detection.supported else [detection.unsupported_reason or ""]
|
|
61
|
+
return Preflight(adapter_id=ADAPTER_ID, supported=detection.supported,
|
|
62
|
+
detected_version=detection.detected_version, summary=summary,
|
|
63
|
+
warnings=[item for item in warnings if item],
|
|
64
|
+
unsupported_reason=detection.unsupported_reason)
|
|
65
|
+
|
|
66
|
+
def prepare(self, request: dict, raw: Path, managed: Path) -> PreparedInput:
|
|
67
|
+
source = Path(request["input_path"]).resolve()
|
|
68
|
+
label = request.get("test_label")
|
|
69
|
+
if not source.is_file():
|
|
70
|
+
raise FileNotFoundError("找不到待导入的 HDF5 文件")
|
|
71
|
+
before = file_sha256(source)
|
|
72
|
+
if not label and (before != HDF5_SHA256 or source.stat().st_size != HDF5_SIZE):
|
|
73
|
+
raise ValueError("HDF5 与固定公开版本不一致;若为故障副本,必须填写独立测试标记")
|
|
74
|
+
shutil.copy2(source, raw / "test.hdf5")
|
|
75
|
+
if before != file_sha256(raw / "test.hdf5") or before != file_sha256(source):
|
|
76
|
+
raise ValueError("复制期间 HDF5 输入发生变化,未登记批次")
|
|
77
|
+
interpretation = {**PROFILE, "kind": "hdf5", "test_label": label,
|
|
78
|
+
"batch_label": str(request.get("label") or "").strip()}
|
|
79
|
+
return PreparedInput(files=file_records(raw, ["test.hdf5"]), interpretation=interpretation)
|
|
80
|
+
|
|
81
|
+
def preview(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
82
|
+
preview_worker(managed / "source/test.hdf5", managed / "preview", request.get("test_label"))
|
|
83
|
+
files = [path.relative_to(managed / "preview").as_posix()
|
|
84
|
+
for path in (managed / "preview").rglob("*") if path.is_file()]
|
|
85
|
+
from ..support import write_json
|
|
86
|
+
write_json(managed / "preview_manifest.json", {"files": file_records(managed / "preview", files)})
|
|
87
|
+
return {"preview_root": str(managed / "preview"),
|
|
88
|
+
"metadata_path": str(managed / "preview/metadata.json")}
|
|
89
|
+
|
|
90
|
+
def inventory(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
91
|
+
metadata = read_json(managed / "preview/metadata.json")
|
|
92
|
+
source = {
|
|
93
|
+
"kind": "hdf5",
|
|
94
|
+
"managed_path": str(managed),
|
|
95
|
+
"input_fingerprint": read_json(managed / "input_manifest.json")["input_fingerprint"],
|
|
96
|
+
"manifest_path": str(managed / "input_manifest.json"),
|
|
97
|
+
"import_run_id": run_dir.name,
|
|
98
|
+
"test_label": request.get("test_label"),
|
|
99
|
+
}
|
|
100
|
+
source.update(**{key: value for key, value in HDF5_SOURCE.items() if key != "format_version"},
|
|
101
|
+
hdf5_path=str(managed / "source/test.hdf5"),
|
|
102
|
+
preview_root=str(managed / "preview"),
|
|
103
|
+
source_statistics=metadata["source_statistics"],
|
|
104
|
+
warnings=metadata.get("warnings", []),
|
|
105
|
+
required_rules=list(HDF5_RULES),
|
|
106
|
+
format_version="HDF5 (source)")
|
|
107
|
+
episodes = [{"episode_index": int(item["episode_index"]), "row_count": int(item["row_count"])}
|
|
108
|
+
for item in metadata["episodes"]]
|
|
109
|
+
return {"label": request.get("label", "本地导入批次"), "source": source, "episodes": episodes}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
adapter = Hdf5Adapter()
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Generic LeRobot v2.1 directory adapter.
|
|
2
|
+
|
|
3
|
+
Unlike the pinned SO-100/ALOHA adapters, this accepts any structurally valid
|
|
4
|
+
LeRobot v2.1 dataset. The official LeRobot converter is used for the
|
|
5
|
+
v2.1 -> v3.0 step, so the input must carry ``meta/episodes_stats.jsonl``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
import shutil
|
|
13
|
+
|
|
14
|
+
from ..contract import (INPUT_DIRECTORY, AdapterDescriptor, Detection, Preflight, PreparedInput,
|
|
15
|
+
SourceAdapter, rejected, supported)
|
|
16
|
+
from ..support import file_records, read_json, write_json
|
|
17
|
+
|
|
18
|
+
ADAPTER_ID = "lerobot_v21"
|
|
19
|
+
VERSION = "lerobot-v2.1-generic"
|
|
20
|
+
MARKER = "robodata_source.json"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _cameras(info: dict) -> list[str]:
|
|
24
|
+
return [key for key, feature in (info.get("features") or {}).items()
|
|
25
|
+
if isinstance(feature, dict) and feature.get("dtype") == "video"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _episode_count(root: Path) -> int:
|
|
29
|
+
jsonl = root / "meta/episodes.jsonl"
|
|
30
|
+
if jsonl.is_file():
|
|
31
|
+
return sum(1 for line in jsonl.read_text(encoding="utf-8").splitlines() if line.strip())
|
|
32
|
+
files = sorted((root / "meta/episodes").glob("chunk-*/file-*.parquet"))
|
|
33
|
+
if not files:
|
|
34
|
+
raise FileNotFoundError("缺少 meta/episodes.jsonl 或 meta/episodes/")
|
|
35
|
+
import pandas as pd
|
|
36
|
+
return len(pd.concat([pd.read_parquet(path) for path in files], ignore_index=True))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _frame_count(root: Path) -> int:
|
|
40
|
+
jsonl = root / "meta/episodes.jsonl"
|
|
41
|
+
if jsonl.is_file():
|
|
42
|
+
total = 0
|
|
43
|
+
for line in jsonl.read_text(encoding="utf-8").splitlines():
|
|
44
|
+
if line.strip():
|
|
45
|
+
total += int(json.loads(line).get("length", 0))
|
|
46
|
+
return total
|
|
47
|
+
import pandas as pd
|
|
48
|
+
files = sorted((root / "meta/episodes").glob("chunk-*/file-*.parquet"))
|
|
49
|
+
table = pd.concat([pd.read_parquet(path) for path in files], ignore_index=True)
|
|
50
|
+
return int(table["length"].sum())
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class LeRobotV21Adapter(SourceAdapter):
|
|
54
|
+
descriptor = AdapterDescriptor(
|
|
55
|
+
adapter_id=ADAPTER_ID,
|
|
56
|
+
label="LeRobot v2.1(通用输入)",
|
|
57
|
+
source_kind=ADAPTER_ID,
|
|
58
|
+
input_kind=INPUT_DIRECTORY,
|
|
59
|
+
supported_versions=(VERSION,),
|
|
60
|
+
pinned=False,
|
|
61
|
+
supports_test_label=False,
|
|
62
|
+
description="任意结构合法的 LeRobot v2.1 目录;官方 v2.1→v3.0 转换要求 meta/episodes_stats.jsonl。",
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
def detect(self, path: Path, *, test_label: str | None = None) -> Detection:
|
|
66
|
+
path = Path(path)
|
|
67
|
+
if not path.is_dir():
|
|
68
|
+
return rejected(ADAPTER_ID, "输入不是目录", reasons=["LeRobot v2.1 需要目录"])
|
|
69
|
+
info_path = path / "meta/info.json"
|
|
70
|
+
if not info_path.is_file():
|
|
71
|
+
return rejected(ADAPTER_ID, "缺少 meta/info.json", confidence=0.1)
|
|
72
|
+
try:
|
|
73
|
+
info = read_json(info_path)
|
|
74
|
+
except (OSError, ValueError) as exc:
|
|
75
|
+
return rejected(ADAPTER_ID, f"meta/info.json 无法读取:{exc}", confidence=0.2)
|
|
76
|
+
version = info.get("codebase_version")
|
|
77
|
+
if version == "v2.0":
|
|
78
|
+
return rejected(ADAPTER_ID, "检测到 LeRobot v2.0;先升级到 v2.1(含 episodes_stats.jsonl)再导入",
|
|
79
|
+
confidence=0.6, version="v2.0", reasons=["v2.0 不在支持矩阵"])
|
|
80
|
+
if version != "v2.1":
|
|
81
|
+
return rejected(ADAPTER_ID, f"不是 LeRobot v2.1:{version!r}",
|
|
82
|
+
confidence=0.4, version=str(version), reasons=["版本不在支持矩阵"])
|
|
83
|
+
if not any((path / "data").rglob("*.parquet")):
|
|
84
|
+
return rejected(ADAPTER_ID, "LeRobot 目录没有 data/*.parquet", confidence=0.5, version=version)
|
|
85
|
+
if not any((path / "videos").rglob("*.mp4")):
|
|
86
|
+
return rejected(ADAPTER_ID, "LeRobot 目录没有 videos/*.mp4", confidence=0.5, version=version)
|
|
87
|
+
if not (path / "meta/episodes_stats.jsonl").is_file():
|
|
88
|
+
return rejected(ADAPTER_ID,
|
|
89
|
+
"v2.1 缺少 meta/episodes_stats.jsonl;官方 v2.1→v3.0 转换需要逐集统计",
|
|
90
|
+
confidence=0.6, version=version)
|
|
91
|
+
cameras = _cameras(info)
|
|
92
|
+
if not cameras:
|
|
93
|
+
return rejected(ADAPTER_ID, "v2.1 元数据没有声明 video 相机", confidence=0.4, version=version)
|
|
94
|
+
return supported(ADAPTER_ID, VERSION, 0.9,
|
|
95
|
+
["LeRobot v2.1 结构", f"声明 {len(cameras)} 路相机",
|
|
96
|
+
"包含 meta/episodes_stats.jsonl"],
|
|
97
|
+
{"codebase_version": version, "cameras": cameras, "fps": info.get("fps")})
|
|
98
|
+
|
|
99
|
+
def preflight(self, path: Path, *, test_label: str | None = None) -> Preflight:
|
|
100
|
+
detection = self.detect(path, test_label=test_label)
|
|
101
|
+
summary = {}
|
|
102
|
+
warnings = []
|
|
103
|
+
if detection.supported:
|
|
104
|
+
try:
|
|
105
|
+
info = read_json(Path(path) / "meta/info.json")
|
|
106
|
+
summary = {"codebase_version": info.get("codebase_version"),
|
|
107
|
+
"episodes": _episode_count(Path(path)),
|
|
108
|
+
"frames": _frame_count(Path(path)),
|
|
109
|
+
"cameras": _cameras(info), "fps": info.get("fps")}
|
|
110
|
+
except (OSError, ValueError, FileNotFoundError) as exc:
|
|
111
|
+
warnings.append(str(exc))
|
|
112
|
+
if detection.unsupported_reason:
|
|
113
|
+
warnings.append(detection.unsupported_reason)
|
|
114
|
+
return Preflight(adapter_id=ADAPTER_ID, supported=detection.supported,
|
|
115
|
+
detected_version=detection.detected_version, summary=summary,
|
|
116
|
+
warnings=warnings, unsupported_reason=detection.unsupported_reason)
|
|
117
|
+
|
|
118
|
+
def prepare(self, request: dict, raw: Path, managed: Path) -> PreparedInput:
|
|
119
|
+
source = Path(request["input_path"]).resolve()
|
|
120
|
+
if request.get("test_label"):
|
|
121
|
+
raise ValueError("通用 LeRobot v2.1 导入不支持故障副本标记")
|
|
122
|
+
if not source.is_dir():
|
|
123
|
+
raise NotADirectoryError("LeRobot v2.1 导入需要本地目录")
|
|
124
|
+
paths = []
|
|
125
|
+
for path in sorted(source.rglob("*")):
|
|
126
|
+
if path.is_symlink():
|
|
127
|
+
raise ValueError("LeRobot v2.1 输入包含符号链接,拒绝复制")
|
|
128
|
+
relative = path.relative_to(source)
|
|
129
|
+
target = raw / relative
|
|
130
|
+
if path.is_dir():
|
|
131
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
132
|
+
elif path.is_file():
|
|
133
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
134
|
+
shutil.copy2(path, target)
|
|
135
|
+
paths.append(relative.as_posix())
|
|
136
|
+
marker = {"schema_version": 1, "kind": "lerobot_v21", "source_format": "v2.1",
|
|
137
|
+
"original_root": str(source), "batch_label": str(request.get("label") or "").strip()}
|
|
138
|
+
write_json(raw / MARKER, marker)
|
|
139
|
+
interpretation = {
|
|
140
|
+
"profile_version": "0.7.0", "kind": ADAPTER_ID, "format_version": "v2.1",
|
|
141
|
+
"source_root": str(source), "episodes": _episode_count(raw),
|
|
142
|
+
"batch_label": str(request.get("label") or "").strip(),
|
|
143
|
+
}
|
|
144
|
+
return PreparedInput(files=file_records(raw, paths), interpretation=interpretation)
|
|
145
|
+
|
|
146
|
+
def preview(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
147
|
+
from ...dataset import load_metadata
|
|
148
|
+
meta = load_metadata(managed / "source")
|
|
149
|
+
return {"data_root": str(managed / "source"), "episode_indices": meta["episode_indices"]}
|
|
150
|
+
|
|
151
|
+
def inventory(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
152
|
+
from ...dataset import load_metadata
|
|
153
|
+
from ...quality import RULES
|
|
154
|
+
metadata = load_metadata(managed / "source")
|
|
155
|
+
manifest = read_json(managed / "input_manifest.json")
|
|
156
|
+
source = {
|
|
157
|
+
"kind": ADAPTER_ID, "managed_path": str(managed),
|
|
158
|
+
"input_fingerprint": manifest["input_fingerprint"],
|
|
159
|
+
"manifest_path": str(managed / "input_manifest.json"),
|
|
160
|
+
"import_run_id": run_dir.name, "test_label": None,
|
|
161
|
+
}
|
|
162
|
+
source.update(metadata["source"], data_root=str(managed / "source"),
|
|
163
|
+
required_rules=list(RULES))
|
|
164
|
+
episodes = [{"episode_index": index,
|
|
165
|
+
"row_count": int(metadata["episodes"][index]["length"])}
|
|
166
|
+
for index in metadata["episode_indices"]]
|
|
167
|
+
return {"label": request.get("label", "本地导入批次"), "source": source, "episodes": episodes}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
adapter = LeRobotV21Adapter()
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Matching Cable per-frame HDF5 directory adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from ...matching import (SOURCE_KIND, discover_episodes, file_records as matching_file_records)
|
|
9
|
+
from ..contract import (INPUT_DIRECTORY, AdapterDescriptor, Detection, Preflight, PreparedInput,
|
|
10
|
+
SourceAdapter, rejected, supported)
|
|
11
|
+
from ..support import PROFILE, digest, matching_preview_worker, read_json, write_json
|
|
12
|
+
|
|
13
|
+
ADAPTER_ID = "matching_cable"
|
|
14
|
+
VERSION = "matching_cable_frames_v1"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _structural_scan(path: Path) -> tuple[list[Path], int]:
|
|
18
|
+
episodes = []
|
|
19
|
+
frames = 0
|
|
20
|
+
if path.is_dir():
|
|
21
|
+
for candidate in sorted(path.iterdir()):
|
|
22
|
+
if not candidate.is_dir() or not candidate.name.isdigit():
|
|
23
|
+
continue
|
|
24
|
+
count = sum(1 for item in candidate.glob("*.hdf5") if item.is_file())
|
|
25
|
+
if count:
|
|
26
|
+
episodes.append(candidate)
|
|
27
|
+
frames += count
|
|
28
|
+
return episodes, frames
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class MatchingCableAdapter(SourceAdapter):
|
|
32
|
+
descriptor = AdapterDescriptor(
|
|
33
|
+
adapter_id=ADAPTER_ID,
|
|
34
|
+
label="Matching Cable(逐帧 HDF5 目录)",
|
|
35
|
+
source_kind=SOURCE_KIND,
|
|
36
|
+
input_kind=INPUT_DIRECTORY,
|
|
37
|
+
supported_versions=(VERSION,),
|
|
38
|
+
pinned=False,
|
|
39
|
+
supports_test_label=False,
|
|
40
|
+
description="父目录下每个数字子目录是一条 Episode,每个 .hdf5 是一帧;可选流按实际存在记录。",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def detect(self, path: Path, *, test_label: str | None = None) -> Detection:
|
|
44
|
+
path = Path(path)
|
|
45
|
+
if not path.is_dir():
|
|
46
|
+
return rejected(ADAPTER_ID, "输入不是目录", reasons=["Matching Cable 需要包含数字 Episode 目录的本地目录"])
|
|
47
|
+
if (path / "meta/info.json").is_file():
|
|
48
|
+
return rejected(ADAPTER_ID, "该目录看起来是 LeRobot 数据集,不是 Matching Cable 逐帧目录",
|
|
49
|
+
confidence=0.2)
|
|
50
|
+
episodes, frames = _structural_scan(path)
|
|
51
|
+
if not episodes:
|
|
52
|
+
return rejected(ADAPTER_ID, "没有找到包含 .hdf5 帧的数字 Episode 目录", confidence=0.1)
|
|
53
|
+
return supported(ADAPTER_ID, VERSION, 0.9,
|
|
54
|
+
[f"找到 {len(episodes)} 个 Episode 目录、{frames} 个 .hdf5 帧",
|
|
55
|
+
"目录结构匹配;字段与可选流将在预览阶段逐帧校验"],
|
|
56
|
+
{"episodes": len(episodes), "frames": frames,
|
|
57
|
+
"episode_ids": [int(item.name) for item in episodes][:50]})
|
|
58
|
+
|
|
59
|
+
def preflight(self, path: Path, *, test_label: str | None = None) -> Preflight:
|
|
60
|
+
detection = self.detect(path, test_label=test_label)
|
|
61
|
+
summary: dict = {}
|
|
62
|
+
warnings: list[str] = []
|
|
63
|
+
if detection.supported:
|
|
64
|
+
try:
|
|
65
|
+
episodes = discover_episodes(Path(path), os.environ.get("ROBODATA_MATCHING_EPISODES"))
|
|
66
|
+
summary = {"episodes": len(episodes),
|
|
67
|
+
"frames": sum(len(item["frames"]) for item in episodes),
|
|
68
|
+
"episode_ids": [int(item["source_episode_id"]) for item in episodes],
|
|
69
|
+
"frame_limit": os.environ.get("ROBODATA_MATCHING_MAX_FRAMES_PER_EPISODE") or None}
|
|
70
|
+
except ValueError as exc:
|
|
71
|
+
return Preflight(adapter_id=ADAPTER_ID, supported=False,
|
|
72
|
+
detected_version=detection.detected_version, summary={},
|
|
73
|
+
warnings=[str(exc)], unsupported_reason=str(exc))
|
|
74
|
+
if detection.unsupported_reason:
|
|
75
|
+
warnings.append(detection.unsupported_reason)
|
|
76
|
+
return Preflight(adapter_id=ADAPTER_ID, supported=detection.supported,
|
|
77
|
+
detected_version=detection.detected_version, summary=summary,
|
|
78
|
+
warnings=warnings, unsupported_reason=detection.unsupported_reason)
|
|
79
|
+
|
|
80
|
+
def prepare(self, request: dict, raw: Path, managed: Path) -> PreparedInput:
|
|
81
|
+
source = Path(request["input_path"]).resolve()
|
|
82
|
+
if request.get("test_label"):
|
|
83
|
+
raise ValueError("Matching Cable 本机数据不支持固定样本故障副本标记")
|
|
84
|
+
episodes = discover_episodes(source, os.environ.get("ROBODATA_MATCHING_EPISODES"))
|
|
85
|
+
files = matching_file_records(source, episodes, include_hashes=False)
|
|
86
|
+
interpretation = {
|
|
87
|
+
**PROFILE, "kind": SOURCE_KIND, "source_root": str(source),
|
|
88
|
+
"episodes": [{"episode_index": item["episode_index"],
|
|
89
|
+
"source_episode_id": item["source_episode_id"],
|
|
90
|
+
"frame_count": len(item["frames"])} for item in episodes],
|
|
91
|
+
"state_field": "puppet/joint_position", "action_field": "master/joint_position",
|
|
92
|
+
"fps": 20, "test_label": None,
|
|
93
|
+
"batch_label": str(request.get("label") or "").strip(),
|
|
94
|
+
}
|
|
95
|
+
return PreparedInput(files=files, interpretation=interpretation)
|
|
96
|
+
|
|
97
|
+
def preview(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
98
|
+
matching_preview_worker(Path(request["input_path"]), managed / "preview")
|
|
99
|
+
preview_manifest = read_json(managed / "preview/source_manifest.json")
|
|
100
|
+
input_manifest = read_json(managed / "input_manifest.json")
|
|
101
|
+
input_manifest["files"] = preview_manifest["files"]
|
|
102
|
+
input_manifest["interpretation"]["episodes"] = [
|
|
103
|
+
{"episode_index": item["episode_index"], "source_episode_id": item["source_episode_id"],
|
|
104
|
+
"frame_count": item["length"]} for item in preview_manifest["episodes"]]
|
|
105
|
+
for key in ("cameras", "missing_cameras", "depth_source_cameras",
|
|
106
|
+
"missing_depth_source_cameras", "optional_fields", "tactile"):
|
|
107
|
+
input_manifest["interpretation"][key] = preview_manifest["source"].get(key)
|
|
108
|
+
fingerprint = digest({"files": input_manifest["files"],
|
|
109
|
+
"interpretation": input_manifest["interpretation"]})
|
|
110
|
+
input_manifest["input_fingerprint"] = fingerprint
|
|
111
|
+
preview_manifest["input_fingerprint"] = fingerprint
|
|
112
|
+
write_json(managed / "input_manifest.json", input_manifest)
|
|
113
|
+
write_json(managed / "preview/source_manifest.json", preview_manifest)
|
|
114
|
+
return {"data_root": str(managed / "preview"), "preview_root": str(managed / "preview"),
|
|
115
|
+
"metadata_path": str(managed / "preview/source_manifest.json"),
|
|
116
|
+
"episode_indices": [item["episode_index"] for item in preview_manifest["episodes"]]}
|
|
117
|
+
|
|
118
|
+
def inventory(self, request: dict, managed: Path, run_dir: Path) -> dict:
|
|
119
|
+
from ...dataset import load_metadata
|
|
120
|
+
from ...quality import RULES
|
|
121
|
+
preview = managed / "preview"
|
|
122
|
+
preview_manifest = read_json(preview / "source_manifest.json")
|
|
123
|
+
manifest = read_json(managed / "input_manifest.json")
|
|
124
|
+
source = {
|
|
125
|
+
"kind": SOURCE_KIND, "managed_path": str(managed),
|
|
126
|
+
"input_fingerprint": manifest["input_fingerprint"],
|
|
127
|
+
"manifest_path": str(managed / "input_manifest.json"),
|
|
128
|
+
"import_run_id": run_dir.name, "test_label": request.get("test_label"),
|
|
129
|
+
"data_root": str(preview),
|
|
130
|
+
"raw_data_root": str(Path(request["input_path"]).resolve()),
|
|
131
|
+
"preview_root": str(preview),
|
|
132
|
+
"repo_id": "local/matching-cable-teleoperation", "revision": "local-source",
|
|
133
|
+
"license": "用户本机数据;许可由数据提供方确认", "robot": "双主从臂遥操作平台",
|
|
134
|
+
"format_version": VERSION, "fps": 20.0,
|
|
135
|
+
"camera": preview_manifest["source"]["camera"],
|
|
136
|
+
"cameras": preview_manifest["source"]["cameras"],
|
|
137
|
+
"camera_metadata": preview_manifest["camera_metadata"],
|
|
138
|
+
"missing_cameras": preview_manifest["source"].get("missing_cameras", []),
|
|
139
|
+
"depth_source_cameras": preview_manifest["source"].get("depth_source_cameras", []),
|
|
140
|
+
"missing_depth_source_cameras": preview_manifest["source"].get("missing_depth_source_cameras", []),
|
|
141
|
+
"optional_fields": preview_manifest["source"].get("optional_fields", {}),
|
|
142
|
+
"tactile": preview_manifest["source"].get("tactile"),
|
|
143
|
+
"episode_mapping": preview_manifest["source"]["episode_mapping"],
|
|
144
|
+
"state_field": "puppet/joint_position", "action_field": "master/joint_position",
|
|
145
|
+
"source_statistics": {"source_episodes": len(preview_manifest["episodes"]),
|
|
146
|
+
"source_frames": preview_manifest["total_frames"]},
|
|
147
|
+
"warnings": preview_manifest.get("timestamp_warnings", []),
|
|
148
|
+
"required_rules": list(RULES),
|
|
149
|
+
"timestamp_semantics": preview_manifest["source"]["timestamp_semantics"],
|
|
150
|
+
}
|
|
151
|
+
episodes = [{"episode_index": item["episode_index"], "row_count": int(item["length"]),
|
|
152
|
+
"source_episode_id": item["source_episode_id"]}
|
|
153
|
+
for item in preview_manifest["episodes"]]
|
|
154
|
+
return {"label": request.get("label", "本地导入批次"), "source": source, "episodes": episodes}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
adapter = MatchingCableAdapter()
|