Upload H2O shared-v1.0 (part 88)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- H2O/shared-v1.0/script/check_dexycb_projection.py +31 -0
- H2O/shared-v1.0/script/config.json +24 -0
- H2O/shared-v1.0/script/convert_dexycb_v1.0.py +349 -0
- H2O/shared-v1.0/script/convert_h2o_v1.0.py +678 -0
- H2O/shared-v1.0/script/convert_hoi4d_v1.0.py +595 -0
- H2O/shared-v1.0/script/convert_visor_v1.0.py +271 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-check-fallback.py +137 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-finalize-quick-validation.py +39 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-pipeline-bench-job.sh +25 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-pipeline-benchmark.py +48 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-pipeline-process-benchmark.py +48 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-prepare-pipeline-bench.py +28 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-prepare-process-full.py +45 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-process-final-tests.log +39 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-quick-validation.py +161 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-shared-final-tests.log +1 -0
- H2O/shared-v1.0/script/provenance/operations/h2o-switch-process-full.sh +12 -0
- H2O/shared-v1.0/script/provenance/operations/watch-steady-cpu.py +38 -0
- H2O/shared-v1.0/script/provenance/previous-run/docs/CONTRACT.md +457 -0
- H2O/shared-v1.0/script/provenance/previous-run/docs/h2o-RAW_TO_SHARED.md +48 -0
- H2O/shared-v1.0/script/provenance/previous-run/docs/schema.json +869 -0
- H2O/shared-v1.0/script/provenance/previous-run/full.log +61 -0
- H2O/shared-v1.0/script/provenance/previous-run/full.status +7 -0
- H2O/shared-v1.0/script/provenance/previous-run/run-full.sh +26 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/check_dexycb_projection.py +31 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/config.json +17 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/convert_dexycb_v1.0.py +349 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/convert_h2o_v1.0.py +545 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/convert_hoi4d_v1.0.py +595 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/convert_visor_v1.0.py +271 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/h2o-benchmark-decode.py +74 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/h2o-prepare-d10.py +55 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/h2o-switch-d10.sh +16 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/worker4-encode10-decode10-depth4-regression.log +37 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/workspace-regression.log +37 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/docs/CONTRACT.md +457 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/docs/h2o-RAW_TO_SHARED.md +30 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/docs/schema.json +869 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/full.log +8 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/full.status +7 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/run-full.sh +26 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/check_dexycb_projection.py +31 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/config.json +15 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_dexycb_v1.0.py +349 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_h2o_v1.0.py +527 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_hoi4d_v1.0.py +595 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_visor_v1.0.py +271 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/provenance/operations/prepare-w4-c10.py +52 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/provenance/operations/retry-w4-c10.sh +11 -0
- H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/provenance/r1/docs/CONTRACT.md +457 -0
H2O/shared-v1.0/script/check_dexycb_projection.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Check saved Dex-YCB source 3D joints against saved source 2D joints in sampled views."""
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import torch
|
| 9 |
+
|
| 10 |
+
root = Path(sys.argv[1])
|
| 11 |
+
report = json.loads((root / 'doc/validation/STRUCTURAL_AUDIT.json').read_text())
|
| 12 |
+
checks = []
|
| 13 |
+
for name in report['sampled_views']:
|
| 14 |
+
view = root / name
|
| 15 |
+
load = lambda path: torch.load(view / path, weights_only=True, map_location='cpu').numpy()
|
| 16 |
+
k = load('camera/intrinsic.pt')
|
| 17 |
+
xyz = load('annotation/keypoints/xyz.pt')
|
| 18 |
+
uv = load('annotation/keypoints/uv.pt')
|
| 19 |
+
valid = load('annotation/keypoints/xyz_valid.pt') & load('annotation/keypoints/uv_valid.pt')
|
| 20 |
+
z = xyz[..., 2]
|
| 21 |
+
valid &= np.isfinite(xyz).all(axis=-1) & np.isfinite(uv).all(axis=-1) & (z > 0)
|
| 22 |
+
z = np.where(valid, z, 1)
|
| 23 |
+
pred = np.stack((k[:, 0, 0, None, None] * xyz[..., 0] / z + k[:, 0, 2, None, None],
|
| 24 |
+
k[:, 1, 1, None, None] * xyz[..., 1] / z + k[:, 1, 2, None, None]), axis=-1)
|
| 25 |
+
errors = np.linalg.norm(pred[valid] - uv[valid], axis=-1)
|
| 26 |
+
checks.append(dict(view=name, points=int(errors.size), median_px=float(np.median(errors)) if errors.size else None,
|
| 27 |
+
p95_px=float(np.percentile(errors, 95)) if errors.size else None))
|
| 28 |
+
(root / 'doc/validation/KEYPOINT_PROJECTION_QC.json').write_text(json.dumps({
|
| 29 |
+
'scope': 'Saved source 3D joints projected with saved color intrinsics vs saved source 2D joints; independent of hand mesh rendering.',
|
| 30 |
+
'views': checks}, ensure_ascii=False, indent=2) + '\n')
|
| 31 |
+
print(json.dumps(checks, ensure_ascii=False), flush=True)
|
H2O/shared-v1.0/script/config.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"root": "/home/xuzhefeng/Datasets/Hand-Datasets-Raw/H2O",
|
| 3 |
+
"out": "/home/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe",
|
| 4 |
+
"release_id": "shared-v1.0",
|
| 5 |
+
"limit": null,
|
| 6 |
+
"max_frames": null,
|
| 7 |
+
"mano_dir": "/home/xuzhefeng/Projects/WiLoR/mano_data",
|
| 8 |
+
"views": null,
|
| 9 |
+
"jpeg_full_check": false,
|
| 10 |
+
"workers": 4,
|
| 11 |
+
"view_backend": "processes",
|
| 12 |
+
"camera_pipeline": true,
|
| 13 |
+
"ffv1_slices": 16,
|
| 14 |
+
"view_workers": 16,
|
| 15 |
+
"ram_stage_dir": "/dev/shm/xuzhefeng-h2o-full-process16-20260930",
|
| 16 |
+
"ram_stage_gib": 32,
|
| 17 |
+
"stream_media": true,
|
| 18 |
+
"codec_threads": 10,
|
| 19 |
+
"decode_threads": 10,
|
| 20 |
+
"depth_threads": 4,
|
| 21 |
+
"subjects": null,
|
| 22 |
+
"include_casa": false,
|
| 23 |
+
"archive": null
|
| 24 |
+
}
|
H2O/shared-v1.0/script/convert_dexycb_v1.0.py
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Dex-YCB source annotations → CONTRACT.md v1.0. No derived annotations."""
|
| 3 |
+
import io
|
| 4 |
+
import re
|
| 5 |
+
import shutil
|
| 6 |
+
import tarfile
|
| 7 |
+
import tempfile
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
from PIL import Image
|
| 12 |
+
import yaml
|
| 13 |
+
|
| 14 |
+
from warehouse_v1_0 import (View, build_record, find_file, locator, mano_models, mesh_asset,
|
| 15 |
+
model_profile, parser, pca_to_axis_angle, release, roots, safe_member, sequence_dir)
|
| 16 |
+
|
| 17 |
+
IMG_W, IMG_H = 640, 480
|
| 18 |
+
|
| 19 |
+
class _Loader(yaml.SafeLoader):
|
| 20 |
+
pass
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_Loader.add_constructor("tag:yaml.org,2002:python/tuple",
|
| 24 |
+
lambda l, n: tuple(l.construct_sequence(n)))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def yaml_load_bytes(data: bytes):
|
| 28 |
+
return yaml.load(io.BytesIO(data), Loader=_Loader)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Calibration:
|
| 32 |
+
def __init__(self, dexycb_root: Path):
|
| 33 |
+
self.intrinsics = {} # serial -> {fx,fy,cx,cy,w,h}
|
| 34 |
+
self.extrinsics = {} # group -> {serial: [12] 行优先 3×4 cam→world}
|
| 35 |
+
self.betas = {} # mano_calib_name -> [10]
|
| 36 |
+
calib_dir = dexycb_root / "calibration"
|
| 37 |
+
if calib_dir.is_dir():
|
| 38 |
+
self._load((p.as_posix(), p.read_bytes())
|
| 39 |
+
for p in sorted(calib_dir.rglob("*")) if p.is_file())
|
| 40 |
+
else:
|
| 41 |
+
tar_path = dexycb_root / "calibration.tar.gz"
|
| 42 |
+
if not tar_path.exists():
|
| 43 |
+
raise FileNotFoundError(f"no calibration/ nor calibration.tar.gz in {dexycb_root}")
|
| 44 |
+
with tarfile.open(tar_path, "r:gz") as tf:
|
| 45 |
+
self._load((m.name, tf.extractfile(m).read()) for m in tf if m.isfile())
|
| 46 |
+
|
| 47 |
+
_RE_INTR = re.compile(r"(?:^|/)intrinsics/(\d+)_\d+x\d+\.yml$")
|
| 48 |
+
_RE_EXTRA = re.compile(r"(?:^|/)extrinsics_(\d{8}_\d{6})/extrinsics\.yml$")
|
| 49 |
+
_RE_MANO = re.compile(r"(?:^|/)mano_(\d{8}_\d{6}_subject-\d{2}_right)/mano\.yml$")
|
| 50 |
+
|
| 51 |
+
def _load(self, files):
|
| 52 |
+
for rel, data in files:
|
| 53 |
+
m = self._RE_INTR.search(rel)
|
| 54 |
+
if m:
|
| 55 |
+
c = yaml_load_bytes(data)["color"]
|
| 56 |
+
self.intrinsics[m.group(1)] = {"fx": float(c["fx"]), "fy": float(c["fy"]),
|
| 57 |
+
"cx": float(c["ppx"]), "cy": float(c["ppy"]),
|
| 58 |
+
"w": IMG_W, "h": IMG_H}
|
| 59 |
+
continue
|
| 60 |
+
m = self._RE_EXTRA.search(rel)
|
| 61 |
+
if m:
|
| 62 |
+
raw = yaml_load_bytes(data)["extrinsics"]
|
| 63 |
+
self.extrinsics[m.group(1)] = {
|
| 64 |
+
str(s): [float(x) for x in np.asarray(v).ravel()] for s, v in raw.items()}
|
| 65 |
+
continue
|
| 66 |
+
m = self._RE_MANO.search(rel)
|
| 67 |
+
if m:
|
| 68 |
+
self.betas[m.group(1)] = [float(b) for b in yaml_load_bytes(data)["betas"]]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def calibration_locator(path, member, **extra):
|
| 73 |
+
if path.is_dir():
|
| 74 |
+
return locator(path / member.removeprefix('calibration/'), **extra)
|
| 75 |
+
return locator(path, member, **extra)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def prepare_models(root, destination):
|
| 79 |
+
archive = find_file(root, 'models.tar.gz')
|
| 80 |
+
if archive is None:
|
| 81 |
+
return {}, None
|
| 82 |
+
pattern = re.compile(r'^models/(\d{3}_[a-z0-9_]+)/(textured_simple\.obj(?:\.mtl)?|texture_map\.png)$')
|
| 83 |
+
names = set()
|
| 84 |
+
with tarfile.open(archive, 'r|gz') as tf:
|
| 85 |
+
for member in tf:
|
| 86 |
+
match = pattern.fullmatch(member.name)
|
| 87 |
+
if member.isfile() and match:
|
| 88 |
+
names.add(match[1])
|
| 89 |
+
path = safe_member(destination, '/'.join(match.groups()))
|
| 90 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 91 |
+
path.write_bytes(tf.extractfile(member).read())
|
| 92 |
+
if len(names) != 21:
|
| 93 |
+
raise ValueError('expected all 21 source YCB model directories')
|
| 94 |
+
return {i: destination / name for i, name in enumerate(sorted(names), 1)}, archive
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def convert_view(path, args, seq, serial, frames, meta, meta_loc, calib, calib_path, models, assets, asset_archive):
|
| 98 |
+
total = int(meta.get('num_frames', max(frames) + 1))
|
| 99 |
+
ids = list(range(min(total, args.max_frames) if args.max_frames else total))
|
| 100 |
+
for f in ids:
|
| 101 |
+
frames.setdefault(f, {})
|
| 102 |
+
if not ids:
|
| 103 |
+
raise ValueError('no RGB frames')
|
| 104 |
+
source_rows = []
|
| 105 |
+
for f in ids:
|
| 106 |
+
row = frames[f]
|
| 107 |
+
source_rows.append(dict(source_frame_id=f, sync_id=f'{seq}:{f}',
|
| 108 |
+
source_locator=row['color'][1] if 'color' in row else (meta_loc | {'source_frame_id': f, 'missing_rgb': True}), annotation_matches={
|
| 109 |
+
'labels': {'source_frame_id': f, 'source_timestamp_ns': None, 'clock_domain': None,
|
| 110 |
+
'match_method': 'index_map', 'delta_ns': None, 'source_locator': row['labels'][1]}
|
| 111 |
+
for _ in [0] if 'labels' in row},
|
| 112 |
+
component_sources={k: v[1] for k, v in row.items()}))
|
| 113 |
+
view = View(path, 'dex-ycb', args.release_id, seq, serial, source_rows,
|
| 114 |
+
sampling='dense' if ids == list(range(ids[0], ids[-1] + 1)) else 'sparse')
|
| 115 |
+
view.valid_rules = {
|
| 116 |
+
'mano': 'Source pose_m present and not all zero; side model/calibration available',
|
| 117 |
+
'keypoints': 'Corresponding joint_2d/joint_3d present; whole-hand all -1 is missing, broadcast to its 21 points',
|
| 118 |
+
'pose': 'Source pose_y for this ycb_ids slot present and not an all-zero matrix',
|
| 119 |
+
'segment': 'Source seg array provided for this frame; region codes and entity references validated',
|
| 120 |
+
'relations': 'Source sequence ycb_grasp_ind resolves through ycb_ids; broadcast sequence grasp to selected frames',
|
| 121 |
+
}
|
| 122 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 123 |
+
view.meta['view_type'] = 'exo'
|
| 124 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'views': args.views}
|
| 125 |
+
subject = re.search(r'subject-(\d+)', seq)
|
| 126 |
+
if subject and 1 <= int(subject[1]) <= 10:
|
| 127 |
+
index = int(subject[1])
|
| 128 |
+
view.meta.update(split='val' if index == 7 else 'test' if index in (8, 9) else 'train',
|
| 129 |
+
split_scheme='Dex-YCB/s1', split_source_locator={
|
| 130 |
+
'url': 'https://github.com/NVlabs/dex-ycb-toolkit/blob/master/dex_ycb_toolkit/dex_ycb.py',
|
| 131 |
+
'rule': 's1 unseen-subject: 01-06/10 train, 07 val, 08-09 test'})
|
| 132 |
+
view.meta.pop('split_reason', None)
|
| 133 |
+
view.rgb([frames[f]['color'][0] if 'color' in frames[f] else None for f in ids], {'frames_ref': 'camera/frames.jsonl'})
|
| 134 |
+
n = len(ids)
|
| 135 |
+
intr = calib.intrinsics.get(serial)
|
| 136 |
+
K = None if intr is None else np.array([[intr['fx'], 0, intr['cx']], [0, intr['fy'], intr['cy']], [0, 0, 1]])
|
| 137 |
+
ext = calib.extrinsics.get(str(meta['extrinsics']), {}).get(serial)
|
| 138 |
+
E = None
|
| 139 |
+
if ext is not None:
|
| 140 |
+
E = np.eye(4)
|
| 141 |
+
E[:3] = np.asarray(ext).reshape(3, 4)
|
| 142 |
+
E = np.linalg.inv(E)
|
| 143 |
+
view.camera(K, calibration_locator(calib_path, f'calibration/intrinsics/{serial}_640x480.yml'), E,
|
| 144 |
+
calibration_locator(calib_path, f'calibration/extrinsics_{meta["extrinsics"]}/extrinsics.yml',
|
| 145 |
+
conversion='inverse of source T_world_from_camera'))
|
| 146 |
+
sides = meta.get('mano_sides')
|
| 147 |
+
if sides not in (['left'], ['right']):
|
| 148 |
+
raise ValueError(f'expected exactly one anatomical source hand: {sides}')
|
| 149 |
+
side = sides[0]
|
| 150 |
+
slot = ['left', 'right'].index(side)
|
| 151 |
+
cal_name = meta['mano_calib'][0] if isinstance(meta['mano_calib'], list) else meta['mano_calib']
|
| 152 |
+
labels = [dict(np.load(frames[f]['labels'][0])) if 'labels' in frames[f] else {} for f in ids]
|
| 153 |
+
label_loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources.labels'}
|
| 154 |
+
motion = np.full((n, 2, 61), np.nan, np.float32)
|
| 155 |
+
mv = np.zeros((n, 2), bool)
|
| 156 |
+
if side in models and any('pose_m' in lab for lab in labels):
|
| 157 |
+
for i, lab in enumerate(labels):
|
| 158 |
+
if 'pose_m' not in lab:
|
| 159 |
+
continue
|
| 160 |
+
pose = np.asarray(lab['pose_m']).reshape(51)
|
| 161 |
+
if not np.any(pose): # Official Dex-YCB missing-pose sentinel, independent of joints/seg.
|
| 162 |
+
continue
|
| 163 |
+
motion[i, slot] = np.r_[pose[:3], pca_to_axis_angle(pose[3:48], models[side]),
|
| 164 |
+
calib.betas[cal_name], pose[48:51]]
|
| 165 |
+
mv[i, slot] = True
|
| 166 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 167 |
+
['T', 'hand', 'parameter'], label_loc, model_profile=model_profile(models),
|
| 168 |
+
calibration_source=calibration_locator(calib_path, f'calibration/mano_{cal_name}/mano.yml'),
|
| 169 |
+
provenance={'kind': 'format_conversion', 'method': 'source PCA @ hands_components + hands_mean; explicit axis-angle consumed with flat_hand_mean=true'})
|
| 170 |
+
elif any('pose_m' in lab for lab in labels):
|
| 171 |
+
view.absent('mano', 'Source PCA exists; provide --mano-dir to expand it', 'dependency_missing')
|
| 172 |
+
else:
|
| 173 |
+
view.absent('mano', 'No source pose_m field')
|
| 174 |
+
for source_key, key, dim, unit in [('joint_2d', 'uv', 2, 'pixel'), ('joint_3d', 'xyz', 3, 'm')]:
|
| 175 |
+
if not any(source_key in x for x in labels):
|
| 176 |
+
view.absent('keypoints_' + key, 'No source ' + source_key)
|
| 177 |
+
continue
|
| 178 |
+
points = np.full((n, 2, 21, dim), np.nan, np.float32)
|
| 179 |
+
valid = np.zeros((n, 2, 21), bool)
|
| 180 |
+
for i, lab in enumerate(labels):
|
| 181 |
+
if source_key not in lab:
|
| 182 |
+
continue
|
| 183 |
+
p = np.asarray(lab[source_key]).reshape(21, dim)
|
| 184 |
+
points[i, slot] = p
|
| 185 |
+
valid[i, slot] = not np.all(p == -1) # Official sentinel covers the whole source hand.
|
| 186 |
+
# An individual off-image point (-1, -1) is not evidence of missing annotation.
|
| 187 |
+
view.tensor('keypoints_' + key, f'keypoints/{key}/v1', f'annotation/keypoints/{key}.pt',
|
| 188 |
+
points, valid, ['T', 'hand', 'keypoint', 'coordinate'], label_loc,
|
| 189 |
+
keypoint_schema='mano21/v1', unit=unit)
|
| 190 |
+
ycb_ids = [int(x) for x in meta['ycb_ids']]
|
| 191 |
+
for j, oid in enumerate(ycb_ids):
|
| 192 |
+
entity = f'ycb_{oid:02d}'
|
| 193 |
+
view.object(entity, meta_loc, source_object_id=oid, category_id=oid)
|
| 194 |
+
poses = np.full((n, 4, 4), np.nan, np.float32)
|
| 195 |
+
valid = np.zeros(n, bool)
|
| 196 |
+
for i, lab in enumerate(labels):
|
| 197 |
+
if 'pose_y' in lab:
|
| 198 |
+
pose = np.asarray(lab['pose_y'])
|
| 199 |
+
if pose.shape != (len(ycb_ids), 3, 4):
|
| 200 |
+
raise ValueError('pose_y shape differs from ycb_ids')
|
| 201 |
+
if np.any(pose[j]): # Official all-zero missing object pose sentinel.
|
| 202 |
+
poses[i] = np.eye(4)
|
| 203 |
+
poses[i, :3] = pose[j]
|
| 204 |
+
valid[i] = True
|
| 205 |
+
if any('pose_y' in lab for lab in labels):
|
| 206 |
+
view.tensor('pose_' + entity, 'object/rigid/v1', f'annotation/object/{entity}/pose.pt',
|
| 207 |
+
poses, valid, ['T', 'row', 'column'], label_loc,
|
| 208 |
+
convention='T_camera_from_object', unit='m')
|
| 209 |
+
else:
|
| 210 |
+
view.absent('pose_' + entity, 'No source pose_y field')
|
| 211 |
+
if oid in assets:
|
| 212 |
+
mesh_asset(view, entity, assets[oid], assets[oid] / 'textured_simple.obj',
|
| 213 |
+
locator(asset_archive, f'models/{assets[oid].name}/textured_simple.obj'))
|
| 214 |
+
else:
|
| 215 |
+
view.absent('mesh_' + entity, 'models.tar.gz unavailable', 'not_downloaded')
|
| 216 |
+
if any('seg' in lab for lab in labels):
|
| 217 |
+
mask_rows = []
|
| 218 |
+
width, height = view.meta['camera']['image_size']
|
| 219 |
+
for i, lab in enumerate(labels):
|
| 220 |
+
values = np.unique(lab.get('seg', np.zeros((height, width), np.uint8)))
|
| 221 |
+
mappings = []
|
| 222 |
+
for value in values:
|
| 223 |
+
value = int(value)
|
| 224 |
+
if value == 0:
|
| 225 |
+
continue
|
| 226 |
+
if value != 255 and value not in ycb_ids:
|
| 227 |
+
raise ValueError(f'unknown Dex-YCB region value {value}')
|
| 228 |
+
mappings.append(dict(mask_value=value, category_id='hand' if value == 255 else value,
|
| 229 |
+
entity_id='hand_' + side if value == 255 else f'ycb_{value:02d}', part_id=None,
|
| 230 |
+
source_instance_id=value))
|
| 231 |
+
mask_rows.append(dict(frame_index=i, labels=mappings))
|
| 232 |
+
view.raster('segment', (lab.get('seg', np.zeros((height, width), np.uint16)) for lab in labels),
|
| 233 |
+
['seg' in lab for lab in labels], label_loc, mask_rows)
|
| 234 |
+
view.meta['components']['segment'].update(coverage={'kind': 'selected_entities',
|
| 235 |
+
'entities': ['hand_' + side] + [f'ycb_{o:02d}' for o in ycb_ids]}, source_zero_meaning='background')
|
| 236 |
+
else:
|
| 237 |
+
view.absent('segment', 'No source seg field')
|
| 238 |
+
if any('aligned_depth_to_color' in frames[f] for f in ids):
|
| 239 |
+
def depths():
|
| 240 |
+
width, height = view.meta['camera']['image_size']
|
| 241 |
+
for f in ids:
|
| 242 |
+
item = frames[f].get('aligned_depth_to_color')
|
| 243 |
+
if item is None:
|
| 244 |
+
yield np.full((height, width), np.nan, np.float32)
|
| 245 |
+
else:
|
| 246 |
+
with Image.open(item[0]) as im:
|
| 247 |
+
yield np.asarray(im).astype(np.float32) / 1000.0
|
| 248 |
+
view.raster('depth', depths(), None, {'frames_ref': 'camera/frames.jsonl',
|
| 249 |
+
'source_field': 'component_sources.aligned_depth_to_color', 'conversion': 'millimetres to metres'})
|
| 250 |
+
else:
|
| 251 |
+
view.absent('depth', 'No source aligned_depth_to_color frames')
|
| 252 |
+
grasp = meta.get('ycb_grasp_ind')
|
| 253 |
+
if grasp is not None:
|
| 254 |
+
if not 0 <= int(grasp) < len(ycb_ids):
|
| 255 |
+
raise ValueError('invalid ycb_grasp_ind')
|
| 256 |
+
relation = dict(relation_type='grasp', subject_id='hand_' + side,
|
| 257 |
+
object_id=f'ycb_{ycb_ids[int(grasp)]:02d}', status='positive', source_locator=meta_loc,
|
| 258 |
+
provenance={'kind': 'source', 'method': 'sequence ycb_grasp_ind resolved through ycb_ids; not per-frame contact'})
|
| 259 |
+
view.relations([{'frame_index': i, 'relations': [relation]} for i in range(n)], np.ones(n, bool), meta_loc)
|
| 260 |
+
else:
|
| 261 |
+
view.absent('relations', 'No source grasp/contact relation')
|
| 262 |
+
return view.finish()
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
MEMBER = re.compile(r'^([^/]+)/(\d{8}_\d{6})/(meta\.yml|(\d{12})/(color|labels|aligned_depth_to_color)_(\d+)\.(jpg|npz|png))$')
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def convert_archive(archive, args, out, calib, calib_path, models, assets, asset_archive):
|
| 269 |
+
selected_views = set(args.views.split(',')) if args.views else None
|
| 270 |
+
done = 0
|
| 271 |
+
current, meta, meta_loc, rows = None, None, None, {}
|
| 272 |
+
with tempfile.TemporaryDirectory(prefix='dex-source-') as wd:
|
| 273 |
+
work = Path(wd)
|
| 274 |
+
def flush():
|
| 275 |
+
nonlocal done
|
| 276 |
+
if not rows:
|
| 277 |
+
return
|
| 278 |
+
seq = archive.name.split('.tar')[0] + '_' + current
|
| 279 |
+
reports = {}
|
| 280 |
+
with sequence_dir(out, seq) as target:
|
| 281 |
+
for serial, frames in sorted(rows.items()):
|
| 282 |
+
reports[serial] = convert_view(target / serial, args, seq, serial, frames, meta,
|
| 283 |
+
meta_loc, calib, calib_path, models, assets, asset_archive)
|
| 284 |
+
build_record(out, seq, reports)
|
| 285 |
+
for staged in list(work.iterdir()):
|
| 286 |
+
if staged.is_dir():
|
| 287 |
+
shutil.rmtree(staged)
|
| 288 |
+
else:
|
| 289 |
+
staged.unlink()
|
| 290 |
+
done += 1
|
| 291 |
+
print(f'Converted {seq}', flush=True)
|
| 292 |
+
with tarfile.open(archive, 'r|gz') as tf:
|
| 293 |
+
for member in tf:
|
| 294 |
+
match = MEMBER.fullmatch(member.name)
|
| 295 |
+
if not member.isfile() or not match:
|
| 296 |
+
continue
|
| 297 |
+
seq = match[2]
|
| 298 |
+
if seq != current:
|
| 299 |
+
flush()
|
| 300 |
+
if args.limit and done >= args.limit:
|
| 301 |
+
break
|
| 302 |
+
current, meta, meta_loc, rows = seq, None, None, {}
|
| 303 |
+
data_kind = match[3]
|
| 304 |
+
if data_kind == 'meta.yml':
|
| 305 |
+
data = tf.extractfile(member).read()
|
| 306 |
+
meta = yaml_load_bytes(data)
|
| 307 |
+
meta_loc = locator(archive, member.name, data)
|
| 308 |
+
continue
|
| 309 |
+
serial, kind, f = match[4], match[5], int(match[6])
|
| 310 |
+
if selected_views and serial not in selected_views or args.max_frames and f >= args.max_frames:
|
| 311 |
+
continue
|
| 312 |
+
data = tf.extractfile(member).read()
|
| 313 |
+
dest = safe_member(work, member.name)
|
| 314 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 315 |
+
dest.write_bytes(data)
|
| 316 |
+
row = rows.setdefault(serial, {}).setdefault(f, {})
|
| 317 |
+
if kind in row:
|
| 318 |
+
raise ValueError('duplicate archive frame')
|
| 319 |
+
row[kind] = (dest, locator(archive, member.name, data))
|
| 320 |
+
else:
|
| 321 |
+
flush()
|
| 322 |
+
return done
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def main(argv=None):
|
| 326 |
+
p = parser('dex-ycb', __doc__)
|
| 327 |
+
p.add_argument('--subjects')
|
| 328 |
+
args = p.parse_args(argv)
|
| 329 |
+
archives = sorted({a for r in roots(args.root) for a in r.glob('*-subject-*.tar.gz')})
|
| 330 |
+
if args.subjects:
|
| 331 |
+
subjects = {s.strip().zfill(2) for s in args.subjects.split(',')}
|
| 332 |
+
archives = [a for a in archives if re.search(r'subject-(\d+)', a.name)[1] in subjects]
|
| 333 |
+
if not archives:
|
| 334 |
+
p.error('no Dex-YCB subject archives found')
|
| 335 |
+
cp = find_file(args.root, 'calibration.tar.gz') or find_file(args.root, 'calibration')
|
| 336 |
+
if cp is None:
|
| 337 |
+
p.error('calibration source missing')
|
| 338 |
+
calib = Calibration(cp.parent)
|
| 339 |
+
models = mano_models(args.mano_dir)
|
| 340 |
+
out = release(args, 'dex-ycb')
|
| 341 |
+
with tempfile.TemporaryDirectory(prefix='dex-models-') as wd:
|
| 342 |
+
assets, asset_archive = prepare_models(args.root, Path(wd))
|
| 343 |
+
for archive in archives:
|
| 344 |
+
convert_archive(archive, args, out, calib, cp, models, assets, asset_archive)
|
| 345 |
+
return 0
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
if __name__ == '__main__':
|
| 349 |
+
raise SystemExit(main())
|
H2O/shared-v1.0/script/convert_h2o_v1.0.py
ADDED
|
@@ -0,0 +1,678 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""H2O native RGB-D, MANO, joints and objects → CONTRACT.md v1.0 (no rendered masks)."""
|
| 3 |
+
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
| 4 |
+
import io
|
| 5 |
+
import json
|
| 6 |
+
import multiprocessing
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
import shutil
|
| 10 |
+
import tarfile
|
| 11 |
+
import tempfile
|
| 12 |
+
import threading
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
import zipfile
|
| 15 |
+
|
| 16 |
+
# Bound native libraries before loading NumPy/Torch; each worker still uses independent FFmpeg processes.
|
| 17 |
+
for key in ('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS', 'NUMEXPR_NUM_THREADS'):
|
| 18 |
+
os.environ[key] = '1'
|
| 19 |
+
|
| 20 |
+
import numpy as np
|
| 21 |
+
from PIL import Image
|
| 22 |
+
import torch
|
| 23 |
+
|
| 24 |
+
from warehouse_v1_0 import (View, build_record, check_mesh, find_file, locator, mano_models, mesh_asset,
|
| 25 |
+
model_profile, parser, release, roots, safe_member, sequence_dir, sha256)
|
| 26 |
+
|
| 27 |
+
OBJECTS = {1: 'book', 2: 'espresso', 3: 'lotion', 4: 'spray',
|
| 28 |
+
5: 'milk', 6: 'cocoa', 7: 'chips', 8: 'cappuccino'}
|
| 29 |
+
MEMBER = re.compile(r'^(?:h2o_CASA/)?(subject\d+)/([^/]+)/(\d+)/(cam\d)/(.+)$')
|
| 30 |
+
FRAME = re.compile(r'(rgb|depth|cam_pose|hand_pose|hand_pose_mano|obj_pose|obj_pose_rt)/(\d+)\.(png|jpg|txt)$')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def load_splits(root):
|
| 34 |
+
archive = find_file(root, 'label_split.zip')
|
| 35 |
+
result = {}
|
| 36 |
+
if archive is not None:
|
| 37 |
+
with zipfile.ZipFile(archive) as z:
|
| 38 |
+
for split in ('train', 'val', 'test'):
|
| 39 |
+
member = f'label_split/action_{split}.txt'
|
| 40 |
+
for line_no, line in enumerate(z.read(member).decode().splitlines(), 1):
|
| 41 |
+
fields = line.split()
|
| 42 |
+
if len(fields) < 2 or fields[1] == 'path':
|
| 43 |
+
continue
|
| 44 |
+
key = fields[1]
|
| 45 |
+
if key in result and result[key][0] != split:
|
| 46 |
+
raise ValueError('conflicting official splits')
|
| 47 |
+
result[key] = (split, locator(archive, member, record=line_no))
|
| 48 |
+
return result
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def load_assets(root, work):
|
| 52 |
+
archive = find_file(root, 'object.zip')
|
| 53 |
+
if archive is None:
|
| 54 |
+
return {}, None
|
| 55 |
+
with zipfile.ZipFile(archive) as z:
|
| 56 |
+
for member in z.infolist():
|
| 57 |
+
if member.is_dir():
|
| 58 |
+
continue
|
| 59 |
+
path = safe_member(work, member.filename)
|
| 60 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 61 |
+
path.write_bytes(z.read(member))
|
| 62 |
+
result = {}
|
| 63 |
+
for oid, name in OBJECTS.items():
|
| 64 |
+
directory = work / 'object' / name
|
| 65 |
+
aliases = []
|
| 66 |
+
# Source cocoa.obj -> ovomaltine.mtl -> cocoa.png, but the ZIP names the
|
| 67 |
+
# supplied texture ovomaltine.png. Keep all originals and add a byte-identical alias.
|
| 68 |
+
if name == 'cocoa' and not (directory / 'cocoa.png').exists():
|
| 69 |
+
mtl = directory / 'ovomaltine.mtl'
|
| 70 |
+
if mtl.is_file() and 'map_Kd cocoa.png' in mtl.read_text().splitlines():
|
| 71 |
+
texture = directory / 'ovomaltine.png'
|
| 72 |
+
shutil.copyfile(texture, directory / 'cocoa.png')
|
| 73 |
+
aliases.append({'file': 'cocoa.png', 'sha256': sha256(texture),
|
| 74 |
+
'source': locator(archive, 'object/cocoa/ovomaltine.png')})
|
| 75 |
+
candidates = list(directory.glob('*.obj'))
|
| 76 |
+
if len(candidates) != 1:
|
| 77 |
+
raise ValueError(f'expected one source OBJ for {name}')
|
| 78 |
+
check_mesh(candidates[0], directory) # Fail before decoding any large subject archive.
|
| 79 |
+
result[oid] = (directory, candidates[0], aliases)
|
| 80 |
+
return result, archive
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def convert_view(path, args, seq, cam, rows, intr, splits, models, assets, asset_archive):
|
| 84 |
+
codec_threads = getattr(args, 'codec_threads', 1)
|
| 85 |
+
ids = list(range(min(rows), max(rows) + 1))
|
| 86 |
+
for f in ids:
|
| 87 |
+
rows.setdefault(f, {})
|
| 88 |
+
n = len(ids)
|
| 89 |
+
if not n:
|
| 90 |
+
raise ValueError('no RGB frames')
|
| 91 |
+
split, split_loc = splits.get(seq, ('unknown', None))
|
| 92 |
+
frame_rows = [dict(source_frame_id=f, sync_id=f'{seq}:{f}', source_locator=rows[f]['rgb'][1] if 'rgb' in rows[f] else {'sequence': seq, 'camera': cam, 'source_frame_id': f, 'missing_rgb': True},
|
| 93 |
+
component_sources={k: item[1] for k, item in rows[f].items()},
|
| 94 |
+
annotation_matches={k: dict(source_frame_id=f, source_timestamp_ns=None,
|
| 95 |
+
clock_domain=None, match_method='index_map', delta_ns=None)
|
| 96 |
+
for k in rows[f] if k != 'rgb'}) for f in ids]
|
| 97 |
+
view = View(path, 'H2O', args.release_id, seq.replace('/', '_'), cam, frame_rows, split=split)
|
| 98 |
+
view.valid_rules = {
|
| 99 |
+
'mano': 'Per-hand hand_pose_mano flag equals 1; corresponding side model available',
|
| 100 |
+
'keypoints': "Per-hand hand_pose flag equals 1, broadcast to that hand's 21 source points independently of MANO",
|
| 101 |
+
'pose': 'Source obj_pose_rt class equals this nonzero object class',
|
| 102 |
+
'points': 'Source obj_pose class equals this nonzero object class, broadcast to its 21 points',
|
| 103 |
+
}
|
| 104 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 105 |
+
view.meta['view_type'] = 'ego' if cam == 'cam4' else 'exo' if cam in ('cam0', 'cam1', 'cam2', 'cam3') else 'unknown'
|
| 106 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'views': args.views}
|
| 107 |
+
if split_loc:
|
| 108 |
+
view.meta.update(split_scheme='official_action_split', split_source_locator=split_loc)
|
| 109 |
+
# In the measured 275 H2O views, exact FFV1 was always smaller than exact H.264.
|
| 110 |
+
view.rgb([rows[f]['rgb'][0] if 'rgb' in rows[f] else None for f in ids],
|
| 111 |
+
{'frames_ref': 'camera/frames.jsonl'}, ffv1_first=True, codec_threads=codec_threads,
|
| 112 |
+
stream_source=getattr(args, 'stream_media', False))
|
| 113 |
+
loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources'}
|
| 114 |
+
if intr is not None:
|
| 115 |
+
fx, fy, cx, cy, width, height = np.loadtxt(io.BytesIO(intr[0])).ravel()
|
| 116 |
+
if [int(width), int(height)] != view.meta['camera']['image_size']:
|
| 117 |
+
raise ValueError('source intrinsics resolution mismatch')
|
| 118 |
+
K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
|
| 119 |
+
view.camera(K, intr[1])
|
| 120 |
+
camps = np.full((n, 4, 4), np.nan, np.float32)
|
| 121 |
+
cv = np.zeros(n, bool)
|
| 122 |
+
data = []
|
| 123 |
+
for i, f in enumerate(ids):
|
| 124 |
+
lab = {k: np.loadtxt(io.BytesIO(item[0])).ravel() for k, item in rows[f].items() if k not in ('rgb', 'depth')}
|
| 125 |
+
data.append(lab)
|
| 126 |
+
if 'cam_pose' in lab:
|
| 127 |
+
camps[i] = np.linalg.inv(lab['cam_pose'].reshape(4, 4))
|
| 128 |
+
cv[i] = True
|
| 129 |
+
if cv.any():
|
| 130 |
+
view.tensor('extrinsic', 'transform/se3/v1', 'camera/extrinsic.pt', camps, cv,
|
| 131 |
+
['T', 'row', 'column'], loc, convention='T_camera_from_world',
|
| 132 |
+
source_convention='T_world_from_camera')
|
| 133 |
+
motion, mv = np.full((n, 2, 61), np.nan, np.float32), np.zeros((n, 2), bool)
|
| 134 |
+
points, pv = np.full((n, 2, 21, 3), np.nan, np.float32), np.zeros((n, 2, 21), bool)
|
| 135 |
+
object_ids = set()
|
| 136 |
+
for i, lab in enumerate(data):
|
| 137 |
+
if 'hand_pose_mano' in lab:
|
| 138 |
+
hands = lab['hand_pose_mano'].reshape(2, 62)
|
| 139 |
+
for side, row in enumerate(hands):
|
| 140 |
+
if row[0] not in (0, 1):
|
| 141 |
+
raise ValueError('unexpected H2O MANO presence flag')
|
| 142 |
+
if row[0] == 1:
|
| 143 |
+
motion[i, side] = np.r_[row[4:52], row[52:62], row[1:4]]
|
| 144 |
+
mv[i, side] = True
|
| 145 |
+
if 'hand_pose' in lab:
|
| 146 |
+
hands = lab['hand_pose'].reshape(2, 64)
|
| 147 |
+
for side, row in enumerate(hands):
|
| 148 |
+
if row[0] not in (0, 1):
|
| 149 |
+
raise ValueError('unexpected H2O keypoint presence flag')
|
| 150 |
+
if row[0] == 1:
|
| 151 |
+
points[i, side] = row[1:].reshape(21, 3)
|
| 152 |
+
pv[i, side] = True
|
| 153 |
+
for key in ('obj_pose', 'obj_pose_rt'):
|
| 154 |
+
if key in lab and lab[key][0] != 0:
|
| 155 |
+
object_ids.add(int(lab[key][0]))
|
| 156 |
+
if any('hand_pose_mano' in lab for lab in data):
|
| 157 |
+
if len(models) == 2:
|
| 158 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 159 |
+
['T', 'hand', 'parameter'], loc, model_profile=model_profile(models))
|
| 160 |
+
else:
|
| 161 |
+
view.absent('mano', 'Source parameters exist; --mano-dir must identify both model profiles', 'dependency_missing')
|
| 162 |
+
if any('hand_pose' in lab for lab in data):
|
| 163 |
+
view.tensor('keypoints_xyz', 'keypoints/xyz/v1', 'annotation/keypoints/xyz.pt', points, pv,
|
| 164 |
+
['T', 'hand', 'keypoint', 'coordinate'], loc, keypoint_schema='mano21/v1', unit='m')
|
| 165 |
+
for oid in sorted(object_ids):
|
| 166 |
+
if oid not in OBJECTS:
|
| 167 |
+
raise ValueError(f'unknown H2O object class {oid}')
|
| 168 |
+
entity = OBJECTS[oid]
|
| 169 |
+
view.object(entity, loc, category_id=oid, source_object_id=oid)
|
| 170 |
+
poses, ov = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 171 |
+
pts, kv = np.full((n, 21, 3), np.nan, np.float32), np.zeros((n, 21), bool)
|
| 172 |
+
for i, lab in enumerate(data):
|
| 173 |
+
if 'obj_pose_rt' in lab and lab['obj_pose_rt'][0] == oid:
|
| 174 |
+
poses[i] = lab['obj_pose_rt'][1:].reshape(4, 4)
|
| 175 |
+
ov[i] = True
|
| 176 |
+
if 'obj_pose' in lab and lab['obj_pose'][0] == oid:
|
| 177 |
+
pts[i] = lab['obj_pose'][1:].reshape(21, 3)
|
| 178 |
+
kv[i] = True
|
| 179 |
+
if ov.any():
|
| 180 |
+
view.tensor('pose_' + entity, 'object/rigid/v1', f'annotation/object/{entity}/pose.pt',
|
| 181 |
+
poses, ov, ['T', 'row', 'column'], loc, convention='T_camera_from_object', unit='m')
|
| 182 |
+
if kv.any():
|
| 183 |
+
view.tensor('points_' + entity, 'object_keypoints/camera/v1',
|
| 184 |
+
f'annotation/object/{entity}/keypoints/xyz.pt', pts, kv,
|
| 185 |
+
['T', 'keypoint', 'coordinate'], loc, keypoint_schema='H2O_official_object21',
|
| 186 |
+
keypoint_names=['center'] + [f'corner_{i}' for i in range(8)] + [f'edge_midpoint_{i}' for i in range(12)],
|
| 187 |
+
source_order='official obj_point_order.jpg: center, 8 corners, 12 edge midpoints', unit='m')
|
| 188 |
+
if oid in assets:
|
| 189 |
+
directory, obj, aliases = assets[oid]
|
| 190 |
+
asset_loc = locator(asset_archive, f'object/{entity}/{obj.name}')
|
| 191 |
+
if aliases:
|
| 192 |
+
asset_loc['texture_aliases'] = aliases
|
| 193 |
+
mesh_asset(view, entity, directory, obj, asset_loc)
|
| 194 |
+
else:
|
| 195 |
+
view.absent('mesh_' + entity, 'Source object.zip unavailable', 'not_downloaded')
|
| 196 |
+
if any('depth' in rows[f] for f in ids):
|
| 197 |
+
width, height = view.meta['camera']['image_size']
|
| 198 |
+
depth_threads = getattr(args, 'depth_threads', 1)
|
| 199 |
+
def read_depth(f):
|
| 200 |
+
item = rows[f].get('depth')
|
| 201 |
+
if item:
|
| 202 |
+
with Image.open(item[0]) as im:
|
| 203 |
+
return np.asarray(im).astype(np.float32) / 1000.0
|
| 204 |
+
return np.full((height, width), np.nan, np.float32)
|
| 205 |
+
def depths():
|
| 206 |
+
if depth_threads == 1:
|
| 207 |
+
yield from map(read_depth, ids)
|
| 208 |
+
else:
|
| 209 |
+
with ThreadPoolExecutor(max_workers=depth_threads) as pool:
|
| 210 |
+
# Ordered batches bound decoded arrays to depth_threads frames per view.
|
| 211 |
+
for start in range(0, len(ids), depth_threads):
|
| 212 |
+
yield from pool.map(read_depth, ids[start:start + depth_threads])
|
| 213 |
+
view.raster('depth', depths(), None, loc | {'source_field': 'component_sources.depth',
|
| 214 |
+
'definition': 'https://github.com/taeinkwon/h2oplayer/blob/main/utils.py',
|
| 215 |
+
'conversion': 'registered millimetre camera-Z to metres; no viewer range clipping'},
|
| 216 |
+
codec_threads=codec_threads, stream=getattr(args, 'stream_media', False))
|
| 217 |
+
else:
|
| 218 |
+
view.absent('depth', 'No source depth frames')
|
| 219 |
+
view.absent('segment', 'H2O provides no native segmentation; rendering deferred to v2.0')
|
| 220 |
+
view.absent('relations', 'No source contact/grasp annotation')
|
| 221 |
+
return view.finish()
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def convert_archive(archive, args, out, splits, models, assets, asset_archive, view_pool=None, ram_budget=None):
|
| 225 |
+
selected_views = set(args.views.split(',')) if args.views else None
|
| 226 |
+
subjects = {'subject' + s.strip() for s in args.subjects.split(',')} if args.subjects else None
|
| 227 |
+
current, rows, intrinsics, done = None, {}, {}, 0
|
| 228 |
+
published_views = set()
|
| 229 |
+
camera_jobs, closed_cameras = {}, set()
|
| 230 |
+
last_camera = None
|
| 231 |
+
pipeline_active = False
|
| 232 |
+
ram_reserved = 0
|
| 233 |
+
try:
|
| 234 |
+
with tempfile.TemporaryDirectory(prefix='h2o-source-') as wd, \
|
| 235 |
+
tempfile.TemporaryDirectory(prefix='h2o-ram-', dir=args.ram_stage_dir) as rd:
|
| 236 |
+
work, ram_work = Path(wd), Path(rd)
|
| 237 |
+
def queue_camera(cam):
|
| 238 |
+
if cam in closed_cameras:
|
| 239 |
+
return
|
| 240 |
+
closed_cameras.add(cam)
|
| 241 |
+
if cam not in published_views and rows.get(cam):
|
| 242 |
+
camera_jobs[cam] = view_pool.submit(convert_view, work / '.converted' / cam,
|
| 243 |
+
args, '/'.join(current), cam, rows[cam], intrinsics.get(cam),
|
| 244 |
+
splits, models, assets, asset_archive)
|
| 245 |
+
def flush():
|
| 246 |
+
nonlocal done, ram_reserved
|
| 247 |
+
if not rows:
|
| 248 |
+
return
|
| 249 |
+
seq = '/'.join(current)
|
| 250 |
+
reports, pending = {}, {}
|
| 251 |
+
for cam, frames in sorted(rows.items()):
|
| 252 |
+
existing = out / 'data' / seq.replace('/', '_') / cam
|
| 253 |
+
if (existing / 'metainfo.json').is_file():
|
| 254 |
+
old_frames = [json.loads(line) for line in (existing / 'camera/frames.jsonl').read_text().splitlines()]
|
| 255 |
+
if [f['source_frame_id'] for f in old_frames] != list(range(min(frames), max(frames) + 1)):
|
| 256 |
+
raise ValueError('existing view has different sampling; choose a new release-id')
|
| 257 |
+
for frame in old_frames:
|
| 258 |
+
incoming = frames.get(frame['source_frame_id'], {})
|
| 259 |
+
previous = frame.get('component_sources', {})
|
| 260 |
+
if set(previous) != set(incoming) or any(previous[k].get('sha256') != v[1].get('sha256') for k, v in incoming.items()):
|
| 261 |
+
raise ValueError('duplicate H2O view differs from the published source; choose a new release-id')
|
| 262 |
+
else:
|
| 263 |
+
pending[cam] = frames
|
| 264 |
+
if pending:
|
| 265 |
+
if pipeline_active:
|
| 266 |
+
for cam in pending:
|
| 267 |
+
queue_camera(cam)
|
| 268 |
+
failure = None
|
| 269 |
+
for cam, job in camera_jobs.items():
|
| 270 |
+
try:
|
| 271 |
+
reports[cam] = job.result()
|
| 272 |
+
except Exception as exc:
|
| 273 |
+
failure = failure or exc
|
| 274 |
+
if failure is not None:
|
| 275 |
+
raise failure
|
| 276 |
+
with sequence_dir(out, seq.replace('/', '_')) as target:
|
| 277 |
+
if pipeline_active:
|
| 278 |
+
for cam in pending:
|
| 279 |
+
shutil.move(work / '.converted' / cam, target / cam)
|
| 280 |
+
elif view_pool is None:
|
| 281 |
+
for cam, frames in pending.items():
|
| 282 |
+
reports[cam] = convert_view(target / cam, args, seq, cam, frames,
|
| 283 |
+
intrinsics.get(cam), splits, models, assets, asset_archive)
|
| 284 |
+
else:
|
| 285 |
+
jobs = {cam: view_pool.submit(convert_view, target / cam, args, seq, cam,
|
| 286 |
+
frames, intrinsics.get(cam), splits, models, assets, asset_archive)
|
| 287 |
+
for cam, frames in pending.items()}
|
| 288 |
+
failure = None
|
| 289 |
+
# Every sibling must finish before sequence_dir can remove its inputs.
|
| 290 |
+
for cam, job in jobs.items():
|
| 291 |
+
try:
|
| 292 |
+
reports[cam] = job.result()
|
| 293 |
+
except Exception as exc:
|
| 294 |
+
failure = failure or exc
|
| 295 |
+
if failure is not None:
|
| 296 |
+
raise failure
|
| 297 |
+
build_record(out, seq.replace('/', '_'), reports)
|
| 298 |
+
for directory in (work, ram_work):
|
| 299 |
+
for staged in list(directory.iterdir()):
|
| 300 |
+
if staged.is_dir():
|
| 301 |
+
shutil.rmtree(staged)
|
| 302 |
+
else:
|
| 303 |
+
staged.unlink()
|
| 304 |
+
if ram_budget is not None:
|
| 305 |
+
lock, used, limit = ram_budget
|
| 306 |
+
with lock:
|
| 307 |
+
used[0] -= ram_reserved
|
| 308 |
+
ram_reserved = 0
|
| 309 |
+
done += 1
|
| 310 |
+
print(f'{"Converted" if pending else "Verified existing"} {seq}', flush=True)
|
| 311 |
+
# Uncompressed CASA supports seeking over large frames; gzip is single-pass.
|
| 312 |
+
mode = 'r:' if archive.suffix == '.tar' else 'r|gz'
|
| 313 |
+
try:
|
| 314 |
+
with tarfile.open(archive, mode) as tf:
|
| 315 |
+
for member in tf:
|
| 316 |
+
match = MEMBER.fullmatch(member.name)
|
| 317 |
+
if not member.isfile() or not match:
|
| 318 |
+
continue
|
| 319 |
+
subj, scene, seq, cam, tail = match.groups()
|
| 320 |
+
if subjects and subj not in subjects:
|
| 321 |
+
continue
|
| 322 |
+
key = (subj, scene, seq)
|
| 323 |
+
if key != current:
|
| 324 |
+
flush()
|
| 325 |
+
if args.limit and done >= args.limit:
|
| 326 |
+
break
|
| 327 |
+
current, rows, intrinsics = key, {}, {}
|
| 328 |
+
camera_jobs.clear()
|
| 329 |
+
closed_cameras.clear()
|
| 330 |
+
last_camera = None
|
| 331 |
+
pipeline_active = args.camera_pipeline
|
| 332 |
+
published_views = {view.name for view in
|
| 333 |
+
(out / 'data' / '_'.join(key)).glob('cam*')
|
| 334 |
+
if (view / 'metainfo.json').is_file()}
|
| 335 |
+
if selected_views and cam not in selected_views:
|
| 336 |
+
continue
|
| 337 |
+
if pipeline_active and cam != last_camera:
|
| 338 |
+
if last_camera is not None:
|
| 339 |
+
queue_camera(last_camera)
|
| 340 |
+
if cam in closed_cameras:
|
| 341 |
+
# Complete queued readers before accepting late fields for those cameras.
|
| 342 |
+
for job in camera_jobs.values():
|
| 343 |
+
try:
|
| 344 |
+
job.result()
|
| 345 |
+
except Exception:
|
| 346 |
+
pass
|
| 347 |
+
shutil.rmtree(work / '.converted', ignore_errors=True)
|
| 348 |
+
camera_jobs.clear()
|
| 349 |
+
closed_cameras.clear()
|
| 350 |
+
pipeline_active = False
|
| 351 |
+
print(f'Camera-order fallback: {"/".join(current)}', flush=True)
|
| 352 |
+
last_camera = cam
|
| 353 |
+
frame = FRAME.fullmatch(tail)
|
| 354 |
+
if tail != 'cam_intrinsics.txt' and not frame:
|
| 355 |
+
continue
|
| 356 |
+
if frame and args.max_frames and int(frame[2]) >= args.max_frames:
|
| 357 |
+
continue
|
| 358 |
+
data = tf.extractfile(member).read()
|
| 359 |
+
if tail.endswith('.txt'):
|
| 360 |
+
payload = data # Small source annotations stay in RAM, not thousands of HDD files.
|
| 361 |
+
else:
|
| 362 |
+
staging = work
|
| 363 |
+
if ram_budget is not None and cam not in published_views:
|
| 364 |
+
lock, used, limit = ram_budget
|
| 365 |
+
needed = (len(data) + 4095) // 4096 * 4096
|
| 366 |
+
with lock:
|
| 367 |
+
if used[0] + needed <= limit:
|
| 368 |
+
used[0] += needed
|
| 369 |
+
ram_reserved += needed
|
| 370 |
+
staging = ram_work
|
| 371 |
+
payload = safe_member(staging, member.name)
|
| 372 |
+
if cam not in published_views:
|
| 373 |
+
payload.parent.mkdir(parents=True, exist_ok=True)
|
| 374 |
+
payload.write_bytes(data)
|
| 375 |
+
# Published views still verify source bytes, but never read their staging paths.
|
| 376 |
+
item = (payload, locator(archive, member.name, data))
|
| 377 |
+
if tail == 'cam_intrinsics.txt':
|
| 378 |
+
intrinsics[cam] = item
|
| 379 |
+
else:
|
| 380 |
+
kind, f = frame[1], int(frame[2])
|
| 381 |
+
row = rows.setdefault(cam, {}).setdefault(f, {})
|
| 382 |
+
if kind in row:
|
| 383 |
+
raise ValueError('duplicate H2O frame')
|
| 384 |
+
row[kind] = item
|
| 385 |
+
else:
|
| 386 |
+
flush()
|
| 387 |
+
finally:
|
| 388 |
+
# Never delete staging while a closed-camera job can still read from it.
|
| 389 |
+
for job in camera_jobs.values():
|
| 390 |
+
try:
|
| 391 |
+
job.result()
|
| 392 |
+
except Exception:
|
| 393 |
+
pass
|
| 394 |
+
finally:
|
| 395 |
+
if ram_budget is not None:
|
| 396 |
+
lock, used, limit = ram_budget
|
| 397 |
+
with lock:
|
| 398 |
+
used[0] -= ram_reserved
|
| 399 |
+
return done
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
def main(argv=None):
|
| 403 |
+
p = parser('H2O', __doc__)
|
| 404 |
+
p.set_defaults(release_id='shared-v1.0')
|
| 405 |
+
p.add_argument('--workers', type=int, choices=range(1, 5), default=1,
|
| 406 |
+
help='Independent subject archives in parallel, 1..4; benchmark before using >2')
|
| 407 |
+
p.add_argument('--view-backend', choices=('threads', 'processes'), default='threads',
|
| 408 |
+
help='Use spawn processes to isolate Python camera processing')
|
| 409 |
+
p.add_argument('--camera-pipeline', action='store_true',
|
| 410 |
+
help='Overlap contiguous-camera extraction and conversion; reject interleaved input')
|
| 411 |
+
p.add_argument('--ffv1-slices', type=int, choices=(16,),
|
| 412 |
+
help='Optional FFV1 v3 slice parallelism; decoded frames must still match exactly')
|
| 413 |
+
p.add_argument('--view-workers', type=int, choices=range(1, 17), default=1,
|
| 414 |
+
help='Shared camera-view conversion pool, independent of archive readers')
|
| 415 |
+
p.add_argument('--ram-stage-dir', type=Path, help='Optional tmpfs staging; excess PNGs fall back to disk')
|
| 416 |
+
p.add_argument('--ram-stage-gib', type=int, choices=range(1, 65), default=32,
|
| 417 |
+
help='Shared PNG tmpfs quota across all archive readers, not per worker')
|
| 418 |
+
p.add_argument('--stream-media', action='store_true',
|
| 419 |
+
help='Pipe RGB/depth frames to FFmpeg instead of spooling huge RAW files')
|
| 420 |
+
p.add_argument('--codec-threads', type=int, choices=(1, 2, 4, 8, 10), default=4,
|
| 421 |
+
help='FFV1 slice threads per encode; default 4, use 10 for the current full run')
|
| 422 |
+
p.add_argument('--decode-threads', type=int, choices=(1, 2, 4, 8, 10), default=1,
|
| 423 |
+
help='FFmpeg threads for source RGB decoding and decoded-media checks')
|
| 424 |
+
p.add_argument('--depth-threads', type=int, choices=(1, 2, 4), default=1,
|
| 425 |
+
help='Bounded ordered source depth PNG loading per worker')
|
| 426 |
+
p.add_argument('--subjects')
|
| 427 |
+
p.add_argument('--include-casa', action='store_true')
|
| 428 |
+
p.add_argument('--archive', type=Path, help='Convert one explicit source archive')
|
| 429 |
+
args = p.parse_args(argv)
|
| 430 |
+
if args.camera_pipeline and args.view_workers < 2:
|
| 431 |
+
p.error('--camera-pipeline requires at least two --view-workers')
|
| 432 |
+
os.environ['HAND_WAREHOUSE_FFMPEG_THREADS'] = str(args.decode_threads)
|
| 433 |
+
if args.ffv1_slices is None:
|
| 434 |
+
os.environ.pop('HAND_WAREHOUSE_FFV1_SLICES', None)
|
| 435 |
+
else:
|
| 436 |
+
os.environ['HAND_WAREHOUSE_FFV1_SLICES'] = str(args.ffv1_slices)
|
| 437 |
+
if args.include_casa and args.workers != 1:
|
| 438 |
+
p.error('CASA can share sequence IDs with subject archives; convert it sequentially in a separate release')
|
| 439 |
+
archives = [args.archive.expanduser()] if args.archive else sorted(
|
| 440 |
+
{a for root in roots(args.root) for a in root.glob('subject*_v1_1.tar.gz')})
|
| 441 |
+
if args.subjects and not args.archive:
|
| 442 |
+
requested = {'subject' + s.strip() for s in args.subjects.split(',')}
|
| 443 |
+
archives = [arc for arc in archives if arc.name.split('_', 1)[0] in requested]
|
| 444 |
+
if args.include_casa:
|
| 445 |
+
casa = find_file(args.root, 'h2o_CASA.tar')
|
| 446 |
+
if casa:
|
| 447 |
+
archives.append(casa)
|
| 448 |
+
if not archives:
|
| 449 |
+
p.error('no H2O archives found')
|
| 450 |
+
out = release(args, 'H2O')
|
| 451 |
+
source_mapping = next(p for p in (Path(__file__).resolve().parents[1] / 'docs/h2o-RAW_TO_SHARED.md',
|
| 452 |
+
Path(__file__).resolve().parents[1] / 'doc/RAW_TO_SHARED.md',
|
| 453 |
+
out / 'doc/RAW_TO_SHARED.md') if p.is_file())
|
| 454 |
+
mapping = out / 'doc/RAW_TO_SHARED.md'
|
| 455 |
+
if mapping.exists() and mapping.read_bytes() != source_mapping.read_bytes():
|
| 456 |
+
raise ValueError('RAW_TO_SHARED.md changed; choose a new release-id')
|
| 457 |
+
if not mapping.exists():
|
| 458 |
+
shutil.copyfile(source_mapping, mapping)
|
| 459 |
+
os.environ.pop('HAND_WAREHOUSE_MEDIA_TMPDIR', None)
|
| 460 |
+
ram_budget = None
|
| 461 |
+
if args.ram_stage_dir is not None:
|
| 462 |
+
args.ram_stage_dir = args.ram_stage_dir.expanduser().resolve()
|
| 463 |
+
if not args.ram_stage_dir.is_relative_to(Path('/dev/shm').resolve()):
|
| 464 |
+
p.error('--ram-stage-dir must be on /dev/shm; it is temporary input, not an output dataset')
|
| 465 |
+
args.ram_stage_dir.mkdir(parents=True, exist_ok=True)
|
| 466 |
+
limit = args.ram_stage_gib * 1024**3
|
| 467 |
+
if shutil.disk_usage(args.ram_stage_dir).free < limit + 8 * 1024**3:
|
| 468 |
+
p.error('not enough tmpfs headroom for the requested shared staging quota')
|
| 469 |
+
ram_budget = (threading.Lock(), [0], limit)
|
| 470 |
+
if args.stream_media:
|
| 471 |
+
os.environ['HAND_WAREHOUSE_MEDIA_TMPDIR'] = str(args.ram_stage_dir)
|
| 472 |
+
torch.set_num_threads(1)
|
| 473 |
+
models, splits = mano_models(args.mano_dir), load_splits(args.root)
|
| 474 |
+
executor = ProcessPoolExecutor if args.view_backend == 'processes' else ThreadPoolExecutor
|
| 475 |
+
options = {'mp_context': multiprocessing.get_context('spawn')} if args.view_backend == 'processes' else {'thread_name_prefix': 'h2o-view'}
|
| 476 |
+
with tempfile.TemporaryDirectory(prefix='h2o-assets-') as wd, \
|
| 477 |
+
executor(max_workers=args.view_workers, **options) as views:
|
| 478 |
+
assets, asset_archive = load_assets(args.root, Path(wd))
|
| 479 |
+
def convert_one(archive):
|
| 480 |
+
return convert_archive(archive, args, out, splits, models, assets, asset_archive,
|
| 481 |
+
views if args.view_workers > 1 else None, ram_budget)
|
| 482 |
+
if args.workers == 1:
|
| 483 |
+
for archive in archives:
|
| 484 |
+
convert_one(archive)
|
| 485 |
+
else:
|
| 486 |
+
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 487 |
+
for archive, count in zip(archives, pool.map(convert_one, archives), strict=True):
|
| 488 |
+
print(f'Archive {archive.name}: {count} sequences', flush=True)
|
| 489 |
+
return 0
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
if __name__ == '__main__':
|
| 493 |
+
raise SystemExit(main())
|
| 494 |
+
|
| 495 |
+
# TODO(v2.0): 以下旧 MANO 网格和渲染分割代码仅保留备查;v1.0 不生成标注。
|
| 496 |
+
# def load_mano_model(path: Path):
|
| 497 |
+
# """MPI MANO pkl → numpy 字典。shapedirs 在 pkl 内为 chumpy Select(对 (778,3,20) 基
|
| 498 |
+
# 底 flat 选取前 10 个 shape 分量;idxs 已核实等价于 base[:,:,:10])。"""
|
| 499 |
+
# with open(path, "rb") as f:
|
| 500 |
+
# d = _ManoUnpickler(f, encoding="latin1").load()
|
| 501 |
+
# sd = d["shapedirs"]
|
| 502 |
+
# base = np.asarray(sd.a.x, np.float64) # (778, 3, 20)
|
| 503 |
+
# shapedirs = base.reshape(-1)[np.asarray(sd.idxs)].reshape(base.shape[0], 3, -1)
|
| 504 |
+
# jreg = d["J_regressor"]
|
| 505 |
+
# jreg = np.asarray(jreg.todense()) if hasattr(jreg, "todense") else np.asarray(jreg)
|
| 506 |
+
# return {"v_template": np.asarray(d["v_template"], np.float64),
|
| 507 |
+
# "shapedirs": shapedirs,
|
| 508 |
+
# "posedirs": np.asarray(d["posedirs"], np.float64),
|
| 509 |
+
# "weights": np.asarray(d["weights"], np.float64),
|
| 510 |
+
# "J_regressor": np.asarray(jreg, np.float64),
|
| 511 |
+
# "kintree": np.asarray(d["kintree_table"], np.int64),
|
| 512 |
+
# "faces": np.asarray(d["f"], np.int64)}
|
| 513 |
+
#
|
| 514 |
+
#
|
| 515 |
+
# def rodrigues(r):
|
| 516 |
+
# """axis-angle (N,3) → 旋转矩阵 (N,3,3)。公式 I + sinθ·K + (1−cosθ)·K²(已对 scipy 核验)。"""
|
| 517 |
+
# r = np.asarray(r, np.float64).reshape(-1, 3)
|
| 518 |
+
# th = np.linalg.norm(r, axis=1)
|
| 519 |
+
# R = np.zeros((len(r), 3, 3))
|
| 520 |
+
# nz = th > 1e-12
|
| 521 |
+
# R[~nz] = np.eye(3)
|
| 522 |
+
# k = r[nz] / th[nz, None]
|
| 523 |
+
# K = np.zeros((len(k), 3, 3))
|
| 524 |
+
# K[:, 0, 1], K[:, 0, 2], K[:, 1, 2] = -k[:, 2], k[:, 1], -k[:, 0]
|
| 525 |
+
# K[:, 1, 0], K[:, 2, 0], K[:, 2, 1] = k[:, 2], -k[:, 1], k[:, 0]
|
| 526 |
+
# s, c = np.sin(th[nz])[:, None, None], np.cos(th[nz])[:, None, None]
|
| 527 |
+
# R[nz] = np.eye(3) + s * K + (1 - c) * (K @ K)
|
| 528 |
+
# return R
|
| 529 |
+
#
|
| 530 |
+
#
|
| 531 |
+
# def _mano_chain(model, betas, pose):
|
| 532 |
+
# """返回 (v_shaped, J, Rs, G):G 为 16 个关节的全局变换(平移列 = 关节位置)。"""
|
| 533 |
+
# v = model["v_template"] + np.einsum("nkc,c->nk", model["shapedirs"], betas)
|
| 534 |
+
# J = model["J_regressor"] @ v
|
| 535 |
+
# Rs = rodrigues(np.asarray(pose, np.float64).reshape(16, 3))
|
| 536 |
+
# kt = model["kintree"]
|
| 537 |
+
# G = np.zeros((16, 4, 4))
|
| 538 |
+
# for j in range(16):
|
| 539 |
+
# p = kt[0, j] if j else -1
|
| 540 |
+
# loc = np.eye(4)
|
| 541 |
+
# loc[:3, :3] = Rs[j]
|
| 542 |
+
# loc[:3, 3] = J[j] - (J[p] if j else 0.0)
|
| 543 |
+
# G[j] = loc if not j else G[p] @ loc
|
| 544 |
+
# return v, J, Rs, G
|
| 545 |
+
#
|
| 546 |
+
#
|
| 547 |
+
# def mano_forward(model, betas, pose, transl):
|
| 548 |
+
# """MANO LBS 前向(经典蒙皮 M_j = G_j·G0_j⁻¹;对 hand_pose 21 关节实证 0.0 mm)。
|
| 549 |
+
# pose: 48 axis-angle([0:3] 全局);返回相机系米顶点 (778,3)。"""
|
| 550 |
+
# v, J, Rs, G = _mano_chain(model, betas, pose)
|
| 551 |
+
# lrot = (Rs[1:] - np.eye(3)).ravel()
|
| 552 |
+
# v_posed = v + np.einsum("nkc,c->nk", model["posedirs"], lrot)
|
| 553 |
+
# kt = model["kintree"]
|
| 554 |
+
# G0 = np.zeros((16, 4, 4))
|
| 555 |
+
# for j in range(16):
|
| 556 |
+
# p = kt[0, j] if j else -1
|
| 557 |
+
# loc = np.eye(4)
|
| 558 |
+
# loc[:3, 3] = J[j] - (J[p] if j else 0.0)
|
| 559 |
+
# G0[j] = loc if not j else G0[p] @ loc
|
| 560 |
+
# M = np.einsum("nj,jab->nab", model["weights"], G @ np.linalg.inv(G0))
|
| 561 |
+
# out = np.einsum("nab,nb->na", M[:, :3, :3], v_posed) + M[:, :3, 3]
|
| 562 |
+
# return out + np.asarray(transl, np.float64)
|
| 563 |
+
#
|
| 564 |
+
#
|
| 565 |
+
# def mano_chain_joints(model, betas, pose, transl):
|
| 566 |
+
# """16 个关节位置(相机系米)= 链平移列;自检用。"""
|
| 567 |
+
# _, _, _, G = _mano_chain(model, betas, pose)
|
| 568 |
+
# return G[:, :3, 3] + np.asarray(transl, np.float64)
|
| 569 |
+
#
|
| 570 |
+
#
|
| 571 |
+
# def rasterize(verts_cam, faces, labels, W, H, fx, fy, cx, cy):
|
| 572 |
+
# z = verts_cam[:, 2]
|
| 573 |
+
# P = faces
|
| 574 |
+
# ok = (z[P] > 0.02).all(1) # 任一顶点在相机后 → 丢弃该三角形
|
| 575 |
+
# P, labels = P[ok], labels[ok]
|
| 576 |
+
# if len(P) == 0:
|
| 577 |
+
# return np.zeros((H, W), np.uint16), np.zeros(0, np.int64)
|
| 578 |
+
# x = verts_cam[:, 0] / z * fx + cx
|
| 579 |
+
# y = verts_cam[:, 1] / z * fy + cy
|
| 580 |
+
# xa = np.maximum(0, np.minimum(np.floor(x[P[:, 0]]), np.minimum(
|
| 581 |
+
# np.floor(x[P[:, 1]]), np.floor(x[P[:, 2]]))).astype(np.int64))
|
| 582 |
+
# xb = np.minimum(W - 1, np.maximum(np.ceil(x[P[:, 0]]), np.maximum(
|
| 583 |
+
# np.ceil(x[P[:, 1]]), np.ceil(x[P[:, 2]]))).astype(np.int64))
|
| 584 |
+
# ya = np.maximum(0, np.minimum(np.floor(y[P[:, 0]]), np.minimum(
|
| 585 |
+
# np.floor(y[P[:, 1]]), np.floor(y[P[:, 2]]))).astype(np.int64))
|
| 586 |
+
# yb = np.minimum(H - 1, np.maximum(np.ceil(y[P[:, 0]]), np.maximum(
|
| 587 |
+
# np.ceil(y[P[:, 1]]), np.ceil(y[P[:, 2]]))).astype(np.int64))
|
| 588 |
+
# xa, ya = np.minimum(xa, xb), np.minimum(ya, yb) # 完全出画的三角形 → 空 bbox
|
| 589 |
+
# wdt, hgt = xb - xa + 1, yb - ya + 1
|
| 590 |
+
# cnt = wdt * hgt
|
| 591 |
+
# tot = int(cnt.sum())
|
| 592 |
+
# tri = np.repeat(np.arange(len(P)), cnt)
|
| 593 |
+
# k = np.arange(tot) - (np.cumsum(cnt) - cnt)[tri]
|
| 594 |
+
# px = xa[tri] + k % wdt[tri] + 0.5
|
| 595 |
+
# py = ya[tri] + k // wdt[tri] + 0.5
|
| 596 |
+
# ax, ay = x[P[tri, 0]], y[P[tri, 0]]
|
| 597 |
+
# bx, by = x[P[tri, 1]], y[P[tri, 1]]
|
| 598 |
+
# cx_, cy_ = x[P[tri, 2]], y[P[tri, 2]]
|
| 599 |
+
# area = ((x[P[:, 1]] - x[P[:, 0]]) * (y[P[:, 2]] - y[P[:, 0]])
|
| 600 |
+
# - (y[P[:, 1]] - y[P[:, 0]]) * (x[P[:, 2]] - x[P[:, 0]]))
|
| 601 |
+
# areat = area[tri]
|
| 602 |
+
# e0 = (bx - ax) * (py - ay) - (by - ay) * (px - ax)
|
| 603 |
+
# e1 = (cx_ - bx) * (py - by) - (cy_ - by) * (px - bx)
|
| 604 |
+
# e2 = (ax - cx_) * (py - cy_) - (ay - cy_) * (px - cx_)
|
| 605 |
+
# s = np.sign(areat)
|
| 606 |
+
# inside = (np.abs(areat) > 1e-9) & ((e0 * s >= 0) & (e1 * s >= 0) & (e2 * s >= 0))
|
| 607 |
+
# px, py, tri = px[inside], py[inside], tri[inside]
|
| 608 |
+
# at = areat[inside]
|
| 609 |
+
# w0, w1, w2 = e1[inside] / at, e2[inside] / at, e0[inside] / at
|
| 610 |
+
# zz = w0 * z[P[tri, 0]] + w1 * z[P[tri, 1]] + w2 * z[P[tri, 2]]
|
| 611 |
+
# pix = py.astype(np.int64) * W + px.astype(np.int64)
|
| 612 |
+
# order = np.lexsort((zz, pix)) # 同像素按深度升序 → 首条即最近
|
| 613 |
+
# pix, tri = pix[order], tri[order]
|
| 614 |
+
# first = np.unique(pix, return_index=True)[1]
|
| 615 |
+
# mask = np.zeros(H * W, np.uint16)
|
| 616 |
+
# win = tri[first]
|
| 617 |
+
# mask[pix[first]] = labels[win] + 1 # 临时标签 +1(0=背景)
|
| 618 |
+
# return mask.reshape(H, W), np.bincount(labels[win] + 1)
|
| 619 |
+
#
|
| 620 |
+
#
|
| 621 |
+
# # ============================================================================
|
| 622 |
+
# # ffmpeg 写出与核验(与 convert_dexycb.py 同构)
|
| 623 |
+
# # ============================================================================
|
| 624 |
+
# verts, faces_all, labels = [], [], []
|
| 625 |
+
# for ti, (tid, kind) in enumerate(tracks):
|
| 626 |
+
# if kind == "hand_left" and b["mano"][0] > 0.5:
|
| 627 |
+
# verts.append(mano_forward(mano_models["left"], b["mano"][52:62],
|
| 628 |
+
# b["mano"][4:52], b["mano"][1:4]))
|
| 629 |
+
# faces_all.append(mano_models["left"]["faces"])
|
| 630 |
+
# elif kind == "hand_right" and b["mano"][62] > 0.5:
|
| 631 |
+
# verts.append(mano_forward(mano_models["right"], b["mano"][114:124],
|
| 632 |
+
# b["mano"][66:114], b["mano"][63:66]))
|
| 633 |
+
# faces_all.append(mano_models["right"]["faces"])
|
| 634 |
+
# elif isinstance(kind, tuple) and int(b["objp"][0]) == kind[1]:
|
| 635 |
+
# M = np.asarray(b["objrt"][1:17], np.float64).reshape(4, 4)
|
| 636 |
+
# V0, F0 = meshes[kind[1]]
|
| 637 |
+
# verts.append(V0 @ M[:3, :3].T + M[:3, 3])
|
| 638 |
+
# faces_all.append(F0)
|
| 639 |
+
# else:
|
| 640 |
+
# continue
|
| 641 |
+
# labels.append(np.full(len(faces_all[-1]), ti))
|
| 642 |
+
# if verts:
|
| 643 |
+
# V = np.concatenate(verts)
|
| 644 |
+
# offs = np.cumsum([0] + [len(v) for v in verts[:-1]])
|
| 645 |
+
# F = np.concatenate([fa + o for fa, o in zip(faces_all, offs)])
|
| 646 |
+
# mask, counts = rasterize(V, F, np.concatenate(labels),
|
| 647 |
+
# IMG_W, IMG_H, fx, fy, cx, cy)
|
| 648 |
+
# else:
|
| 649 |
+
# mask, counts = np.zeros((IMG_H, IMG_W), np.uint16), np.zeros(0, np.int64)
|
| 650 |
+
# lut = np.zeros(n_tracks + 1, np.uint16)
|
| 651 |
+
# for ti in range(n_tracks):
|
| 652 |
+
# present = ti + 1 < len(counts) and counts[ti + 1] > 0
|
| 653 |
+
# if present:
|
| 654 |
+
# presence[tracks[ti][0]][f] = True
|
| 655 |
+
# if active_id[ti] is None:
|
| 656 |
+
# pid = next(i for i in range(1, 65535) if i not in used)
|
| 657 |
+
# used.add(pid)
|
| 658 |
+
# active_id[ti], seg_start[ti] = pid, f
|
| 659 |
+
# frame_maps[ti].append({"id": pid})
|
| 660 |
+
# lut[ti + 1] = active_id[ti]
|
| 661 |
+
# elif active_id[ti] is not None:
|
| 662 |
+
# frame_maps[ti][-1]["frames"] = [seg_start[ti], f - 1]
|
| 663 |
+
# segments[ti].append([seg_start[ti], f - 1])
|
| 664 |
+
# used.discard(active_id[ti])
|
| 665 |
+
# active_id[ti] = None
|
| 666 |
+
# mw.write(lut[mask])
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
# TODO(v2.0): 旧物体尺寸派生代码;v1.0 仅保留源物体关键点。
|
| 670 |
+
# pts = np.asarray(b["objp"][1:64], np.float64).reshape(21, 3)
|
| 671 |
+
# half = np.abs((pts[1:9] - pts[0]) @ M[:3, :3]).max(0)
|
| 672 |
+
# obj_recs.append({
|
| 673 |
+
# "track_id": f"o{classes.index(c)}", "frame": f,
|
| 674 |
+
# "mesh_ref": f"h2o/{OBJ_CLASSES[c]}.obj",
|
| 675 |
+
# "pose": {"quat": rotmat_to_quat_wxyz(M[:3, :3])[0].tolist(),
|
| 676 |
+
# "trans": M[:3, 3].tolist()},
|
| 677 |
+
# "bbox_center3d": pts[0].tolist(),
|
| 678 |
+
# "bbox_size": (2 * half).tolist()})
|
H2O/shared-v1.0/script/convert_hoi4d_v1.0.py
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""HOI4D native observations and annotations → CONTRACT.md v1.0."""
|
| 3 |
+
from collections import Counter
|
| 4 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 5 |
+
from contextlib import ExitStack
|
| 6 |
+
from functools import lru_cache
|
| 7 |
+
import gzip
|
| 8 |
+
import io
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
import pickle
|
| 13 |
+
import re
|
| 14 |
+
import shutil
|
| 15 |
+
import shlex
|
| 16 |
+
import posixpath
|
| 17 |
+
import subprocess
|
| 18 |
+
import tempfile
|
| 19 |
+
import tarfile
|
| 20 |
+
import threading
|
| 21 |
+
import zipfile
|
| 22 |
+
|
| 23 |
+
# Each worker owns one Python thread; prevent native libraries spawning CPU pools.
|
| 24 |
+
for key in ('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS', 'NUMEXPR_NUM_THREADS'):
|
| 25 |
+
os.environ[key] = '1'
|
| 26 |
+
|
| 27 |
+
import numpy as np
|
| 28 |
+
from PIL import Image
|
| 29 |
+
from scipy.spatial.transform import Rotation
|
| 30 |
+
|
| 31 |
+
import torch
|
| 32 |
+
|
| 33 |
+
from warehouse_v1_0 import (View, build_record, check_mesh, decode_args, find_file, json_write, locator,
|
| 34 |
+
mano_models, model_profile, parser, probe, release, run, safe_member, sequence_dir)
|
| 35 |
+
|
| 36 |
+
CATEGORIES = {
|
| 37 |
+
1: dict(cad="rigid/ToyCar", groups=[("main", [1], "Toy Car", 1)],
|
| 38 |
+
hands={2: "right"}, objmap={"Toycar": "main"}),
|
| 39 |
+
2: dict(cad="rigid/Mug", groups=[("a", [1], "Mug", 2), ("b", [3], "Mug", 2)],
|
| 40 |
+
hands={2: "right"}, objmap={"Watercup": "a"}),
|
| 41 |
+
3: dict(cad="articulated/Laptop", groups=[("main", [1, 3], "Laptop", 3)],
|
| 42 |
+
hands={2: "right"},
|
| 43 |
+
objmap={"Laptopdisplay": "main", "Laptopkeyboard": "main"}),
|
| 44 |
+
4: dict(cad="articulated/StorageFurniture",
|
| 45 |
+
groups=[("main", [1, 3, 4], "Storage Furniture", 4),
|
| 46 |
+
("bottle", [5], "Bottle", 5)],
|
| 47 |
+
hands={2: "right"},
|
| 48 |
+
objmap={"Lockerbody": "main", "Lockersldingdoor": "main",
|
| 49 |
+
"Lockerdrawer": "main", "Safebox": "main"}),
|
| 50 |
+
5: dict(cad="rigid/Bottle", groups=[("main", [1], "Bottle", 5),
|
| 51 |
+
("mug", [3], "Mug", 2)],
|
| 52 |
+
hands={2: "right"}, objmap={"bottleddrinks": "main"}),
|
| 53 |
+
6: dict(cad="articulated/Safe", groups=[("main", [1, 3], "Safe", 6),
|
| 54 |
+
("bottle", [4], "Bottle", 5)],
|
| 55 |
+
hands={2: "right"}, objmap={"Safebox": "main", "Safedoor": "main"}),
|
| 56 |
+
7: dict(cad="rigid/Bowl", groups=[("main", [1], "Bowl", 7),
|
| 57 |
+
("ball", [3], "Ball", None)],
|
| 58 |
+
hands={2: "right"}, objmap={"bowl": "main"}),
|
| 59 |
+
8: dict(cad="articulated/Bucket",
|
| 60 |
+
groups=[("a", [1, 3], "Bucket", 8), ("b", [4, 5], "Bucket", 8)],
|
| 61 |
+
hands={2: "right", 6: "left"},
|
| 62 |
+
objmap={"bucket": "a", "Buckethandle": "a"}),
|
| 63 |
+
9: dict(cad="articulated/Scissors", groups=[("main", [1, 3], "Scissors", 9)],
|
| 64 |
+
hands={2: "right"},
|
| 65 |
+
objmap={"scissors": "main", "scissors2": None}), # scissors2:场景道具,无掩码
|
| 66 |
+
11: dict(cad="articulated/Pliers", groups=[("main", [1, 3], "Pliers", 11)],
|
| 67 |
+
hands={2: "right"}, objmap={"Pliersleft": "main", "Pliersright": "main"}),
|
| 68 |
+
12: dict(cad="rigid/Kettle", groups=[("main", [1], "Kettle", 12),
|
| 69 |
+
("mug", [3], "Mug", 2)],
|
| 70 |
+
hands={2: "right"}, objmap={"kettle": "main"}),
|
| 71 |
+
13: dict(cad="rigid/Knife", groups=[("main", [1], "Knife", 13),
|
| 72 |
+
("apple", [3], "Apple", None)],
|
| 73 |
+
hands={2: "right"}, objmap={"knife": "main"}),
|
| 74 |
+
14: dict(cad="articulated/TrashCan",
|
| 75 |
+
groups=[("main", [1, 3], "Trash Can", 14), ("bottle", [4], "Bottle", 5)],
|
| 76 |
+
hands={2: "right"}, objmap={"Dustbinbase": "main", "Dustbincover": "main"}),
|
| 77 |
+
17: dict(cad="articulated/Lamp", groups=[("main", [1, 3, 4, 5], "Lamp", 17)],
|
| 78 |
+
hands={2: "right", 6: "left"},
|
| 79 |
+
objmap={"Lampbase": "main", "Tablelampfirstjoint": "main",
|
| 80 |
+
"Tablelampsecondjoint": "main", "Thirdjointoftablelamp": "main"}),
|
| 81 |
+
18: dict(cad="articulated/Stapler",
|
| 82 |
+
groups=[("main", [1, 3, 4], "Stapler", 18), ("paper", [5], "Paper", None)],
|
| 83 |
+
hands={2: "right", 6: "left"}, # 6=左手:官方 label.csv 缺列,实测修正
|
| 84 |
+
objmap={"Staplerbase": "main", "Staplercover": "main"}),
|
| 85 |
+
20: dict(cad="rigid/Chair", groups=[("main", [1], "Chair", 20)],
|
| 86 |
+
hands={2: "right", 3: "left"}, objmap={"chair": "main"}),
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
# Official HOI4D definitions/motion segmentation/label.csv; no spatial side inference.
|
| 91 |
+
REGION_NAMES = {1: {1: 'Toy Car', 2: 'Right Hand'}, 2: {1: 'Mug', 2: 'Right Hand', 3: 'Mug'}, 3: {1: 'Screen', 2: 'Right Hand', 3: 'Keyboard'}, 4: {1: 'Door', 2: 'Right Hand', 3: 'Body of the Cabinet', 4: 'Drawer', 5: 'Bottle'}, 5: {1: 'Bottle', 2: 'Right Hand', 3: 'Mug'}, 6: {1: 'Body of the Safe', 2: 'Right Hand', 3: 'Door', 4: 'Bottle'}, 7: {1: 'Bowl', 2: 'Right Hand', 3: 'Ball'}, 8: {1: 'Body of the Bucket', 2: 'Right Hand', 3: 'Handle', 4: 'Body of the Bucket', 5: 'Handle', 6: 'Left Hand'}, 9: {1: 'Left Part of the Scissors', 2: 'Right Hand', 3: 'Right Part of the Scissors'}, 11: {1: 'Left Part of the Pliers', 2: 'Right Hand', 3: 'Right Part of the Pliers'}, 12: {1: 'Kettle', 2: 'Right Hand', 3: 'Mug'}, 13: {1: 'Knife', 2: 'Right Hand', 3: 'Apple'}, 14: {1: 'Body of the Trash Can', 2: 'Right Hand', 3: 'Lid', 4: 'Bottle'}, 17: {1: 'Base', 2: 'Right Hand', 3: 'Tube', 4: 'Top Link', 5: 'Bottom Link', 6: 'Left Hand'}, 18: {1: 'Base', 2: 'Right Hand', 3: 'Slot', 4: 'Lid', 5: 'Paper'}, 20: {1: 'Chair', 2: 'Right Hand', 3: 'Left Hand'}}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class SplitFiles(io.RawIOBase):
|
| 95 |
+
"""Read concatenated source gzip parts without concatenating 119 GB on disk."""
|
| 96 |
+
def __init__(self, paths):
|
| 97 |
+
self.paths = iter(paths)
|
| 98 |
+
self.current = None
|
| 99 |
+
|
| 100 |
+
def readable(self):
|
| 101 |
+
return True
|
| 102 |
+
|
| 103 |
+
def readinto(self, buffer):
|
| 104 |
+
while True:
|
| 105 |
+
if self.current is None:
|
| 106 |
+
path = next(self.paths, None)
|
| 107 |
+
if path is None:
|
| 108 |
+
return 0
|
| 109 |
+
self.current = path.open('rb')
|
| 110 |
+
n = self.current.readinto(buffer)
|
| 111 |
+
if n:
|
| 112 |
+
return n
|
| 113 |
+
self.current.close()
|
| 114 |
+
self.current = None
|
| 115 |
+
|
| 116 |
+
def close(self):
|
| 117 |
+
if self.current is not None:
|
| 118 |
+
self.current.close()
|
| 119 |
+
super().close()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def extract_depths(root, sequences, work):
|
| 123 |
+
directory = find_file(root, 'DEPTH')
|
| 124 |
+
if directory is None:
|
| 125 |
+
return {}, []
|
| 126 |
+
parts = sorted(directory.glob('HOI4D_depth_video.tar.gz*'), key=lambda p: int(p.name.split('.gz')[1] or 0))
|
| 127 |
+
if not parts:
|
| 128 |
+
return {}, []
|
| 129 |
+
wanted = {f'HOI4D_depth_video/{seq}/align_depth/depth_video.avi': seq for seq in sequences}
|
| 130 |
+
found = {}
|
| 131 |
+
with SplitFiles(parts) as joined, io.BufferedReader(joined) as inp, gzip.GzipFile(fileobj=inp) as gz:
|
| 132 |
+
with tarfile.open(fileobj=gz, mode='r|') as tf:
|
| 133 |
+
for member in tf:
|
| 134 |
+
if member.isfile() and member.name in wanted:
|
| 135 |
+
seq = wanted[member.name]
|
| 136 |
+
dest = work / (seq.replace('/', '_') + '.avi')
|
| 137 |
+
with tf.extractfile(member) as src, dest.open('wb') as dst:
|
| 138 |
+
shutil.copyfileobj(src, dst)
|
| 139 |
+
found[seq] = (dest, {'files': [str(p.resolve()) for p in parts], 'member': member.name})
|
| 140 |
+
if len(found) == len(wanted):
|
| 141 |
+
break
|
| 142 |
+
return found, parts
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def palette_mask(data):
|
| 146 |
+
with Image.open(io.BytesIO(data)) as im:
|
| 147 |
+
arr = np.asarray(im)
|
| 148 |
+
if arr.ndim == 2:
|
| 149 |
+
return arr.astype(np.uint16)
|
| 150 |
+
if arr.shape[-1] != 3:
|
| 151 |
+
raise ValueError('unsupported HOI4D mask representation')
|
| 152 |
+
# VOC's 256-color palette interleaves eight label bits into the high RGB bits.
|
| 153 |
+
# Invert it directly instead of sorting every pixel with np.unique.
|
| 154 |
+
if np.any(arr & np.array([31, 31, 63], dtype=np.uint8)):
|
| 155 |
+
raise ValueError('source mask has colors outside official VOC palette')
|
| 156 |
+
mask = np.zeros(arr.shape[:2], dtype=np.uint16)
|
| 157 |
+
for bit in range(8):
|
| 158 |
+
mask |= ((arr[..., bit % 3] >> (7 - bit // 3)) & 1).astype(np.uint16) << bit
|
| 159 |
+
return mask
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
# Four workers each reuse annotation and hand indices instead of rebuilding the ZIP directory.
|
| 163 |
+
@lru_cache(maxsize=8)
|
| 164 |
+
def index_frames(z):
|
| 165 |
+
index = {}
|
| 166 |
+
for name in z.namelist():
|
| 167 |
+
parent, _, filename = name.rpartition('/')
|
| 168 |
+
stem, dot, suffix = filename.rpartition('.')
|
| 169 |
+
if not dot or not stem.isdigit() or suffix not in ('png', 'json', 'pickle'):
|
| 170 |
+
continue
|
| 171 |
+
entries = index.setdefault((parent + '/', '.' + suffix), {})
|
| 172 |
+
f = int(stem)
|
| 173 |
+
if f in entries:
|
| 174 |
+
raise ValueError(f'duplicate frame number under {parent}')
|
| 175 |
+
entries[f] = name
|
| 176 |
+
return index
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def frame_members(z, prefix, suffix):
|
| 180 |
+
return index_frames(z).get((prefix, suffix), {})
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def convert_sequence(seq, args, target, rgbz, annz, hpz, calz, cadz, paths, models, depth):
|
| 184 |
+
# ponytail: cache only one sequence's encoded annotation bytes; no decoded masks or CAD cache.
|
| 185 |
+
@lru_cache(maxsize=None)
|
| 186 |
+
def read_annotation(archive, name):
|
| 187 |
+
return archive.read(name)
|
| 188 |
+
|
| 189 |
+
category = int(re.search(r'/C(\d+)/', seq)[1])
|
| 190 |
+
definition = CATEGORIES.get(category)
|
| 191 |
+
if definition is None:
|
| 192 |
+
raise ValueError(f'category mapping unavailable: {category}')
|
| 193 |
+
prefix = f'HOI4D_annotations/{seq}'
|
| 194 |
+
mask_members = frame_members(annz, prefix + '/2Dseg/mask/', '.png')
|
| 195 |
+
shifted = frame_members(annz, prefix + '/2Dseg/shift_mask/', '.png')
|
| 196 |
+
if not mask_members:
|
| 197 |
+
mask_members = shifted
|
| 198 |
+
pose_members = frame_members(annz, prefix + '/objpose/', '.json')
|
| 199 |
+
hand_members = {side: frame_members(hpz, f'Hand_pose/handpose_{side}_hand/{seq}/', '.pickle')
|
| 200 |
+
for side in ('left', 'right')} if hpz else {'left': {}, 'right': {}}
|
| 201 |
+
with tempfile.TemporaryDirectory(prefix='hoi4d-source-') as wd:
|
| 202 |
+
work = Path(wd)
|
| 203 |
+
member = f'HOI4D_release/{seq}/align_rgb/image.mp4'
|
| 204 |
+
video = work / 'rgb.mp4'
|
| 205 |
+
with rgbz.open(member) as src, video.open('wb') as dst:
|
| 206 |
+
shutil.copyfileobj(src, dst)
|
| 207 |
+
info = probe(video)
|
| 208 |
+
if 'nb_frames' not in info:
|
| 209 |
+
info['nb_frames'] = json.loads(run(['ffprobe', '-v', 'error', '-count_frames', '-select_streams', 'v:0',
|
| 210 |
+
'-show_entries', 'stream=nb_read_frames', '-of', 'json', str(video)], stdout=subprocess.PIPE).stdout)['streams'][0]['nb_read_frames']
|
| 211 |
+
n = int(info['nb_frames'])
|
| 212 |
+
if args.max_frames:
|
| 213 |
+
n = min(n, args.max_frames)
|
| 214 |
+
if shifted and mask_members != shifted and any(f not in mask_members and f in shifted for f in range(n)):
|
| 215 |
+
raise ValueError('shift_mask has frames absent from mask; correspondence unverified')
|
| 216 |
+
frames = []
|
| 217 |
+
for f in range(n):
|
| 218 |
+
sources = {}
|
| 219 |
+
if f in mask_members:
|
| 220 |
+
sources['segment'] = locator(paths['annotations'], mask_members[f], read_annotation(annz, mask_members[f]))
|
| 221 |
+
if f in pose_members:
|
| 222 |
+
sources['object'] = locator(paths['annotations'], pose_members[f], read_annotation(annz, pose_members[f]))
|
| 223 |
+
for side in ('left', 'right'):
|
| 224 |
+
if f in hand_members[side]:
|
| 225 |
+
sources['hand_' + side] = locator(paths['hand'], hand_members[side][f], read_annotation(hpz, hand_members[side][f]))
|
| 226 |
+
frames.append(dict(source_frame_id=f, source_locator=locator(paths['release'], member, frame=f),
|
| 227 |
+
component_sources=sources, annotation_matches={k: dict(source_frame_id=f, source_timestamp_ns=None,
|
| 228 |
+
clock_domain=None, match_method='index_map', delta_ns=None) for k in sources}))
|
| 229 |
+
view = View(target, 'HOI4D', args.release_id, seq.replace('/', '_'), 'ego', frames)
|
| 230 |
+
view.valid_rules = {
|
| 231 |
+
'mano': 'Matched side pickle contains poseCoeff, beta, trans and corresponding model available; zero angles are not missing',
|
| 232 |
+
'keypoints': 'Matched side pickle contains kps2D; independently provided source points, no visibility gate',
|
| 233 |
+
'pose': 'Matched source object record contains rotation and center; record identity retained',
|
| 234 |
+
'dimensions': 'Matched source object record contains dimensions; size/mesh relation remains source_unspecified',
|
| 235 |
+
'segment': 'Source mask or shift_mask present with verified palette codes and entity/part mapping',
|
| 236 |
+
}
|
| 237 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 238 |
+
view.meta['view_type'] = 'ego'
|
| 239 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'source_sequence': seq}
|
| 240 |
+
view.rgb([], locator(paths['release'], member), video=video, count=n)
|
| 241 |
+
intr_name = f'camera_params/{seq.split("/")[0]}/intrin.npy'
|
| 242 |
+
if calz and intr_name in calz.namelist():
|
| 243 |
+
view.camera(np.load(io.BytesIO(calz.read(intr_name))), locator(paths['camera'], intr_name))
|
| 244 |
+
extr_name = prefix + '/3Dseg/output.log'
|
| 245 |
+
if extr_name in annz.NameToInfo:
|
| 246 |
+
lines = [line for line in annz.read(extr_name).decode().splitlines() if line.strip()]
|
| 247 |
+
if len(lines) % 5:
|
| 248 |
+
raise ValueError('invalid Open3D camera trajectory')
|
| 249 |
+
extr, valid = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 250 |
+
for i in range(0, len(lines), 5):
|
| 251 |
+
idx = int(lines[i].split()[0])
|
| 252 |
+
if idx < n:
|
| 253 |
+
if valid[idx]:
|
| 254 |
+
raise ValueError('duplicate trajectory index')
|
| 255 |
+
extr[idx] = np.linalg.inv(np.loadtxt(io.StringIO('\n'.join(lines[i + 1:i + 5]))))
|
| 256 |
+
valid[idx] = True
|
| 257 |
+
view.tensor('extrinsic', 'transform/se3/v1', 'camera/extrinsic.pt', extr, valid,
|
| 258 |
+
['T', 'row', 'column'], locator(paths['annotations'], extr_name),
|
| 259 |
+
convention='T_camera_from_world', source_convention='Open3D LOG camera-to-world; inverted')
|
| 260 |
+
loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources'}
|
| 261 |
+
motion, mv = np.full((n, 2, 61), np.nan, np.float32), np.zeros((n, 2), bool)
|
| 262 |
+
points, pv = np.full((n, 2, 21, 2), np.nan, np.float32), np.zeros((n, 2, 21), bool)
|
| 263 |
+
for slot, side in enumerate(('left', 'right')):
|
| 264 |
+
for f, name in hand_members[side].items():
|
| 265 |
+
if f >= n:
|
| 266 |
+
continue
|
| 267 |
+
data = pickle.loads(read_annotation(hpz, name), encoding='latin1')
|
| 268 |
+
if all(k in data for k in ('poseCoeff', 'beta', 'trans')):
|
| 269 |
+
motion[f, slot] = np.r_[np.asarray(data['poseCoeff']).reshape(48),
|
| 270 |
+
np.asarray(data['beta']).reshape(10), np.asarray(data['trans']).reshape(3)]
|
| 271 |
+
mv[f, slot] = True # Zero angles are a valid pose, not a missing sentinel.
|
| 272 |
+
if 'kps2D' in data:
|
| 273 |
+
points[f, slot] = np.asarray(data['kps2D']).reshape(21, 2)
|
| 274 |
+
pv[f, slot] = True
|
| 275 |
+
if mv.any():
|
| 276 |
+
if all(side in models for slot, side in enumerate(('left', 'right')) if mv[:, slot].any()):
|
| 277 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 278 |
+
['T', 'hand', 'parameter'], loc, model_profile=model_profile(models))
|
| 279 |
+
else:
|
| 280 |
+
view.absent('mano', 'Source MANO exists; provide --mano-dir to fix model identity', 'dependency_missing')
|
| 281 |
+
if pv.any():
|
| 282 |
+
view.tensor('keypoints_uv', 'keypoints/uv/v1', 'annotation/keypoints/uv.pt', points, pv,
|
| 283 |
+
['T', 'hand', 'keypoint', 'coordinate'], loc, keypoint_schema='mano21/v1', unit='pixel',
|
| 284 |
+
source_method='Upstream fitted MANO projection already present in kps2D')
|
| 285 |
+
objects = {}
|
| 286 |
+
groups = {key: (vals, name, cls) for key, vals, name, cls in definition['groups']}
|
| 287 |
+
def ensure_object(key, source_loc, category_id=None, frame=None, source_id=None):
|
| 288 |
+
if key not in objects:
|
| 289 |
+
view.object(key, source_loc, scope='frame' if frame is not None else 'sequence',
|
| 290 |
+
scope_id=f'{seq}:{frame}' if frame is not None else None,
|
| 291 |
+
category_id=category_id, source_object_id=source_id)
|
| 292 |
+
objects[key] = {}
|
| 293 |
+
mappings = []
|
| 294 |
+
mask_valid = [f in mask_members for f in range(n)]
|
| 295 |
+
if any(mask_valid):
|
| 296 |
+
width, height = view.meta['camera']['image_size']
|
| 297 |
+
def masks():
|
| 298 |
+
for f in range(n):
|
| 299 |
+
labels = []
|
| 300 |
+
if f in mask_members:
|
| 301 |
+
mask = palette_mask(read_annotation(annz, mask_members[f]))
|
| 302 |
+
for value in np.unique(mask):
|
| 303 |
+
value = int(value)
|
| 304 |
+
if value in (0, 255):
|
| 305 |
+
if value == 255:
|
| 306 |
+
raise ValueError('HOI4D 255 region semantics unverified')
|
| 307 |
+
continue
|
| 308 |
+
if REGION_NAMES[category].get(value) in ('Left Hand', 'Right Hand'):
|
| 309 |
+
entity, part, cls = 'hand_' + REGION_NAMES[category][value].split()[0].lower(), None, 'hand'
|
| 310 |
+
else:
|
| 311 |
+
group = next((k for k, (vals, _, _) in groups.items() if value in vals), None)
|
| 312 |
+
entity = group or f'unknown_region_{value}'
|
| 313 |
+
cls = groups[group][2] if group else None
|
| 314 |
+
part = f'region_{value}' if group and len(groups[group][0]) > 1 else None
|
| 315 |
+
ensure_object(entity, frames[f]['component_sources']['segment'], cls)
|
| 316 |
+
if part:
|
| 317 |
+
objects[entity].setdefault('parts', {})[part] = {'part_id': part, 'parent_id': None,
|
| 318 |
+
'has_model': False, 'mesh_ref': None, 'source_region_code': value, 'name': REGION_NAMES[category].get(value)}
|
| 319 |
+
labels.append(dict(mask_value=value, category_id=cls, entity_id=entity,
|
| 320 |
+
part_id=part, source_instance_id=value,
|
| 321 |
+
source_attributes={'region_name': REGION_NAMES[category].get(value)}))
|
| 322 |
+
else:
|
| 323 |
+
mask = np.zeros((height, width), np.uint16)
|
| 324 |
+
mappings.append(dict(frame_index=f, labels=labels))
|
| 325 |
+
yield mask
|
| 326 |
+
view.raster('segment', masks(), mask_valid, loc, mappings)
|
| 327 |
+
view.meta['components']['segment']['coverage'] = {'kind': 'unknown'}
|
| 328 |
+
if any(label['part_id'] for row in mappings for label in row['labels']):
|
| 329 |
+
view.meta['components']['segment']['segmentation_type'] = 'part'
|
| 330 |
+
else:
|
| 331 |
+
view.absent('segment', 'No native segmentation for this source sequence')
|
| 332 |
+
records = {}
|
| 333 |
+
for f, name in pose_members.items():
|
| 334 |
+
if f >= n:
|
| 335 |
+
continue
|
| 336 |
+
data = json.loads(read_annotation(annz, name))
|
| 337 |
+
# isEffective is not used to erase existing numerical annotations.
|
| 338 |
+
source_records = data.get('dataList', data.get('objects'))
|
| 339 |
+
if source_records is None:
|
| 340 |
+
raise ValueError('unrecognized source object annotation structure')
|
| 341 |
+
if category == 2 and source_records and (len(source_records) != 1 or
|
| 342 |
+
source_records[0].get('id') != 1 or source_records[0].get('label') != 'Watercup'):
|
| 343 |
+
raise ValueError('C2 native pose differs from the verified one-object target; cannot map to mask region 1')
|
| 344 |
+
label_counts = Counter(record['label'] for record in source_records)
|
| 345 |
+
per_frame = set()
|
| 346 |
+
for record_index, record in enumerate(source_records):
|
| 347 |
+
label = record['label']
|
| 348 |
+
group = definition['objmap'].get(label)
|
| 349 |
+
# Pinned official ObjTracking reads dataList[0] with segmentation label 1.
|
| 350 |
+
source_primary = category == 2 and record_index == 0 and record.get('id') == 1 and group == 'a'
|
| 351 |
+
ambiguous = group is not None and sum(g[2] == groups[group][2] for g in groups.values()) > 1 and not source_primary
|
| 352 |
+
ambiguous = ambiguous or (label_counts[label] > 1 and not source_primary) or group is None
|
| 353 |
+
entity = f'pose_frame_{f}_{record_index}' if ambiguous else group
|
| 354 |
+
ensure_object(entity, locator(paths['annotations'], name, record=record_index),
|
| 355 |
+
groups[group][2] if group else None, frame=f if ambiguous else None, source_id=record.get('id'))
|
| 356 |
+
if ambiguous:
|
| 357 |
+
view.build['unresolved'].append({'component': entity, 'status': 'source_semantics_unverified',
|
| 358 |
+
'reason': 'Source pose retained with frame identity; no guessed association to same-class mask instances'})
|
| 359 |
+
label_key = (entity, label)
|
| 360 |
+
if label_key in per_frame:
|
| 361 |
+
raise ValueError(f'ambiguous repeated object label {label}; source identity must be resolved')
|
| 362 |
+
per_frame.add(label_key)
|
| 363 |
+
records.setdefault(label_key, {})[f] = (record, locator(paths['annotations'], name, record=record.get('id')))
|
| 364 |
+
if category == 2 and any(entity == 'a' for entity, _ in records):
|
| 365 |
+
view.build['validation'].append({'component': 'C2_source_pose_mask_identity',
|
| 366 |
+
'rule': 'Official ObjTracking process_data.py reads dataList[0] with semantic mask label 1',
|
| 367 |
+
'source_revision': 'afa7bf37b02b7e33cf245acd08b98c207ccc175c',
|
| 368 |
+
'source_pose_id': 1, 'mask_value': 1, 'matched_frames': sum(len(by_frame) for (entity, _), by_frame in records.items() if entity == 'a')})
|
| 369 |
+
for (entity, label), by_frame in records.items():
|
| 370 |
+
part_labels = [k[1] for k in records if k[0] == entity]
|
| 371 |
+
articulated = definition['cad'].startswith('articulated/') and entity == definition['groups'][0][0]
|
| 372 |
+
part = 'pose_' + re.sub(r'[^a-zA-Z0-9_]', '_', label) if articulated or len(part_labels) > 1 else None
|
| 373 |
+
base = f'annotation/object/{entity}'
|
| 374 |
+
if part:
|
| 375 |
+
base += '/parts/' + part
|
| 376 |
+
objects[entity].setdefault('parts', {})[part] = dict(part_id=part, parent_id=None,
|
| 377 |
+
has_model=False, mesh_ref=None, source_label=label)
|
| 378 |
+
poses, valid = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 379 |
+
dimensions = np.full((n, 3), np.nan, np.float32)
|
| 380 |
+
dv = np.zeros(n, bool)
|
| 381 |
+
for f, (record, _) in by_frame.items():
|
| 382 |
+
if all(k in record for k in ('rotation', 'center')):
|
| 383 |
+
poses[f] = np.eye(4)
|
| 384 |
+
poses[f, :3, :3] = Rotation.from_euler('XYZ', [record['rotation'][k] for k in ('x', 'y', 'z')]).as_matrix()
|
| 385 |
+
poses[f, :3, 3] = [record['center'][k] for k in ('x', 'y', 'z')]
|
| 386 |
+
valid[f] = True
|
| 387 |
+
if 'dimensions' in record:
|
| 388 |
+
dimensions[f] = [record['dimensions'][k] for k in ('length', 'width', 'height')]
|
| 389 |
+
dv[f] = True
|
| 390 |
+
key = entity + ('_' + part if part else '')
|
| 391 |
+
view.tensor('pose_' + key, 'transform/se3/v1' if part else 'object/rigid/v1', base + '/pose.pt', poses, valid,
|
| 392 |
+
['T', 'row', 'column'], loc, convention='T_camera_from_part' if part else 'T_camera_from_object',
|
| 393 |
+
unit='m', source_label=label, source_euler_order='XYZ',
|
| 394 |
+
definition='https://github.com/hoi4d/ObjTracking/blob/main/process_data.py')
|
| 395 |
+
if dv.any():
|
| 396 |
+
view.tensor('dimensions_' + key, 'object/dimensions/v1', base + '/dimensions.pt', dimensions, dv,
|
| 397 |
+
['T', 'dimension'], loc, dimensions_semantics='source_unspecified', unit='m', scale_applied_to_mesh=False)
|
| 398 |
+
if cadz:
|
| 399 |
+
primary = definition['groups'][0][0]
|
| 400 |
+
if category != 2 and sum(g[2] == category for g in groups.values()) > 1:
|
| 401 |
+
primary = 'source_cad_instance'
|
| 402 |
+
instance = int(re.search(r'/N(\d+)/', seq)[1])
|
| 403 |
+
mesh_prefix = f'HOI4D_CAD_Model_for_release/{definition["cad"]}/{instance:03d}'
|
| 404 |
+
candidates = [name for name in cadz.namelist() if not name.endswith('/') and
|
| 405 |
+
(name == mesh_prefix + '.obj' or name.startswith(mesh_prefix + '/'))]
|
| 406 |
+
if candidates:
|
| 407 |
+
# Retain OBJ material/texture dependencies beside their original names.
|
| 408 |
+
queue = list(candidates)
|
| 409 |
+
for name in queue:
|
| 410 |
+
if Path(name).suffix.lower() not in ('.obj', '.mtl'):
|
| 411 |
+
continue
|
| 412 |
+
for line in cadz.read(name).decode().splitlines():
|
| 413 |
+
fields = shlex.split(line, comments=True)
|
| 414 |
+
if not fields:
|
| 415 |
+
continue
|
| 416 |
+
refs = fields[1:] if fields[0] == 'mtllib' else ([fields[-1]] if
|
| 417 |
+
fields[0].startswith('map_') or fields[0] in ('bump', 'norm', 'disp', 'decal') else [])
|
| 418 |
+
for ref in refs:
|
| 419 |
+
dependency = posixpath.normpath(posixpath.join(posixpath.dirname(name), ref))
|
| 420 |
+
if dependency not in cadz.NameToInfo:
|
| 421 |
+
raise ValueError(f'missing CAD dependency: {dependency}')
|
| 422 |
+
if dependency not in candidates:
|
| 423 |
+
candidates.append(dependency)
|
| 424 |
+
queue.append(dependency)
|
| 425 |
+
ensure_object(primary, locator(paths['cad'], mesh_prefix), category)
|
| 426 |
+
asset_dir = view.path / f'annotation/object/{primary}/assets'
|
| 427 |
+
asset_refs = []
|
| 428 |
+
for name in candidates:
|
| 429 |
+
relative = posixpath.relpath(name, mesh_prefix if definition['cad'].startswith('articulated/') else posixpath.dirname(mesh_prefix))
|
| 430 |
+
dest = safe_member(asset_dir, relative)
|
| 431 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 432 |
+
dest.write_bytes(cadz.read(name))
|
| 433 |
+
ref = dest.relative_to(view.path).as_posix()
|
| 434 |
+
if dest.suffix.lower() == '.obj':
|
| 435 |
+
asset_key = re.sub(r'[^a-zA-Z0-9_]', '_', relative)
|
| 436 |
+
view.component('mesh_' + primary + '_' + asset_key, 'mesh/obj/v1', ref, ['vertex'],
|
| 437 |
+
locator(paths['cad'], name), unit='m', valid=True,
|
| 438 |
+
scale_applied_to_mesh=False, dimensions_semantics='source_unspecified')
|
| 439 |
+
asset_refs.append(ref)
|
| 440 |
+
if definition['cad'].startswith('articulated/'):
|
| 441 |
+
part_id = 'asset_' + asset_key
|
| 442 |
+
objects[primary].setdefault('parts', {})[part_id] = dict(part_id=part_id,
|
| 443 |
+
parent_id=None, has_model=True, mesh_ref=ref, source_asset=relative,
|
| 444 |
+
note='Source asset; correspondence to motion part labels remains unverified')
|
| 445 |
+
for asset_ref in asset_refs:
|
| 446 |
+
mesh_check = check_mesh(view.path / asset_ref, asset_dir)
|
| 447 |
+
view.build['validation'].append({'component': asset_ref, **mesh_check,
|
| 448 |
+
'unit_basis': 'official ObjTracking loads source canonical CAD without scaling in metre camera coordinates',
|
| 449 |
+
'geometric_acceptance': 'physical dimensions-to-mesh relation remains source_unspecified'})
|
| 450 |
+
metadata_path = view.path / f'annotation/object/{primary}/metainfo.json'
|
| 451 |
+
metadata = json.loads(metadata_path.read_text())
|
| 452 |
+
metadata.update(has_model=bool(asset_refs), asset_refs=asset_refs)
|
| 453 |
+
if definition['cad'].startswith('rigid/') and len(asset_refs) == 1:
|
| 454 |
+
metadata['mesh_ref'] = asset_refs[0]
|
| 455 |
+
json_write(metadata_path, metadata)
|
| 456 |
+
if definition['cad'].startswith('articulated/'):
|
| 457 |
+
view.build['unresolved'].append({'component': 'object_part_asset_association',
|
| 458 |
+
'status': 'source_semantics_unverified',
|
| 459 |
+
'reason': 'All source assets and motion labels retained, but no guessed correspondence or joint_state'})
|
| 460 |
+
for entity, info in objects.items():
|
| 461 |
+
if 'parts' in info:
|
| 462 |
+
ref = f'annotation/object/{entity}/articulation.json'
|
| 463 |
+
json_write(view.path / ref, {'parts': list(info['parts'].values()), 'joints': [],
|
| 464 |
+
'hierarchy_semantics': 'semantic_containment',
|
| 465 |
+
'note': 'Unassociated source region, motion and asset nodes; original CAD trees retained in assets'})
|
| 466 |
+
view.component('articulation_' + entity, 'object/articulated/v1', ref, [], loc)
|
| 467 |
+
meta_path = view.path / f'annotation/object/{entity}/metainfo.json'
|
| 468 |
+
metadata = json.loads(meta_path.read_text())
|
| 469 |
+
metadata['articulation_ref'] = ref
|
| 470 |
+
json_write(meta_path, metadata)
|
| 471 |
+
if depth is not None:
|
| 472 |
+
dpath, dloc = depth
|
| 473 |
+
dmeta = probe(dpath)
|
| 474 |
+
if [dmeta['width'], dmeta['height']] != view.meta['camera']['image_size']:
|
| 475 |
+
raise ValueError('HOI4D depth grid differs from RGB')
|
| 476 |
+
if dmeta['pix_fmt'] != 'gray16le':
|
| 477 |
+
raise ValueError('unexpected HOI4D depth pixel format')
|
| 478 |
+
width, height = view.meta['camera']['image_size']
|
| 479 |
+
raw = work / 'depth.raw'
|
| 480 |
+
limits = ['-frames:v', str(n)] if args.max_frames else []
|
| 481 |
+
run(decode_args(dpath, 'gray16le') + limits + ['-y', str(raw)])
|
| 482 |
+
if raw.stat().st_size != n * width * height * 2:
|
| 483 |
+
raise ValueError('depth/RGB frame count or grid mismatch')
|
| 484 |
+
def depths():
|
| 485 |
+
with raw.open('rb') as inp:
|
| 486 |
+
for _ in range(n):
|
| 487 |
+
yield np.frombuffer(inp.read(width * height * 2), '<u2').reshape(height, width).astype(np.float32) / 1000
|
| 488 |
+
view.raster('depth', depths(), None, dloc | {'conversion': 'registered millimetre camera-Z to metres'})
|
| 489 |
+
else:
|
| 490 |
+
if find_file(args.root, 'DEPTH'):
|
| 491 |
+
raise ValueError('DEPTH source exists, but no matching depth video was found')
|
| 492 |
+
view.absent('depth', 'Depth source not downloaded', 'not_downloaded')
|
| 493 |
+
return view.finish()
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
def main(argv=None):
|
| 497 |
+
p = parser('HOI4D', __doc__)
|
| 498 |
+
p.set_defaults(release_id='shared-v1.0')
|
| 499 |
+
# Four workers reached 21 observed OS threads including timing; stay below the 24-thread budget.
|
| 500 |
+
p.add_argument('--workers', type=int, choices=range(1, 5), default=1,
|
| 501 |
+
help='Independent views in parallel, 1..4; codec/BLAS threads fixed at 1')
|
| 502 |
+
p.add_argument('--tasks', help='Comma-separated substrings of source sequence paths')
|
| 503 |
+
p.add_argument('--sessions', help='Comma-separated sessions')
|
| 504 |
+
p.add_argument('--categories', help='Comma-separated category numbers')
|
| 505 |
+
args = p.parse_args(argv)
|
| 506 |
+
if args.views and args.views != 'ego':
|
| 507 |
+
p.error('HOI4D source camera ID is ego')
|
| 508 |
+
paths = {key: find_file(args.root, name) for key, name in {
|
| 509 |
+
'release': 'HOI4D_release.zip', 'annotations': 'HOI4D_annotations.zip', 'hand': 'HOI4D_Hand_pose.zip',
|
| 510 |
+
'camera': 'camera_params.zip', 'cad': 'HOI4D_CAD_Model_for_release.zip'}.items()}
|
| 511 |
+
if not paths['release'] or not paths['annotations']:
|
| 512 |
+
p.error('HOI4D release and annotation ZIPs are required')
|
| 513 |
+
out = release(args, 'HOI4D')
|
| 514 |
+
mapping = Path(__file__).resolve().parent.parent / 'docs/hoi4d-RAW_TO_SHARED.md'
|
| 515 |
+
published_mapping = out / 'doc/RAW_TO_SHARED.md'
|
| 516 |
+
if published_mapping.exists() and published_mapping.read_bytes() != mapping.read_bytes():
|
| 517 |
+
raise ValueError('RAW_TO_SHARED.md changed; choose a new release-id')
|
| 518 |
+
if not published_mapping.exists():
|
| 519 |
+
shutil.copyfile(mapping, published_mapping)
|
| 520 |
+
torch.set_num_threads(1)
|
| 521 |
+
models = mano_models(args.mano_dir)
|
| 522 |
+
with ExitStack() as stack, tempfile.TemporaryDirectory(prefix='hoi4d-depth-') as wd:
|
| 523 |
+
archives = {key: stack.enter_context(zipfile.ZipFile(path)) if path else None for key, path in paths.items()}
|
| 524 |
+
sequences = sorted(name.removeprefix('HOI4D_release/').removesuffix('/align_rgb/image.mp4')
|
| 525 |
+
for name in archives['release'].namelist() if name.endswith('/align_rgb/image.mp4'))
|
| 526 |
+
if args.tasks:
|
| 527 |
+
sequences = [s for s in sequences if any(token in s for token in args.tasks.split(','))]
|
| 528 |
+
if args.sessions:
|
| 529 |
+
sequences = [s for s in sequences if s.split('/')[0] in args.sessions.split(',')]
|
| 530 |
+
if args.categories:
|
| 531 |
+
sequences = [s for s in sequences if re.search(r'/C(\d+)/', s)[1] in args.categories.split(',')]
|
| 532 |
+
if args.limit:
|
| 533 |
+
sequences = sequences[:args.limit]
|
| 534 |
+
if not sequences:
|
| 535 |
+
p.error('no matching source sequences')
|
| 536 |
+
depths, _ = extract_depths(args.root, sequences, Path(wd))
|
| 537 |
+
worker = threading.local()
|
| 538 |
+
worker_stacks = []
|
| 539 |
+
def init_worker():
|
| 540 |
+
owned = ExitStack()
|
| 541 |
+
try:
|
| 542 |
+
# ZipFile.read mutates a shared seek position: never share a handle across workers.
|
| 543 |
+
worker.archives = {key: owned.enter_context(zipfile.ZipFile(path)) if path else None
|
| 544 |
+
for key, path in paths.items()}
|
| 545 |
+
index_frames(worker.archives['annotations'])
|
| 546 |
+
if worker.archives['hand']:
|
| 547 |
+
index_frames(worker.archives['hand'])
|
| 548 |
+
except BaseException:
|
| 549 |
+
owned.close()
|
| 550 |
+
raise
|
| 551 |
+
worker_stacks.append(owned)
|
| 552 |
+
def convert_one(seq):
|
| 553 |
+
source = archives if args.workers == 1 else worker.archives
|
| 554 |
+
name = seq.replace('/', '_')
|
| 555 |
+
with sequence_dir(out, name) as target:
|
| 556 |
+
report = convert_sequence(seq, args, target / 'ego', source['release'], source['annotations'],
|
| 557 |
+
source['hand'], source['camera'], source['cad'], paths, models, depths.get(seq))
|
| 558 |
+
build_record(out, name, {'ego': report})
|
| 559 |
+
return seq
|
| 560 |
+
if args.workers == 1:
|
| 561 |
+
for seq in map(convert_one, sequences):
|
| 562 |
+
print(f'Converted {seq}', flush=True)
|
| 563 |
+
else:
|
| 564 |
+
try:
|
| 565 |
+
with ThreadPoolExecutor(max_workers=args.workers, initializer=init_worker) as pool:
|
| 566 |
+
for seq in pool.map(convert_one, sequences):
|
| 567 |
+
print(f'Converted {seq}', flush=True)
|
| 568 |
+
finally:
|
| 569 |
+
for owned in worker_stacks:
|
| 570 |
+
owned.close()
|
| 571 |
+
return 0
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
if __name__ == '__main__':
|
| 575 |
+
raise SystemExit(main())
|
| 576 |
+
|
| 577 |
+
# TODO(v2.0): 旧 bbox IoU 实例重分配属于推断,注释保留,不在 v1.0 执行。
|
| 578 |
+
# # 同类多实例(C8 双桶 / C2 双杯):2dBox 可用时按 IoU 复核归属
|
| 579 |
+
# cls = next(x[3] for x in cat["groups"] if x[0] == gk)
|
| 580 |
+
# sibs = [g for g in cat["groups"]
|
| 581 |
+
# if g[0] != gk and cls is not None and g[3] == cls]
|
| 582 |
+
# box = (d.get("2dBox") or {}).get("camera1")
|
| 583 |
+
# box = (box[0][0], box[0][1], box[1][0], box[1][1]) \
|
| 584 |
+
# if box and len(box) == 2 else None
|
| 585 |
+
# if box is not None and sibs:
|
| 586 |
+
# gvals = next(x[1] for x in cat["groups"] if x[0] == gk)
|
| 587 |
+
# best, best_iou = gk, box_iou(box, bbox_of(mask, gvals))
|
| 588 |
+
# for s in sibs:
|
| 589 |
+
# if ("obj", s[0]) not in tid_of_group:
|
| 590 |
+
# continue
|
| 591 |
+
# i = box_iou(box, bbox_of(mask, s[1]))
|
| 592 |
+
# if i > best_iou + 0.1 and i > 0.15:
|
| 593 |
+
# best, best_iou = s[0], i
|
| 594 |
+
# if best != gk:
|
| 595 |
+
# gk, iou_fixups = best, iou_fixups + 1
|
H2O/shared-v1.0/script/convert_visor_v1.0.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""VISOR source polygons and contact → CONTRACT.md v1.0, without rasterization or side inference."""
|
| 3 |
+
from collections import Counter
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
import re
|
| 7 |
+
import shutil
|
| 8 |
+
import tempfile
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import zipfile
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from warehouse_v1_0 import (View, build_record, find_file, jsonl_write, locator, parser,
|
| 16 |
+
release, roots, sequence_dir, source)
|
| 17 |
+
|
| 18 |
+
FRAME = re.compile(r'frame_(\d+)')
|
| 19 |
+
HAND = {300: 'left', 301: 'right'}
|
| 20 |
+
GLOVE = {303: 'left', 304: 'right'}
|
| 21 |
+
STATES = {'hand-not-in-contact': 'negative', 'glove-not-in-contact': 'negative',
|
| 22 |
+
'none-of-the-above': 'target_unannotated', 'inconclusive': 'unknown'}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def hand_side(ann):
|
| 26 |
+
if ann['class_id'] in HAND:
|
| 27 |
+
return HAND[ann['class_id']]
|
| 28 |
+
if ann['class_id'] not in (60, 303, 304):
|
| 29 |
+
return None
|
| 30 |
+
raw = ann.get('on_which_hand')
|
| 31 |
+
raw = raw if isinstance(raw, list) else [raw]
|
| 32 |
+
sides = set()
|
| 33 |
+
for item in raw:
|
| 34 |
+
if item == 'left hand':
|
| 35 |
+
sides.add('left')
|
| 36 |
+
if item in ('right hand', 'rigth hand'):
|
| 37 |
+
sides.add('right')
|
| 38 |
+
if len(sides) == 1:
|
| 39 |
+
return next(iter(sides))
|
| 40 |
+
if not sides and ann['class_id'] in GLOVE:
|
| 41 |
+
return GLOVE[ann['class_id']]
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def convert_video(video, split, annotation, ann_loc, rgb_zip, rgb_loc, mapping, args, target):
|
| 46 |
+
indexed = sorted(enumerate(annotation['video_annotations']), key=lambda row: int(FRAME.search(row[1]['image']['name'])[1]))
|
| 47 |
+
if args.max_frames:
|
| 48 |
+
indexed = indexed[:args.max_frames]
|
| 49 |
+
if len({row['image']['name'] for _, row in indexed}) != len(indexed):
|
| 50 |
+
raise ValueError('duplicate VISOR frame')
|
| 51 |
+
keys = lambda row, ann: (row['image']['subsequence'], ann['class_id'], ann['name'])
|
| 52 |
+
collisions = set()
|
| 53 |
+
for _, row in indexed:
|
| 54 |
+
collisions.update(key for key, number in Counter(keys(row, a) for a in row['annotations']).items() if number > 1)
|
| 55 |
+
frames, paths = [], []
|
| 56 |
+
with tempfile.TemporaryDirectory(prefix='visor-rgb-') as wd, zipfile.ZipFile(rgb_zip) as z:
|
| 57 |
+
work = Path(wd)
|
| 58 |
+
for original_index, row in indexed:
|
| 59 |
+
name = row['image']['name']
|
| 60 |
+
data = z.read(name)
|
| 61 |
+
path = work / Path(name).name
|
| 62 |
+
path.write_bytes(data)
|
| 63 |
+
paths.append(path)
|
| 64 |
+
loc = rgb_loc | {'nested_member': name, 'sha256': hashlib.sha256(data).hexdigest()}
|
| 65 |
+
frames.append(dict(source_frame_id=int(FRAME.search(name)[1]), source_locator=loc,
|
| 66 |
+
source_image=row['image'], original_frame_name=mapping.get(name),
|
| 67 |
+
annotation_matches={'segment': dict(source_frame_id=name, source_timestamp_ns=None,
|
| 68 |
+
clock_domain=None, match_method='index_map', delta_ns=None,
|
| 69 |
+
source_locator=ann_loc | {'record': f'video_annotations[{original_index}]'})}))
|
| 70 |
+
view = View(target, 'EPIC-KITCHENS-VISOR', args.release_id, video, 'ego', frames, sampling='sparse', split=split)
|
| 71 |
+
view.valid_rules = {
|
| 72 |
+
'segment': 'Selected sparse annotation frame present; all source polygons finite with at least three vertices and entity mapping valid',
|
| 73 |
+
'relations': 'At least one source in_contact_object value present; positive targets resolve in the same frame; unknown is an explicit usable status',
|
| 74 |
+
}
|
| 75 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 76 |
+
view.meta.update(view_type='ego', split_scheme='VISOR_GroundTruth_SparseAnnotations', split_source_locator=ann_loc)
|
| 77 |
+
view.meta['sampling']['selection'] = {'representation': 'official sparse annotations', 'max_frames': args.max_frames}
|
| 78 |
+
view.rgb(paths, rgb_loc)
|
| 79 |
+
entities = {}
|
| 80 |
+
polygons, mappings, relations, relation_valid = [], [], [], []
|
| 81 |
+
for f, (original_index, row) in enumerate(indexed):
|
| 82 |
+
frame_loc = ann_loc | {'record': f'video_annotations[{original_index}]'}
|
| 83 |
+
id_map, labels, polys = {}, [], []
|
| 84 |
+
for code, ann in enumerate(row['annotations'], 1):
|
| 85 |
+
if code >= 65535:
|
| 86 |
+
raise ValueError('too many source instances')
|
| 87 |
+
sid = ann['id']
|
| 88 |
+
if sid in id_map:
|
| 89 |
+
raise ValueError('duplicate source instance ID within a frame')
|
| 90 |
+
side = hand_side(ann)
|
| 91 |
+
if side is not None:
|
| 92 |
+
entity = 'hand_' + side
|
| 93 |
+
else:
|
| 94 |
+
key = keys(row, ann)
|
| 95 |
+
identity = key + (sid, row['image']['name']) if key in collisions else key
|
| 96 |
+
entity = 'object_' + hashlib.sha256(json.dumps(identity).encode()).hexdigest()[:20]
|
| 97 |
+
if entity not in entities:
|
| 98 |
+
scope = 'frame' if key in collisions else 'subsequence'
|
| 99 |
+
scope_id = f'{video}:{row["image"]["name"]}' if scope == 'frame' else f'{video}:{key[0]}'
|
| 100 |
+
view.object(entity, frame_loc | {'source_instance_id': sid}, scope, scope_id,
|
| 101 |
+
category_id=ann['class_id'], name=ann['name'],
|
| 102 |
+
association_basis='source_frame_instance' if scope == 'frame' else 'official_subsequence_entity_name')
|
| 103 |
+
entities[entity] = True
|
| 104 |
+
id_map[sid] = entity
|
| 105 |
+
for polygon in ann.get('segments', []):
|
| 106 |
+
p = np.asarray(polygon)
|
| 107 |
+
if p.ndim != 2 or p.shape[1] != 2 or len(p) < 3 or not np.isfinite(p).all():
|
| 108 |
+
raise ValueError(f'invalid source polygon {sid}')
|
| 109 |
+
polys.append(dict(mask_value=code, polygons=ann.get('segments', [])))
|
| 110 |
+
labels.append(dict(mask_value=code, category_id=ann['class_id'], entity_id=entity,
|
| 111 |
+
part_id=None, source_instance_id=sid,
|
| 112 |
+
source_attributes={k: v for k, v in ann.items() if k != 'segments'}))
|
| 113 |
+
rr = []
|
| 114 |
+
provided = False
|
| 115 |
+
for ann in row['annotations']:
|
| 116 |
+
raw = ann.get('in_contact_object')
|
| 117 |
+
values = raw if isinstance(raw, list) else [raw]
|
| 118 |
+
for value in values:
|
| 119 |
+
if value is None:
|
| 120 |
+
continue
|
| 121 |
+
provided = True
|
| 122 |
+
status = STATES.get(value)
|
| 123 |
+
obj = None
|
| 124 |
+
if status is None:
|
| 125 |
+
if value not in id_map:
|
| 126 |
+
raise ValueError(f'unresolved source contact target {value} in {video} frame {f}')
|
| 127 |
+
status, obj = 'positive', id_map[value]
|
| 128 |
+
rr.append(dict(relation_type='contact', subject_id=id_map[ann['id']], object_id=obj,
|
| 129 |
+
status=status, source_value=value, source_locator=frame_loc | {'source_instance_id': ann['id']},
|
| 130 |
+
provenance=source('Resolve source contact ID against instances in this frame')))
|
| 131 |
+
polygons.append(dict(frame_index=f, instances=polys))
|
| 132 |
+
mappings.append(dict(frame_index=f, labels=labels))
|
| 133 |
+
relations.append(dict(frame_index=f, relations=rr))
|
| 134 |
+
relation_valid.append(provided)
|
| 135 |
+
jsonl_write(view.path / 'annotation/segment/polygons.jsonl', polygons)
|
| 136 |
+
jsonl_write(view.path / 'annotation/segment/instances.jsonl', mappings)
|
| 137 |
+
torch.save(torch.ones(len(frames), dtype=torch.bool, device='cpu'), view.path / 'annotation/segment/mask_valid.pt')
|
| 138 |
+
view.component('segment', 'segment/instance_polygons/v1', 'annotation/segment/polygons.jsonl', ['T'], ann_loc,
|
| 139 |
+
valid_ref='annotation/segment/mask_valid.pt', valid_axes=['T'], segmentation_type='instance',
|
| 140 |
+
mapping_ref='annotation/segment/instances.jsonl', coverage={'kind': 'unknown', 'exhaustive_ref': 'annotation/segment/instances.jsonl'})
|
| 141 |
+
view.relations(relations, relation_valid, ann_loc)
|
| 142 |
+
for component in ('depth', 'mano', 'keypoints_uv', 'keypoints_xyz', 'intrinsic', 'extrinsic'):
|
| 143 |
+
view.absent(component, 'Not provided by VISOR sparse source annotations')
|
| 144 |
+
return view.finish()
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def main(argv=None):
|
| 148 |
+
p = parser('EPIC-KITCHENS-VISOR', __doc__)
|
| 149 |
+
p.add_argument('--videos', help='Comma-separated video names')
|
| 150 |
+
p.add_argument('--splits', default='train,val')
|
| 151 |
+
args = p.parse_args(argv)
|
| 152 |
+
wanted = set(args.videos.split(',')) if args.videos else None
|
| 153 |
+
splits = set(args.splits.split(','))
|
| 154 |
+
if not splits <= {'train', 'val'}:
|
| 155 |
+
p.error('only annotated train/val splits are available')
|
| 156 |
+
out = release(args, 'EPIC-KITCHENS-VISOR')
|
| 157 |
+
archive = find_file(args.root, 'EPIC-KITCHENS VISOR.zip')
|
| 158 |
+
with tempfile.TemporaryDirectory(prefix='visor-source-') as wd:
|
| 159 |
+
work = Path(wd)
|
| 160 |
+
if archive:
|
| 161 |
+
with zipfile.ZipFile(archive) as z:
|
| 162 |
+
suffix = 'GroundTruth-SparseAnnotations/annotations/'
|
| 163 |
+
members = [n for n in z.namelist() if suffix in n and n.endswith('.json')]
|
| 164 |
+
prefix = members[0].split(suffix)[0]
|
| 165 |
+
fm = json.loads(z.read(prefix + 'frame_mapping.json'))
|
| 166 |
+
done = 0
|
| 167 |
+
for member in sorted(members):
|
| 168 |
+
split, filename = member.split(suffix)[1].split('/')
|
| 169 |
+
video = Path(filename).stem
|
| 170 |
+
if split not in splits or wanted and video not in wanted:
|
| 171 |
+
continue
|
| 172 |
+
data = z.read(member)
|
| 173 |
+
rgb_member = prefix + f'GroundTruth-SparseAnnotations/rgb_frames/{split}/{video.split("_")[0]}/{video}.zip'
|
| 174 |
+
rgb_zip = work / (video + '.zip')
|
| 175 |
+
with z.open(rgb_member) as inp, rgb_zip.open('wb') as dest:
|
| 176 |
+
shutil.copyfileobj(inp, dest)
|
| 177 |
+
with sequence_dir(out, video) as dest:
|
| 178 |
+
report = convert_video(video, split, json.loads(data), locator(archive, member, data),
|
| 179 |
+
rgb_zip, locator(archive, rgb_member), fm.get(video, {}), args, dest / 'ego')
|
| 180 |
+
build_record(out, video, {'ego': report})
|
| 181 |
+
rgb_zip.unlink()
|
| 182 |
+
done += 1
|
| 183 |
+
print(f'Converted {video}', flush=True)
|
| 184 |
+
if args.limit and done >= args.limit:
|
| 185 |
+
break
|
| 186 |
+
else:
|
| 187 |
+
root = next((r for r in roots(args.root) if (r / 'GroundTruth-SparseAnnotations').is_dir()), None)
|
| 188 |
+
if root is None:
|
| 189 |
+
p.error('VISOR outer ZIP or extracted source directory not found')
|
| 190 |
+
fm = json.loads((root / 'frame_mapping.json').read_text()) if (root / 'frame_mapping.json').exists() else {}
|
| 191 |
+
done = 0
|
| 192 |
+
for split in sorted(splits):
|
| 193 |
+
for ann in sorted((root / 'GroundTruth-SparseAnnotations/annotations' / split).glob('*.json')):
|
| 194 |
+
video = ann.stem
|
| 195 |
+
if wanted and video not in wanted:
|
| 196 |
+
continue
|
| 197 |
+
rgb = root / f'GroundTruth-SparseAnnotations/rgb_frames/{split}/{video.split("_")[0]}/{video}.zip'
|
| 198 |
+
with sequence_dir(out, video) as dest:
|
| 199 |
+
report = convert_video(video, split, json.loads(ann.read_text()), locator(ann), rgb,
|
| 200 |
+
locator(rgb), fm.get(video, {}), args, dest / 'ego')
|
| 201 |
+
build_record(out, video, {'ego': report})
|
| 202 |
+
done += 1
|
| 203 |
+
if args.limit and done >= args.limit:
|
| 204 |
+
return 0
|
| 205 |
+
if not done:
|
| 206 |
+
p.error('no matching annotated videos found')
|
| 207 |
+
return 0
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
if __name__ == '__main__':
|
| 211 |
+
raise SystemExit(main())
|
| 212 |
+
|
| 213 |
+
# TODO(v2.0): 旧距离猜侧和单层掩码生成仅注释保留;v1.0 不执行。
|
| 214 |
+
# if side is None and len(frame_hands) == 1:
|
| 215 |
+
# # 空间门槛:脱下放在远处的手套不并入(实测双峰 0..25px / ≥44px)
|
| 216 |
+
# hb = frame_hands[0][1]
|
| 217 |
+
# gb = _bbox_of(polys)
|
| 218 |
+
# if hb and gb and _bbox_dist(gb, hb) <= GLOVE60_MERGE_BBOX_DIST:
|
| 219 |
+
# side = frame_hands[0][0]
|
| 220 |
+
# stats["glove60_merged_into_sole_hand"] += 1
|
| 221 |
+
# if side is None:
|
| 222 |
+
# stats["dropped_glove60_unresolved"] += 1
|
| 223 |
+
# id_disp[mid] = ("dropped", "glove60")
|
| 224 |
+
# continue
|
| 225 |
+
# def rasterize_and_encode(vdir, frames, frame_draw, zip_path, n, stats):
|
| 226 |
+
# """流式读 zip 内 jpg + 光栅化多边形 → rgb.mkv / mask.mkv;返回 (w, h)。"""
|
| 227 |
+
# from PIL import Image, ImageDraw
|
| 228 |
+
#
|
| 229 |
+
# with zipfile.ZipFile(zip_path) as zf:
|
| 230 |
+
# member_of = {}
|
| 231 |
+
# for nm in zf.namelist():
|
| 232 |
+
# member_of[os.path.basename(nm)] = nm
|
| 233 |
+
# names = [im["name"] for im in frames]
|
| 234 |
+
# missing = [nm for nm in names if nm not in member_of]
|
| 235 |
+
# if missing:
|
| 236 |
+
# raise RuntimeError(f"{len(missing)} annotated frames missing in zip, "
|
| 237 |
+
# f"e.g. {missing[:3]}")
|
| 238 |
+
# stats["zip_extra_members"] = len(member_of) - len(names)
|
| 239 |
+
#
|
| 240 |
+
# # 首帧定分辨率(官方 1920×1080,实测每帧校验)
|
| 241 |
+
# img0 = Image.open(io.BytesIO(zf.read(member_of[names[0]]))).convert("RGB")
|
| 242 |
+
# w, h = img0.size
|
| 243 |
+
#
|
| 244 |
+
# bin_img = Image.new("L", (w, h), 0)
|
| 245 |
+
# bin_draw = ImageDraw.Draw(bin_img)
|
| 246 |
+
# canvas = np.zeros((h, w), np.uint16)
|
| 247 |
+
# with VideoPipe(vdir / "mask.mkv", w, h, FPS, "mask") as mw, \
|
| 248 |
+
# VideoPipe(vdir / "rgb.mkv", w, h, FPS, "rgb") as rw:
|
| 249 |
+
# for f in range(n):
|
| 250 |
+
# canvas[:] = 0
|
| 251 |
+
# for pid, polys in frame_draw[f]:
|
| 252 |
+
# bin_draw.rectangle((0, 0, w, h), fill=0)
|
| 253 |
+
# for poly in polys:
|
| 254 |
+
# bin_draw.polygon([(float(x), float(y)) for x, y in poly], fill=255)
|
| 255 |
+
# arr = np.asarray(bin_img)
|
| 256 |
+
# canvas[arr > 0] = pid # 后画覆盖先画:物体→手(modal)
|
| 257 |
+
# mw.write(canvas)
|
| 258 |
+
# img = img0 if f == 0 else Image.open(
|
| 259 |
+
# io.BytesIO(zf.read(member_of[names[f]]))).convert("RGB")
|
| 260 |
+
# if img.size != (w, h):
|
| 261 |
+
# raise RuntimeError(f"frame {names[f]}: size {img.size} != {(w, h)}")
|
| 262 |
+
# rw.write(np.asarray(img))
|
| 263 |
+
# n_mask, n_rgb = mw.n, rw.n
|
| 264 |
+
# if (n_rgb, n_mask) != (n, n):
|
| 265 |
+
# raise RuntimeError(f"wrote rgb={n_rgb} mask={n_mask} != {n}")
|
| 266 |
+
# got = (count_frames(vdir / "rgb.mkv"), count_frames(vdir / "mask.mkv"))
|
| 267 |
+
# if got != (n, n):
|
| 268 |
+
# raise RuntimeError(f"encoded rgb={got[0]} mask={got[1]} != {n} (decode verify)")
|
| 269 |
+
# return w, h
|
| 270 |
+
#
|
| 271 |
+
#
|
H2O/shared-v1.0/script/provenance/operations/h2o-check-fallback.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Full coverage/numeric audit, plus representative persisted-media QC and offline HTML."""
|
| 2 |
+
import os
|
| 3 |
+
for key in ('OMP_NUM_THREADS','OPENBLAS_NUM_THREADS','MKL_NUM_THREADS','NUMEXPR_NUM_THREADS'):
|
| 4 |
+
os.environ[key]='1'
|
| 5 |
+
os.environ['HAND_WAREHOUSE_FFMPEG_THREADS']='4'
|
| 6 |
+
os.environ.pop('HAND_WAREHOUSE_FFV1_SLICES',None)
|
| 7 |
+
os.environ.pop('HAND_WAREHOUSE_MEDIA_TMPDIR',None)
|
| 8 |
+
import collections,datetime,hashlib,html,json,re,sys,time,zipfile
|
| 9 |
+
from concurrent.futures import ThreadPoolExecutor,as_completed
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from zoneinfo import ZoneInfo
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
root=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe')
|
| 15 |
+
release=root/'H2O/shared-v1.0'
|
| 16 |
+
sys.path.insert(0,str(root/'frozen-code/scripts'))
|
| 17 |
+
from warehouse_v1_0 import SCHEMA,check_transform,check_valid_policy,check_view_type,safe_member,sha256
|
| 18 |
+
from render_h2o_validation import render
|
| 19 |
+
out=release/'doc/validation/final-quick-check'
|
| 20 |
+
out.mkdir(exist_ok=True)
|
| 21 |
+
torch.set_num_threads(1)
|
| 22 |
+
started=time.monotonic()
|
| 23 |
+
expected={}
|
| 24 |
+
with zipfile.ZipFile('/data/xuzhefeng/Datasets/Hand-Datasets-Raw/H2O/raw/data/label_split.zip') as z:
|
| 25 |
+
for name in z.namelist():
|
| 26 |
+
if '/action_' not in name:continue
|
| 27 |
+
for line in z.read(name).decode().splitlines():
|
| 28 |
+
fields=line.split()
|
| 29 |
+
if len(fields)>1 and fields[1]!='path':
|
| 30 |
+
seq=fields[1].replace('/','_')
|
| 31 |
+
expected[seq]=max(expected.get(seq,0),int(fields[-1])+1)
|
| 32 |
+
folders={p.name:p for p in (release/'data').iterdir() if p.is_dir()}
|
| 33 |
+
assert set(folders)==set(expected),(sorted(set(expected)-set(folders)),sorted(set(folders)-set(expected)))
|
| 34 |
+
assert len(expected)==184 and sum(expected.values())==114329
|
| 35 |
+
receipts={p.name.removesuffix('.build.json'):p for p in (release/'doc').glob('*.build.json')}
|
| 36 |
+
assert set(receipts)==set(expected)
|
| 37 |
+
assert 'EXIT=0' in (root/'full.status').read_text()
|
| 38 |
+
failures=[]
|
| 39 |
+
rows=[]
|
| 40 |
+
def require(ok,message):
|
| 41 |
+
if not ok:raise ValueError(message)
|
| 42 |
+
def load(path):
|
| 43 |
+
def cpu(storage,location):
|
| 44 |
+
require(location=='cpu',f'non-CPU storage: {path}')
|
| 45 |
+
return storage
|
| 46 |
+
obj=torch.load(path,map_location=cpu,weights_only=True)
|
| 47 |
+
require(type(obj) is torch.Tensor,f'non-tensor: {path}')
|
| 48 |
+
return obj.numpy()
|
| 49 |
+
def check_sequence(seq):
|
| 50 |
+
folder=folders[seq];n=expected[seq]
|
| 51 |
+
require({p.name for p in folder.iterdir() if p.is_dir()}=={f'cam{i}' for i in range(5)},'five-camera coverage')
|
| 52 |
+
receipt=json.loads(receipts[seq].read_text())
|
| 53 |
+
require(receipt['sequence_id']==seq and set(receipt['views'])=={f'cam{i}' for i in range(5)},'build receipt')
|
| 54 |
+
result=[]
|
| 55 |
+
for i in range(5):
|
| 56 |
+
cam=f'cam{i}';view=folder/cam
|
| 57 |
+
meta=json.loads((view/'metainfo.json').read_text())
|
| 58 |
+
require((meta['dataset_id'],meta['sequence_id'],meta['camera_id'],meta['num_frames'])==('H2O',seq,cam,n),'header/timeline')
|
| 59 |
+
require(meta['view_type']==('ego' if i==4 else 'exo'),'view role')
|
| 60 |
+
require(meta['sampling']['selection']=={'max_frames':None,'views':None},'unexpected subsampling')
|
| 61 |
+
check_view_type(meta)
|
| 62 |
+
components=meta['components']
|
| 63 |
+
require(all(components[k].get('available') for k in ('rgb','depth','mano','keypoints_xyz','intrinsic','extrinsic')),'required modality absent')
|
| 64 |
+
require(not components['segment']['available'] and not components['relations']['available'],'unexpected synthesized component')
|
| 65 |
+
rgb_sources=[];depth_sources=[];rgb_count=depth_count=0
|
| 66 |
+
with (view/'camera/frames.jsonl').open() as inp:
|
| 67 |
+
count=0
|
| 68 |
+
for index,line in enumerate(inp):
|
| 69 |
+
f=json.loads(line)
|
| 70 |
+
require(f['frame_index']==index and f['source_frame_id']==index,'source frame index')
|
| 71 |
+
require(f['sync_id']==f'{seq.replace("_","/")}:{index}','synchronization ID')
|
| 72 |
+
sources=f['component_sources']
|
| 73 |
+
for kind,loc in sources.items():
|
| 74 |
+
require(re.fullmatch('[0-9a-f]{64}',loc.get('sha256','')) is not None,f'source SHA256: {kind}')
|
| 75 |
+
require(f'/{cam}/' in loc.get('member',''),'wrong source camera')
|
| 76 |
+
rgb_sources.append('rgb' in sources);depth_sources.append('depth' in sources)
|
| 77 |
+
rgb_count+=rgb_sources[-1];depth_count+=depth_sources[-1];count+=1
|
| 78 |
+
require(count==n,'frames.jsonl length')
|
| 79 |
+
numeric=0
|
| 80 |
+
object_names=[]
|
| 81 |
+
for key,c in components.items():
|
| 82 |
+
if not c['available']:continue
|
| 83 |
+
for field in ('data_ref','valid_ref','mapping_ref'):
|
| 84 |
+
if c.get(field):
|
| 85 |
+
path=safe_member(view,c[field])
|
| 86 |
+
require(path.is_file() and path.stat().st_size>0,f'missing/empty {c[field]}')
|
| 87 |
+
schema=SCHEMA['components'][c['schema_id']]
|
| 88 |
+
if c.get('valid_policy'):check_valid_policy(c,n)
|
| 89 |
+
valid=load(view/c['valid_ref']) if c.get('valid_ref','').endswith('.pt') else None
|
| 90 |
+
if valid is not None:
|
| 91 |
+
shape=schema.get('valid_shape')
|
| 92 |
+
require(valid.dtype==np.bool_ and valid.shape[0]==n,f'{key}: validity dtype/timeline')
|
| 93 |
+
if shape:require(len(shape)==valid.ndim and all(not isinstance(s,int) or valid.shape[j]==s for j,s in enumerate(shape)),f'{key}: validity shape')
|
| 94 |
+
if key=='rgb':require(np.array_equal(valid,np.asarray(rgb_sources)), 'RGB existence validity mismatch')
|
| 95 |
+
if c['data_ref'].endswith('.pt'):
|
| 96 |
+
arr=load(view/c['data_ref']);numeric+=1
|
| 97 |
+
require(arr.dtype==np.float32 and arr.shape[0]==n,f'{key}: dtype/timeline')
|
| 98 |
+
shape=schema.get('shape')
|
| 99 |
+
if shape:require(len(shape)==arr.ndim and all(not isinstance(s,int) or arr.shape[j]==s for j,s in enumerate(shape)),f'{key}: tensor shape')
|
| 100 |
+
if valid is not None:
|
| 101 |
+
require(arr.shape[:valid.ndim]==valid.shape and np.isfinite(arr[valid]).all() and np.isnan(arr[~valid]).all(),f'{key}: finite/NaN validity semantics')
|
| 102 |
+
if c['schema_id'] in ('transform/se3/v1','object/rigid/v1'):check_transform(arr[valid])
|
| 103 |
+
if key=='intrinsic':require(np.allclose(arr[:,2],[0,0,1]) and (arr[:,0,0]>0).all() and (arr[:,1,1]>0).all(),'camera intrinsics')
|
| 104 |
+
if key.startswith('mesh_'):object_names.append(key.removeprefix('mesh_'))
|
| 105 |
+
proof=receipt['views'][cam]
|
| 106 |
+
require(not proof['unresolved'],'unresolved QC components')
|
| 107 |
+
media={}
|
| 108 |
+
for p in proof['validation']:
|
| 109 |
+
if p.get('profile')==components['rgb']['storage']['profile'] and p.get('all_frames_exact') is True:media['rgb']=p
|
| 110 |
+
elif p.get('component') in ('depth','depth_valid'):media[p['component']]=p
|
| 111 |
+
require(set(media)=={'rgb','depth','depth_valid'},'media roundtrip proof missing')
|
| 112 |
+
for key,p in media.items():
|
| 113 |
+
require(p.get('all_frames_exact') is True and re.fullmatch('[0-9a-f]{64}',p.get('decoded_sha256','')) is not None,f'{key}: failed original roundtrip proof')
|
| 114 |
+
require((view/'observation'/f'{key}.mkv').stat().st_size==p['bytes'],f'{key}: encoded file size changed since conversion')
|
| 115 |
+
result.append({'sequence_id':seq,'camera':cam,'frames':n,'numeric_components':numeric,
|
| 116 |
+
'rgb_source_frames':rgb_count,'depth_source_frames':depth_count,'objects':sorted(object_names)})
|
| 117 |
+
return result
|
| 118 |
+
|
| 119 |
+
result=check_sequence('subject1_k2_6')
|
| 120 |
+
from warehouse_v1_0 import decoded_digest
|
| 121 |
+
receipt=json.loads(receipts['subject1_k2_6'].read_text())
|
| 122 |
+
view=folders['subject1_k2_6']/'cam0'
|
| 123 |
+
meta=json.loads((view/'metainfo.json').read_text())
|
| 124 |
+
proofs=receipt['views']['cam0']['validation']
|
| 125 |
+
verified=[]
|
| 126 |
+
for name,pix in (('rgb','rgb24'),('depth','gray16le'),('depth_valid','gray')):
|
| 127 |
+
p=next(x for x in proofs if (x.get('profile')==meta['components']['rgb']['storage']['profile'] if name=='rgb' else x.get('component')==name))
|
| 128 |
+
digest,size,seconds=decoded_digest(view/'observation'/f'{name}.mkv',pix)
|
| 129 |
+
assert digest==p['decoded_sha256'],(name,digest,p['decoded_sha256'])
|
| 130 |
+
expected_bytes=expected['subject1_k2_6']*1280*720*({'rgb':3,'depth':4,'depth_valid':1}[name])
|
| 131 |
+
assert size==expected_bytes,(name,size,expected_bytes)
|
| 132 |
+
verified.append({'component':name,'decoded_sha256':digest,'decoded_bytes':size,'seconds':seconds})
|
| 133 |
+
page=render(view,out/'subject1_k2_6_cam0_fallback')
|
| 134 |
+
json_result={'passed':True,'views':result,'full_decode_comparison':verified,'html':str(page.relative_to(out)),
|
| 135 |
+
'note':'Registered lossless H.264 fallback; all current decoded media digests equal original conversion receipts'}
|
| 136 |
+
(out/'H264_FALLBACK_CHECK.json').write_text(json.dumps(json_result,indent=2)+'\n')
|
| 137 |
+
print('FALLBACK_PASS',json.dumps(json_result),flush=True)
|
H2O/shared-v1.0/script/provenance/operations/h2o-finalize-quick-validation.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime,html,json,shutil
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from zoneinfo import ZoneInfo
|
| 4 |
+
release=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe/H2O/shared-v1.0')
|
| 5 |
+
out=release/'doc/validation/final-quick-check'
|
| 6 |
+
report=json.loads((out/'QUICK_VALIDATION.json').read_text())
|
| 7 |
+
assert report['failures']==[{'sequence':'subject1_k2_6','error':"ValueError('rgb: failed original roundtrip proof')"}]
|
| 8 |
+
fallback=json.loads((out/'H264_FALLBACK_CHECK.json').read_text());assert fallback['passed']
|
| 9 |
+
shutil.copy2(out/'QUICK_VALIDATION.json',out/'INITIAL_CHECKER_ALERT.json')
|
| 10 |
+
rows=fallback['views']
|
| 11 |
+
report['checked_sequences']+=1;report['checked_views']+=len(rows)
|
| 12 |
+
report['checked_view_frames']+=sum(r['frames'] for r in rows)
|
| 13 |
+
report['rgb_source_frames']+=sum(r['rgb_source_frames'] for r in rows)
|
| 14 |
+
report['depth_source_frames']+=sum(r['depth_source_frames'] for r in rows)
|
| 15 |
+
report['numeric_components']+=sum(r['numeric_components'] for r in rows)
|
| 16 |
+
report['samples'].append({'sequence_id':'subject1_k2_6','camera':'cam0','object':'espresso',
|
| 17 |
+
'frames':678,'passed':True,'html':fallback['html'],
|
| 18 |
+
'extra_check':'Full RGB/depth/valid current decoded digests equal original receipts'})
|
| 19 |
+
report['resolved_alerts']=[{'view':'subject1_k2_6/cam0','classification':'Registered lossless H.264 fallback, not missing data or corruption',
|
| 20 |
+
'original_checker_limitation':'First pass selected only FFV1 proofs; fixed to select the profile actually declared by metainfo',
|
| 21 |
+
'followup':'All five cameras rechecked; problematic view RGB, depth and validity fully decoded and matched original SHA256/byte length'}]
|
| 22 |
+
report['failures']=[];report['passed']=True
|
| 23 |
+
report['time']=datetime.datetime.now(ZoneInfo('Asia/Shanghai')).isoformat()
|
| 24 |
+
report['sample_views']=len(report['samples'])
|
| 25 |
+
assert report['checked_sequences']==184 and report['checked_views']==920
|
| 26 |
+
assert report['checked_view_frames']==report['rgb_source_frames']==report['depth_source_frames']==571645
|
| 27 |
+
report['rgb_profiles']={}
|
| 28 |
+
for meta in (release/'data').glob('*/cam*/metainfo.json'):
|
| 29 |
+
name=json.loads(meta.read_text())['components']['rgb']['storage']['profile']
|
| 30 |
+
report['rgb_profiles'][name]=report['rgb_profiles'].get(name,0)+1
|
| 31 |
+
(out/'QUICK_VALIDATION.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
|
| 32 |
+
summary={k:v for k,v in report.items() if k!='samples'}
|
| 33 |
+
(out/'index.html').write_text('<!doctype html><html lang="zh"><meta charset="utf-8"><title>H2O 全量后抽样验收</title><h1>H2O 全量后抽样验收</h1><p>自动检查通过不等于原始几何标注准确。覆盖四个 subject、八类物体、ego/exo;青色为源手部关节点投影,粉色为源物体点投影,仅用于预览。</p><ul>'+''.join('<li><a href="'+html.escape(x['html'],quote=True)+'">'+html.escape(x['sequence_id']+' '+x['camera']+' '+x['object'])+'</a></li>' for x in sorted(report['samples'],key=lambda x:(x['object'],x['sequence_id'],x['camera'])))+'</ul><pre>'+html.escape(json.dumps(summary,ensure_ascii=False,indent=2))+'</pre></html>')
|
| 34 |
+
operations=release/'script/provenance/operations'
|
| 35 |
+
for src in ('h2o-quick-validation.py','h2o-check-fallback.py','h2o-finalize-quick-validation.py'):
|
| 36 |
+
shutil.copy2(Path('/tmp')/src,operations/src)
|
| 37 |
+
shutil.copy2('/tmp/h2o-quick-validation.log',out/'INITIAL_RUN.log')
|
| 38 |
+
shutil.copy2('/tmp/h2o-fallback-check.log',out/'FALLBACK_RUN.log')
|
| 39 |
+
print(json.dumps(summary,ensure_ascii=False,indent=2),flush=True)
|
H2O/shared-v1.0/script/provenance/operations/h2o-pipeline-bench-job.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -u
|
| 3 |
+
cd /home/xuzhefeng/Projects/uni-hoi-dataset || exit 1
|
| 4 |
+
case "$1" in
|
| 5 |
+
old) code=/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10/frozen-code/scripts/convert_h2o_v1.0.py; extra=();;
|
| 6 |
+
v8) code=/tmp/h2o-stream-v8-recovery/scripts/convert_h2o_v1.0.py; extra=(--view-workers 8 --stream-media);;
|
| 7 |
+
v8ram) code=/tmp/h2o-stream-v8ram-recovery/scripts/convert_h2o_v1.0.py; extra=(--view-workers 8 --stream-media --ram-stage-dir /dev/shm/xuzhefeng-h2o-pipeline-v8ram-20260930 --ram-stage-gib 32);;
|
| 8 |
+
s16) code=/tmp/h2o-stream-s16-recovery/scripts/convert_h2o_v1.0.py; extra=(--view-workers 16 --stream-media --ffv1-slices 16 --ram-stage-dir /dev/shm/xuzhefeng-h2o-pipeline-s16-20260930 --ram-stage-gib 32);;
|
| 9 |
+
pipeline) code=/tmp/h2o-stream-pipeline-recovery/scripts/convert_h2o_v1.0.py; extra=(--view-workers 16 --camera-pipeline --stream-media --ffv1-slices 16 --ram-stage-dir /dev/shm/xuzhefeng-h2o-pipeline-overlap-20260930 --ram-stage-gib 32);;
|
| 10 |
+
process) code=/tmp/h2o-process-pipeline-recovery/scripts/convert_h2o_v1.0.py; extra=(--view-workers 16 --view-backend processes --camera-pipeline --stream-media --ffv1-slices 16 --ram-stage-dir /dev/shm/xuzhefeng-h2o-pipeline-process-20260930 --ram-stage-gib 32);;
|
| 11 |
+
v16) code=/tmp/h2o-stream-v8-recovery/scripts/convert_h2o_v1.0.py; extra=(--view-workers 16 --stream-media);;
|
| 12 |
+
*) exit 2;;
|
| 13 |
+
esac
|
| 14 |
+
root=/data/xuzhefeng/Datasets/uni-hoi-h2o-pipeline-bench-20260930
|
| 15 |
+
caseout="$root/$1"
|
| 16 |
+
mkdir -p "$caseout/scratch"
|
| 17 |
+
export TMPDIR="$caseout/scratch" PYTHONUNBUFFERED=1
|
| 18 |
+
cg=$(awk -F: '$1=="0" {print $3}' /proc/self/cgroup)
|
| 19 |
+
cat "/sys/fs/cgroup$cg/cpu.stat" > "$caseout/cpu.start"
|
| 20 |
+
date -Is > "$caseout/start"
|
| 21 |
+
.venv/bin/python "$code" --root "$root/raw" --out "$caseout" --workers 4 --codec-threads 10 --decode-threads 10 --depth-threads 4 --max-frames 200 --mano-dir /home/xuzhefeng/Projects/WiLoR/mano_data "${extra[@]}" > "$caseout/convert.log" 2>&1
|
| 22 |
+
code=$?
|
| 23 |
+
cat "/sys/fs/cgroup$cg/cpu.stat" > "$caseout/cpu.end"
|
| 24 |
+
printf '%s\n' "$code" > "$caseout/exit"
|
| 25 |
+
exit "$code"
|
H2O/shared-v1.0/script/provenance/operations/h2o-pipeline-benchmark.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime,json,os,subprocess,time
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
root=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-pipeline-bench-20260930')
|
| 4 |
+
cpus=os.cpu_count()
|
| 5 |
+
records=[]
|
| 6 |
+
for mode in ('old','v8'):
|
| 7 |
+
unit=f'h2o-pipeline-{mode}-20260930.scope'
|
| 8 |
+
begin=time.monotonic()
|
| 9 |
+
proc=subprocess.Popen(['systemd-run','--user','--scope','--unit='+unit,'-p','CPUAccounting=yes',
|
| 10 |
+
'/bin/bash','/tmp/h2o-pipeline-bench-job.sh',mode])
|
| 11 |
+
path=Path(f'/sys/fs/cgroup/user.slice/user-{os.getuid()}.slice/user@{os.getuid()}.service/app.slice/{unit}')
|
| 12 |
+
samples=[]
|
| 13 |
+
while proc.poll() is None:
|
| 14 |
+
try:
|
| 15 |
+
stat=dict(line.split() for line in (path/'cpu.stat').read_text().splitlines())
|
| 16 |
+
samples.append((time.monotonic()-begin,int(stat['usage_usec'])))
|
| 17 |
+
except (FileNotFoundError,PermissionError):pass
|
| 18 |
+
time.sleep(0.5)
|
| 19 |
+
elapsed=time.monotonic()-begin
|
| 20 |
+
assert proc.returncode==0,(mode,(root/mode/'convert.log').read_text()[-3000:])
|
| 21 |
+
def usage(name):return int(dict(line.split() for line in (root/mode/name).read_text().splitlines())['usage_usec'])
|
| 22 |
+
total=usage('cpu.end')-usage('cpu.start')
|
| 23 |
+
peak=max(((b[1]-a[1])/(b[0]-a[0])/1e6/cpus*100 for a,b in zip(samples,samples[10:])),default=0)
|
| 24 |
+
row=dict(mode=mode,seconds=elapsed,cpu_seconds=total/1e6,cpu_percent_machine=total/elapsed/1e6/cpus*100,
|
| 25 |
+
peak_5s_cpu_percent_machine=peak,samples=samples)
|
| 26 |
+
records.append(row)
|
| 27 |
+
(root/'performance.json').write_text(json.dumps(records,indent=2)+'\n')
|
| 28 |
+
print(json.dumps({k:v for k,v in row.items() if k!='samples'}),flush=True)
|
| 29 |
+
# Prove actual media and every numeric tensor match, not just wall-clock speed.
|
| 30 |
+
os.environ['HAND_WAREHOUSE_FFMPEG_THREADS'] = '10'
|
| 31 |
+
import sys
|
| 32 |
+
sys.path.insert(0,'/tmp/h2o-stream-v8-recovery/scripts')
|
| 33 |
+
from warehouse_v1_0 import decoded_digest,validate_view
|
| 34 |
+
import torch
|
| 35 |
+
for view in sorted((root/'old/H2O/shared-v1.0/data').glob('*/cam*')):
|
| 36 |
+
rel=view.relative_to(root/'old/H2O/shared-v1.0/data')
|
| 37 |
+
candidate=root/'v8/H2O/shared-v1.0/data'/rel
|
| 38 |
+
assert validate_view(candidate)['validated']
|
| 39 |
+
for name,pix in (('rgb','rgb24'),('depth','gray16le'),('depth_valid','gray')):
|
| 40 |
+
aa=decoded_digest(view/'observation'/f'{name}.mkv',pix)[:2]
|
| 41 |
+
bb=decoded_digest(candidate/'observation'/f'{name}.mkv',pix)[:2]
|
| 42 |
+
assert aa==bb,(rel,name)
|
| 43 |
+
for pt in view.rglob('*.pt'):
|
| 44 |
+
aa=torch.load(pt,weights_only=True)
|
| 45 |
+
bb=torch.load(candidate/pt.relative_to(view),weights_only=True)
|
| 46 |
+
assert aa.shape==bb.shape and aa.dtype==bb.dtype and aa.numpy().tobytes()==bb.numpy().tobytes(),(rel,pt)
|
| 47 |
+
print('PASS all 10 real views: full RGB/depth/valid decoded digests and every numeric tensor match',flush=True)
|
| 48 |
+
(root/'validation.exit').write_text('0\n')
|
H2O/shared-v1.0/script/provenance/operations/h2o-pipeline-process-benchmark.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime,json,os,subprocess,time
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
root=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-pipeline-bench-20260930')
|
| 4 |
+
cpus=os.cpu_count()
|
| 5 |
+
records=[]
|
| 6 |
+
for mode in ('process',):
|
| 7 |
+
unit=f'h2o-pipeline-{mode}-20260930.scope'
|
| 8 |
+
begin=time.monotonic()
|
| 9 |
+
proc=subprocess.Popen(['systemd-run','--user','--scope','--unit='+unit,'-p','CPUAccounting=yes',
|
| 10 |
+
'/bin/bash','/tmp/h2o-pipeline-bench-job.sh',mode])
|
| 11 |
+
path=Path(f'/sys/fs/cgroup/user.slice/user-{os.getuid()}.slice/user@{os.getuid()}.service/app.slice/{unit}')
|
| 12 |
+
samples=[]
|
| 13 |
+
while proc.poll() is None:
|
| 14 |
+
try:
|
| 15 |
+
stat=dict(line.split() for line in (path/'cpu.stat').read_text().splitlines())
|
| 16 |
+
samples.append((time.monotonic()-begin,int(stat['usage_usec'])))
|
| 17 |
+
except (FileNotFoundError,PermissionError):pass
|
| 18 |
+
time.sleep(0.5)
|
| 19 |
+
elapsed=time.monotonic()-begin
|
| 20 |
+
assert proc.returncode==0,(mode,(root/mode/'convert.log').read_text()[-3000:])
|
| 21 |
+
def usage(name):return int(dict(line.split() for line in (root/mode/name).read_text().splitlines())['usage_usec'])
|
| 22 |
+
total=usage('cpu.end')-usage('cpu.start')
|
| 23 |
+
peak=max(((b[1]-a[1])/(b[0]-a[0])/1e6/cpus*100 for a,b in zip(samples,samples[10:])),default=0)
|
| 24 |
+
row=dict(mode=mode,seconds=elapsed,cpu_seconds=total/1e6,cpu_percent_machine=total/elapsed/1e6/cpus*100,
|
| 25 |
+
peak_5s_cpu_percent_machine=peak,samples=samples)
|
| 26 |
+
records.append(row)
|
| 27 |
+
(root/'performance-process.json').write_text(json.dumps(records,indent=2)+'\n')
|
| 28 |
+
print(json.dumps({k:v for k,v in row.items() if k!='samples'}),flush=True)
|
| 29 |
+
# Prove actual media and every numeric tensor match, not just wall-clock speed.
|
| 30 |
+
os.environ['HAND_WAREHOUSE_FFMPEG_THREADS'] = '10'
|
| 31 |
+
import sys
|
| 32 |
+
sys.path.insert(0,'/tmp/h2o-process-pipeline-recovery/scripts')
|
| 33 |
+
from warehouse_v1_0 import decoded_digest,validate_view
|
| 34 |
+
import torch
|
| 35 |
+
for view in sorted((root/'old/H2O/shared-v1.0/data').glob('*/cam*')):
|
| 36 |
+
rel=view.relative_to(root/'old/H2O/shared-v1.0/data')
|
| 37 |
+
candidate=root/'process/H2O/shared-v1.0/data'/rel
|
| 38 |
+
assert validate_view(candidate)['validated']
|
| 39 |
+
for name,pix in (('rgb','rgb24'),('depth','gray16le'),('depth_valid','gray')):
|
| 40 |
+
aa=decoded_digest(view/'observation'/f'{name}.mkv',pix)[:2]
|
| 41 |
+
bb=decoded_digest(candidate/'observation'/f'{name}.mkv',pix)[:2]
|
| 42 |
+
assert aa==bb,(rel,name)
|
| 43 |
+
for pt in view.rglob('*.pt'):
|
| 44 |
+
aa=torch.load(pt,weights_only=True)
|
| 45 |
+
bb=torch.load(candidate/pt.relative_to(view),weights_only=True)
|
| 46 |
+
assert aa.shape==bb.shape and aa.dtype==bb.dtype and aa.numpy().tobytes()==bb.numpy().tobytes(),(rel,pt)
|
| 47 |
+
print('PASS all 10 real views: full RGB/depth/valid decoded digests and every numeric tensor match',flush=True)
|
| 48 |
+
(root/'validation-process.exit').write_text('0\n')
|
H2O/shared-v1.0/script/provenance/operations/h2o-prepare-pipeline-bench.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json,os,tarfile,shutil
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
root=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-pipeline-bench-20260930')
|
| 4 |
+
root.mkdir(exist_ok=True)
|
| 5 |
+
raw=root/'raw'; raw.mkdir(exist_ok=True)
|
| 6 |
+
old=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10')
|
| 7 |
+
records=[]
|
| 8 |
+
for subj in ('subject3','subject4'):
|
| 9 |
+
subject=next((old/'scratch').glob('h2o-source-*/'+subj))
|
| 10 |
+
sequences=[p for p in subject.glob('*/*') if all((p/f'cam{i}/rgb/000199.png').is_file() for i in range(5))]
|
| 11 |
+
assert sequences, (subj,subject)
|
| 12 |
+
seq=sequences[0]
|
| 13 |
+
snapshot=root/'input-snapshot'/subj/seq.relative_to(subject)
|
| 14 |
+
for src in seq.glob('cam*/*/*'):
|
| 15 |
+
if src.is_file() and src.parent.name in ('rgb','depth','cam_pose','hand_pose','hand_pose_mano','obj_pose','obj_pose_rt') and int(src.stem)<200:
|
| 16 |
+
dest=snapshot/src.relative_to(seq);dest.parent.mkdir(parents=True,exist_ok=True)
|
| 17 |
+
os.link(src,dest)
|
| 18 |
+
for src in seq.glob('cam*/cam_intrinsics.txt'):
|
| 19 |
+
dest=snapshot/src.relative_to(seq);dest.parent.mkdir(parents=True,exist_ok=True);os.link(src,dest)
|
| 20 |
+
archive=raw/f'{subj}_v1_1.tar.gz'
|
| 21 |
+
with tarfile.open(archive,'w:gz',compresslevel=0) as tf:
|
| 22 |
+
tf.add(snapshot,arcname=str(snapshot.relative_to(root/'input-snapshot')))
|
| 23 |
+
records.append({'sequence':str(snapshot.relative_to(root/'input-snapshot')),'frames':200,'views':5,'archive':str(archive),
|
| 24 |
+
'origin':str(seq),'gzip_compression_level':0})
|
| 25 |
+
for name in ('object.zip','label_split.zip'):
|
| 26 |
+
os.link(Path('/data/xuzhefeng/Datasets/Hand-Datasets-Raw/H2O/raw/data')/name,raw/name)
|
| 27 |
+
(root/'input-manifest.json').write_text(json.dumps(records,indent=2)+'\n')
|
| 28 |
+
print('PREPARED',records,flush=True)
|
H2O/shared-v1.0/script/provenance/operations/h2o-prepare-process-full.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Preserve complete persistent views; frozen process pipeline only changes execution/storage work."""
|
| 2 |
+
import datetime,json,os,shutil
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
old=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10')
|
| 5 |
+
new=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe')
|
| 6 |
+
new.mkdir()
|
| 7 |
+
shutil.copytree('/tmp/h2o-process-pipeline-recovery',new/'frozen-code')
|
| 8 |
+
release=new/'H2O/shared-v1.0'
|
| 9 |
+
for directory in ('data','doc/validation','script/provenance/previous-run','script/provenance/operations'):
|
| 10 |
+
(release/directory).mkdir(parents=True,exist_ok=True)
|
| 11 |
+
history=release/'script/provenance/previous-run'
|
| 12 |
+
shutil.copytree(old/'H2O/shared-v1.0/script',history/'script')
|
| 13 |
+
shutil.copytree(old/'frozen-code/docs',history/'docs')
|
| 14 |
+
for name in ('full.log','full.status','run-full.sh'):
|
| 15 |
+
shutil.copy2(old/name,history/name)
|
| 16 |
+
records=[]
|
| 17 |
+
for record in sorted((old/'H2O/shared-v1.0/doc').glob('*.build.json')):
|
| 18 |
+
build=json.loads(record.read_text());seq=build['sequence_id']
|
| 19 |
+
assert Path(seq).name==seq and seq not in ('.','..')
|
| 20 |
+
assert set(build['views'])=={f'cam{i}' for i in range(5)}
|
| 21 |
+
folder=old/'H2O/shared-v1.0/data'/seq
|
| 22 |
+
for cam in build['views']:assert (folder/cam/'metainfo.json').is_file()
|
| 23 |
+
shutil.copytree(folder,release/'data'/seq,copy_function=os.link)
|
| 24 |
+
shutil.copy2(record,release/'doc'/record.name)
|
| 25 |
+
records.append({'sequence_id':seq,'original_script_sha256':build['scripts']})
|
| 26 |
+
manifest={'time':datetime.datetime.now().astimezone().isoformat(),'source_run':str(old),'destination_run':str(new),
|
| 27 |
+
'reason':'Native bytes unchanged; process/view pipeline, streaming RAW and bounded RAM staging',
|
| 28 |
+
'target_cpu_percent_machine':80,'cpu_limit':None,'reused_sequences':records,
|
| 29 |
+
'reuse':'Read-only hardlinks; original build records retained; source frame/component SHA256 checked on resume',
|
| 30 |
+
'previous_run_provenance':'script/provenance/previous-run'}
|
| 31 |
+
(release/'doc/RESTART_PROVENANCE.json').write_text(json.dumps(manifest,indent=2)+'\n')
|
| 32 |
+
operations=release/'script/provenance/operations'
|
| 33 |
+
for name in ('h2o-prepare-process-full.py','h2o-switch-process-full.sh','h2o-pipeline-benchmark.py',
|
| 34 |
+
'h2o-pipeline-process-benchmark.py','h2o-pipeline-bench-job.sh','h2o-prepare-pipeline-bench.py',
|
| 35 |
+
'h2o-process-final-tests.log','h2o-shared-final-tests.log'):
|
| 36 |
+
shutil.copy2(Path('/tmp')/name,operations/name)
|
| 37 |
+
bench=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-pipeline-bench-20260930')
|
| 38 |
+
for p in bench.glob('performance*.json'):shutil.copy2(p,release/'doc/validation'/p.name)
|
| 39 |
+
shutil.copy2(bench/'input-manifest.json',release/'doc/validation/PIPELINE_BENCH_INPUTS.json')
|
| 40 |
+
shutil.copy2('/tmp/h2o-pipeline-process-benchmark.log',release/'doc/validation/PIPELINE_BENCHMARK.log')
|
| 41 |
+
shutil.copy2('/tmp/h2o-runtime-profile.log',release/'doc/validation/BEFORE_RUNTIME_PROFILE.log')
|
| 42 |
+
shutil.copy2('/tmp/h2o-current-iostat.log',release/'doc/validation/BEFORE_IOSTAT.log')
|
| 43 |
+
for destination in (new/'run-full.sh',release/'script/run-full.sh'):
|
| 44 |
+
shutil.copy2('/tmp/h2o-run-process-full.sh',destination)
|
| 45 |
+
print('REUSED_SEQUENCES',len(records),'REUSED_VIEWS',5*len(records),flush=True)
|
H2O/shared-v1.0/script/provenance/operations/h2o-process-final-tests.log
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Converted subject1/h1/0
|
| 2 |
+
Converted subject2/h1/0
|
| 3 |
+
Converted subject3/h1/0
|
| 4 |
+
Converted subject4/h1/0
|
| 5 |
+
Converted subject1/h1/0
|
| 6 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 7 |
+
Converted subject2/h1/0
|
| 8 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 9 |
+
Converted subject3/h1/0
|
| 10 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 11 |
+
Converted subject4/h1/0
|
| 12 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 13 |
+
Converted subject2/h1/0
|
| 14 |
+
Converted subject3/h1/0
|
| 15 |
+
Converted subject1/h1/0
|
| 16 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 17 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 18 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 19 |
+
Converted subject4/h1/0
|
| 20 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 21 |
+
Verified existing subject1/h1/0
|
| 22 |
+
Verified existing subject3/h1/0
|
| 23 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 24 |
+
Verified existing subject2/h1/0
|
| 25 |
+
Verified existing subject4/h1/0
|
| 26 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 27 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 28 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 29 |
+
Camera-order fallback: subject1/h1/0
|
| 30 |
+
Converted subject1/h1/0
|
| 31 |
+
Converted subject2/h1/0
|
| 32 |
+
Converted subject1/h1/0
|
| 33 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 34 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 35 |
+
Converted subject3/h1/0
|
| 36 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 37 |
+
Converted subject4/h1/0
|
| 38 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 39 |
+
PASS H2O pipe RGB/depth, RAM annotations, shared view pool 1/4/8, four archive workers, codec/decode 1/4/10, ordered depth 1/2/4 and missing-depth preservation, no resume PNG writes, RGB FFV1-only, depth and persistent QC
|
H2O/shared-v1.0/script/provenance/operations/h2o-quick-validation.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Full coverage/numeric audit, plus representative persisted-media QC and offline HTML."""
|
| 2 |
+
import os
|
| 3 |
+
for key in ('OMP_NUM_THREADS','OPENBLAS_NUM_THREADS','MKL_NUM_THREADS','NUMEXPR_NUM_THREADS'):
|
| 4 |
+
os.environ[key]='1'
|
| 5 |
+
os.environ['HAND_WAREHOUSE_FFMPEG_THREADS']='4'
|
| 6 |
+
os.environ.pop('HAND_WAREHOUSE_FFV1_SLICES',None)
|
| 7 |
+
os.environ.pop('HAND_WAREHOUSE_MEDIA_TMPDIR',None)
|
| 8 |
+
import collections,datetime,hashlib,html,json,re,sys,time,zipfile
|
| 9 |
+
from concurrent.futures import ThreadPoolExecutor,as_completed
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from zoneinfo import ZoneInfo
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
root=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe')
|
| 15 |
+
release=root/'H2O/shared-v1.0'
|
| 16 |
+
sys.path.insert(0,str(root/'frozen-code/scripts'))
|
| 17 |
+
from warehouse_v1_0 import SCHEMA,check_transform,check_valid_policy,check_view_type,safe_member,sha256
|
| 18 |
+
from render_h2o_validation import render
|
| 19 |
+
out=release/'doc/validation/final-quick-check'
|
| 20 |
+
out.mkdir(exist_ok=True)
|
| 21 |
+
torch.set_num_threads(1)
|
| 22 |
+
started=time.monotonic()
|
| 23 |
+
expected={}
|
| 24 |
+
with zipfile.ZipFile('/data/xuzhefeng/Datasets/Hand-Datasets-Raw/H2O/raw/data/label_split.zip') as z:
|
| 25 |
+
for name in z.namelist():
|
| 26 |
+
if '/action_' not in name:continue
|
| 27 |
+
for line in z.read(name).decode().splitlines():
|
| 28 |
+
fields=line.split()
|
| 29 |
+
if len(fields)>1 and fields[1]!='path':
|
| 30 |
+
seq=fields[1].replace('/','_')
|
| 31 |
+
expected[seq]=max(expected.get(seq,0),int(fields[-1])+1)
|
| 32 |
+
folders={p.name:p for p in (release/'data').iterdir() if p.is_dir()}
|
| 33 |
+
assert set(folders)==set(expected),(sorted(set(expected)-set(folders)),sorted(set(folders)-set(expected)))
|
| 34 |
+
assert len(expected)==184 and sum(expected.values())==114329
|
| 35 |
+
receipts={p.name.removesuffix('.build.json'):p for p in (release/'doc').glob('*.build.json')}
|
| 36 |
+
assert set(receipts)==set(expected)
|
| 37 |
+
assert 'EXIT=0' in (root/'full.status').read_text()
|
| 38 |
+
failures=[]
|
| 39 |
+
rows=[]
|
| 40 |
+
def require(ok,message):
|
| 41 |
+
if not ok:raise ValueError(message)
|
| 42 |
+
def load(path):
|
| 43 |
+
def cpu(storage,location):
|
| 44 |
+
require(location=='cpu',f'non-CPU storage: {path}')
|
| 45 |
+
return storage
|
| 46 |
+
obj=torch.load(path,map_location=cpu,weights_only=True)
|
| 47 |
+
require(type(obj) is torch.Tensor,f'non-tensor: {path}')
|
| 48 |
+
return obj.numpy()
|
| 49 |
+
def check_sequence(seq):
|
| 50 |
+
folder=folders[seq];n=expected[seq]
|
| 51 |
+
require({p.name for p in folder.iterdir() if p.is_dir()}=={f'cam{i}' for i in range(5)},'five-camera coverage')
|
| 52 |
+
receipt=json.loads(receipts[seq].read_text())
|
| 53 |
+
require(receipt['sequence_id']==seq and set(receipt['views'])=={f'cam{i}' for i in range(5)},'build receipt')
|
| 54 |
+
result=[]
|
| 55 |
+
for i in range(5):
|
| 56 |
+
cam=f'cam{i}';view=folder/cam
|
| 57 |
+
meta=json.loads((view/'metainfo.json').read_text())
|
| 58 |
+
require((meta['dataset_id'],meta['sequence_id'],meta['camera_id'],meta['num_frames'])==('H2O',seq,cam,n),'header/timeline')
|
| 59 |
+
require(meta['view_type']==('ego' if i==4 else 'exo'),'view role')
|
| 60 |
+
require(meta['sampling']['selection']=={'max_frames':None,'views':None},'unexpected subsampling')
|
| 61 |
+
check_view_type(meta)
|
| 62 |
+
components=meta['components']
|
| 63 |
+
require(all(components[k].get('available') for k in ('rgb','depth','mano','keypoints_xyz','intrinsic','extrinsic')),'required modality absent')
|
| 64 |
+
require(not components['segment']['available'] and not components['relations']['available'],'unexpected synthesized component')
|
| 65 |
+
rgb_sources=[];depth_sources=[];rgb_count=depth_count=0
|
| 66 |
+
with (view/'camera/frames.jsonl').open() as inp:
|
| 67 |
+
count=0
|
| 68 |
+
for index,line in enumerate(inp):
|
| 69 |
+
f=json.loads(line)
|
| 70 |
+
require(f['frame_index']==index and f['source_frame_id']==index,'source frame index')
|
| 71 |
+
require(f['sync_id']==f'{seq.replace("_","/")}:{index}','synchronization ID')
|
| 72 |
+
sources=f['component_sources']
|
| 73 |
+
for kind,loc in sources.items():
|
| 74 |
+
require(re.fullmatch('[0-9a-f]{64}',loc.get('sha256','')) is not None,f'source SHA256: {kind}')
|
| 75 |
+
require(f'/{cam}/' in loc.get('member',''),'wrong source camera')
|
| 76 |
+
rgb_sources.append('rgb' in sources);depth_sources.append('depth' in sources)
|
| 77 |
+
rgb_count+=rgb_sources[-1];depth_count+=depth_sources[-1];count+=1
|
| 78 |
+
require(count==n,'frames.jsonl length')
|
| 79 |
+
numeric=0
|
| 80 |
+
object_names=[]
|
| 81 |
+
for key,c in components.items():
|
| 82 |
+
if not c['available']:continue
|
| 83 |
+
for field in ('data_ref','valid_ref','mapping_ref'):
|
| 84 |
+
if c.get(field):
|
| 85 |
+
path=safe_member(view,c[field])
|
| 86 |
+
require(path.is_file() and path.stat().st_size>0,f'missing/empty {c[field]}')
|
| 87 |
+
schema=SCHEMA['components'][c['schema_id']]
|
| 88 |
+
if c.get('valid_policy'):check_valid_policy(c,n)
|
| 89 |
+
valid=load(view/c['valid_ref']) if c.get('valid_ref','').endswith('.pt') else None
|
| 90 |
+
if valid is not None:
|
| 91 |
+
shape=schema.get('valid_shape')
|
| 92 |
+
require(valid.dtype==np.bool_ and valid.shape[0]==n,f'{key}: validity dtype/timeline')
|
| 93 |
+
if shape:require(len(shape)==valid.ndim and all(not isinstance(s,int) or valid.shape[j]==s for j,s in enumerate(shape)),f'{key}: validity shape')
|
| 94 |
+
if key=='rgb':require(np.array_equal(valid,np.asarray(rgb_sources)), 'RGB existence validity mismatch')
|
| 95 |
+
if c['data_ref'].endswith('.pt'):
|
| 96 |
+
arr=load(view/c['data_ref']);numeric+=1
|
| 97 |
+
require(arr.dtype==np.float32 and arr.shape[0]==n,f'{key}: dtype/timeline')
|
| 98 |
+
shape=schema.get('shape')
|
| 99 |
+
if shape:require(len(shape)==arr.ndim and all(not isinstance(s,int) or arr.shape[j]==s for j,s in enumerate(shape)),f'{key}: tensor shape')
|
| 100 |
+
if valid is not None:
|
| 101 |
+
require(arr.shape[:valid.ndim]==valid.shape and np.isfinite(arr[valid]).all() and np.isnan(arr[~valid]).all(),f'{key}: finite/NaN validity semantics')
|
| 102 |
+
if c['schema_id'] in ('transform/se3/v1','object/rigid/v1'):check_transform(arr[valid])
|
| 103 |
+
if key=='intrinsic':require(np.allclose(arr[:,2],[0,0,1]) and (arr[:,0,0]>0).all() and (arr[:,1,1]>0).all(),'camera intrinsics')
|
| 104 |
+
if key.startswith('mesh_'):object_names.append(key.removeprefix('mesh_'))
|
| 105 |
+
proof=receipt['views'][cam]
|
| 106 |
+
require(not proof['unresolved'],'unresolved QC components')
|
| 107 |
+
media={}
|
| 108 |
+
for p in proof['validation']:
|
| 109 |
+
if p.get('profile')==components['rgb']['storage']['profile'] and p.get('all_frames_exact') is True:media['rgb']=p
|
| 110 |
+
elif p.get('component') in ('depth','depth_valid'):media[p['component']]=p
|
| 111 |
+
require(set(media)=={'rgb','depth','depth_valid'},'media roundtrip proof missing')
|
| 112 |
+
for key,p in media.items():
|
| 113 |
+
require(p.get('all_frames_exact') is True and re.fullmatch('[0-9a-f]{64}',p.get('decoded_sha256','')) is not None,f'{key}: failed original roundtrip proof')
|
| 114 |
+
require((view/'observation'/f'{key}.mkv').stat().st_size==p['bytes'],f'{key}: encoded file size changed since conversion')
|
| 115 |
+
result.append({'sequence_id':seq,'camera':cam,'frames':n,'numeric_components':numeric,
|
| 116 |
+
'rgb_source_frames':rgb_count,'depth_source_frames':depth_count,'objects':sorted(object_names)})
|
| 117 |
+
return result
|
| 118 |
+
with ThreadPoolExecutor(max_workers=4) as pool:
|
| 119 |
+
jobs={pool.submit(check_sequence,seq):seq for seq in sorted(expected)}
|
| 120 |
+
for job in as_completed(jobs):
|
| 121 |
+
seq=jobs[job]
|
| 122 |
+
try:rows.extend(job.result())
|
| 123 |
+
except Exception as exc:failures.append({'sequence':seq,'error':repr(exc)})
|
| 124 |
+
if len(rows)%100==0:print('STRUCTURAL_VIEWS',len(rows),'FAILURES',len(failures),flush=True)
|
| 125 |
+
print('STRUCTURAL_COMPLETE',len(rows),'FAILURES',failures,flush=True)
|
| 126 |
+
# Balance subjects while covering all eight source object classes; include matching exo views.
|
| 127 |
+
objects=('book','espresso','lotion','spray','milk','cocoa','chips','cappuccino')
|
| 128 |
+
selected=[]
|
| 129 |
+
for j,name in enumerate(objects):
|
| 130 |
+
subject=f'subject{j%4+1}_'
|
| 131 |
+
candidates=[r for r in rows if r['camera']=='cam4' and name in r['objects']]
|
| 132 |
+
require(candidates,f'no output for object {name}')
|
| 133 |
+
own=[r for r in candidates if r['sequence_id'].startswith(subject)]
|
| 134 |
+
r=min(own or candidates,key=lambda x:(x['frames'],x['sequence_id']))
|
| 135 |
+
selected.append((r['sequence_id'],'cam4',name))
|
| 136 |
+
selected.append((r['sequence_id'],'cam0',name))
|
| 137 |
+
samples=[]
|
| 138 |
+
def full_sample(item):
|
| 139 |
+
seq,cam,name=item
|
| 140 |
+
view=folders[seq]/cam
|
| 141 |
+
destination=out/f'{seq}_{cam}'
|
| 142 |
+
page=render(view,destination) # Reuse persisted contract QC, depth semantics, frame snapshots, native mesh preview.
|
| 143 |
+
return {'sequence_id':seq,'camera':cam,'object':name,'frames':expected[seq],
|
| 144 |
+
'passed':True,'html':str(page.relative_to(out))}
|
| 145 |
+
with ThreadPoolExecutor(max_workers=4) as pool:
|
| 146 |
+
jobs={pool.submit(full_sample,item):item for item in selected}
|
| 147 |
+
for job in as_completed(jobs):
|
| 148 |
+
item=jobs[job]
|
| 149 |
+
try:samples.append(job.result());print('SAMPLE_PASS',item,flush=True)
|
| 150 |
+
except Exception as exc:failures.append({'sample':item,'error':repr(exc)});print('SAMPLE_FAIL',item,repr(exc),flush=True)
|
| 151 |
+
report={'time':datetime.datetime.now(ZoneInfo('Asia/Shanghai')).isoformat(),'elapsed_seconds':time.monotonic()-started,
|
| 152 |
+
'release':str(release),'passed':not failures,'scope':'All sequence/camera coverage, frame/source manifests, all numeric tensors and original media receipts; 16 representative full persisted-view QC checks and offline previews. Not a new all-video source-pixel comparison.',
|
| 153 |
+
'expected_sequences':len(expected),'expected_sync_frames':sum(expected.values()),
|
| 154 |
+
'checked_sequences':len(rows)//5,'checked_views':len(rows),'checked_view_frames':sum(r['frames'] for r in rows),
|
| 155 |
+
'rgb_source_frames':sum(r['rgb_source_frames'] for r in rows),'depth_source_frames':sum(r['depth_source_frames'] for r in rows),
|
| 156 |
+
'numeric_components':sum(r['numeric_components'] for r in rows),'samples':samples,'failures':failures,
|
| 157 |
+
'next_step':'Human inspection of representative offline HTML; automatic QC is not proof of source geometric accuracy.'}
|
| 158 |
+
(out/'QUICK_VALIDATION.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
|
| 159 |
+
(out/'index.html').write_text('<!doctype html><html lang="zh"><meta charset="utf-8"><title>H2O 全量后抽样验收</title><h1>H2O 全量后抽样验收</h1><p>自动检查通过不等于源几何标注正确;以下为四个 subject、八类物体、ego/exo 的源数据预览。</p><ul>'+''.join('<li><a href="'+html.escape(x['html'],quote=True)+'">'+html.escape(x['sequence_id']+' '+x['camera']+' '+x['object'])+'</a></li>' for x in sorted(samples,key=lambda x:(x['object'],x['camera'])))+'</ul><pre>'+html.escape(json.dumps({k:v for k,v in report.items() if k not in ('samples',)},ensure_ascii=False,indent=2))+'</pre></html>')
|
| 160 |
+
print('FINAL_REPORT',json.dumps({k:v for k,v in report.items() if k!='samples'},ensure_ascii=False),flush=True)
|
| 161 |
+
raise SystemExit(0 if report['passed'] else 1)
|
H2O/shared-v1.0/script/provenance/operations/h2o-shared-final-tests.log
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
PASS: RGB full/prefix hashes, source depth frames, depth/valid/segment bits and missing-frame rejection
|
H2O/shared-v1.0/script/provenance/operations/h2o-switch-process-full.sh
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
cd /home/xuzhefeng/Projects/uni-hoi-dataset
|
| 4 |
+
test "$(cat /tmp/h2o-process-final-tests.exit)" = 0
|
| 5 |
+
test "$(cat /tmp/h2o-shared-final-tests.exit)" = 0
|
| 6 |
+
test "$(cat /tmp/h2o-pipeline-process-benchmark.exit)" = 0
|
| 7 |
+
test ! -e /data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe
|
| 8 |
+
old=/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10
|
| 9 |
+
printf '\nRECONFIGURE=%s REASON=process16_camera_pipeline_ram32_streaming\n' "$(date -Is)" >> "$old/full.status"
|
| 10 |
+
systemctl --user stop h2o-full-d10-20260930.scope
|
| 11 |
+
.venv/bin/python /tmp/h2o-prepare-process-full.py
|
| 12 |
+
systemd-run --user --scope --unit=h2o-full-process16-20260930 -p CPUAccounting=yes /bin/bash /data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe/run-full.sh
|
H2O/shared-v1.0/script/provenance/operations/watch-steady-cpu.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Measure the whole process tree only after conversion FFmpeg is active; no CPU-fill work."""
|
| 2 |
+
import datetime,json,os,time
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
unit='h2o-full-process16-20260930.scope'
|
| 5 |
+
cg=Path(f'/sys/fs/cgroup/user.slice/user-{os.getuid()}.slice/user@{os.getuid()}.service/app.slice/{unit}')
|
| 6 |
+
root=Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-process16-pipe')
|
| 7 |
+
report=root/'H2O/shared-v1.0/doc/validation/STEADY_CPU_5MIN.json'
|
| 8 |
+
start_wait=time.monotonic()
|
| 9 |
+
while time.monotonic()-start_wait<7200:
|
| 10 |
+
if not (cg/'cgroup.procs').exists():
|
| 11 |
+
print('Scope exited before a steady conversion sample',flush=True);raise SystemExit(1)
|
| 12 |
+
ffmpeg=False
|
| 13 |
+
for pid in (cg/'cgroup.procs').read_text().split():
|
| 14 |
+
try:ffmpeg |= Path('/proc',pid,'comm').read_text().strip()=='ffmpeg'
|
| 15 |
+
except FileNotFoundError:pass
|
| 16 |
+
if ffmpeg:break
|
| 17 |
+
time.sleep(5)
|
| 18 |
+
else:
|
| 19 |
+
print('No conversion FFmpeg within two hours; no steady CPU claim made',flush=True);raise SystemExit(2)
|
| 20 |
+
def sample():
|
| 21 |
+
values=dict(line.split() for line in (cg/'cpu.stat').read_text().splitlines())
|
| 22 |
+
return time.monotonic(),int(values['usage_usec'])
|
| 23 |
+
begin=datetime.datetime.now().astimezone().isoformat()
|
| 24 |
+
samples=[sample()]
|
| 25 |
+
for _ in range(60):
|
| 26 |
+
time.sleep(5)
|
| 27 |
+
try:samples.append(sample())
|
| 28 |
+
except FileNotFoundError:
|
| 29 |
+
print('Scope exited during sample; inspect full.status',flush=True);raise SystemExit(1)
|
| 30 |
+
cpus=os.cpu_count()
|
| 31 |
+
intervals=[(b[1]-a[1])/(b[0]-a[0])/1e6/cpus*100 for a,b in zip(samples,samples[1:])]
|
| 32 |
+
result={'start':begin,'end':datetime.datetime.now().astimezone().isoformat(),'logical_cpus':cpus,
|
| 33 |
+
'whole_scope_cpu_percent_machine':(samples[-1][1]-samples[0][1])/(samples[-1][0]-samples[0][0])/1e6/cpus*100,
|
| 34 |
+
'highest_5sec_cpu_percent_machine':max(intervals),'lowest_5sec_cpu_percent_machine':min(intervals),
|
| 35 |
+
'target_percent':80,'intervals_percent_machine':intervals,'samples':samples,
|
| 36 |
+
'scope':unit,'includes':'All scope threads and child processes, including children already exited'}
|
| 37 |
+
report.write_text(json.dumps(result,indent=2)+'\n')
|
| 38 |
+
print(json.dumps({k:v for k,v in result.items() if k not in ('samples','intervals_percent_machine')}),flush=True)
|
H2O/shared-v1.0/script/provenance/previous-run/docs/CONTRACT.md
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 手物数据仓库统一约定 v1.0
|
| 2 |
+
|
| 3 |
+
格式版本:`hand-warehouse/1.0`。存储约定:`lossless-video-2026-09-18`。
|
| 4 |
+
|
| 5 |
+
范围限于手物交互重建。按本任务纳入的源模态转换,不要求每个数据集填满所有组件。缺失模态、尚未下载、语义未核实分别报告,不能互相替代。
|
| 6 |
+
|
| 7 |
+
本文定义各字段的含义与使用规则,机器可读注册表见 [schema.json](schema.json)。两者互相补充;如有冲突,应先核实并统一定义。
|
| 8 |
+
|
| 9 |
+
## 1. 目录
|
| 10 |
+
|
| 11 |
+
```text
|
| 12 |
+
hand-datasets/
|
| 13 |
+
<dataset_name>/
|
| 14 |
+
raw/
|
| 15 |
+
doc/ # 官方说明、来源与校验记录
|
| 16 |
+
script/ # 官方下载脚本、必要包装脚本
|
| 17 |
+
data/ # 保留原始包,不原地解压或改写
|
| 18 |
+
<dataset_version>/
|
| 19 |
+
doc/ # 发布说明、schema、来源清单
|
| 20 |
+
script/ # 转换、校验脚本及运行配置
|
| 21 |
+
data/
|
| 22 |
+
<sequence_id>/
|
| 23 |
+
<camera_id>/
|
| 24 |
+
metainfo.json
|
| 25 |
+
observation/
|
| 26 |
+
rgb.mkv
|
| 27 |
+
rgb_valid.pt
|
| 28 |
+
depth.mkv # float32 深度的可逆视频编码
|
| 29 |
+
depth_valid.mkv # 逐像素 bool 的无损视频编码
|
| 30 |
+
camera/
|
| 31 |
+
frames.jsonl
|
| 32 |
+
intrinsic.pt
|
| 33 |
+
intrinsic_valid.pt
|
| 34 |
+
extrinsic.pt
|
| 35 |
+
extrinsic_valid.pt
|
| 36 |
+
annotation/
|
| 37 |
+
mano/
|
| 38 |
+
motion.pt
|
| 39 |
+
motion_valid.pt
|
| 40 |
+
visibility.pt
|
| 41 |
+
keypoints/
|
| 42 |
+
uv.pt
|
| 43 |
+
uv_valid.pt
|
| 44 |
+
xyz.pt
|
| 45 |
+
xyz_valid.pt
|
| 46 |
+
visibility.pt # 源数据有时提供
|
| 47 |
+
object/
|
| 48 |
+
<object_id>/
|
| 49 |
+
assets/ # 该物体的网格、材质、纹理及部件资产
|
| 50 |
+
<mesh_id>.obj
|
| 51 |
+
pose.pt
|
| 52 |
+
pose_valid.pt
|
| 53 |
+
visibility.pt
|
| 54 |
+
metainfo.json # 物体身份、类别、mesh、尺寸与部件引用
|
| 55 |
+
articulation.json
|
| 56 |
+
keypoints/
|
| 57 |
+
vertex_part_ids.pt
|
| 58 |
+
joint_state.pt
|
| 59 |
+
joint_state_valid.pt
|
| 60 |
+
parts/<part_id>/pose.pt
|
| 61 |
+
parts/<part_id>/pose_valid.pt
|
| 62 |
+
segment/
|
| 63 |
+
mask.mkv
|
| 64 |
+
mask_valid.pt
|
| 65 |
+
instances.jsonl
|
| 66 |
+
contact/
|
| 67 |
+
relations.jsonl
|
| 68 |
+
<subject_id>__<object_id>/ # 对应实体间的距离/接触区域
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
目录展示可能存在的组件,不要求填满。具体文件、字段和缺省规则分别见后续对应小节。原始包的解压发生在临时工作区,raw 内原始包保持不变。
|
| 72 |
+
|
| 73 |
+
## 2. 相机视图的 metainfo.json
|
| 74 |
+
|
| 75 |
+
### 2.1 顶层字段与发布信息
|
| 76 |
+
|
| 77 |
+
每个相机视图必须有 `metainfo.json`。以下字段除另行说明外均为必填:
|
| 78 |
+
|
| 79 |
+
| 字段 | 填写内容 |
|
| 80 |
+
|---|---|
|
| 81 |
+
| schema_version | 结构版本,本版为 `hand-warehouse/1.0` |
|
| 82 |
+
| dataset_id | 数据集的逻辑标识 |
|
| 83 |
+
| release_id | 本次数据发布版本,对应目录中的 dataset_version |
|
| 84 |
+
| sequence_id | 所属序列或独立图片样本的标识 |
|
| 85 |
+
| camera_id | 当前相机视图标识 |
|
| 86 |
+
| sample_type | `image` 或 `video`,规则见 2.2 |
|
| 87 |
+
| num_frames | 当前视图帧数 T,所有随帧组件按同一时间轴组织 |
|
| 88 |
+
| hand_slots | 固定为 `["left", "right"]`;解剖学左右的使用规则见 5.1 |
|
| 89 |
+
| sampling | 采样类型、源 FPS、帧索引引用及选择策略,见 2.2 |
|
| 90 |
+
| camera | 当前相机模型与图像尺寸,见 2.3 |
|
| 91 |
+
| components | 实际提供的组件及其文件、schema、有效性和来源,见 2.5 |
|
| 92 |
+
| split | `train/val/test/unknown`,划分协议见 2.4 |
|
| 93 |
+
| view_type | 可选,`ego/exo/unknown` |
|
| 94 |
+
|
| 95 |
+
`dataset_version` 是数据发布版本;`schema_version` 是结构版本,两者独立。原始包校验摘要、官方来源和转换配置应记录在发布清单中。解压发生在临时工作区,原始包保持不变。
|
| 96 |
+
|
| 97 |
+
### 2.2 图片、视频与 sampling
|
| 98 |
+
|
| 99 |
+
`sample_type=image`:允许单图 T=1、`sampling.type=single`,也允许将独立图片批量装入一个视频容器,T>1 时 `sampling.type=independent`、`source_fps=null`。分片大小按数据集选择;FreiHAND 默认每片最多 4096 张,训练与评估分开,尾片不补帧。该数量不是其他数据集的强制要求;同批分辨率、相机模型类型及划分协议一致。每行 frames 必须有稳定且唯一的 `sample_id`、原始文件定位;内参、手形状等仍逐帧保留,不能因打包而共享错误的标定或身份。`sequence_id` 在这里仅是批次标识,不代表真实序列;不得按相邻帧推断跟踪、同步或接触延续。源 camera_id、image_variant、split 等随样本变化时放在 frames 的对应字段中。真实采集时间未知则 timestamp_ns=null。合成背景变体不视为真实多相机。
|
| 100 |
+
|
| 101 |
+
`sample_type=video`:`sampling.type=dense/sparse`;`source_fps` 是真实采集 FPS,未知为 null。非连续取样必须保留源帧号和已知源时间,不可用采样后索引除以 FPS 冒充源时间。可另记采样策略与步长。
|
| 102 |
+
|
| 103 |
+
shared 可以仅存所选 RGB 帧对应的数据。OakInk2 图像/动捕不同采样率时用 annotation_matches 明确映射;不要求将未采样动捕点硬塞进 T。多视角身份和源同步关系要保留;选择了哪些帧/相机及原因写在 sampling 中。
|
| 104 |
+
|
| 105 |
+
`sampling.frames_ref` 指向 `camera/frames.jsonl`。帧号、逐帧时间、同步与标注匹配记录的结构见 4.1;MKV 封装时间的约定见 3.1。
|
| 106 |
+
|
| 107 |
+
### 2.3 camera 模型声明
|
| 108 |
+
|
| 109 |
+
`camera` 至少包含 `model`、`schema_id`、`image_size:[W,H]`。模型未知使用 `unknown` 和 `null`,不猜成针孔。实际内参、畸变及外参数组放在 `camera/`,各模型的固定结构见第 4 节。
|
| 110 |
+
|
| 111 |
+
### 2.4 split 与划分协议
|
| 112 |
+
|
| 113 |
+
保留上游划分,不将同一采集序列的相邻帧随意拆到不同集合。
|
| 114 |
+
|
| 115 |
+
有官方划分时必填 split_scheme 和 split_source_locator,split_scheme 区分如 Dex-YCB s0/s1、ARCTIC P1/P2 等选定协议;不知道时 split=unknown 并给理由,不凭空分配。每发布可选择一种协议;存在逐帧差异时 frames 中的 split 覆盖视图默认值,并登记其来源。
|
| 116 |
+
|
| 117 |
+
### 2.5 components 组件登记
|
| 118 |
+
|
| 119 |
+
组件表的键是本发布内唯一名称,例如 `rgb`、`depth`、`mano`、`keypoints_uv`。每个已提供组件声明以下信息;模态特有参数在第 3–5 节对应小节中定义。
|
| 120 |
+
|
| 121 |
+
| 字段 | 约定 |
|
| 122 |
+
|---|---|
|
| 123 |
+
| available | 本发布是否提供该组件;缺省也表示未提供 |
|
| 124 |
+
| schema_id | 已登记的具体存储与语义类型,不得临时创造未登记名称 |
|
| 125 |
+
| data_ref | 数据文件路径,相对当前相机视图根目录,使用 POSIX 路径 |
|
| 126 |
+
| axes | 数组各维度的含义 |
|
| 127 |
+
| valid_ref / valid_axes | 有效性文件及其维度;语义由所属组件规定 |
|
| 128 |
+
| storage / valid_storage | 视频数据/视频有效性的存储配置;包含已登记 profile、实际 codec、pixel_format、encoded_size,见 3.1;非视频组件按原数组规则 |
|
| 129 |
+
| provenance | source / format_conversion / derived,以及转换或生成方法 |
|
| 130 |
+
| source_locator | 原文件、压缩包成员和记录/帧的定位信息 |
|
| 131 |
+
|
| 132 |
+
不存在的组件允许缺省或写作 `{ "available": false, "reason": "..." }`,不用引用不存在的文件。静态网格可声明标量有效性;具体见 5.4。观测的 valid 见第 3 节,标注的 valid 与 visibility 区分见 5.1。
|
| 133 |
+
|
| 134 |
+
`provenance.kind` 使用 source/format_conversion/derived,`method` 说明转换或生成方法;发布清单补充脚本版本、参数、输入摘要。`source_locator` 定位到原始文件/压缩包成员和记录、帧号;允许引用有完整溯源清单的前一发布,但链条最终应能回到 raw。不得仅写一个无法定位记录的数据集名字。
|
| 135 |
+
|
| 136 |
+
`.pt` 仅保存 CPU Tensor,不保存 Python 自定义对象;浮点默认 float32,有效性为 bool,浮点无效位置填 NaN。所有随帧数组保留首维 T,单帧也不 squeeze;静态资产按其 schema 单独声明。单位、坐标及固定形状见各组件小节。
|
| 137 |
+
|
| 138 |
+
机器注册表 `schema.json` 中,`components` 固定解码后的数据类型、形状、单位和语义;`storage_profiles` 固定视频内的编码/还原方式。不得临时创造未登记的 schema_id 或 storage.profile。同一语义允许选择其登记的不同无损存储 profile。
|
| 139 |
+
|
| 140 |
+
## 3. observation 观测数据
|
| 141 |
+
|
| 142 |
+
### 3.1 rgb.mkv 与 rgb_valid.pt
|
| 143 |
+
|
| 144 |
+
RGB、深度和栅格 mask 在 shared 中统一使用 MKV 视频容器,不展开为逐帧图片或图像 tar。MANO、关键点、位姿等数值标注仍用数组;分割的重叠多边形仍用 JSONL,不为了视频化而有损栅格化。单图可为一帧视频,独立图批量封装规则见 2.2。
|
| 145 |
+
|
| 146 |
+
**无损指共享层不增加信息损失。** 源 JPEG/H.264 等本身可能已是有损编码,原样保留并不恢复已丢失信息;不得重新以有损 JPEG、H.264、H.265、AV1 参数编码。源视频/图片的色彩、位深、分辨率和几何关系不得被静默改变。RGB schema `rgb/uint8/v1` 的统一读取结果是 `[T,H,W,3] uint8`、RGB 通道,有效性仍为 `rgb_valid.pt [T] bool`。超出该 schema 的高位深或 HDR 源必须报告并扩展定义,不能降到 8 位冒充无损。
|
| 147 |
+
|
| 148 |
+
#### 3.1.1 允许的 RGB 存储 profile
|
| 149 |
+
|
| 150 |
+
| storage.profile | 编码方式 | 适用规则 |
|
| 151 |
+
|---|---|---|
|
| 152 |
+
| mkv/mjpeg_copy/v1 | 源 JPEG 压缩帧直接封装成 MJPEG/MKV | 不解码重编码;保持每张 JPEG 码流字节;普通 8 位 JPEG 且 MKV/解码器支持时使用 |
|
| 153 |
+
| mkv/source_copy/v1 | 已有视频的 RGB 对应码流直接封装为 MKV | 仅源编码能被 MKV 和选定解码器支持时使用,不伪造帧;需维持正确的呈现顺序与依赖帧 |
|
| 154 |
+
| mkv/h264_rgb_lossless/v1 | libx264rgb 的真正无损模式 | 必须 RGB 路径、CRF=0,并通过全帧 RGB 字节比较;不能替换成默认 libx264 YUV420 路径 |
|
| 155 |
+
| mkv/ffv1_rgb/v1 | FFV1 的 RGB 可逆编码路径 | 作为通用候选;解码回 RGB 后必须逐字节相同,不做色度降采样 |
|
| 156 |
+
|
| 157 |
+
优先尝试源码流直接封装;不能封装或需要选择稀疏帧时,比较 FFV1 与无损 RGB H.264。对完整待发布片段,只在通过无损验收的候选中选择文件较小者,不假设某个编码器总最小;编码时间和随机读取代价记入构建记录。中间候选不作为 shared 多份常驻。H.264 跨帧压缩允许较长 GOP,必须记录 GOP/关键帧间隔,随机取帧需从前一关键帧正确解码,不能把 seek 返回的近似帧当目标帧。
|
| 158 |
+
|
| 159 |
+
普通源视频可以保留它已有的有损码流,但不允许新增有损重编码。源是 VRS 等记录容器时,先查明图像流实际编码:已有兼容 JPEG/视频包可直接提取封装,否则解码后使用真正无损编码;不把整个 VRS 改后缀当 MKV。PNG 不要求直接塞进 MKV,可选上表两种无损重编码方式。
|
| 160 |
+
|
| 161 |
+
#### 3.1.2 视频配置与校验
|
| 162 |
+
|
| 163 |
+
每个视频组件在 metainfo 中登记 `storage`,至少包含:
|
| 164 |
+
|
| 165 |
+
| 字段 | 内容 |
|
| 166 |
+
|---|---|
|
| 167 |
+
| profile | 上述登记的存储 profile;语义仍由组件 schema_id 指定 |
|
| 168 |
+
| codec | 文件中实际 codec,例如 mjpeg、h264、ffv1;source_copy 必须写实际 codec |
|
| 169 |
+
| pixel_format | 实际编码像素格式;不得仅凭编码器参数猜测 |
|
| 170 |
+
| encoded_size | 视频物理像素尺寸 `[width,height]`;深度可能不同于逻辑尺寸,见 3.2 |
|
| 171 |
+
| decoder | 解码器名称、版本,以及颜色矩阵/范围/旋转处理等实际像素解释配置;未知的源色彩声明 unknown,不擅自称为 sRGB |
|
| 172 |
+
| encoder_parameters | 重编码时的编码器、版本、无损模式和 GOP 等参数;直接封装时记录 stream_copy |
|
| 173 |
+
| source_lossy | 源是否已有损:true / false / unknown;不是共享层再有损编码的许可 |
|
| 174 |
+
|
| 175 |
+
无损重新编码的 RGB 必须使用同一固定解码配置,比较**全部帧**的统一 RGB 字节、数量及顺序。MJPEG-copy 不重新编码,生产校验采用 `jpeg-packets-all-rgb-sample16/v1`:从 MKV 逐包取回,对全部源 JPEG 的 SHA256、数量、顺序和图像尺寸进行精确核对;每视图另用同一固定解码配置比较最多 16 帧的源与目标 RGB 字节(含首尾与四分位位置,其余由固定种子抽取)。记录策略、实际索引、种子与结果;不足 16 帧时全查。试点与最终完整序列随机抽查,对选中视图的全部帧复核解码 RGB。历史已做全帧像素检查的证明继续保留。
|
| 176 |
+
|
| 177 |
+
逐包一致与像素抽查的范围必须分别声明,不能将抽查写成全量像素检查。不能用 PSNR 高、视觉相似、编码器参数称为 lossless 等替代精确检查。同时保留源编码的色彩标记和必要元数据;原图有 EXIF/色彩/方向等元数据时保留 raw 和必要来源信息;不能静默自动旋转图像而不更新像素对应与标定。以上加速策略仅适用于原 JPEG 码流直接封装,不适用于深度、标签或重新编码的 RGB。
|
| 178 |
+
|
| 179 |
+
所有共享视频的呈现帧顺序与统一 frame_index 一一对应,每个栅格组件恰好 T 帧。MKV 的 `storage_fps` 只服务封装,声明 `timebase_role=index_only`;source_copy 可以保留源 PTS 以避免改坏码流,但真实时间与标注对齐仍以 frames 为准。未知真实时间保留 null。缺失某帧组件时保留索引位置并使用该组件的无效占位/valid 标识,不删帧;不能以重复相邻图像冒充已知观测。
|
| 180 |
+
|
| 181 |
+
### 3.2 depth.mkv 与 depth_valid.mkv
|
| 182 |
+
|
| 183 |
+
深度语义仍是 `depth/z_float32/v1`:统一读取结果 `[T,H,W] float32`,米制相机 Z 分量,`depth_type=z`。有效深度有限且大于 0,无效位置为 NaN。`depth_origin=measured/rendered/unknown` 必填,来源不明时 unknown。默认与 RGB 共用像素网格及相机参考系,不处理未注册 RGB-D。射线距离必须依据源定义转换成 z,不能只改声明。
|
| 184 |
+
|
| 185 |
+
#### 3.2.1 float32 的可逆视频编码
|
| 186 |
+
|
| 187 |
+
采用 `mkv/depth_float32_bits/v1`:**不是把深度量化成 uint16**,而是将规范化后每个 IEEE-754 float32 的完整 32 位拆成两个 uint16,使用 FFV1 gray16le 保存。视频物理尺寸为 `[2W,H]`:每行前 W 列存原 float32 位串的低 16 位,后 W 列存高 16 位。读取时先合并为 uint32 位串,再按 float32 重新解释,不能数值 cast 成 float32。
|
| 188 |
+
|
| 189 |
+
```text
|
| 190 |
+
u = reinterpret_uint32(depth_float32)
|
| 191 |
+
encoded[:, :, :W] = uint16(u & 65535)
|
| 192 |
+
encoded[:, :, W:] = uint16(u >> 16)
|
| 193 |
+
u_restored = uint32(low) | (uint32(high) << 16)
|
| 194 |
+
depth_float32 = reinterpret_float32(u_restored)
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
统一采用 little-endian 原始字节接口。`camera.image_size` 始终是逻辑 RGB 尺寸 `[W,H]`,不能改成编���视频的 2W;`storage.encoded_size=[2W,H]`。包括 NaN 在内的 float32 位串必须全帧完全恢复,不允许改成 float16、整数毫米、归一化灰度或 RGB 伪彩色。这里的无损验收基准是完成既定米制/坐标转换后的标准 float32 数组,不声称消除 float64→float32 等原约定转换本身的舍入。
|
| 198 |
+
|
| 199 |
+
#### 3.2.2 逐像素有效性
|
| 200 |
+
|
| 201 |
+
`depth_valid.mkv` 使用 `mkv/bool_ffv1/v1`,FFV1 gray8(FFmpeg pixel_format=`gray`),物理尺寸 `[W,H]`。像素只能为 0 或 1,统一解码为 `[T,H,W] bool`,逐像素含义不变。这样不再把庞大的 bool 数组保存为未压缩 `.pt`;标注的帧级/手级 valid 仍保留原有小数组。
|
| 202 |
+
|
| 203 |
+
登记示例(W、H 以下取 640、480;decoder/encoder_parameters 的实际版本由转换器填写):
|
| 204 |
+
|
| 205 |
+
```json
|
| 206 |
+
{
|
| 207 |
+
"available": true,
|
| 208 |
+
"schema_id": "depth/z_float32/v1",
|
| 209 |
+
"data_ref": "observation/depth.mkv",
|
| 210 |
+
"axes": ["T", "height", "width"],
|
| 211 |
+
"valid_ref": "observation/depth_valid.mkv",
|
| 212 |
+
"valid_axes": ["T", "height", "width"],
|
| 213 |
+
"unit": "m",
|
| 214 |
+
"depth_type": "z",
|
| 215 |
+
"depth_origin": "measured",
|
| 216 |
+
"invalid_value": "NaN",
|
| 217 |
+
"storage": {
|
| 218 |
+
"profile": "mkv/depth_float32_bits/v1",
|
| 219 |
+
"codec": "ffv1",
|
| 220 |
+
"pixel_format": "gray16le",
|
| 221 |
+
"encoded_size": [1280, 480],
|
| 222 |
+
"source_lossy": false,
|
| 223 |
+
"decoder": {"name": "ffmpeg", "version": "填写实际版本"},
|
| 224 |
+
"encoder_parameters": {"name": "ffv1", "level": 3, "version": "填写实际版本"}
|
| 225 |
+
},
|
| 226 |
+
"valid_storage": {
|
| 227 |
+
"profile": "mkv/bool_ffv1/v1",
|
| 228 |
+
"codec": "ffv1",
|
| 229 |
+
"pixel_format": "gray",
|
| 230 |
+
"encoded_size": [640, 480],
|
| 231 |
+
"source_lossy": false,
|
| 232 |
+
"decoder": {"name": "ffmpeg", "version": "填写实际版本"},
|
| 233 |
+
"encoder_parameters": {"name": "ffv1", "version": "填写实际版本"}
|
| 234 |
+
},
|
| 235 |
+
"provenance": {"kind": "format_conversion", "method": "源深度转米制 z float32;逐位打包为 FFV1"},
|
| 236 |
+
"source_locator": {"file": "raw/data/depth.zip", "member": "depth/0001.png"}
|
| 237 |
+
}
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
深度和有效性视频都必须逐帧解码验收:float32 位串相同、bool 相同、T 相同,并检查 valid=true 的正有限值和 valid=false 的 NaN。读取器必须按 profile 还原,不能把 depth.mkv 的编码像素直接当深度值。
|
| 241 |
+
|
| 242 |
+
## 4. camera 相机、帧索引与标定
|
| 243 |
+
|
| 244 |
+
### 4.1 frames.jsonl:索引、时间与对应关系
|
| 245 |
+
|
| 246 |
+
`camera/frames.jsonl` 每行对应统一帧号 `frame_index=0..T-1`,是所有组件的唯一行索引。至少包含 `frame_index`、`timestamp_ns`、`clock_domain`、`source_locator`;原始帧号/文件名保存在 `source_frame_id`,不能被新帧号替代。每行还可有 `annotation_matches`,按组件键保存 `source_frame_id`、`source_timestamp_ns`、`clock_domain`、`match_method` 和 `delta_ns`;方法为 exact/index_map/nearest/interpolated,索引映射无时间依据时 delta_ns=null。nearest 必须记录允许误差;interpolated 必须记录两端源标识和权重。delta_ns 仅在同一时间域中计算为源标注时间减图像时间。多相机共享 `sequence_id`;已知同步关系必须用 `sync_id` 或明确的源帧/时间映射表达,不能仅凭相同数组索引认定同步。
|
| 247 |
+
|
| 248 |
+
每个视图必须提供此文件。源时间使用整数纳秒及 `clock_domain`,未知写 JSON `null`;不同时间域不能直接比较。逐帧 split 可以覆盖 metainfo 的视图默认划分,并保留来源,见 2.4。
|
| 249 |
+
|
| 250 |
+
### 4.2 坐标系与标定通则
|
| 251 |
+
|
| 252 |
+
| 项目 | 统一约定 |
|
| 253 |
+
|---|---|
|
| 254 |
+
| 相机坐标 | 右手系,X 向右、Y 向下、Z 向前,长度单位米 |
|
| 255 |
+
| 齐次变换 | 列向量,`p_target = T_target_from_source @ p_source` |
|
| 256 |
+
| 图像坐标 | `(u,v)`;左上像素中心为 `(0,0)`,u 向右、v 向下,单位 pixel |
|
| 257 |
+
| 固定标定 | 本版展开为 T 份,同一 schema 不混用静态与动态形状 |
|
| 258 |
+
| 分辨率或模型变化 | 分开存储为视图/片段,不在同一组件中混装 |
|
| 259 |
+
| 未知标定 | 相机内外参允许缺省,不填单位阵冒充已知标定 |
|
| 260 |
+
|
| 261 |
+
### 4.3 intrinsic.pt 与畸变参数
|
| 262 |
+
|
| 263 |
+
| model / schema_id | intrinsic.pt 的固定结构 |
|
| 264 |
+
|---|---|
|
| 265 |
+
| pinhole / camera/pinhole/v1 | `[T,3,3]`,标准 K,最后一行为 `[0,0,1]`;限无畸变或已校正图像 |
|
| 266 |
+
| fisheye624 / camera/fisheye624/v1 | `[T,15]`,`[f,cx,cy,k0,k1,k2,k3,k4,k5,p0,p1,s0,s1,s2,s3]`,采用 Project Aria Fisheye624 投影定义 |
|
| 267 |
+
| opencv_fisheye4 / camera/opencv_fisheye4/v1 | `intrinsic.pt [T,3,3]` 保存 K;同组件 `distortion_ref` 指向 `[T,4]`,顺序 `[k1,k2,k3,k4]`,使用 OpenCV fisheye 等距角度多项式;已由 ReInterHand 实际原始相机参数验证 |
|
| 268 |
+
| rational8 / camera/rational8/v1 | `intrinsic.pt [T,3,3]` 保存 K;同组件必需 `distortion_ref` 指向 `[T,8]`,顺序 `[k1,k2,p1,p2,k3,k4,k5,k6]` |
|
| 269 |
+
| unknown / null | 不提供可用 intrinsic,不声称可以投影 |
|
| 270 |
+
|
| 271 |
+
有畸变的其他模型必须注册新 schema,固定参数名、顺序和投影公式;不能塞进针孔 K 后遗失畸变项。`metainfo.camera.schema_id` 必须与 intrinsic 组件一致。同一模型的别名不可隐式改变参数布局。
|
| 272 |
+
|
| 273 |
+
`opencv_fisheye4`:对前方点令 `x=X/Z, y=Y/Z, r=sqrt(x²+y²), theta=atan(r)`,`theta_d=theta*(1+k1*theta²+k2*theta⁴+k3*theta⁶+k4*theta⁸)`;`u=fx*x*theta_d/r+cx, v=fy*y*theta_d/r+cy`。光轴 r=0 时使用连续极限 `theta_d/r=1`。四系数不能按普通径向畸变解释,也不能补零冒充 Fisheye624。
|
| 274 |
+
|
| 275 |
+
rational8 对归一化坐标 x=X/Z、y=Y/Z,令 r²=x²+y²,径向项为 `(1+k1*r²+k2*r⁴+k3*r⁶)/(1+k4*r²+k5*r⁴+k6*r⁶)`;再加 p1/p2 切向项并经 K 得到像素。`distortion_ref` 与 intrinsic 共用 `[T]` valid,保存到 camera/distortion.pt。不得把这种畸变三维坐标当作真实相机系 xyz 保存。
|
| 276 |
+
|
| 277 |
+
内参有效性为 `intrinsic_valid.pt [T] bool`;有畸变时使用对应 `distortion_ref`。同一模型的参数名和顺序固定。
|
| 278 |
+
|
| 279 |
+
### 4.4 extrinsic.pt 与 extrinsic_valid.pt
|
| 280 |
+
|
| 281 |
+
`extrinsic.pt` 为 `[T,4,4]`,schema `transform/se3/v1`,方向固定 `T_camera_from_world`,有效性 `[T]`。世界坐标含义及源坐标转换记录在 provenance 中;只有相机坐标标注不要求虚构世界坐标。旋转块须正交且 determinant≈1。
|
| 282 |
+
|
| 283 |
+
## 5. annotation 标注数据
|
| 284 |
+
|
| 285 |
+
### 5.1 标注通则:手槽、valid 与 visibility
|
| 286 |
+
|
| 287 |
+
手槽固定为 0=left、1=right,指解剖学左右,不按画面位置或可见性重排。本阶段只处理左右手两槽,不处理更多手。实体引用使用 `hand_left`、`hand_right`;手槽不证明跨采集片段的个人身份。
|
| 288 |
+
|
| 289 |
+
#### 5.1.1 valid:标注是否可用于监督
|
| 290 |
+
|
| 291 |
+
标注的 `valid=true` 表示:有对应实际标注、通过本 schema 数值检查,且通过来源明确提供并适用于该组件的有效性/QA 条件。`valid=false` 可由缺标注、无法建立帧对应、源无效占位或官方 QA 不通过导致;不等于画面没有手或手不可见。各组件独立判断,MANO 按 `[T,2]` 标记左右手,关键点按 `[T,2,K]` 标记。
|
| 292 |
+
|
| 293 |
+
**2026-09-20 将标注 valid 从“仅表示存在”修订为“可用于监督”,字段形状不变。** 公式为 `source_annotation_present AND numerical_checks_pass AND applicable_official_QA_pass`。没有官方 QA 时省略最后一项,不伪造 QA;不能把未知当成已通过已存在的 QA。适配器在组件 `valid_policy` 中记录具体规则、来源、聚合/广播作用域。缺失官方必需 QA 的记录须明确处理为未知或暂停验收,不能静默通过。无效浮点项仍填 NaN,原始数据保留在 raw;被排除原值可用于 doc 中明确标识的诊断渲染,不能冒充 shared 有效监督。
|
| 294 |
+
|
| 295 |
+
本地筛选须依据明确的规则,并在 `valid_policy.local_excluded_frame_indices`、排除原因和正式报告中记录。单个可疑投影作为问题记录,不直接硬编码排除该帧。已确认的曝光异常须明确作用范围,不能把一个序列的“前两帧有问题”套到所有序列。RGB 编码完好与几何监督可用是两件事,允许保留原图及帧索引而屏蔽对应标注;未发现问题不等于完成全部人工审核,试点待确认时不能作为已验收发布使用。
|
| 296 |
+
|
| 297 |
+
源字段必须按官方语义映射,不能直接按名字复制:
|
| 298 |
+
|
| 299 |
+
| 来源 | 官方含义 | 映射原则 |
|
| 300 |
+
|---|---|---|
|
| 301 |
+
| [H2O](https://github.com/taeinkwon/h2odataset) 的手标注首位 | 0 未标注、1 已标注 | 可作为对应手标注存在性的依据,不推断未标注原因 |
|
| 302 |
+
| [HOT3D](https://github.com/facebookresearch/hot3d#using-mask-files) 的 pose_available、visible、mask_qa_pass | 分别表达姿态存在、可见性、对画面中可见手物位姿的人工 QA | 逐手/物体记录决定存在性,再 AND 当前相机当前帧 QA;QA 是整帧聚合判定,保守排除该帧全部手物几何监督,不声称每个实体均有错误;源可见性基于位姿推导时,其自身 valid 同样受 QA 约束 |
|
| 303 |
+
| [Dex-YCB](https://github.com/NVlabs/dex-ycb-toolkit#loading-dataset-and-visualizing-samples) 的全零 pose_m、全 -1 joints | 不可见的手或缺标注共用占位表示 | 对应组件 valid=false;不能从该值判定 visibility=false,也不能声称原因是动捕缺失 |
|
| 304 |
+
| [ARCTIC](https://github.com/zc-alexfan/arctic/blob/master/docs/data/data_doc.md) 的 is_valid/left_valid/right_valid | 是否有效用于官方评估 | 核实每项筛选依据;不把可见性/评估选择直接等同 QA。本次原始 mano.npy 不含这些派生评估标记,按原记录与数值检查生成 valid,并声明没有额外官方 QA 输入 |
|
| 305 |
+
|
| 306 |
+
源 valid=false 若代表评估筛选或其他条件,应检查实际标注和源约定后映射;不能一律清空坐标。反之,占位零或 -1 只有在源官方明确规定时才判为缺失,不泛化成所有数据的判断规则。
|
| 307 |
+
|
| 308 |
+
`valid=true` 的标注应通过其 schema 的数值与形状检查;检查失败必须报告或修复,不能静默隐藏。QA 不通过应报告排除数量与原因,并保留可追溯信息;不能把这类无效称为缺标注。RGB、深度等观测有效性仍按各自 schema;手物 QA 不自动否定 RGB、静态相机内参或物体资产。相机外参是否过滤须依据其自身来源规则;HOT3D 本次保留源外参用于溯源和诊断,不能用其存在性证明 QA 失败帧的几何监督正确。
|
| 309 |
+
|
| 310 |
+
#### 5.1.2 visibility:可见性属性
|
| 311 |
+
|
| 312 |
+
附加质量属性只保留 `visibility`,存放在对应模态或标注集内,不设 quality 目录。同一份可见性仅存一次;uv 与 xyz 共用时引用同一个文件。
|
| 313 |
+
|
| 314 |
+
visibility 通过所属组件 attributes 登记 data_ref、axes、dtype、visibility_type、meaning、provenance、source_locator;未知值通过属性 valid_ref 标识,全已知可声明 valid=true。比例与布尔值不相互强转,也不按任意阈值二值化。没有 MANO 时,整手可见性挂在 keypoints 组件,使用独立的 whole_hand_visibility.pt,明确 meaning=whole_hand,不与逐关键点可见性混用。
|
| 315 |
+
|
| 316 |
+
`valid` 回答“这项标注能否用于监督”,`visibility` 回答“在当前图像中是否可见(或可见多少)”。不可见的手或关键点仍可有有效标注;不能因 visibility=0 就清空坐标。源没有 visibility 时缺省或标为未知,不由 valid 推断。
|
| 317 |
+
|
| 318 |
+
| 情况 | 手标注 valid | visibility |
|
| 319 |
+
|---|---|---|
|
| 320 |
+
| RGB 已开始录制,动捕尚未开始,没有其他对应手标注 | false | 以独立源可见性标注为准;没有则未知 |
|
| 321 |
+
| 手被遮挡,但源有标注且通过适用有效性检查 | true | 若源声明不可见,则 false 或源可见比例 |
|
| 322 |
+
| 手可见且有对应标注,通过适用 QA | true | 若源有此信息,则 true 或源可见比例 |
|
| 323 |
+
| 手可见,但该帧漏标或动捕中断 | false | 可以为 true,但必须有独立来源依据 |
|
| 324 |
+
| 有手部参数,但官方 QA 明确不通过 | false | 不据此断言不可见;源可见比例若基于不可靠位姿,其属性 valid 也为 false |
|
| 325 |
+
|
| 326 |
+
visibility 自己的 valid_ref 表示该可见性标注是否可用,不复用 MANO 或关键点坐标的 valid_ref;明确记录源存在性及适用的 QA 条件。上述例子不要求凭图像自动生成可见性。
|
| 327 |
+
|
| 328 |
+
不设 quality 组件或目录,不另存拟合误差、曝光、截断比例等通用质量数组。适用的官方 QA 合并进对应 valid,在 `valid_policy` 记录来源与规则;正式校验报告保留原始 QA 时间区间及排除统计。原始 QA 文件仍在 raw,官方 split 保留。
|
| 329 |
+
|
| 330 |
+
### 5.2 mano:参数与整手可见性
|
| 331 |
+
|
| 332 |
+
MANO schema `mano/axis_angle61/v1`:`motion.pt [T,2,61]`,顺序为完整 16 关节 axis-angle 48、shape betas 10、全局平移 3。姿态使用弧度,平移米,位于当前相机系。有效性 `[T,2]`;缺少一侧整槽 NaN。PCA 必须先按对应模型展开,不能将 PCA 系数直接填入 axis-angle。
|
| 333 |
+
|
| 334 |
+
`model_profile` 必须固定 MANO 版本、`flat_hand_mean=true`、左手 shapedirs 修正状态。平移表示模型输出顶点所加的全局平移,不是某个腕关节的坐标;源语义不同须转换。shape 无量纲。模型权重不作为共享数据附带上传。
|
| 335 |
+
|
| 336 |
+
`mano/visibility.pt [T,2]` 保存源整手可见比例时使用 float32 [0,1],`visibility_type=ratio`;只有实际采用 0–100 的百分比才除以100,不能只凭表头判断。HOT3D 的 `visibility_ratio[%]` 实值已经是0–1,官方读取器原样读取,必须保留原值。通过 MANO 组件 attributes 登记,使用独立有效性,不复用 motion_valid。
|
| 337 |
+
|
| 338 |
+
手部共享表示仅保留 MANO 参数与选定关键点,不发布独立手表面几何。需要渲染或接触计算时由 MANO 参数生成,几何引用使用固定 MANO 模型配置与顶点顺序;不影响 object 下的物体模型和材质资产。
|
| 339 |
+
|
| 340 |
+
### 5.3 keypoints:二维点、三维点与逐点可见性
|
| 341 |
+
|
| 342 |
+
关键点独立于 MANO 参数存在;没有 motion 也可有关键点。`uv.pt [T,2,K,2]` 与 `xyz.pt [T,2,K,3]`,有效性 `[T,2,K]`,分别采用 `keypoints/uv/v1` 和 `keypoints/xyz/v1`。K 由 `keypoint_schema` 固定,不能在同一数组中逐帧变化;同体系统一顺序。数值使用像素坐标或米制相机系。
|
| 343 |
+
|
| 344 |
+
| keypoint_schema | K 与固定索引 |
|
| 345 |
+
|---|---|
|
| 346 |
+
| mano21/v1 | 21;wrist 后依次 thumb/index/middle/ring/little,每指由近端至指尖 |
|
| 347 |
+
| rhd21/v1 | 21;保持 wrist,然后五指由近端至指尖;原始每指 tip→palm 反序。只统一顺序,不宣称解剖学位置等价于 MANO |
|
| 348 |
+
|
| 349 |
+
具体名称与源索引映射见 `schema.json`。当前只登记 MANO21 与 RHD21;不登记 MediaPipe、ReInterHand capture21 或 fit24 中间关键点。
|
| 350 |
+
|
| 351 |
+
每个发布中的每个视图只提供一套标准手关键点,直接放在 keypoints 下,不设 annotation_set_id 字段或目录。uv 与 xyz 是这套关键点的二维与三维表示,不是两套标注。provenance 分别记录二者来自原始标注还是计算结果;不要求已有 2D 必须由当前 xyz 重新投影覆盖。
|
| 352 |
+
|
| 353 |
+
ReInterHand 的 Original keypoints���Original fits keypoints 及带前臂关键点不纳入 shared;如需手关键点,从选定 MANO 参数生成 MANO21 并记录模型/指尖回归约定。其他数据集默认使用选定的官方关键点,不额外生成平行的 MANO 派生集合。后续主动更换生成方法或结果时发布新的 dataset_version,不在同一版本内增设方法分支。
|
| 354 |
+
|
| 355 |
+
manual/projection/fitting 只记录在 provenance,不作为目录或类型分支。不得通过坐标为零、是否出画或 visibility 判断标注是否存在。派生标注仅在实际生成并通过数值检查后声明 valid=true;没有生成的项为 false,不伪造坐标。
|
| 356 |
+
|
| 357 |
+
`keypoints/visibility.pt [T,2,K]` 保存源逐点可见性,布尔表示使用 `visibility_type=boolean`。uv 与 xyz 共用时引用同一份文件。整手比例属性没有 MANO 可挂载时使用 `whole_hand_visibility.pt [T,2]`,`meaning=whole_hand`;它与逐点可见性分开,通用登记规则见 5.1。
|
| 358 |
+
|
| 359 |
+
不使用 annotation_set_id;ReInterHand 中间关键点集合不进入 shared,raw 保留来源文件。
|
| 360 |
+
|
| 361 |
+
### 5.4 object:身份、资产、位姿与几何
|
| 362 |
+
|
| 363 |
+
#### 5.4.1 metainfo.json:物体身份与跟踪作用域
|
| 364 |
+
|
| 365 |
+
手用 `hand_left`、`hand_right` 及槽位 0、1 表示,不再另存 entities.json。物体身份登记在 `annotation/object/<object_id>/metainfo.json`,必填 `object_id`、`identity_scope`、`scope_id`、`source_locator`;可含 `category_id`、`source_object_id`、`mesh_ref`、`has_model`、部件引用。即使只有分割、没有 pose/mesh,也可只有这份物体元信息。
|
| 366 |
+
|
| 367 |
+
`identity_scope` 为 frame/subsequence/sequence,`scope_id` 指定具体作用域;跨相机共享身份只在已有源对应证据时使用。VISOR 按官方 subsequence 与实体名关联时记录 `association_basis=official_subsequence_entity_name`,不能声称这是全视频物理实例跟踪。无需与 object_id 一一对应的标准 track_id;官方独立轨迹标识存在时保留为 source_track_id,并声明作用域。手槽不证明跨采集片段的个人身份。
|
| 368 |
+
|
| 369 |
+
#### 5.4.2 assets:网格、材质与纹理
|
| 370 |
+
|
| 371 |
+
资产属于物体,统一存放在 `annotation/object/<object_id>/` 内,可用 `assets/` 子目录组织网格、材质、纹理和部件资产。序列层不设共享 assets。所有引用采用视图根目录为基准;其中物体资产组件的 `data_ref` 与部件的 `mesh_ref` 采用相对于当前视图目录的 POSIX 路径,例如 `annotation/object/cup_01/assets/cup.obj`,且必须指向所属物体目录内的资产。OBJ 内部的材质、纹理引用遵循文件格式自身的相对路径规则,依赖文件一并保留。不同相机视图允许各自保存物体资产,不要求跨视图去重;下载物体时包含其资产依赖。
|
| 372 |
+
|
| 373 |
+
网格 schema 为 `mesh/obj/v1`,顶点米制,静态有效性可直接声明标量 `valid`,或通过 `valid_ref` 指向标量 bool Tensor;不按 T 重复静态资产。由物体/部件通过引用关联,不仅凭文件名猜测。
|
| 374 |
+
|
| 375 |
+
#### 5.4.3 pose.pt、pose_valid.pt 与 visibility.pt
|
| 376 |
+
|
| 377 |
+
刚体 schema 为 `object/rigid/v1`,`pose.pt [T,4,4]` 固定为 `T_camera_from_object`,平移米制,有效性 `[T]`。物体坐标原点、轴向必须与 mesh 一致;旋转块为正交矩阵且 determinant≈1。
|
| 378 |
+
|
| 379 |
+
`object/<id>/visibility.pt [T]` 保存源物体可见比例,float32 [0,1],`visibility_type=ratio`。通过所属物体组件 attributes 登记,独立表达其有效性。
|
| 380 |
+
|
| 381 |
+
#### 5.4.4 articulation.json、部件位姿与 joint_state.pt
|
| 382 |
+
|
| 383 |
+
关节物体:schema `object/articulated/v1`,`articulation.json` 登记 `parts` 与 `joints`。每个 part 有 `part_id`、`parent_id`(根为 null)、`has_model`、`mesh_ref`;has_model=false 时 mesh_ref=null,结构节点允许没有网格。父链不得成环。每个 joint 有唯一 `joint_id`、`parent_part`、`child_part`、`type`;fixed 单位 null、revolute 弧度、prismatic 米。有源限位时保存 `limits:[lower,upper]`;没有时 null,不伪造上下限。部件姿态统一为 `T_camera_from_part [T,4,4]`,不与父局部变换混装。
|
| 384 |
+
|
| 385 |
+
若提供 `joint_state.pt [T,J]`,必须登记固定 joint_order、轴在父部件系的表达、零位变换与正方向,valid 为 `[T,J]`;缺少这些运动学定义时只发布部件位姿与已有来源信息,不伪造可驱动的关节模型。关节值与部件位姿同时存在时需验证一致性。
|
| 386 |
+
|
| 387 |
+
部件层级应声明语义:纯语义包含树允许 `joints=[]`,不将包含关系推断为机械关节。关节状态 schema 为 `object/joint_state/v1`;转动用弧度、移动用米,混合类型按 joint_order 对应的关节定义解释。
|
| 388 |
+
|
| 389 |
+
#### 5.4.5 dimensions、几何关键点与顶点部件标签
|
| 390 |
+
|
| 391 |
+
`dimensions.pt [T,3]` 采用 `object/dimensions/v1`,有效性为 `[T]`。
|
| 392 |
+
|
| 393 |
+
物体/部件 `dimensions` 为 `[length,width,height]` 米,轴顺序与该 mesh 的局部坐标关联,登记 `dimensions_semantics` 和来源。HOI4D dimensions 与 mesh 的具体尺度关���未验证前标为 source_unspecified,保留源值并暂停依赖该关系的几何验收,不能默认为待施加缩放。需要施加缩放时明确 scale_applied_to_mesh,禁止重复应用。
|
| 394 |
+
|
| 395 |
+
源物体关键点放 `object/<id>/keypoints/xyz.pt [T,K,3]`(相机系)或 `template_xyz.pt [K,3]`(物体系),schema 分别为 object_keypoints/camera/v1 和 object_keypoints/template/v1。明确 keypoint_schema、keypoint_names、单位及有效性;模板点配合 pose 可投影,无须重复生成全部帧。H2O 中心/角点/棱中点,以及 ARCTIC 部件点分别登记具体源顺序,不套用手的 21 点 schema。每个发布选择一套源几何点并记录选择,不另建方法分支。
|
| 396 |
+
|
| 397 |
+
`vertex_part_ids.pt [V] int64` 绑定 `mesh_ref` 与 topology_id,登记整数到 part_id 的映射;未知用 -1。ARCTIC 不同拓扑的资产分别绑定,不能共用未经转换的顶点标签。部件层级中 is_instance/has_model 等源属性保留,几何文件仍全部归 object。
|
| 398 |
+
|
| 399 |
+
### 5.5 segment:分割类别、编码与覆盖范围
|
| 400 |
+
|
| 401 |
+
每个发布选择一套任务使用的分割表示,不建立方法/标注集分支。没有分割就不创建 segment 目录,不为其他模态创建空的实体表。
|
| 402 |
+
|
| 403 |
+
| schema_id | 文件与数值语义 |
|
| 404 |
+
|---|---|
|
| 405 |
+
| segment/uint16_labels/v1 | mask.mkv;整数区域编号,通过 instances.jsonl 解释 |
|
| 406 |
+
| segment/instance_polygons/v1 | polygons.jsonl;实例多边形,可重叠;当前不支持孔洞拓扑 |
|
| 407 |
+
| segment/foreground_intensity/v1 | mask.mkv;0–255 前景强度,不是区域编号或经过校准的概率 |
|
| 408 |
+
|
| 409 |
+
#### 5.5.1 uint16 标签图与 instances.jsonl
|
| 410 |
+
|
| 411 |
+
组件声明 `segmentation_type=semantic/instance/part`;同一组件固定一种类型。`mask.mkv` 解码为 `[T,H,W] uint16`,schema `segment/uint16_labels/v1`,使用 `mkv/uint16_ffv1/v1`,FFV1 gray16le 无损;只有所有区域编码均 ≤255 时允许 gray8(pixel_format=gray),读取后转 uint16,数值不变。禁止调色板和有损编码。有效性 `[T]`,表示该帧有可用分割标注。数值 0 固定为 unassigned,65535 固定为 ignore,1–65534 为区域编码,不能直接等同 entity_id。
|
| 412 |
+
|
| 413 |
+
`instances.jsonl` 每帧一行,包含 `frame_index` 与 `labels`。每条标签包含 `mask_value`、`category_id`、`entity_id`、`part_id`;无意义或未知字段为 null。semantic 允许 entity_id=null;instance 必须引用 hand_left/hand_right 或登记的 object_id;part 还须关联登记部件。源实例 ID 和其他属性分别保存在 `source_instance_id`、`source_attributes`。mask 中每个非保留编码必须有且仅有一个映射。
|
| 414 |
+
|
| 415 |
+
FreiHAND 的试点按本任务需要,统一到手/背景类别,保留每个原生区域编码;不要求给原生细分区域猜测手指名称。需要细部件监督时,尚未核实的部件名称必须保持未知,不能因粗粒度手类别已核实便声称部件语义也已统一。
|
| 416 |
+
|
| 417 |
+
#### 5.5.2 重叠实例多边形
|
| 418 |
+
|
| 419 |
+
每发布选择一套任务使用的分割表示,不建立方法/标注集分支。VISOR 的实际试点存在重叠实例多边形,单层标签图不能无损表达。对此补充 `segment/instance_polygons/v1`:`segment/polygons.jsonl` 每帧包含 `frame_index` 和 `instances`,每实例包含 `mask_value` 与 `polygons`(列表,每个多边形为源图像像素坐标顶点序列,保留原始精度)。身份和类别仍由同一 `instances.jsonl` 映射,有效性仍为 `[T]`,通过 schema 区分物理编码。允许多实例重叠,不采用后画覆盖前画。消费者按需栅格化为独立实例二值 mask;不能声称合并的单层 mask 无损。
|
| 420 |
+
|
| 421 |
+
#### 5.5.3 灰度前景强度
|
| 422 |
+
|
| 423 |
+
ReInterHand 的官方渲染 mask 为双手合并的灰度前景掩码,实测存在 0–255 的中间值,不是左右手实例编号。登记 `segment/foreground_intensity/v1`:仍存 `segment/mask.mkv`,解码为 `[T,H,W] uint16`,使用 `mkv/uint16_ffv1/v1`,此类数据优先编码为 FFV1 gray8(pixel_format=gray),读取后转 uint16。有效值范围 0–255,归一化值为 `float32(value)/255`;0 为背景端点、255 为前景端点。组件声明 `foreground_category=hand`、`entity_id=null` 和双手合并语义,不使用区域编号映射。这里保留原始渲染 mask 强度,不把它称为经过校准的概率。若任务需要二值 mask,阈值化属于任务层派生操作,记录阈值;共享层不丢弃中间灰度。不同 schema 的数值含义不同,不能将该文件按整数类别图解码。
|
| 424 |
+
|
| 425 |
+
FreiHAND 训练集的 JPEG mask 使用 `segment/foreground_intensity/v1`,逐像素保留 JPEG 解码后的灰度,`entity_id=hand_right`。该 schema 不限定双手合并:单手或合并范围由 `entity_id` 与 `coverage` 明确声明。评估集整数区域图仍用 `segment/uint16_labels/v1`,两者不能仅凭文件名使用同一种解码语义。
|
| 426 |
+
|
| 427 |
+
#### 5.5.4 coverage 与有效性
|
| 428 |
+
|
| 429 |
+
`coverage.kind=full/selected_entities/partial/unknown`。full 指声明���标注范围完整;selected_entities 还应列出目标范围。无论哪种,0 本身不自动成为背景;背景要有明确类别映射,未标注区域不能用于构造负样本。保留源逐类/逐实例 exhaustive 信息,未知不可改写为完整。
|
| 430 |
+
|
| 431 |
+
三种表示的帧级有效性均为 `[T]`,表示该帧是否提供此分割标注;对应 valid_ref 在组件中登记,仍用小型 bool `.pt` 数组。栅格 mask 必须登记 storage,格式见 3.1.2,所有帧的整数编码或强度逐值完全相同。编码语义由 schema_id 决定,读取器不能仅依据 mask.mkv 文件名选择解码方式。
|
| 432 |
+
|
| 433 |
+
### 5.6 contact:接触、抓取、区域与距离
|
| 434 |
+
|
| 435 |
+
#### 5.6.1 relations.jsonl 与 relations_valid.pt
|
| 436 |
+
|
| 437 |
+
`annotation/contact/relations.jsonl`,schema contact/relations/v1,每帧一行含 frame_index、relations。每条记录含 relation_type(contact/grasp)、subject_id(手槽或登记实体)、object_id、status、source_locator、provenance。status 固定为 positive/negative/unknown/target_unannotated:positive 必须有可解析目标,negative 表示源明确否定该关系,unknown 为不确定,target_unannotated 为确有接触但目标未标注。非 positive 的 object_id 可 null,不能用 null 冒充“不接触”。稀疏源无记录的帧不自动补 negative。
|
| 438 |
+
|
| 439 |
+
VISOR 的对象 mask ID 必须先按同帧 source_instance_id 解析成 object_id;hand-not-in-contact、none-of-the-above、inconclusive 分别映射 negative、target_unannotated、unknown,保留原始字符串。Dex ycb_grasp_ind 通过 ycb_ids 映射到登记物体,以 relation_type=grasp 保存;不得当作逐顶点接触。
|
| 440 |
+
|
| 441 |
+
relations 组件的 valid_ref 指向 `relations_valid.pt [T] bool`,表示该帧是否有可用源关系标注。有效帧中可以存在 status=unknown 的明确不确定标注;无源标注的帧为 valid=false、relations=[]。组件仍声明 available/provenance/source_locator。
|
| 442 |
+
|
| 443 |
+
#### 5.6.2 实体对的顶点区域与距离
|
| 444 |
+
|
| 445 |
+
已发布的接触区域/距离按参与关系的 subject_id 与 object_id 组织,每对实体保留选定的一套结果,以精确 geometry_ref/topology_id 关联到手或物体/部件;不要求每套数据都有。顶点区域 schema contact/vertex_region/v1:bool `[T,V]` 加同形 valid;顶点距离 schema contact/vertex_distance/v1:float32 `[T,V]`、米、同形 valid,声明 source/target geometry_ref、distance_definition(signed/unsigned、测量到点集或表面等明确源定义)。geometry_ref 必须指向已登记 mesh 或由固定 MANO 模型配置确定的拓扑;拓扑/顶点数变化时按拓扑拆分片段。其他源区域表示只有在实际接入并登记 schema 后才可转换,不能随意栅格化宣称等价。
|
| 446 |
+
|
| 447 |
+
顶点区域/距离已有存储定义,但尚未完成真实输入试点;接入时必须提供源语义与几何验收证据,不因已经登记 schema 就视为通过。
|
| 448 |
+
|
| 449 |
+
## 附录:任务范围
|
| 450 |
+
|
| 451 |
+
不强制收录 2D bbox、完整高频动捕、动作程序、身体 SMPL-X、点云或网络特征。范围内的接触、visibility、选定手关键点、物体几何不能因不便处理而静默丢弃。分割采用的物理编码由第 5.5 节决定,存在重叠时不能以单层标签图声称无损。
|
| 452 |
+
|
| 453 |
+
不设置 entities_ref/segment/entities.json,不要求与 object_id 重复的 track_id。MediaPipe 不在当前关键点定义中;旧版本迁移必须保留可追溯关系,不能直接删表。手部共享表示不含独立 hand_mesh。
|
| 454 |
+
|
| 455 |
+
schema.json 是普通注册表,不是 JSON Schema 文档或可执行验收器;定义存在不代表真实数据已验证。验收须保留实测范围与未决项。
|
| 456 |
+
|
| 457 |
+
本存储约定只更新标准,不代表既有 FFV1/depth.pt 试点已迁移。新发布必须显式写 storage 配置;旧产物按其旧定义读取,不能只改文件后缀或版本标识伪装为合规。
|
H2O/shared-v1.0/script/provenance/previous-run/docs/h2o-RAW_TO_SHARED.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# H2O raw → shared-v1.0
|
| 2 |
+
|
| 3 |
+
## 范围与来源
|
| 4 |
+
|
| 5 |
+
本版本仅转换 `raw/data/subject{1,2,3,4}_v1_1.tar.gz` 的真实五视角 (`cam0`–`cam4`) 序列;`h2o_CASA.tar` 是单独的扩展,不与标准序列混合。每个原始序列存于 `data/subjectN_<scene>_<sequence>/cam{0..4}/`。源压缩包保持不变,不合成源不存在的标注。输出仅在本地制作;完整序列试点及人工检查通过、更新全量预估之前,不启动全量。
|
| 6 |
+
|
| 7 |
+
| 源包/字段 | shared 文件/处理 |
|
| 8 |
+
| --- | --- |
|
| 9 |
+
| `subjectN_v1_1.tar.gz`: `camX/rgb/<frame>.png` | `observation/rgb.mkv`:逐帧源 RGB 解码为 RGB24,FFV1 直接编码;输出**每帧**解码与源 RGB 字节摘要完全一致。`rgb_valid.pt` 记录存在性,源帧号和每组件的包成员及 SHA256 写入 `camera/frames.jsonl`。不再额外编码未采用的 H.264 RGB 候选;FFV1 编码器进程失败时才尝试 H.264。 |
|
| 10 |
+
| 同包 `camX/depth/<frame>.png` | `observation/depth.mkv` 和 `depth_valid.mkv`;按源毫米单位除以 1000 转米,保留无效深度与全帧时间轴,深度位串以 FFV1 保真封装并逐帧校验。既不做 3 米裁剪也不造出缺失的深度。 |
|
| 11 |
+
| `camX/cam_intrinsics.txt`、`camX/cam_pose/<frame>.txt` | `camera/intrinsic.pt`、`extrinsic.pt`:保留源内参;逐帧源 `T_world_from_camera` 求逆后存 `T_camera_from_world`;声明变换约定与有效性。 |
|
| 12 |
+
| `camX/hand_pose_mano/<frame>.txt` | `annotation/mano/motion.pt`、`motion_valid.pt`:源左/右手标志各自判断有效性;姿态与平移保持源数值,声明 MANO 模型配置,缺模型则明确标依赖缺失,不伪造网格或掩码。 |
|
| 13 |
+
| `camX/hand_pose/<frame>.txt` | `annotation/keypoints/xyz.pt`、`xyz_valid.pt`:源双手 21 点,相机坐标系米制,与 MANO 有效性彼此独立。HTML 中的投影仅用于人工预览,不写回训练数据。 |
|
| 14 |
+
| `camX/obj_pose/<frame>.txt`、`obj_pose_rt/<frame>.txt` | `annotation/object/<name>/keypoints/xyz.pt`、`pose.pt`:按源类号关联 21 个物体点及物体→相机位姿;仅源存在时登记组件及有效性。 |
|
| 15 |
+
| `object.zip` | `annotation/object/<name>/assets/` 与源 OBJ、MTL、纹理;静态形状预览不等于所有帧网格位姿的投影证明。 |
|
| 16 |
+
| `label_split.zip` 的 `action_{train,val,test}.txt` | 序列元数据的官方划分及来源;未知映射明确记 `unknown`,不自行编排。 |
|
| 17 |
+
|
| 18 |
+
`cam4` 是 ego,`cam0`–`cam3` 是 exo。真实时间/FPS 缺乏可靠来源时使用 null,不把 MKV 封装帧率冒充采集时钟。源 `action_label`、`verb_label`、pose 任务帧列表和 `manolabel_v1.1.tar.gz` 保留在 raw;当前契约没有相应动作组件,本发布不宣称它们已转换。源没有像素分割,本版本不投影网格生成替代分割。
|
| 19 |
+
|
| 20 |
+
## 源资产文件名修复
|
| 21 |
+
|
| 22 |
+
源 `object/cocoa/cocoa.obj` 引用 `ovomaltine.mtl`,材质内写的是 `map_Kd cocoa.png`,但原 ZIP 只提供 `ovomaltine.png`。仅在临时解压目录为该已确认的纹理增加**字节相同**的 `cocoa.png` 别名,保留原 PNG、OBJ、MTL 不变;在网格 `source_locator.texture_aliases` 中记录别名、原始包成员和 SHA256。别名与已保留的旧 cocoa 资产一致,不替换图像、标注或网格。全部八类物体的材质依赖在读取大 subject 包之前预检,其他缺失/越界依赖仍报错。
|
| 23 |
+
|
| 24 |
+
## 加速与验收
|
| 25 |
+
|
| 26 |
+
四个互不依赖的 subject 压缩包可由 `--workers 1..4` 并行顺序读取,各 worker 一次只处理一个序列。数值库保持单线程;FFV1 编码支持 `--codec-threads 1|2|4|8|10`,当前全量按用户要求使用 10;`--decode-threads 10` 通过现有 `HAND_WAREHOUSE_FFMPEG_THREADS` 控制源 RGB PNG→RGB24、完整视频解码摘要、深度/有效性语义校验与 RGB 索引抽取的解码线程,完整校验仍保留。深度 PNG 使用 `--depth-threads 4` 有序分批读取,每批最多读取 4 帧,避免缓存整条序列,缺帧仍按原时间轴写 NaN;不并行改写姿态、标注或原始包。并发数由相同输入实测吞吐量决定,记录 OS 线程峰值和磁盘占用,不以 CPU 线程数本身作为提速证据。RGB 源为 PNG,不适用 ARCTIC/HOT3D 的 JPEG 包直封和 16 帧抽查:RGB、深度、有效性与数值模态仍逐帧精确校验。临时文件在 `/data` 上隔离放置,历史 62 条目录不复用、不覆盖;调整并发时,在新的运行目录复用本次全量已经原子发布的完整序列,并从源重新核对帧号及逐组件 SHA256;已发布视图只读源包并核对摘要,不再把源 PNG/标注写入临时目录,待转换视图才正常暂存。未完成的临时序列不复用,原运行的脚本、配置及 QC 保留用于溯源。
|
| 27 |
+
|
| 28 |
+
先运行不截帧的代表性完整序列试点,保存自动 QC、真实耗时和 `doc/validation/index.html`(RGB、深度、源 3D 关键点投影、原生物体网格和全组件数值/有效性)。试点由人工核查之后再决定全量;全量后再次抽样人工核查。报告须区分数据完整性、源未提供的模态与仅供人工判断的几何对齐。
|
| 29 |
+
|
| 30 |
+
2026-09-29 完整序列试点已获人工确认,用户已授权本地全量。2026-09-30 用户取消 CPU 使用量上限,指定 4 个独立压缩包 worker、每个 FFV1 编码器 10 线程、每个校验解码器 10 线程、每 worker 深度 PNG 读取 4 线程;Python worker、读取及校验子进程不计入这最多 40 个编码线程,因此总线程数不固定为 40。该配置不代表已证明加速倍数。源包和旧产物保留;代码变化使用独立运行目录,已完成序列保留原始构建记录及生产脚本快照。
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
## 多线程解码测速(2026-09-30)
|
| 34 |
+
|
| 35 |
+
在 101 上以真实 `subject4/h1/0/cam0` 的完整 RGB、深度和有效性视频,以及源头 100 帧 PNG 测试;采用 1、10、10、1 的解码线程顺序,源深度 PNG 另比较 1/2/4 线程。逐字节摘要和输出长度必须相同,测速脚本、全部轮次及结果保存在 `script/provenance/operations/` 和 `doc/validation/`。测速期间旧全量任务仍运行,磁盘负载和缓存会影响结果;不得将阶段加速比冒充整套转换加速比。四个 gzip 包已经独立并行读取,暂不引入多进程重构或增加数值库线程;小矩阵及标注处理没有已测得的进一步并行收益。
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
本次同输入结果(解码后长度和 SHA256 全部相同):
|
| 39 |
+
|
| 40 |
+
| 阶段 | 1 线程(秒) | 新配置(秒) | 范围 |
|
| 41 |
+
| --- | ---: | ---: | --- |
|
| 42 |
+
| FFV1 RGB 解码与摘要 | 39.46 | 8.70(10 线程) | 完整 501 帧,中位数 |
|
| 43 |
+
| FFV1 深度位串解码与摘要 | 34.91 | 11.56(10 线程) | 完整 501 帧,中位数 |
|
| 44 |
+
| 有效性视频解码与摘要 | 2.24 | 2.27(10 线程) | 完整 501 帧;未获提速 |
|
| 45 |
+
| 源 RGB PNG 解码 | 2.67 | 1.49(10 线程) | 100 帧,1 线程使用热缓存轮次,不使用冷缓存较慢轮次来夸大提速 |
|
| 46 |
+
| 源深度 PNG 读取及毫米→米 | 4.67 | 2.61(4 线程) | 100 帧,中位数;帧序与数值相同 |
|
| 47 |
+
|
| 48 |
+
这些结果只代表相应阶段;全流程还包括顺序 gzip 扫描、文件创建、源 SHA256、资产复制和磁盘读写,实际全量 ETA 待稳定吞吐后再更新。
|
H2O/shared-v1.0/script/provenance/previous-run/docs/schema.json
ADDED
|
@@ -0,0 +1,869 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": "hand-warehouse/1.0",
|
| 3 |
+
"validity_revision": "usable-annotation-2026-09-20",
|
| 4 |
+
"annotation_validity": {
|
| 5 |
+
"meaning": "annotation usable for supervision, not merely record presence",
|
| 6 |
+
"formula": "source_annotation_present AND numerical_checks_pass AND applicable_official_QA_pass AND NOT explicitly_reviewed_local_exclusion",
|
| 7 |
+
"without_official_qa": "omit QA term; declare source rules; do not fabricate QA",
|
| 8 |
+
"policy_field": "components.<name>.valid_policy",
|
| 9 |
+
"visibility_is_independent": true,
|
| 10 |
+
"invalid_float_value": "NaN",
|
| 11 |
+
"hot3d": "broadcast per-camera frame manual QA conservatively to hand/object labels and pose-derived visibility; retain RGB and source calibration; keep native QA in raw and review report",
|
| 12 |
+
"hot3d_visibility": "native visibility_ratio[%] already ranges from 0 to 1; do not divide by 100"
|
| 13 |
+
},
|
| 14 |
+
"hand_slots": [
|
| 15 |
+
"left",
|
| 16 |
+
"right"
|
| 17 |
+
],
|
| 18 |
+
"keypoints": {
|
| 19 |
+
"mano21/v1": {
|
| 20 |
+
"count": 21,
|
| 21 |
+
"names": [
|
| 22 |
+
"wrist",
|
| 23 |
+
"thumb_1",
|
| 24 |
+
"thumb_2",
|
| 25 |
+
"thumb_3",
|
| 26 |
+
"thumb_4",
|
| 27 |
+
"index_1",
|
| 28 |
+
"index_2",
|
| 29 |
+
"index_3",
|
| 30 |
+
"index_4",
|
| 31 |
+
"middle_1",
|
| 32 |
+
"middle_2",
|
| 33 |
+
"middle_3",
|
| 34 |
+
"middle_4",
|
| 35 |
+
"ring_1",
|
| 36 |
+
"ring_2",
|
| 37 |
+
"ring_3",
|
| 38 |
+
"ring_4",
|
| 39 |
+
"little_1",
|
| 40 |
+
"little_2",
|
| 41 |
+
"little_3",
|
| 42 |
+
"little_4"
|
| 43 |
+
],
|
| 44 |
+
"source_index_map": null,
|
| 45 |
+
"note": "adapter maps official MANO joint and fingertip convention"
|
| 46 |
+
},
|
| 47 |
+
"rhd21/v1": {
|
| 48 |
+
"count": 21,
|
| 49 |
+
"names": [
|
| 50 |
+
"wrist",
|
| 51 |
+
"thumb_1",
|
| 52 |
+
"thumb_2",
|
| 53 |
+
"thumb_3",
|
| 54 |
+
"thumb_4",
|
| 55 |
+
"index_1",
|
| 56 |
+
"index_2",
|
| 57 |
+
"index_3",
|
| 58 |
+
"index_4",
|
| 59 |
+
"middle_1",
|
| 60 |
+
"middle_2",
|
| 61 |
+
"middle_3",
|
| 62 |
+
"middle_4",
|
| 63 |
+
"ring_1",
|
| 64 |
+
"ring_2",
|
| 65 |
+
"ring_3",
|
| 66 |
+
"ring_4",
|
| 67 |
+
"little_1",
|
| 68 |
+
"little_2",
|
| 69 |
+
"little_3",
|
| 70 |
+
"little_4"
|
| 71 |
+
],
|
| 72 |
+
"source_index_map_per_hand": [
|
| 73 |
+
0,
|
| 74 |
+
4,
|
| 75 |
+
3,
|
| 76 |
+
2,
|
| 77 |
+
1,
|
| 78 |
+
8,
|
| 79 |
+
7,
|
| 80 |
+
6,
|
| 81 |
+
5,
|
| 82 |
+
12,
|
| 83 |
+
11,
|
| 84 |
+
10,
|
| 85 |
+
9,
|
| 86 |
+
16,
|
| 87 |
+
15,
|
| 88 |
+
14,
|
| 89 |
+
13,
|
| 90 |
+
20,
|
| 91 |
+
19,
|
| 92 |
+
18,
|
| 93 |
+
17
|
| 94 |
+
]
|
| 95 |
+
}
|
| 96 |
+
},
|
| 97 |
+
"camera": {
|
| 98 |
+
"opencv_fisheye4": {
|
| 99 |
+
"K": [
|
| 100 |
+
3,
|
| 101 |
+
3
|
| 102 |
+
],
|
| 103 |
+
"distortion": [
|
| 104 |
+
"k1",
|
| 105 |
+
"k2",
|
| 106 |
+
"k3",
|
| 107 |
+
"k4"
|
| 108 |
+
],
|
| 109 |
+
"projection": "theta=atan(r); theta_d=theta*(1+k1*theta^2+k2*theta^4+k3*theta^6+k4*theta^8); source ReInterHand"
|
| 110 |
+
},
|
| 111 |
+
"pinhole": {
|
| 112 |
+
"K": [
|
| 113 |
+
3,
|
| 114 |
+
3
|
| 115 |
+
]
|
| 116 |
+
},
|
| 117 |
+
"fisheye624": {
|
| 118 |
+
"parameters": [
|
| 119 |
+
"f",
|
| 120 |
+
"cx",
|
| 121 |
+
"cy",
|
| 122 |
+
"k0",
|
| 123 |
+
"k1",
|
| 124 |
+
"k2",
|
| 125 |
+
"k3",
|
| 126 |
+
"k4",
|
| 127 |
+
"k5",
|
| 128 |
+
"p0",
|
| 129 |
+
"p1",
|
| 130 |
+
"s0",
|
| 131 |
+
"s1",
|
| 132 |
+
"s2",
|
| 133 |
+
"s3"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
"rational8": {
|
| 137 |
+
"K": [
|
| 138 |
+
3,
|
| 139 |
+
3
|
| 140 |
+
],
|
| 141 |
+
"distortion": [
|
| 142 |
+
"k1",
|
| 143 |
+
"k2",
|
| 144 |
+
"p1",
|
| 145 |
+
"p2",
|
| 146 |
+
"k3",
|
| 147 |
+
"k4",
|
| 148 |
+
"k5",
|
| 149 |
+
"k6"
|
| 150 |
+
]
|
| 151 |
+
}
|
| 152 |
+
},
|
| 153 |
+
"segmentation": {
|
| 154 |
+
"segment/uint16_labels/v1": {
|
| 155 |
+
"storage": "mask.mkv",
|
| 156 |
+
"dtype": "uint16",
|
| 157 |
+
"mapping": "instances.jsonl",
|
| 158 |
+
"valid_shape": [
|
| 159 |
+
"T"
|
| 160 |
+
],
|
| 161 |
+
"required_metadata": [
|
| 162 |
+
"segmentation_type",
|
| 163 |
+
"coverage",
|
| 164 |
+
"mapping_ref",
|
| 165 |
+
"storage"
|
| 166 |
+
],
|
| 167 |
+
"shape": [
|
| 168 |
+
"T",
|
| 169 |
+
"H",
|
| 170 |
+
"W"
|
| 171 |
+
],
|
| 172 |
+
"reserved_codes": {
|
| 173 |
+
"0": "unassigned",
|
| 174 |
+
"65535": "ignore"
|
| 175 |
+
},
|
| 176 |
+
"region_codes": [
|
| 177 |
+
1,
|
| 178 |
+
65534
|
| 179 |
+
],
|
| 180 |
+
"allowed_storage_profiles": [
|
| 181 |
+
"mkv/uint16_ffv1/v1"
|
| 182 |
+
]
|
| 183 |
+
},
|
| 184 |
+
"segment/instance_polygons/v1": {
|
| 185 |
+
"storage": "polygons.jsonl",
|
| 186 |
+
"mapping": "instances.jsonl",
|
| 187 |
+
"frame_keys": [
|
| 188 |
+
"frame_index",
|
| 189 |
+
"instances"
|
| 190 |
+
],
|
| 191 |
+
"instance_keys": [
|
| 192 |
+
"mask_value",
|
| 193 |
+
"polygons"
|
| 194 |
+
],
|
| 195 |
+
"coordinate_unit": "pixel",
|
| 196 |
+
"overlap_allowed": true,
|
| 197 |
+
"valid_shape": [
|
| 198 |
+
"T"
|
| 199 |
+
],
|
| 200 |
+
"required_metadata": [
|
| 201 |
+
"segmentation_type",
|
| 202 |
+
"coverage",
|
| 203 |
+
"mapping_ref"
|
| 204 |
+
],
|
| 205 |
+
"polygon_shape": [
|
| 206 |
+
"N",
|
| 207 |
+
2
|
| 208 |
+
],
|
| 209 |
+
"holes_supported": false
|
| 210 |
+
},
|
| 211 |
+
"segment/foreground_intensity/v1": {
|
| 212 |
+
"storage": "mask.mkv",
|
| 213 |
+
"dtype": "uint16",
|
| 214 |
+
"value_range": [
|
| 215 |
+
0,
|
| 216 |
+
255
|
| 217 |
+
],
|
| 218 |
+
"normalization_scale": 0.00392156862745098,
|
| 219 |
+
"axes": [
|
| 220 |
+
"T",
|
| 221 |
+
"height",
|
| 222 |
+
"width"
|
| 223 |
+
],
|
| 224 |
+
"meaning": "native hand foreground intensity; individual hand or union declared in metadata; not instance codes or calibrated probability",
|
| 225 |
+
"zero": "background",
|
| 226 |
+
"full_scale": "foreground",
|
| 227 |
+
"mapping": "foreground_category in component metadata",
|
| 228 |
+
"valid_shape": [
|
| 229 |
+
"T"
|
| 230 |
+
],
|
| 231 |
+
"required_metadata": [
|
| 232 |
+
"segmentation_type",
|
| 233 |
+
"coverage",
|
| 234 |
+
"value_range",
|
| 235 |
+
"normalization_scale",
|
| 236 |
+
"foreground_category",
|
| 237 |
+
"entity_id",
|
| 238 |
+
"storage"
|
| 239 |
+
],
|
| 240 |
+
"shape": [
|
| 241 |
+
"T",
|
| 242 |
+
"H",
|
| 243 |
+
"W"
|
| 244 |
+
],
|
| 245 |
+
"allowed_storage_profiles": [
|
| 246 |
+
"mkv/uint16_ffv1/v1"
|
| 247 |
+
]
|
| 248 |
+
}
|
| 249 |
+
},
|
| 250 |
+
"note": "Registry for hand-warehouse/1.0. Read CONTRACT.md for field semantics. This is not a JSON Schema document or executable validator.",
|
| 251 |
+
"components": {
|
| 252 |
+
"mano/axis_angle61/v1": {
|
| 253 |
+
"storage": "pt",
|
| 254 |
+
"dtype": "float32",
|
| 255 |
+
"shape": [
|
| 256 |
+
"T",
|
| 257 |
+
2,
|
| 258 |
+
61
|
| 259 |
+
],
|
| 260 |
+
"valid_shape": [
|
| 261 |
+
"T",
|
| 262 |
+
2
|
| 263 |
+
],
|
| 264 |
+
"unit": "m",
|
| 265 |
+
"angle_unit": "rad",
|
| 266 |
+
"coordinate_frame": "camera",
|
| 267 |
+
"layout": {
|
| 268 |
+
"pose_axis_angle": [
|
| 269 |
+
0,
|
| 270 |
+
48
|
| 271 |
+
],
|
| 272 |
+
"shape": [
|
| 273 |
+
48,
|
| 274 |
+
58
|
| 275 |
+
],
|
| 276 |
+
"translation": [
|
| 277 |
+
58,
|
| 278 |
+
61
|
| 279 |
+
]
|
| 280 |
+
}
|
| 281 |
+
},
|
| 282 |
+
"keypoints/uv/v1": {
|
| 283 |
+
"storage": "pt",
|
| 284 |
+
"dtype": "float32",
|
| 285 |
+
"shape": [
|
| 286 |
+
"T",
|
| 287 |
+
2,
|
| 288 |
+
21,
|
| 289 |
+
2
|
| 290 |
+
],
|
| 291 |
+
"valid_shape": [
|
| 292 |
+
"T",
|
| 293 |
+
2,
|
| 294 |
+
21
|
| 295 |
+
],
|
| 296 |
+
"unit": "pixel",
|
| 297 |
+
"required_metadata": [
|
| 298 |
+
"keypoint_schema"
|
| 299 |
+
]
|
| 300 |
+
},
|
| 301 |
+
"keypoints/xyz/v1": {
|
| 302 |
+
"storage": "pt",
|
| 303 |
+
"dtype": "float32",
|
| 304 |
+
"shape": [
|
| 305 |
+
"T",
|
| 306 |
+
2,
|
| 307 |
+
21,
|
| 308 |
+
3
|
| 309 |
+
],
|
| 310 |
+
"valid_shape": [
|
| 311 |
+
"T",
|
| 312 |
+
2,
|
| 313 |
+
21
|
| 314 |
+
],
|
| 315 |
+
"unit": "m",
|
| 316 |
+
"required_metadata": [
|
| 317 |
+
"keypoint_schema"
|
| 318 |
+
]
|
| 319 |
+
},
|
| 320 |
+
"depth/z_float32/v1": {
|
| 321 |
+
"storage": "mkv",
|
| 322 |
+
"dtype": "float32",
|
| 323 |
+
"shape": [
|
| 324 |
+
"T",
|
| 325 |
+
"H",
|
| 326 |
+
"W"
|
| 327 |
+
],
|
| 328 |
+
"valid_shape": [
|
| 329 |
+
"T",
|
| 330 |
+
"H",
|
| 331 |
+
"W"
|
| 332 |
+
],
|
| 333 |
+
"unit": "m",
|
| 334 |
+
"depth_type": "z",
|
| 335 |
+
"pixel_grid": "current_rgb",
|
| 336 |
+
"coordinate_frame": "current_rgb_camera",
|
| 337 |
+
"valid_storage": "mkv",
|
| 338 |
+
"allowed_storage_profiles": [
|
| 339 |
+
"mkv/depth_float32_bits/v1"
|
| 340 |
+
],
|
| 341 |
+
"allowed_valid_storage_profiles": [
|
| 342 |
+
"mkv/bool_ffv1/v1"
|
| 343 |
+
],
|
| 344 |
+
"required_metadata": [
|
| 345 |
+
"storage",
|
| 346 |
+
"valid_storage",
|
| 347 |
+
"depth_origin"
|
| 348 |
+
],
|
| 349 |
+
"depth_origin_values": [
|
| 350 |
+
"measured",
|
| 351 |
+
"rendered",
|
| 352 |
+
"unknown"
|
| 353 |
+
]
|
| 354 |
+
},
|
| 355 |
+
"transform/se3/v1": {
|
| 356 |
+
"storage": "pt",
|
| 357 |
+
"dtype": "float32",
|
| 358 |
+
"shape": [
|
| 359 |
+
"T",
|
| 360 |
+
4,
|
| 361 |
+
4
|
| 362 |
+
],
|
| 363 |
+
"valid_shape": [
|
| 364 |
+
"T"
|
| 365 |
+
],
|
| 366 |
+
"unit": "m",
|
| 367 |
+
"required_metadata": [
|
| 368 |
+
"convention"
|
| 369 |
+
]
|
| 370 |
+
},
|
| 371 |
+
"object/rigid/v1": {
|
| 372 |
+
"storage": "pt",
|
| 373 |
+
"dtype": "float32",
|
| 374 |
+
"shape": [
|
| 375 |
+
"T",
|
| 376 |
+
4,
|
| 377 |
+
4
|
| 378 |
+
],
|
| 379 |
+
"valid_shape": [
|
| 380 |
+
"T"
|
| 381 |
+
],
|
| 382 |
+
"unit": "m",
|
| 383 |
+
"required_metadata": [
|
| 384 |
+
"convention"
|
| 385 |
+
]
|
| 386 |
+
},
|
| 387 |
+
"camera/pinhole/v1": {
|
| 388 |
+
"storage": "pt",
|
| 389 |
+
"dtype": "float32",
|
| 390 |
+
"shape": [
|
| 391 |
+
"T",
|
| 392 |
+
3,
|
| 393 |
+
3
|
| 394 |
+
],
|
| 395 |
+
"valid_shape": [
|
| 396 |
+
"T"
|
| 397 |
+
]
|
| 398 |
+
},
|
| 399 |
+
"camera/rational8/v1": {
|
| 400 |
+
"storage": "pt",
|
| 401 |
+
"dtype": "float32",
|
| 402 |
+
"shape": [
|
| 403 |
+
"T",
|
| 404 |
+
3,
|
| 405 |
+
3
|
| 406 |
+
],
|
| 407 |
+
"valid_shape": [
|
| 408 |
+
"T"
|
| 409 |
+
]
|
| 410 |
+
},
|
| 411 |
+
"camera/opencv_fisheye4/v1": {
|
| 412 |
+
"storage": "pt",
|
| 413 |
+
"dtype": "float32",
|
| 414 |
+
"shape": [
|
| 415 |
+
"T",
|
| 416 |
+
3,
|
| 417 |
+
3
|
| 418 |
+
],
|
| 419 |
+
"valid_shape": [
|
| 420 |
+
"T"
|
| 421 |
+
]
|
| 422 |
+
},
|
| 423 |
+
"camera/fisheye624/v1": {
|
| 424 |
+
"storage": "pt",
|
| 425 |
+
"dtype": "float32",
|
| 426 |
+
"shape": [
|
| 427 |
+
"T",
|
| 428 |
+
15
|
| 429 |
+
],
|
| 430 |
+
"valid_shape": [
|
| 431 |
+
"T"
|
| 432 |
+
]
|
| 433 |
+
},
|
| 434 |
+
"camera/distortion8/v1": {
|
| 435 |
+
"storage": "pt",
|
| 436 |
+
"dtype": "float32",
|
| 437 |
+
"shape": [
|
| 438 |
+
"T",
|
| 439 |
+
8
|
| 440 |
+
],
|
| 441 |
+
"valid_shape": [
|
| 442 |
+
"T"
|
| 443 |
+
]
|
| 444 |
+
},
|
| 445 |
+
"camera/fisheye4_distortion/v1": {
|
| 446 |
+
"storage": "pt",
|
| 447 |
+
"dtype": "float32",
|
| 448 |
+
"shape": [
|
| 449 |
+
"T",
|
| 450 |
+
4
|
| 451 |
+
],
|
| 452 |
+
"valid_shape": [
|
| 453 |
+
"T"
|
| 454 |
+
]
|
| 455 |
+
},
|
| 456 |
+
"object/joint_state/v1": {
|
| 457 |
+
"storage": "pt",
|
| 458 |
+
"dtype": "float32",
|
| 459 |
+
"shape": [
|
| 460 |
+
"T",
|
| 461 |
+
"J"
|
| 462 |
+
],
|
| 463 |
+
"valid_shape": [
|
| 464 |
+
"T",
|
| 465 |
+
"J"
|
| 466 |
+
],
|
| 467 |
+
"required_metadata": [
|
| 468 |
+
"joint_order"
|
| 469 |
+
],
|
| 470 |
+
"unit_rule": "revolute radians; prismatic metres; mixed types declared per joint"
|
| 471 |
+
},
|
| 472 |
+
"object_keypoints/camera/v1": {
|
| 473 |
+
"storage": "pt",
|
| 474 |
+
"dtype": "float32",
|
| 475 |
+
"shape": [
|
| 476 |
+
"T",
|
| 477 |
+
"K",
|
| 478 |
+
3
|
| 479 |
+
],
|
| 480 |
+
"valid_shape": [
|
| 481 |
+
"T",
|
| 482 |
+
"K"
|
| 483 |
+
],
|
| 484 |
+
"unit": "m",
|
| 485 |
+
"coordinate_frame": "camera",
|
| 486 |
+
"required_metadata": [
|
| 487 |
+
"keypoint_schema"
|
| 488 |
+
]
|
| 489 |
+
},
|
| 490 |
+
"object/dimensions/v1": {
|
| 491 |
+
"storage": "pt",
|
| 492 |
+
"dtype": "float32",
|
| 493 |
+
"shape": [
|
| 494 |
+
"T",
|
| 495 |
+
3
|
| 496 |
+
],
|
| 497 |
+
"valid_shape": [
|
| 498 |
+
"T"
|
| 499 |
+
],
|
| 500 |
+
"unit": "m",
|
| 501 |
+
"required_metadata": [
|
| 502 |
+
"dimensions_semantics"
|
| 503 |
+
],
|
| 504 |
+
"axis_order": [
|
| 505 |
+
"length",
|
| 506 |
+
"width",
|
| 507 |
+
"height"
|
| 508 |
+
],
|
| 509 |
+
"scale_rule": "do not apply to mesh without source-supported size/scale relation"
|
| 510 |
+
},
|
| 511 |
+
"object_keypoints/template/v1": {
|
| 512 |
+
"storage": "pt",
|
| 513 |
+
"dtype": "float32",
|
| 514 |
+
"shape": [
|
| 515 |
+
"K",
|
| 516 |
+
3
|
| 517 |
+
],
|
| 518 |
+
"valid_shape": [
|
| 519 |
+
"K"
|
| 520 |
+
],
|
| 521 |
+
"unit": "m",
|
| 522 |
+
"coordinate_frame": "object",
|
| 523 |
+
"static": true,
|
| 524 |
+
"required_metadata": [
|
| 525 |
+
"keypoint_schema"
|
| 526 |
+
]
|
| 527 |
+
},
|
| 528 |
+
"mesh/obj/v1": {
|
| 529 |
+
"storage": "obj",
|
| 530 |
+
"unit": "m",
|
| 531 |
+
"static": true,
|
| 532 |
+
"valid_shape": [],
|
| 533 |
+
"dependencies": "MTL and textures retained under owning object"
|
| 534 |
+
},
|
| 535 |
+
"rgb/uint8/v1": {
|
| 536 |
+
"storage": "mkv",
|
| 537 |
+
"dtype": "uint8",
|
| 538 |
+
"shape": [
|
| 539 |
+
"T",
|
| 540 |
+
"H",
|
| 541 |
+
"W",
|
| 542 |
+
3
|
| 543 |
+
],
|
| 544 |
+
"valid_shape": [
|
| 545 |
+
"T"
|
| 546 |
+
],
|
| 547 |
+
"color_order": "RGB",
|
| 548 |
+
"allowed_storage_profiles": [
|
| 549 |
+
"mkv/mjpeg_copy/v1",
|
| 550 |
+
"mkv/source_copy/v1",
|
| 551 |
+
"mkv/h264_rgb_lossless/v1",
|
| 552 |
+
"mkv/ffv1_rgb/v1"
|
| 553 |
+
],
|
| 554 |
+
"required_metadata": [
|
| 555 |
+
"storage"
|
| 556 |
+
]
|
| 557 |
+
},
|
| 558 |
+
"contact/relations/v1": {
|
| 559 |
+
"storage": "jsonl",
|
| 560 |
+
"valid_shape": [
|
| 561 |
+
"T"
|
| 562 |
+
],
|
| 563 |
+
"frame_keys": [
|
| 564 |
+
"frame_index",
|
| 565 |
+
"relations"
|
| 566 |
+
],
|
| 567 |
+
"absence_semantics": "no record is not a negative contact annotation"
|
| 568 |
+
},
|
| 569 |
+
"contact/vertex_region/v1": {
|
| 570 |
+
"storage": "pt",
|
| 571 |
+
"dtype": "bool",
|
| 572 |
+
"shape": [
|
| 573 |
+
"T",
|
| 574 |
+
"V"
|
| 575 |
+
],
|
| 576 |
+
"valid_shape": [
|
| 577 |
+
"T",
|
| 578 |
+
"V"
|
| 579 |
+
],
|
| 580 |
+
"required_metadata": [
|
| 581 |
+
"source_geometry_ref",
|
| 582 |
+
"target_geometry_ref",
|
| 583 |
+
"topology_id"
|
| 584 |
+
],
|
| 585 |
+
"pilot_status": "defined_not_empirically_validated"
|
| 586 |
+
},
|
| 587 |
+
"contact/vertex_distance/v1": {
|
| 588 |
+
"storage": "pt",
|
| 589 |
+
"dtype": "float32",
|
| 590 |
+
"shape": [
|
| 591 |
+
"T",
|
| 592 |
+
"V"
|
| 593 |
+
],
|
| 594 |
+
"valid_shape": [
|
| 595 |
+
"T",
|
| 596 |
+
"V"
|
| 597 |
+
],
|
| 598 |
+
"unit": "m",
|
| 599 |
+
"required_metadata": [
|
| 600 |
+
"source_geometry_ref",
|
| 601 |
+
"target_geometry_ref",
|
| 602 |
+
"topology_id",
|
| 603 |
+
"distance_definition"
|
| 604 |
+
],
|
| 605 |
+
"pilot_status": "defined_not_empirically_validated"
|
| 606 |
+
},
|
| 607 |
+
"object/articulated/v1": {
|
| 608 |
+
"storage": "json",
|
| 609 |
+
"required_keys": [
|
| 610 |
+
"parts",
|
| 611 |
+
"joints"
|
| 612 |
+
],
|
| 613 |
+
"part_keys": [
|
| 614 |
+
"part_id",
|
| 615 |
+
"parent_id",
|
| 616 |
+
"has_model",
|
| 617 |
+
"mesh_ref"
|
| 618 |
+
],
|
| 619 |
+
"hierarchy_semantics": "declare mechanical articulation or semantic containment; containment alone does not imply joints",
|
| 620 |
+
"acyclic": true
|
| 621 |
+
},
|
| 622 |
+
"segment/uint16_labels/v1": {
|
| 623 |
+
"storage": "mkv",
|
| 624 |
+
"dtype": "uint16",
|
| 625 |
+
"mapping": "instances.jsonl",
|
| 626 |
+
"valid_shape": [
|
| 627 |
+
"T"
|
| 628 |
+
],
|
| 629 |
+
"required_metadata": [
|
| 630 |
+
"segmentation_type",
|
| 631 |
+
"coverage",
|
| 632 |
+
"mapping_ref",
|
| 633 |
+
"storage"
|
| 634 |
+
],
|
| 635 |
+
"shape": [
|
| 636 |
+
"T",
|
| 637 |
+
"H",
|
| 638 |
+
"W"
|
| 639 |
+
],
|
| 640 |
+
"reserved_codes": {
|
| 641 |
+
"0": "unassigned",
|
| 642 |
+
"65535": "ignore"
|
| 643 |
+
},
|
| 644 |
+
"region_codes": [
|
| 645 |
+
1,
|
| 646 |
+
65534
|
| 647 |
+
],
|
| 648 |
+
"allowed_storage_profiles": [
|
| 649 |
+
"mkv/uint16_ffv1/v1"
|
| 650 |
+
]
|
| 651 |
+
},
|
| 652 |
+
"segment/instance_polygons/v1": {
|
| 653 |
+
"storage": "jsonl",
|
| 654 |
+
"mapping": "instances.jsonl",
|
| 655 |
+
"frame_keys": [
|
| 656 |
+
"frame_index",
|
| 657 |
+
"instances"
|
| 658 |
+
],
|
| 659 |
+
"instance_keys": [
|
| 660 |
+
"mask_value",
|
| 661 |
+
"polygons"
|
| 662 |
+
],
|
| 663 |
+
"coordinate_unit": "pixel",
|
| 664 |
+
"overlap_allowed": true,
|
| 665 |
+
"valid_shape": [
|
| 666 |
+
"T"
|
| 667 |
+
],
|
| 668 |
+
"required_metadata": [
|
| 669 |
+
"segmentation_type",
|
| 670 |
+
"coverage",
|
| 671 |
+
"mapping_ref"
|
| 672 |
+
],
|
| 673 |
+
"polygon_shape": [
|
| 674 |
+
"N",
|
| 675 |
+
2
|
| 676 |
+
],
|
| 677 |
+
"holes_supported": false
|
| 678 |
+
},
|
| 679 |
+
"segment/foreground_intensity/v1": {
|
| 680 |
+
"storage": "mkv",
|
| 681 |
+
"dtype": "uint16",
|
| 682 |
+
"value_range": [
|
| 683 |
+
0,
|
| 684 |
+
255
|
| 685 |
+
],
|
| 686 |
+
"normalization_scale": 0.00392156862745098,
|
| 687 |
+
"axes": [
|
| 688 |
+
"T",
|
| 689 |
+
"height",
|
| 690 |
+
"width"
|
| 691 |
+
],
|
| 692 |
+
"meaning": "native hand foreground intensity; individual hand or union declared in metadata; not instance codes or calibrated probability",
|
| 693 |
+
"zero": "background",
|
| 694 |
+
"full_scale": "foreground",
|
| 695 |
+
"mapping": "foreground_category in component metadata",
|
| 696 |
+
"valid_shape": [
|
| 697 |
+
"T"
|
| 698 |
+
],
|
| 699 |
+
"required_metadata": [
|
| 700 |
+
"segmentation_type",
|
| 701 |
+
"coverage",
|
| 702 |
+
"value_range",
|
| 703 |
+
"normalization_scale",
|
| 704 |
+
"foreground_category",
|
| 705 |
+
"entity_id",
|
| 706 |
+
"storage"
|
| 707 |
+
],
|
| 708 |
+
"shape": [
|
| 709 |
+
"T",
|
| 710 |
+
"H",
|
| 711 |
+
"W"
|
| 712 |
+
],
|
| 713 |
+
"allowed_storage_profiles": [
|
| 714 |
+
"mkv/uint16_ffv1/v1"
|
| 715 |
+
]
|
| 716 |
+
}
|
| 717 |
+
},
|
| 718 |
+
"storage_revision": "lossless-video-2026-09-18",
|
| 719 |
+
"sampling": {
|
| 720 |
+
"image": {
|
| 721 |
+
"single": {
|
| 722 |
+
"T": 1
|
| 723 |
+
},
|
| 724 |
+
"independent": {
|
| 725 |
+
"T": ">=2",
|
| 726 |
+
"required_frame_fields": [
|
| 727 |
+
"sample_id",
|
| 728 |
+
"source_locator"
|
| 729 |
+
],
|
| 730 |
+
"temporal_relationship": false
|
| 731 |
+
},
|
| 732 |
+
"source_fps": null
|
| 733 |
+
},
|
| 734 |
+
"video": {
|
| 735 |
+
"sampling_types": [
|
| 736 |
+
"dense",
|
| 737 |
+
"sparse"
|
| 738 |
+
]
|
| 739 |
+
}
|
| 740 |
+
},
|
| 741 |
+
"storage_profiles": {
|
| 742 |
+
"mkv/mjpeg_copy/v1": {
|
| 743 |
+
"container": "matroska",
|
| 744 |
+
"codec": "mjpeg",
|
| 745 |
+
"method": "stream_copy_from_source_jpeg",
|
| 746 |
+
"logical_dtype": "uint8",
|
| 747 |
+
"decoded_pixel_format": "rgb24",
|
| 748 |
+
"validation": [
|
| 749 |
+
"source_jpeg_packet_sha256_exact",
|
| 750 |
+
"all_packet_count_order_and_dimensions_exact",
|
| 751 |
+
"deterministic_decoded_rgb_sample_exact",
|
| 752 |
+
"pilot_and_final_selected_whole_sequences_decoded_rgb_exact"
|
| 753 |
+
],
|
| 754 |
+
"validation_policy": {
|
| 755 |
+
"id": "jpeg-packets-all-rgb-sample16/v1",
|
| 756 |
+
"sample_count_per_view": 16,
|
| 757 |
+
"short_views": "all_frames_if_T_less_than_16",
|
| 758 |
+
"fixed_indices": "0,T-1,T//4,T//2,3*T//4, deduplicated",
|
| 759 |
+
"remaining_indices": "sample without replacement to min(T,16) using Python random.Random(seed)",
|
| 760 |
+
"seed": "first 8 bytes of SHA256(sequence_id/camera_id/20260920), big-endian integer",
|
| 761 |
+
"report": "policy, exact selected frame indices, seed, separate packet and pixel coverage",
|
| 762 |
+
"legacy_all_frame_pixel_proofs": "still accepted; preserve historical evidence"
|
| 763 |
+
}
|
| 764 |
+
},
|
| 765 |
+
"mkv/source_copy/v1": {
|
| 766 |
+
"container": "matroska",
|
| 767 |
+
"codec": "source_codec_declared_in_metadata",
|
| 768 |
+
"method": "stream_copy_only",
|
| 769 |
+
"logical_dtype": "uint8",
|
| 770 |
+
"decoded_pixel_format": "rgb24",
|
| 771 |
+
"validation": [
|
| 772 |
+
"no_reencoding",
|
| 773 |
+
"all_decoded_rgb_frames_exact",
|
| 774 |
+
"presentation_frame_order_exact"
|
| 775 |
+
]
|
| 776 |
+
},
|
| 777 |
+
"mkv/h264_rgb_lossless/v1": {
|
| 778 |
+
"container": "matroska",
|
| 779 |
+
"codec": "h264",
|
| 780 |
+
"encoder": "libx264rgb",
|
| 781 |
+
"crf": 0,
|
| 782 |
+
"decoded_pixel_format": "rgb24",
|
| 783 |
+
"logical_dtype": "uint8",
|
| 784 |
+
"gop": "declared_in_encoder_parameters",
|
| 785 |
+
"validation": [
|
| 786 |
+
"all_decoded_rgb_frames_exact"
|
| 787 |
+
],
|
| 788 |
+
"forbidden": [
|
| 789 |
+
"lossy_rate_control",
|
| 790 |
+
"rgb_to_yuv420_subsampling"
|
| 791 |
+
]
|
| 792 |
+
},
|
| 793 |
+
"mkv/ffv1_rgb/v1": {
|
| 794 |
+
"container": "matroska",
|
| 795 |
+
"codec": "ffv1",
|
| 796 |
+
"decoded_pixel_format": "rgb24",
|
| 797 |
+
"logical_dtype": "uint8",
|
| 798 |
+
"validation": [
|
| 799 |
+
"all_decoded_rgb_frames_exact"
|
| 800 |
+
]
|
| 801 |
+
},
|
| 802 |
+
"mkv/depth_float32_bits/v1": {
|
| 803 |
+
"container": "matroska",
|
| 804 |
+
"codec": "ffv1",
|
| 805 |
+
"pixel_format": "gray16le",
|
| 806 |
+
"logical_dtype": "float32",
|
| 807 |
+
"logical_shape": [
|
| 808 |
+
"T",
|
| 809 |
+
"H",
|
| 810 |
+
"W"
|
| 811 |
+
],
|
| 812 |
+
"encoded_shape": [
|
| 813 |
+
"T",
|
| 814 |
+
"H",
|
| 815 |
+
"2*W"
|
| 816 |
+
],
|
| 817 |
+
"packing": "IEEE754 little-endian float32 bits; low uint16 in first W columns, high uint16 in last W columns",
|
| 818 |
+
"decode": "reinterpret_float32(uint32(low) | (uint32(high) << 16))",
|
| 819 |
+
"validation": [
|
| 820 |
+
"all_float32_bits_exact_including_nan"
|
| 821 |
+
]
|
| 822 |
+
},
|
| 823 |
+
"mkv/bool_ffv1/v1": {
|
| 824 |
+
"container": "matroska",
|
| 825 |
+
"codec": "ffv1",
|
| 826 |
+
"pixel_format": "gray",
|
| 827 |
+
"logical_dtype": "bool",
|
| 828 |
+
"stored_values": [
|
| 829 |
+
0,
|
| 830 |
+
1
|
| 831 |
+
],
|
| 832 |
+
"validation": [
|
| 833 |
+
"all_bool_values_exact"
|
| 834 |
+
]
|
| 835 |
+
},
|
| 836 |
+
"mkv/uint16_ffv1/v1": {
|
| 837 |
+
"container": "matroska",
|
| 838 |
+
"codec": "ffv1",
|
| 839 |
+
"pixel_formats": [
|
| 840 |
+
"gray",
|
| 841 |
+
"gray16le"
|
| 842 |
+
],
|
| 843 |
+
"logical_dtype": "uint16",
|
| 844 |
+
"gray_condition": "all values <=255; decode by exact uint8-to-uint16 promotion",
|
| 845 |
+
"validation": [
|
| 846 |
+
"all_integer_values_exact"
|
| 847 |
+
]
|
| 848 |
+
}
|
| 849 |
+
},
|
| 850 |
+
"video_metadata": {
|
| 851 |
+
"required": [
|
| 852 |
+
"profile",
|
| 853 |
+
"codec",
|
| 854 |
+
"pixel_format",
|
| 855 |
+
"encoded_size",
|
| 856 |
+
"decoder",
|
| 857 |
+
"encoder_parameters",
|
| 858 |
+
"source_lossy"
|
| 859 |
+
],
|
| 860 |
+
"source_lossy_values": [
|
| 861 |
+
true,
|
| 862 |
+
false,
|
| 863 |
+
"unknown"
|
| 864 |
+
],
|
| 865 |
+
"timebase_role": "index_only",
|
| 866 |
+
"lossless_reference": "source compressed packets or fixed-decoder source pixels; depth uses normalized standard float32 bits",
|
| 867 |
+
"selection": "choose smaller complete candidate only after exact roundtrip validation"
|
| 868 |
+
}
|
| 869 |
+
}
|
H2O/shared-v1.0/script/provenance/previous-run/full.log
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Verified existing subject1/h1/0
|
| 2 |
+
Verified existing subject4/h1/0
|
| 3 |
+
Verified existing subject3/h1/0
|
| 4 |
+
Verified existing subject1/h1/6
|
| 5 |
+
Verified existing subject2/h1/0
|
| 6 |
+
Verified existing subject1/h1/3
|
| 7 |
+
Verified existing subject2/h1/6
|
| 8 |
+
Verified existing subject1/h1/7
|
| 9 |
+
Converted subject3/h1/6
|
| 10 |
+
Converted subject4/h1/6
|
| 11 |
+
Verified existing subject1/h1/4
|
| 12 |
+
Verified existing subject1/h1/2
|
| 13 |
+
Verified existing subject2/h1/3
|
| 14 |
+
Verified existing subject1/h1/1
|
| 15 |
+
Verified existing subject1/h1/5
|
| 16 |
+
Verified existing subject1/o1/0
|
| 17 |
+
Converted subject3/h1/3
|
| 18 |
+
Verified existing subject2/h1/7
|
| 19 |
+
Verified existing subject1/o1/6
|
| 20 |
+
Converted subject4/h1/3
|
| 21 |
+
Verified existing subject1/o1/3
|
| 22 |
+
Verified existing subject2/h1/4
|
| 23 |
+
Verified existing subject1/o1/7
|
| 24 |
+
Verified existing subject1/o1/4
|
| 25 |
+
Verified existing subject2/h1/2
|
| 26 |
+
Verified existing subject1/o1/2
|
| 27 |
+
Converted subject3/h1/7
|
| 28 |
+
Converted subject4/h1/7
|
| 29 |
+
Verified existing subject1/o1/1
|
| 30 |
+
Verified existing subject2/h1/1
|
| 31 |
+
Verified existing subject1/o1/5
|
| 32 |
+
Verified existing subject1/o2/0
|
| 33 |
+
Converted subject3/h1/4
|
| 34 |
+
Verified existing subject2/h1/5
|
| 35 |
+
Verified existing subject1/o2/6
|
| 36 |
+
Verified existing subject1/o2/3
|
| 37 |
+
Verified existing subject2/o1/0
|
| 38 |
+
Converted subject4/h1/4
|
| 39 |
+
Verified existing subject1/o2/7
|
| 40 |
+
Verified existing subject1/o2/4
|
| 41 |
+
Converted subject3/h1/2
|
| 42 |
+
Verified existing subject2/o1/6
|
| 43 |
+
Converted subject4/h1/2
|
| 44 |
+
Verified existing subject1/o2/2
|
| 45 |
+
Verified existing subject2/o1/3
|
| 46 |
+
Converted subject3/h1/1
|
| 47 |
+
Verified existing subject1/o2/1
|
| 48 |
+
Verified existing subject1/o2/5
|
| 49 |
+
Verified existing subject1/k1/0
|
| 50 |
+
Verified existing subject1/k1/6
|
| 51 |
+
Verified existing subject2/o1/4
|
| 52 |
+
Verified existing subject1/k1/3
|
| 53 |
+
Converted subject3/h1/5
|
| 54 |
+
Converted subject4/h1/1
|
| 55 |
+
Verified existing subject1/k1/7
|
| 56 |
+
Verified existing subject2/o1/2
|
| 57 |
+
Converted subject4/h1/5
|
| 58 |
+
Converted subject3/o1/0
|
| 59 |
+
Converted subject1/k1/4
|
| 60 |
+
Converted subject4/o1/0
|
| 61 |
+
Verified existing subject2/o1/1
|
H2O/shared-v1.0/script/provenance/previous-run/full.status
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
START=2026-09-30T11:03:05+08:00
|
| 2 |
+
WORKERS=4 CODEC_THREADS=10 DECODE_THREADS=10 DEPTH_THREADS=4 SUBJECTS=1,2,3,4 CASA=false
|
| 3 |
+
CPU_LIMIT=none
|
| 4 |
+
CGROUP=/user.slice/user-25044.slice/user@25044.service/app.slice/h2o-full-d10-20260930.scope
|
| 5 |
+
CPU_MAX=max controller_disabled
|
| 6 |
+
|
| 7 |
+
RECONFIGURE=2026-09-30T15:47:55+08:00 REASON=process16_camera_pipeline_ram32_streaming
|
H2O/shared-v1.0/script/provenance/previous-run/run-full.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -u
|
| 3 |
+
base="$HOME/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10"
|
| 4 |
+
raw="$HOME/Datasets/Hand-Datasets-Raw/H2O"
|
| 5 |
+
cd "$HOME/Projects/uni-hoi-dataset" || exit 1
|
| 6 |
+
mkdir -p "$base/scratch"
|
| 7 |
+
export TMPDIR="$base/scratch" PYTHONUNBUFFERED=1
|
| 8 |
+
for n in 1 2 3 4; do test -s "$raw/raw/data/subject${n}_v1_1.tar.gz" || exit 2; done
|
| 9 |
+
test ! -e "$base/full.status" || exit 3
|
| 10 |
+
cg=$(awk -F: '$1=="0" {print $3}' /proc/self/cgroup)
|
| 11 |
+
if [[ -f "/sys/fs/cgroup$cg/cpu.max" ]]; then
|
| 12 |
+
read -r quota period < "/sys/fs/cgroup$cg/cpu.max"
|
| 13 |
+
else
|
| 14 |
+
quota=max
|
| 15 |
+
period=controller_disabled
|
| 16 |
+
fi
|
| 17 |
+
printf 'START=%s\nWORKERS=4 CODEC_THREADS=10 DECODE_THREADS=10 DEPTH_THREADS=4 SUBJECTS=1,2,3,4 CASA=false\nCPU_LIMIT=none\nCGROUP=%s\nCPU_MAX=%s %s\n' "$(date -Is)" "$cg" "$quota" "$period" > "$base/full.status"
|
| 18 |
+
if [[ "$quota" != max ]]; then
|
| 19 |
+
printf 'EXIT=4 ERROR=UNEXPECTED_CPU_QUOTA\n' >> "$base/full.status"
|
| 20 |
+
exit 4
|
| 21 |
+
fi
|
| 22 |
+
/usr/bin/time -v .venv/bin/python "$base/frozen-code/scripts/convert_h2o_v1.0.py" --root "$raw" --out "$base" --release-id shared-v1.0 --workers 4 --codec-threads 10 --decode-threads 10 --depth-threads 4 --mano-dir "$HOME/Projects/WiLoR/mano_data" > "$base/full.log" 2>&1
|
| 23 |
+
code=$?
|
| 24 |
+
printf 'EXIT=%s END=%s\n' "$code" "$(date -Is)" >> "$base/full.status"
|
| 25 |
+
if [[ -f "/sys/fs/cgroup$cg/cpu.stat" ]]; then cat "/sys/fs/cgroup$cg/cpu.stat" >> "$base/full.status"; fi
|
| 26 |
+
exit "$code"
|
H2O/shared-v1.0/script/provenance/previous-run/script/check_dexycb_projection.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Check saved Dex-YCB source 3D joints against saved source 2D joints in sampled views."""
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import torch
|
| 9 |
+
|
| 10 |
+
root = Path(sys.argv[1])
|
| 11 |
+
report = json.loads((root / 'doc/validation/STRUCTURAL_AUDIT.json').read_text())
|
| 12 |
+
checks = []
|
| 13 |
+
for name in report['sampled_views']:
|
| 14 |
+
view = root / name
|
| 15 |
+
load = lambda path: torch.load(view / path, weights_only=True, map_location='cpu').numpy()
|
| 16 |
+
k = load('camera/intrinsic.pt')
|
| 17 |
+
xyz = load('annotation/keypoints/xyz.pt')
|
| 18 |
+
uv = load('annotation/keypoints/uv.pt')
|
| 19 |
+
valid = load('annotation/keypoints/xyz_valid.pt') & load('annotation/keypoints/uv_valid.pt')
|
| 20 |
+
z = xyz[..., 2]
|
| 21 |
+
valid &= np.isfinite(xyz).all(axis=-1) & np.isfinite(uv).all(axis=-1) & (z > 0)
|
| 22 |
+
z = np.where(valid, z, 1)
|
| 23 |
+
pred = np.stack((k[:, 0, 0, None, None] * xyz[..., 0] / z + k[:, 0, 2, None, None],
|
| 24 |
+
k[:, 1, 1, None, None] * xyz[..., 1] / z + k[:, 1, 2, None, None]), axis=-1)
|
| 25 |
+
errors = np.linalg.norm(pred[valid] - uv[valid], axis=-1)
|
| 26 |
+
checks.append(dict(view=name, points=int(errors.size), median_px=float(np.median(errors)) if errors.size else None,
|
| 27 |
+
p95_px=float(np.percentile(errors, 95)) if errors.size else None))
|
| 28 |
+
(root / 'doc/validation/KEYPOINT_PROJECTION_QC.json').write_text(json.dumps({
|
| 29 |
+
'scope': 'Saved source 3D joints projected with saved color intrinsics vs saved source 2D joints; independent of hand mesh rendering.',
|
| 30 |
+
'views': checks}, ensure_ascii=False, indent=2) + '\n')
|
| 31 |
+
print(json.dumps(checks, ensure_ascii=False), flush=True)
|
H2O/shared-v1.0/script/provenance/previous-run/script/config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"root": "/home/xuzhefeng/Datasets/Hand-Datasets-Raw/H2O",
|
| 3 |
+
"out": "/home/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10",
|
| 4 |
+
"release_id": "shared-v1.0",
|
| 5 |
+
"limit": null,
|
| 6 |
+
"max_frames": null,
|
| 7 |
+
"mano_dir": "/home/xuzhefeng/Projects/WiLoR/mano_data",
|
| 8 |
+
"views": null,
|
| 9 |
+
"jpeg_full_check": false,
|
| 10 |
+
"workers": 4,
|
| 11 |
+
"codec_threads": 10,
|
| 12 |
+
"decode_threads": 10,
|
| 13 |
+
"depth_threads": 4,
|
| 14 |
+
"subjects": null,
|
| 15 |
+
"include_casa": false,
|
| 16 |
+
"archive": null
|
| 17 |
+
}
|
H2O/shared-v1.0/script/provenance/previous-run/script/convert_dexycb_v1.0.py
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Dex-YCB source annotations → CONTRACT.md v1.0. No derived annotations."""
|
| 3 |
+
import io
|
| 4 |
+
import re
|
| 5 |
+
import shutil
|
| 6 |
+
import tarfile
|
| 7 |
+
import tempfile
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
from PIL import Image
|
| 12 |
+
import yaml
|
| 13 |
+
|
| 14 |
+
from warehouse_v1_0 import (View, build_record, find_file, locator, mano_models, mesh_asset,
|
| 15 |
+
model_profile, parser, pca_to_axis_angle, release, roots, safe_member, sequence_dir)
|
| 16 |
+
|
| 17 |
+
IMG_W, IMG_H = 640, 480
|
| 18 |
+
|
| 19 |
+
class _Loader(yaml.SafeLoader):
|
| 20 |
+
pass
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_Loader.add_constructor("tag:yaml.org,2002:python/tuple",
|
| 24 |
+
lambda l, n: tuple(l.construct_sequence(n)))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def yaml_load_bytes(data: bytes):
|
| 28 |
+
return yaml.load(io.BytesIO(data), Loader=_Loader)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Calibration:
|
| 32 |
+
def __init__(self, dexycb_root: Path):
|
| 33 |
+
self.intrinsics = {} # serial -> {fx,fy,cx,cy,w,h}
|
| 34 |
+
self.extrinsics = {} # group -> {serial: [12] 行优先 3×4 cam→world}
|
| 35 |
+
self.betas = {} # mano_calib_name -> [10]
|
| 36 |
+
calib_dir = dexycb_root / "calibration"
|
| 37 |
+
if calib_dir.is_dir():
|
| 38 |
+
self._load((p.as_posix(), p.read_bytes())
|
| 39 |
+
for p in sorted(calib_dir.rglob("*")) if p.is_file())
|
| 40 |
+
else:
|
| 41 |
+
tar_path = dexycb_root / "calibration.tar.gz"
|
| 42 |
+
if not tar_path.exists():
|
| 43 |
+
raise FileNotFoundError(f"no calibration/ nor calibration.tar.gz in {dexycb_root}")
|
| 44 |
+
with tarfile.open(tar_path, "r:gz") as tf:
|
| 45 |
+
self._load((m.name, tf.extractfile(m).read()) for m in tf if m.isfile())
|
| 46 |
+
|
| 47 |
+
_RE_INTR = re.compile(r"(?:^|/)intrinsics/(\d+)_\d+x\d+\.yml$")
|
| 48 |
+
_RE_EXTRA = re.compile(r"(?:^|/)extrinsics_(\d{8}_\d{6})/extrinsics\.yml$")
|
| 49 |
+
_RE_MANO = re.compile(r"(?:^|/)mano_(\d{8}_\d{6}_subject-\d{2}_right)/mano\.yml$")
|
| 50 |
+
|
| 51 |
+
def _load(self, files):
|
| 52 |
+
for rel, data in files:
|
| 53 |
+
m = self._RE_INTR.search(rel)
|
| 54 |
+
if m:
|
| 55 |
+
c = yaml_load_bytes(data)["color"]
|
| 56 |
+
self.intrinsics[m.group(1)] = {"fx": float(c["fx"]), "fy": float(c["fy"]),
|
| 57 |
+
"cx": float(c["ppx"]), "cy": float(c["ppy"]),
|
| 58 |
+
"w": IMG_W, "h": IMG_H}
|
| 59 |
+
continue
|
| 60 |
+
m = self._RE_EXTRA.search(rel)
|
| 61 |
+
if m:
|
| 62 |
+
raw = yaml_load_bytes(data)["extrinsics"]
|
| 63 |
+
self.extrinsics[m.group(1)] = {
|
| 64 |
+
str(s): [float(x) for x in np.asarray(v).ravel()] for s, v in raw.items()}
|
| 65 |
+
continue
|
| 66 |
+
m = self._RE_MANO.search(rel)
|
| 67 |
+
if m:
|
| 68 |
+
self.betas[m.group(1)] = [float(b) for b in yaml_load_bytes(data)["betas"]]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def calibration_locator(path, member, **extra):
|
| 73 |
+
if path.is_dir():
|
| 74 |
+
return locator(path / member.removeprefix('calibration/'), **extra)
|
| 75 |
+
return locator(path, member, **extra)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def prepare_models(root, destination):
|
| 79 |
+
archive = find_file(root, 'models.tar.gz')
|
| 80 |
+
if archive is None:
|
| 81 |
+
return {}, None
|
| 82 |
+
pattern = re.compile(r'^models/(\d{3}_[a-z0-9_]+)/(textured_simple\.obj(?:\.mtl)?|texture_map\.png)$')
|
| 83 |
+
names = set()
|
| 84 |
+
with tarfile.open(archive, 'r|gz') as tf:
|
| 85 |
+
for member in tf:
|
| 86 |
+
match = pattern.fullmatch(member.name)
|
| 87 |
+
if member.isfile() and match:
|
| 88 |
+
names.add(match[1])
|
| 89 |
+
path = safe_member(destination, '/'.join(match.groups()))
|
| 90 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 91 |
+
path.write_bytes(tf.extractfile(member).read())
|
| 92 |
+
if len(names) != 21:
|
| 93 |
+
raise ValueError('expected all 21 source YCB model directories')
|
| 94 |
+
return {i: destination / name for i, name in enumerate(sorted(names), 1)}, archive
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def convert_view(path, args, seq, serial, frames, meta, meta_loc, calib, calib_path, models, assets, asset_archive):
|
| 98 |
+
total = int(meta.get('num_frames', max(frames) + 1))
|
| 99 |
+
ids = list(range(min(total, args.max_frames) if args.max_frames else total))
|
| 100 |
+
for f in ids:
|
| 101 |
+
frames.setdefault(f, {})
|
| 102 |
+
if not ids:
|
| 103 |
+
raise ValueError('no RGB frames')
|
| 104 |
+
source_rows = []
|
| 105 |
+
for f in ids:
|
| 106 |
+
row = frames[f]
|
| 107 |
+
source_rows.append(dict(source_frame_id=f, sync_id=f'{seq}:{f}',
|
| 108 |
+
source_locator=row['color'][1] if 'color' in row else (meta_loc | {'source_frame_id': f, 'missing_rgb': True}), annotation_matches={
|
| 109 |
+
'labels': {'source_frame_id': f, 'source_timestamp_ns': None, 'clock_domain': None,
|
| 110 |
+
'match_method': 'index_map', 'delta_ns': None, 'source_locator': row['labels'][1]}
|
| 111 |
+
for _ in [0] if 'labels' in row},
|
| 112 |
+
component_sources={k: v[1] for k, v in row.items()}))
|
| 113 |
+
view = View(path, 'dex-ycb', args.release_id, seq, serial, source_rows,
|
| 114 |
+
sampling='dense' if ids == list(range(ids[0], ids[-1] + 1)) else 'sparse')
|
| 115 |
+
view.valid_rules = {
|
| 116 |
+
'mano': 'Source pose_m present and not all zero; side model/calibration available',
|
| 117 |
+
'keypoints': 'Corresponding joint_2d/joint_3d present; whole-hand all -1 is missing, broadcast to its 21 points',
|
| 118 |
+
'pose': 'Source pose_y for this ycb_ids slot present and not an all-zero matrix',
|
| 119 |
+
'segment': 'Source seg array provided for this frame; region codes and entity references validated',
|
| 120 |
+
'relations': 'Source sequence ycb_grasp_ind resolves through ycb_ids; broadcast sequence grasp to selected frames',
|
| 121 |
+
}
|
| 122 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 123 |
+
view.meta['view_type'] = 'exo'
|
| 124 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'views': args.views}
|
| 125 |
+
subject = re.search(r'subject-(\d+)', seq)
|
| 126 |
+
if subject and 1 <= int(subject[1]) <= 10:
|
| 127 |
+
index = int(subject[1])
|
| 128 |
+
view.meta.update(split='val' if index == 7 else 'test' if index in (8, 9) else 'train',
|
| 129 |
+
split_scheme='Dex-YCB/s1', split_source_locator={
|
| 130 |
+
'url': 'https://github.com/NVlabs/dex-ycb-toolkit/blob/master/dex_ycb_toolkit/dex_ycb.py',
|
| 131 |
+
'rule': 's1 unseen-subject: 01-06/10 train, 07 val, 08-09 test'})
|
| 132 |
+
view.meta.pop('split_reason', None)
|
| 133 |
+
view.rgb([frames[f]['color'][0] if 'color' in frames[f] else None for f in ids], {'frames_ref': 'camera/frames.jsonl'})
|
| 134 |
+
n = len(ids)
|
| 135 |
+
intr = calib.intrinsics.get(serial)
|
| 136 |
+
K = None if intr is None else np.array([[intr['fx'], 0, intr['cx']], [0, intr['fy'], intr['cy']], [0, 0, 1]])
|
| 137 |
+
ext = calib.extrinsics.get(str(meta['extrinsics']), {}).get(serial)
|
| 138 |
+
E = None
|
| 139 |
+
if ext is not None:
|
| 140 |
+
E = np.eye(4)
|
| 141 |
+
E[:3] = np.asarray(ext).reshape(3, 4)
|
| 142 |
+
E = np.linalg.inv(E)
|
| 143 |
+
view.camera(K, calibration_locator(calib_path, f'calibration/intrinsics/{serial}_640x480.yml'), E,
|
| 144 |
+
calibration_locator(calib_path, f'calibration/extrinsics_{meta["extrinsics"]}/extrinsics.yml',
|
| 145 |
+
conversion='inverse of source T_world_from_camera'))
|
| 146 |
+
sides = meta.get('mano_sides')
|
| 147 |
+
if sides not in (['left'], ['right']):
|
| 148 |
+
raise ValueError(f'expected exactly one anatomical source hand: {sides}')
|
| 149 |
+
side = sides[0]
|
| 150 |
+
slot = ['left', 'right'].index(side)
|
| 151 |
+
cal_name = meta['mano_calib'][0] if isinstance(meta['mano_calib'], list) else meta['mano_calib']
|
| 152 |
+
labels = [dict(np.load(frames[f]['labels'][0])) if 'labels' in frames[f] else {} for f in ids]
|
| 153 |
+
label_loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources.labels'}
|
| 154 |
+
motion = np.full((n, 2, 61), np.nan, np.float32)
|
| 155 |
+
mv = np.zeros((n, 2), bool)
|
| 156 |
+
if side in models and any('pose_m' in lab for lab in labels):
|
| 157 |
+
for i, lab in enumerate(labels):
|
| 158 |
+
if 'pose_m' not in lab:
|
| 159 |
+
continue
|
| 160 |
+
pose = np.asarray(lab['pose_m']).reshape(51)
|
| 161 |
+
if not np.any(pose): # Official Dex-YCB missing-pose sentinel, independent of joints/seg.
|
| 162 |
+
continue
|
| 163 |
+
motion[i, slot] = np.r_[pose[:3], pca_to_axis_angle(pose[3:48], models[side]),
|
| 164 |
+
calib.betas[cal_name], pose[48:51]]
|
| 165 |
+
mv[i, slot] = True
|
| 166 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 167 |
+
['T', 'hand', 'parameter'], label_loc, model_profile=model_profile(models),
|
| 168 |
+
calibration_source=calibration_locator(calib_path, f'calibration/mano_{cal_name}/mano.yml'),
|
| 169 |
+
provenance={'kind': 'format_conversion', 'method': 'source PCA @ hands_components + hands_mean; explicit axis-angle consumed with flat_hand_mean=true'})
|
| 170 |
+
elif any('pose_m' in lab for lab in labels):
|
| 171 |
+
view.absent('mano', 'Source PCA exists; provide --mano-dir to expand it', 'dependency_missing')
|
| 172 |
+
else:
|
| 173 |
+
view.absent('mano', 'No source pose_m field')
|
| 174 |
+
for source_key, key, dim, unit in [('joint_2d', 'uv', 2, 'pixel'), ('joint_3d', 'xyz', 3, 'm')]:
|
| 175 |
+
if not any(source_key in x for x in labels):
|
| 176 |
+
view.absent('keypoints_' + key, 'No source ' + source_key)
|
| 177 |
+
continue
|
| 178 |
+
points = np.full((n, 2, 21, dim), np.nan, np.float32)
|
| 179 |
+
valid = np.zeros((n, 2, 21), bool)
|
| 180 |
+
for i, lab in enumerate(labels):
|
| 181 |
+
if source_key not in lab:
|
| 182 |
+
continue
|
| 183 |
+
p = np.asarray(lab[source_key]).reshape(21, dim)
|
| 184 |
+
points[i, slot] = p
|
| 185 |
+
valid[i, slot] = not np.all(p == -1) # Official sentinel covers the whole source hand.
|
| 186 |
+
# An individual off-image point (-1, -1) is not evidence of missing annotation.
|
| 187 |
+
view.tensor('keypoints_' + key, f'keypoints/{key}/v1', f'annotation/keypoints/{key}.pt',
|
| 188 |
+
points, valid, ['T', 'hand', 'keypoint', 'coordinate'], label_loc,
|
| 189 |
+
keypoint_schema='mano21/v1', unit=unit)
|
| 190 |
+
ycb_ids = [int(x) for x in meta['ycb_ids']]
|
| 191 |
+
for j, oid in enumerate(ycb_ids):
|
| 192 |
+
entity = f'ycb_{oid:02d}'
|
| 193 |
+
view.object(entity, meta_loc, source_object_id=oid, category_id=oid)
|
| 194 |
+
poses = np.full((n, 4, 4), np.nan, np.float32)
|
| 195 |
+
valid = np.zeros(n, bool)
|
| 196 |
+
for i, lab in enumerate(labels):
|
| 197 |
+
if 'pose_y' in lab:
|
| 198 |
+
pose = np.asarray(lab['pose_y'])
|
| 199 |
+
if pose.shape != (len(ycb_ids), 3, 4):
|
| 200 |
+
raise ValueError('pose_y shape differs from ycb_ids')
|
| 201 |
+
if np.any(pose[j]): # Official all-zero missing object pose sentinel.
|
| 202 |
+
poses[i] = np.eye(4)
|
| 203 |
+
poses[i, :3] = pose[j]
|
| 204 |
+
valid[i] = True
|
| 205 |
+
if any('pose_y' in lab for lab in labels):
|
| 206 |
+
view.tensor('pose_' + entity, 'object/rigid/v1', f'annotation/object/{entity}/pose.pt',
|
| 207 |
+
poses, valid, ['T', 'row', 'column'], label_loc,
|
| 208 |
+
convention='T_camera_from_object', unit='m')
|
| 209 |
+
else:
|
| 210 |
+
view.absent('pose_' + entity, 'No source pose_y field')
|
| 211 |
+
if oid in assets:
|
| 212 |
+
mesh_asset(view, entity, assets[oid], assets[oid] / 'textured_simple.obj',
|
| 213 |
+
locator(asset_archive, f'models/{assets[oid].name}/textured_simple.obj'))
|
| 214 |
+
else:
|
| 215 |
+
view.absent('mesh_' + entity, 'models.tar.gz unavailable', 'not_downloaded')
|
| 216 |
+
if any('seg' in lab for lab in labels):
|
| 217 |
+
mask_rows = []
|
| 218 |
+
width, height = view.meta['camera']['image_size']
|
| 219 |
+
for i, lab in enumerate(labels):
|
| 220 |
+
values = np.unique(lab.get('seg', np.zeros((height, width), np.uint8)))
|
| 221 |
+
mappings = []
|
| 222 |
+
for value in values:
|
| 223 |
+
value = int(value)
|
| 224 |
+
if value == 0:
|
| 225 |
+
continue
|
| 226 |
+
if value != 255 and value not in ycb_ids:
|
| 227 |
+
raise ValueError(f'unknown Dex-YCB region value {value}')
|
| 228 |
+
mappings.append(dict(mask_value=value, category_id='hand' if value == 255 else value,
|
| 229 |
+
entity_id='hand_' + side if value == 255 else f'ycb_{value:02d}', part_id=None,
|
| 230 |
+
source_instance_id=value))
|
| 231 |
+
mask_rows.append(dict(frame_index=i, labels=mappings))
|
| 232 |
+
view.raster('segment', (lab.get('seg', np.zeros((height, width), np.uint16)) for lab in labels),
|
| 233 |
+
['seg' in lab for lab in labels], label_loc, mask_rows)
|
| 234 |
+
view.meta['components']['segment'].update(coverage={'kind': 'selected_entities',
|
| 235 |
+
'entities': ['hand_' + side] + [f'ycb_{o:02d}' for o in ycb_ids]}, source_zero_meaning='background')
|
| 236 |
+
else:
|
| 237 |
+
view.absent('segment', 'No source seg field')
|
| 238 |
+
if any('aligned_depth_to_color' in frames[f] for f in ids):
|
| 239 |
+
def depths():
|
| 240 |
+
width, height = view.meta['camera']['image_size']
|
| 241 |
+
for f in ids:
|
| 242 |
+
item = frames[f].get('aligned_depth_to_color')
|
| 243 |
+
if item is None:
|
| 244 |
+
yield np.full((height, width), np.nan, np.float32)
|
| 245 |
+
else:
|
| 246 |
+
with Image.open(item[0]) as im:
|
| 247 |
+
yield np.asarray(im).astype(np.float32) / 1000.0
|
| 248 |
+
view.raster('depth', depths(), None, {'frames_ref': 'camera/frames.jsonl',
|
| 249 |
+
'source_field': 'component_sources.aligned_depth_to_color', 'conversion': 'millimetres to metres'})
|
| 250 |
+
else:
|
| 251 |
+
view.absent('depth', 'No source aligned_depth_to_color frames')
|
| 252 |
+
grasp = meta.get('ycb_grasp_ind')
|
| 253 |
+
if grasp is not None:
|
| 254 |
+
if not 0 <= int(grasp) < len(ycb_ids):
|
| 255 |
+
raise ValueError('invalid ycb_grasp_ind')
|
| 256 |
+
relation = dict(relation_type='grasp', subject_id='hand_' + side,
|
| 257 |
+
object_id=f'ycb_{ycb_ids[int(grasp)]:02d}', status='positive', source_locator=meta_loc,
|
| 258 |
+
provenance={'kind': 'source', 'method': 'sequence ycb_grasp_ind resolved through ycb_ids; not per-frame contact'})
|
| 259 |
+
view.relations([{'frame_index': i, 'relations': [relation]} for i in range(n)], np.ones(n, bool), meta_loc)
|
| 260 |
+
else:
|
| 261 |
+
view.absent('relations', 'No source grasp/contact relation')
|
| 262 |
+
return view.finish()
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
MEMBER = re.compile(r'^([^/]+)/(\d{8}_\d{6})/(meta\.yml|(\d{12})/(color|labels|aligned_depth_to_color)_(\d+)\.(jpg|npz|png))$')
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def convert_archive(archive, args, out, calib, calib_path, models, assets, asset_archive):
|
| 269 |
+
selected_views = set(args.views.split(',')) if args.views else None
|
| 270 |
+
done = 0
|
| 271 |
+
current, meta, meta_loc, rows = None, None, None, {}
|
| 272 |
+
with tempfile.TemporaryDirectory(prefix='dex-source-') as wd:
|
| 273 |
+
work = Path(wd)
|
| 274 |
+
def flush():
|
| 275 |
+
nonlocal done
|
| 276 |
+
if not rows:
|
| 277 |
+
return
|
| 278 |
+
seq = archive.name.split('.tar')[0] + '_' + current
|
| 279 |
+
reports = {}
|
| 280 |
+
with sequence_dir(out, seq) as target:
|
| 281 |
+
for serial, frames in sorted(rows.items()):
|
| 282 |
+
reports[serial] = convert_view(target / serial, args, seq, serial, frames, meta,
|
| 283 |
+
meta_loc, calib, calib_path, models, assets, asset_archive)
|
| 284 |
+
build_record(out, seq, reports)
|
| 285 |
+
for staged in list(work.iterdir()):
|
| 286 |
+
if staged.is_dir():
|
| 287 |
+
shutil.rmtree(staged)
|
| 288 |
+
else:
|
| 289 |
+
staged.unlink()
|
| 290 |
+
done += 1
|
| 291 |
+
print(f'Converted {seq}', flush=True)
|
| 292 |
+
with tarfile.open(archive, 'r|gz') as tf:
|
| 293 |
+
for member in tf:
|
| 294 |
+
match = MEMBER.fullmatch(member.name)
|
| 295 |
+
if not member.isfile() or not match:
|
| 296 |
+
continue
|
| 297 |
+
seq = match[2]
|
| 298 |
+
if seq != current:
|
| 299 |
+
flush()
|
| 300 |
+
if args.limit and done >= args.limit:
|
| 301 |
+
break
|
| 302 |
+
current, meta, meta_loc, rows = seq, None, None, {}
|
| 303 |
+
data_kind = match[3]
|
| 304 |
+
if data_kind == 'meta.yml':
|
| 305 |
+
data = tf.extractfile(member).read()
|
| 306 |
+
meta = yaml_load_bytes(data)
|
| 307 |
+
meta_loc = locator(archive, member.name, data)
|
| 308 |
+
continue
|
| 309 |
+
serial, kind, f = match[4], match[5], int(match[6])
|
| 310 |
+
if selected_views and serial not in selected_views or args.max_frames and f >= args.max_frames:
|
| 311 |
+
continue
|
| 312 |
+
data = tf.extractfile(member).read()
|
| 313 |
+
dest = safe_member(work, member.name)
|
| 314 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 315 |
+
dest.write_bytes(data)
|
| 316 |
+
row = rows.setdefault(serial, {}).setdefault(f, {})
|
| 317 |
+
if kind in row:
|
| 318 |
+
raise ValueError('duplicate archive frame')
|
| 319 |
+
row[kind] = (dest, locator(archive, member.name, data))
|
| 320 |
+
else:
|
| 321 |
+
flush()
|
| 322 |
+
return done
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def main(argv=None):
|
| 326 |
+
p = parser('dex-ycb', __doc__)
|
| 327 |
+
p.add_argument('--subjects')
|
| 328 |
+
args = p.parse_args(argv)
|
| 329 |
+
archives = sorted({a for r in roots(args.root) for a in r.glob('*-subject-*.tar.gz')})
|
| 330 |
+
if args.subjects:
|
| 331 |
+
subjects = {s.strip().zfill(2) for s in args.subjects.split(',')}
|
| 332 |
+
archives = [a for a in archives if re.search(r'subject-(\d+)', a.name)[1] in subjects]
|
| 333 |
+
if not archives:
|
| 334 |
+
p.error('no Dex-YCB subject archives found')
|
| 335 |
+
cp = find_file(args.root, 'calibration.tar.gz') or find_file(args.root, 'calibration')
|
| 336 |
+
if cp is None:
|
| 337 |
+
p.error('calibration source missing')
|
| 338 |
+
calib = Calibration(cp.parent)
|
| 339 |
+
models = mano_models(args.mano_dir)
|
| 340 |
+
out = release(args, 'dex-ycb')
|
| 341 |
+
with tempfile.TemporaryDirectory(prefix='dex-models-') as wd:
|
| 342 |
+
assets, asset_archive = prepare_models(args.root, Path(wd))
|
| 343 |
+
for archive in archives:
|
| 344 |
+
convert_archive(archive, args, out, calib, cp, models, assets, asset_archive)
|
| 345 |
+
return 0
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
if __name__ == '__main__':
|
| 349 |
+
raise SystemExit(main())
|
H2O/shared-v1.0/script/provenance/previous-run/script/convert_h2o_v1.0.py
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""H2O native RGB-D, MANO, joints and objects → CONTRACT.md v1.0 (no rendered masks)."""
|
| 3 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
import shutil
|
| 8 |
+
import tarfile
|
| 9 |
+
import tempfile
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
import zipfile
|
| 12 |
+
|
| 13 |
+
# Bound native libraries before loading NumPy/Torch; each worker still uses independent FFmpeg processes.
|
| 14 |
+
for key in ('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS', 'NUMEXPR_NUM_THREADS'):
|
| 15 |
+
os.environ[key] = '1'
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
from PIL import Image
|
| 19 |
+
import torch
|
| 20 |
+
|
| 21 |
+
from warehouse_v1_0 import (View, build_record, check_mesh, find_file, locator, mano_models, mesh_asset,
|
| 22 |
+
model_profile, parser, release, roots, safe_member, sequence_dir, sha256)
|
| 23 |
+
|
| 24 |
+
OBJECTS = {1: 'book', 2: 'espresso', 3: 'lotion', 4: 'spray',
|
| 25 |
+
5: 'milk', 6: 'cocoa', 7: 'chips', 8: 'cappuccino'}
|
| 26 |
+
MEMBER = re.compile(r'^(?:h2o_CASA/)?(subject\d+)/([^/]+)/(\d+)/(cam\d)/(.+)$')
|
| 27 |
+
FRAME = re.compile(r'(rgb|depth|cam_pose|hand_pose|hand_pose_mano|obj_pose|obj_pose_rt)/(\d+)\.(png|jpg|txt)$')
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def load_splits(root):
|
| 31 |
+
archive = find_file(root, 'label_split.zip')
|
| 32 |
+
result = {}
|
| 33 |
+
if archive is not None:
|
| 34 |
+
with zipfile.ZipFile(archive) as z:
|
| 35 |
+
for split in ('train', 'val', 'test'):
|
| 36 |
+
member = f'label_split/action_{split}.txt'
|
| 37 |
+
for line_no, line in enumerate(z.read(member).decode().splitlines(), 1):
|
| 38 |
+
fields = line.split()
|
| 39 |
+
if len(fields) < 2 or fields[1] == 'path':
|
| 40 |
+
continue
|
| 41 |
+
key = fields[1]
|
| 42 |
+
if key in result and result[key][0] != split:
|
| 43 |
+
raise ValueError('conflicting official splits')
|
| 44 |
+
result[key] = (split, locator(archive, member, record=line_no))
|
| 45 |
+
return result
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def load_assets(root, work):
|
| 49 |
+
archive = find_file(root, 'object.zip')
|
| 50 |
+
if archive is None:
|
| 51 |
+
return {}, None
|
| 52 |
+
with zipfile.ZipFile(archive) as z:
|
| 53 |
+
for member in z.infolist():
|
| 54 |
+
if member.is_dir():
|
| 55 |
+
continue
|
| 56 |
+
path = safe_member(work, member.filename)
|
| 57 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 58 |
+
path.write_bytes(z.read(member))
|
| 59 |
+
result = {}
|
| 60 |
+
for oid, name in OBJECTS.items():
|
| 61 |
+
directory = work / 'object' / name
|
| 62 |
+
aliases = []
|
| 63 |
+
# Source cocoa.obj -> ovomaltine.mtl -> cocoa.png, but the ZIP names the
|
| 64 |
+
# supplied texture ovomaltine.png. Keep all originals and add a byte-identical alias.
|
| 65 |
+
if name == 'cocoa' and not (directory / 'cocoa.png').exists():
|
| 66 |
+
mtl = directory / 'ovomaltine.mtl'
|
| 67 |
+
if mtl.is_file() and 'map_Kd cocoa.png' in mtl.read_text().splitlines():
|
| 68 |
+
texture = directory / 'ovomaltine.png'
|
| 69 |
+
shutil.copyfile(texture, directory / 'cocoa.png')
|
| 70 |
+
aliases.append({'file': 'cocoa.png', 'sha256': sha256(texture),
|
| 71 |
+
'source': locator(archive, 'object/cocoa/ovomaltine.png')})
|
| 72 |
+
candidates = list(directory.glob('*.obj'))
|
| 73 |
+
if len(candidates) != 1:
|
| 74 |
+
raise ValueError(f'expected one source OBJ for {name}')
|
| 75 |
+
check_mesh(candidates[0], directory) # Fail before decoding any large subject archive.
|
| 76 |
+
result[oid] = (directory, candidates[0], aliases)
|
| 77 |
+
return result, archive
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def convert_view(path, args, seq, cam, rows, intr, splits, models, assets, asset_archive):
|
| 81 |
+
codec_threads = getattr(args, 'codec_threads', 1)
|
| 82 |
+
ids = list(range(min(rows), max(rows) + 1))
|
| 83 |
+
for f in ids:
|
| 84 |
+
rows.setdefault(f, {})
|
| 85 |
+
n = len(ids)
|
| 86 |
+
if not n:
|
| 87 |
+
raise ValueError('no RGB frames')
|
| 88 |
+
split, split_loc = splits.get(seq, ('unknown', None))
|
| 89 |
+
frame_rows = [dict(source_frame_id=f, sync_id=f'{seq}:{f}', source_locator=rows[f]['rgb'][1] if 'rgb' in rows[f] else {'sequence': seq, 'camera': cam, 'source_frame_id': f, 'missing_rgb': True},
|
| 90 |
+
component_sources={k: item[1] for k, item in rows[f].items()},
|
| 91 |
+
annotation_matches={k: dict(source_frame_id=f, source_timestamp_ns=None,
|
| 92 |
+
clock_domain=None, match_method='index_map', delta_ns=None)
|
| 93 |
+
for k in rows[f] if k != 'rgb'}) for f in ids]
|
| 94 |
+
view = View(path, 'H2O', args.release_id, seq.replace('/', '_'), cam, frame_rows, split=split)
|
| 95 |
+
view.valid_rules = {
|
| 96 |
+
'mano': 'Per-hand hand_pose_mano flag equals 1; corresponding side model available',
|
| 97 |
+
'keypoints': "Per-hand hand_pose flag equals 1, broadcast to that hand's 21 source points independently of MANO",
|
| 98 |
+
'pose': 'Source obj_pose_rt class equals this nonzero object class',
|
| 99 |
+
'points': 'Source obj_pose class equals this nonzero object class, broadcast to its 21 points',
|
| 100 |
+
}
|
| 101 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 102 |
+
view.meta['view_type'] = 'ego' if cam == 'cam4' else 'exo' if cam in ('cam0', 'cam1', 'cam2', 'cam3') else 'unknown'
|
| 103 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'views': args.views}
|
| 104 |
+
if split_loc:
|
| 105 |
+
view.meta.update(split_scheme='official_action_split', split_source_locator=split_loc)
|
| 106 |
+
# In the measured 275 H2O views, exact FFV1 was always smaller than exact H.264.
|
| 107 |
+
view.rgb([rows[f]['rgb'][0] if 'rgb' in rows[f] else None for f in ids],
|
| 108 |
+
{'frames_ref': 'camera/frames.jsonl'}, ffv1_first=True, codec_threads=codec_threads)
|
| 109 |
+
loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources'}
|
| 110 |
+
if intr is not None:
|
| 111 |
+
fx, fy, cx, cy, width, height = np.loadtxt(intr[0]).ravel()
|
| 112 |
+
if [int(width), int(height)] != view.meta['camera']['image_size']:
|
| 113 |
+
raise ValueError('source intrinsics resolution mismatch')
|
| 114 |
+
K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
|
| 115 |
+
view.camera(K, intr[1])
|
| 116 |
+
camps = np.full((n, 4, 4), np.nan, np.float32)
|
| 117 |
+
cv = np.zeros(n, bool)
|
| 118 |
+
data = []
|
| 119 |
+
for i, f in enumerate(ids):
|
| 120 |
+
lab = {k: np.loadtxt(item[0]).ravel() for k, item in rows[f].items() if k not in ('rgb', 'depth')}
|
| 121 |
+
data.append(lab)
|
| 122 |
+
if 'cam_pose' in lab:
|
| 123 |
+
camps[i] = np.linalg.inv(lab['cam_pose'].reshape(4, 4))
|
| 124 |
+
cv[i] = True
|
| 125 |
+
if cv.any():
|
| 126 |
+
view.tensor('extrinsic', 'transform/se3/v1', 'camera/extrinsic.pt', camps, cv,
|
| 127 |
+
['T', 'row', 'column'], loc, convention='T_camera_from_world',
|
| 128 |
+
source_convention='T_world_from_camera')
|
| 129 |
+
motion, mv = np.full((n, 2, 61), np.nan, np.float32), np.zeros((n, 2), bool)
|
| 130 |
+
points, pv = np.full((n, 2, 21, 3), np.nan, np.float32), np.zeros((n, 2, 21), bool)
|
| 131 |
+
object_ids = set()
|
| 132 |
+
for i, lab in enumerate(data):
|
| 133 |
+
if 'hand_pose_mano' in lab:
|
| 134 |
+
hands = lab['hand_pose_mano'].reshape(2, 62)
|
| 135 |
+
for side, row in enumerate(hands):
|
| 136 |
+
if row[0] not in (0, 1):
|
| 137 |
+
raise ValueError('unexpected H2O MANO presence flag')
|
| 138 |
+
if row[0] == 1:
|
| 139 |
+
motion[i, side] = np.r_[row[4:52], row[52:62], row[1:4]]
|
| 140 |
+
mv[i, side] = True
|
| 141 |
+
if 'hand_pose' in lab:
|
| 142 |
+
hands = lab['hand_pose'].reshape(2, 64)
|
| 143 |
+
for side, row in enumerate(hands):
|
| 144 |
+
if row[0] not in (0, 1):
|
| 145 |
+
raise ValueError('unexpected H2O keypoint presence flag')
|
| 146 |
+
if row[0] == 1:
|
| 147 |
+
points[i, side] = row[1:].reshape(21, 3)
|
| 148 |
+
pv[i, side] = True
|
| 149 |
+
for key in ('obj_pose', 'obj_pose_rt'):
|
| 150 |
+
if key in lab and lab[key][0] != 0:
|
| 151 |
+
object_ids.add(int(lab[key][0]))
|
| 152 |
+
if any('hand_pose_mano' in lab for lab in data):
|
| 153 |
+
if len(models) == 2:
|
| 154 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 155 |
+
['T', 'hand', 'parameter'], loc, model_profile=model_profile(models))
|
| 156 |
+
else:
|
| 157 |
+
view.absent('mano', 'Source parameters exist; --mano-dir must identify both model profiles', 'dependency_missing')
|
| 158 |
+
if any('hand_pose' in lab for lab in data):
|
| 159 |
+
view.tensor('keypoints_xyz', 'keypoints/xyz/v1', 'annotation/keypoints/xyz.pt', points, pv,
|
| 160 |
+
['T', 'hand', 'keypoint', 'coordinate'], loc, keypoint_schema='mano21/v1', unit='m')
|
| 161 |
+
for oid in sorted(object_ids):
|
| 162 |
+
if oid not in OBJECTS:
|
| 163 |
+
raise ValueError(f'unknown H2O object class {oid}')
|
| 164 |
+
entity = OBJECTS[oid]
|
| 165 |
+
view.object(entity, loc, category_id=oid, source_object_id=oid)
|
| 166 |
+
poses, ov = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 167 |
+
pts, kv = np.full((n, 21, 3), np.nan, np.float32), np.zeros((n, 21), bool)
|
| 168 |
+
for i, lab in enumerate(data):
|
| 169 |
+
if 'obj_pose_rt' in lab and lab['obj_pose_rt'][0] == oid:
|
| 170 |
+
poses[i] = lab['obj_pose_rt'][1:].reshape(4, 4)
|
| 171 |
+
ov[i] = True
|
| 172 |
+
if 'obj_pose' in lab and lab['obj_pose'][0] == oid:
|
| 173 |
+
pts[i] = lab['obj_pose'][1:].reshape(21, 3)
|
| 174 |
+
kv[i] = True
|
| 175 |
+
if ov.any():
|
| 176 |
+
view.tensor('pose_' + entity, 'object/rigid/v1', f'annotation/object/{entity}/pose.pt',
|
| 177 |
+
poses, ov, ['T', 'row', 'column'], loc, convention='T_camera_from_object', unit='m')
|
| 178 |
+
if kv.any():
|
| 179 |
+
view.tensor('points_' + entity, 'object_keypoints/camera/v1',
|
| 180 |
+
f'annotation/object/{entity}/keypoints/xyz.pt', pts, kv,
|
| 181 |
+
['T', 'keypoint', 'coordinate'], loc, keypoint_schema='H2O_official_object21',
|
| 182 |
+
keypoint_names=['center'] + [f'corner_{i}' for i in range(8)] + [f'edge_midpoint_{i}' for i in range(12)],
|
| 183 |
+
source_order='official obj_point_order.jpg: center, 8 corners, 12 edge midpoints', unit='m')
|
| 184 |
+
if oid in assets:
|
| 185 |
+
directory, obj, aliases = assets[oid]
|
| 186 |
+
asset_loc = locator(asset_archive, f'object/{entity}/{obj.name}')
|
| 187 |
+
if aliases:
|
| 188 |
+
asset_loc['texture_aliases'] = aliases
|
| 189 |
+
mesh_asset(view, entity, directory, obj, asset_loc)
|
| 190 |
+
else:
|
| 191 |
+
view.absent('mesh_' + entity, 'Source object.zip unavailable', 'not_downloaded')
|
| 192 |
+
if any('depth' in rows[f] for f in ids):
|
| 193 |
+
width, height = view.meta['camera']['image_size']
|
| 194 |
+
depth_threads = getattr(args, 'depth_threads', 1)
|
| 195 |
+
def read_depth(f):
|
| 196 |
+
item = rows[f].get('depth')
|
| 197 |
+
if item:
|
| 198 |
+
with Image.open(item[0]) as im:
|
| 199 |
+
return np.asarray(im).astype(np.float32) / 1000.0
|
| 200 |
+
return np.full((height, width), np.nan, np.float32)
|
| 201 |
+
def depths():
|
| 202 |
+
if depth_threads == 1:
|
| 203 |
+
yield from map(read_depth, ids)
|
| 204 |
+
else:
|
| 205 |
+
with ThreadPoolExecutor(max_workers=depth_threads) as pool:
|
| 206 |
+
# Ordered batches bound decoded arrays to depth_threads frames per view.
|
| 207 |
+
for start in range(0, len(ids), depth_threads):
|
| 208 |
+
yield from pool.map(read_depth, ids[start:start + depth_threads])
|
| 209 |
+
view.raster('depth', depths(), None, loc | {'source_field': 'component_sources.depth',
|
| 210 |
+
'definition': 'https://github.com/taeinkwon/h2oplayer/blob/main/utils.py',
|
| 211 |
+
'conversion': 'registered millimetre camera-Z to metres; no viewer range clipping'},
|
| 212 |
+
codec_threads=codec_threads)
|
| 213 |
+
else:
|
| 214 |
+
view.absent('depth', 'No source depth frames')
|
| 215 |
+
view.absent('segment', 'H2O provides no native segmentation; rendering deferred to v2.0')
|
| 216 |
+
view.absent('relations', 'No source contact/grasp annotation')
|
| 217 |
+
return view.finish()
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def convert_archive(archive, args, out, splits, models, assets, asset_archive):
|
| 221 |
+
selected_views = set(args.views.split(',')) if args.views else None
|
| 222 |
+
subjects = {'subject' + s.strip() for s in args.subjects.split(',')} if args.subjects else None
|
| 223 |
+
current, rows, intrinsics, done = None, {}, {}, 0
|
| 224 |
+
published_views = set()
|
| 225 |
+
with tempfile.TemporaryDirectory(prefix='h2o-source-') as wd:
|
| 226 |
+
work = Path(wd)
|
| 227 |
+
def flush():
|
| 228 |
+
nonlocal done
|
| 229 |
+
if not rows:
|
| 230 |
+
return
|
| 231 |
+
seq = '/'.join(current)
|
| 232 |
+
reports, pending = {}, {}
|
| 233 |
+
for cam, frames in sorted(rows.items()):
|
| 234 |
+
existing = out / 'data' / seq.replace('/', '_') / cam
|
| 235 |
+
if (existing / 'metainfo.json').is_file():
|
| 236 |
+
old_frames = [json.loads(line) for line in (existing / 'camera/frames.jsonl').read_text().splitlines()]
|
| 237 |
+
if [f['source_frame_id'] for f in old_frames] != list(range(min(frames), max(frames) + 1)):
|
| 238 |
+
raise ValueError('existing view has different sampling; choose a new release-id')
|
| 239 |
+
for frame in old_frames:
|
| 240 |
+
incoming = frames.get(frame['source_frame_id'], {})
|
| 241 |
+
previous = frame.get('component_sources', {})
|
| 242 |
+
if set(previous) != set(incoming) or any(previous[k].get('sha256') != v[1].get('sha256') for k, v in incoming.items()):
|
| 243 |
+
raise ValueError('duplicate H2O view differs from the published source; choose a new release-id')
|
| 244 |
+
else:
|
| 245 |
+
pending[cam] = frames
|
| 246 |
+
if pending:
|
| 247 |
+
with sequence_dir(out, seq.replace('/', '_')) as target:
|
| 248 |
+
for cam, frames in pending.items():
|
| 249 |
+
reports[cam] = convert_view(target / cam, args, seq, cam, frames,
|
| 250 |
+
intrinsics.get(cam), splits, models, assets, asset_archive)
|
| 251 |
+
build_record(out, seq.replace('/', '_'), reports)
|
| 252 |
+
for staged in list(work.iterdir()):
|
| 253 |
+
if staged.is_dir():
|
| 254 |
+
shutil.rmtree(staged)
|
| 255 |
+
else:
|
| 256 |
+
staged.unlink()
|
| 257 |
+
done += 1
|
| 258 |
+
print(f'{"Converted" if pending else "Verified existing"} {seq}', flush=True)
|
| 259 |
+
# Uncompressed CASA supports seeking over large frames; gzip is single-pass.
|
| 260 |
+
mode = 'r:' if archive.suffix == '.tar' else 'r|gz'
|
| 261 |
+
with tarfile.open(archive, mode) as tf:
|
| 262 |
+
for member in tf:
|
| 263 |
+
match = MEMBER.fullmatch(member.name)
|
| 264 |
+
if not member.isfile() or not match:
|
| 265 |
+
continue
|
| 266 |
+
subj, scene, seq, cam, tail = match.groups()
|
| 267 |
+
if subjects and subj not in subjects:
|
| 268 |
+
continue
|
| 269 |
+
key = (subj, scene, seq)
|
| 270 |
+
if key != current:
|
| 271 |
+
flush()
|
| 272 |
+
if args.limit and done >= args.limit:
|
| 273 |
+
break
|
| 274 |
+
current, rows, intrinsics = key, {}, {}
|
| 275 |
+
published_views = {view.name for view in
|
| 276 |
+
(out / 'data' / '_'.join(key)).glob('cam*')
|
| 277 |
+
if (view / 'metainfo.json').is_file()}
|
| 278 |
+
if selected_views and cam not in selected_views:
|
| 279 |
+
continue
|
| 280 |
+
frame = FRAME.fullmatch(tail)
|
| 281 |
+
if tail != 'cam_intrinsics.txt' and not frame:
|
| 282 |
+
continue
|
| 283 |
+
if frame and args.max_frames and int(frame[2]) >= args.max_frames:
|
| 284 |
+
continue
|
| 285 |
+
data = tf.extractfile(member).read()
|
| 286 |
+
dest = safe_member(work, member.name)
|
| 287 |
+
if cam not in published_views:
|
| 288 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 289 |
+
dest.write_bytes(data)
|
| 290 |
+
# Published views still verify source bytes, but never read their staging paths.
|
| 291 |
+
item = (dest, locator(archive, member.name, data))
|
| 292 |
+
if tail == 'cam_intrinsics.txt':
|
| 293 |
+
intrinsics[cam] = item
|
| 294 |
+
else:
|
| 295 |
+
kind, f = frame[1], int(frame[2])
|
| 296 |
+
row = rows.setdefault(cam, {}).setdefault(f, {})
|
| 297 |
+
if kind in row:
|
| 298 |
+
raise ValueError('duplicate H2O frame')
|
| 299 |
+
row[kind] = item
|
| 300 |
+
else:
|
| 301 |
+
flush()
|
| 302 |
+
return done
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def main(argv=None):
|
| 306 |
+
p = parser('H2O', __doc__)
|
| 307 |
+
p.set_defaults(release_id='shared-v1.0')
|
| 308 |
+
p.add_argument('--workers', type=int, choices=range(1, 5), default=1,
|
| 309 |
+
help='Independent subject archives in parallel, 1..4; benchmark before using >2')
|
| 310 |
+
p.add_argument('--codec-threads', type=int, choices=(1, 2, 4, 8, 10), default=4,
|
| 311 |
+
help='FFV1 slice threads per encode; default 4, use 10 for the current full run')
|
| 312 |
+
p.add_argument('--decode-threads', type=int, choices=(1, 2, 4, 8, 10), default=1,
|
| 313 |
+
help='FFmpeg threads for source RGB decoding and decoded-media checks')
|
| 314 |
+
p.add_argument('--depth-threads', type=int, choices=(1, 2, 4), default=1,
|
| 315 |
+
help='Bounded ordered source depth PNG loading per worker')
|
| 316 |
+
p.add_argument('--subjects')
|
| 317 |
+
p.add_argument('--include-casa', action='store_true')
|
| 318 |
+
p.add_argument('--archive', type=Path, help='Convert one explicit source archive')
|
| 319 |
+
args = p.parse_args(argv)
|
| 320 |
+
os.environ['HAND_WAREHOUSE_FFMPEG_THREADS'] = str(args.decode_threads)
|
| 321 |
+
if args.include_casa and args.workers != 1:
|
| 322 |
+
p.error('CASA can share sequence IDs with subject archives; convert it sequentially in a separate release')
|
| 323 |
+
archives = [args.archive.expanduser()] if args.archive else sorted(
|
| 324 |
+
{a for root in roots(args.root) for a in root.glob('subject*_v1_1.tar.gz')})
|
| 325 |
+
if args.subjects and not args.archive:
|
| 326 |
+
requested = {'subject' + s.strip() for s in args.subjects.split(',')}
|
| 327 |
+
archives = [arc for arc in archives if arc.name.split('_', 1)[0] in requested]
|
| 328 |
+
if args.include_casa:
|
| 329 |
+
casa = find_file(args.root, 'h2o_CASA.tar')
|
| 330 |
+
if casa:
|
| 331 |
+
archives.append(casa)
|
| 332 |
+
if not archives:
|
| 333 |
+
p.error('no H2O archives found')
|
| 334 |
+
out = release(args, 'H2O')
|
| 335 |
+
source_mapping = next(p for p in (Path(__file__).resolve().parents[1] / 'docs/h2o-RAW_TO_SHARED.md',
|
| 336 |
+
Path(__file__).resolve().parents[1] / 'doc/RAW_TO_SHARED.md',
|
| 337 |
+
out / 'doc/RAW_TO_SHARED.md') if p.is_file())
|
| 338 |
+
mapping = out / 'doc/RAW_TO_SHARED.md'
|
| 339 |
+
if mapping.exists() and mapping.read_bytes() != source_mapping.read_bytes():
|
| 340 |
+
raise ValueError('RAW_TO_SHARED.md changed; choose a new release-id')
|
| 341 |
+
if not mapping.exists():
|
| 342 |
+
shutil.copyfile(source_mapping, mapping)
|
| 343 |
+
torch.set_num_threads(1)
|
| 344 |
+
models, splits = mano_models(args.mano_dir), load_splits(args.root)
|
| 345 |
+
with tempfile.TemporaryDirectory(prefix='h2o-assets-') as wd:
|
| 346 |
+
assets, asset_archive = load_assets(args.root, Path(wd))
|
| 347 |
+
def convert_one(archive):
|
| 348 |
+
return convert_archive(archive, args, out, splits, models, assets, asset_archive)
|
| 349 |
+
if args.workers == 1:
|
| 350 |
+
for archive in archives:
|
| 351 |
+
convert_one(archive)
|
| 352 |
+
else:
|
| 353 |
+
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 354 |
+
for archive, count in zip(archives, pool.map(convert_one, archives), strict=True):
|
| 355 |
+
print(f'Archive {archive.name}: {count} sequences', flush=True)
|
| 356 |
+
return 0
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
if __name__ == '__main__':
|
| 360 |
+
raise SystemExit(main())
|
| 361 |
+
|
| 362 |
+
# TODO(v2.0): 以下旧 MANO 网格和渲染分割代码仅保留备查;v1.0 不生成标注。
|
| 363 |
+
# def load_mano_model(path: Path):
|
| 364 |
+
# """MPI MANO pkl → numpy 字典。shapedirs 在 pkl 内为 chumpy Select(对 (778,3,20) 基
|
| 365 |
+
# 底 flat 选取前 10 个 shape 分量;idxs 已核实等价于 base[:,:,:10])。"""
|
| 366 |
+
# with open(path, "rb") as f:
|
| 367 |
+
# d = _ManoUnpickler(f, encoding="latin1").load()
|
| 368 |
+
# sd = d["shapedirs"]
|
| 369 |
+
# base = np.asarray(sd.a.x, np.float64) # (778, 3, 20)
|
| 370 |
+
# shapedirs = base.reshape(-1)[np.asarray(sd.idxs)].reshape(base.shape[0], 3, -1)
|
| 371 |
+
# jreg = d["J_regressor"]
|
| 372 |
+
# jreg = np.asarray(jreg.todense()) if hasattr(jreg, "todense") else np.asarray(jreg)
|
| 373 |
+
# return {"v_template": np.asarray(d["v_template"], np.float64),
|
| 374 |
+
# "shapedirs": shapedirs,
|
| 375 |
+
# "posedirs": np.asarray(d["posedirs"], np.float64),
|
| 376 |
+
# "weights": np.asarray(d["weights"], np.float64),
|
| 377 |
+
# "J_regressor": np.asarray(jreg, np.float64),
|
| 378 |
+
# "kintree": np.asarray(d["kintree_table"], np.int64),
|
| 379 |
+
# "faces": np.asarray(d["f"], np.int64)}
|
| 380 |
+
#
|
| 381 |
+
#
|
| 382 |
+
# def rodrigues(r):
|
| 383 |
+
# """axis-angle (N,3) → 旋转矩阵 (N,3,3)。公式 I + sinθ·K + (1−cosθ)·K²(已对 scipy 核验)。"""
|
| 384 |
+
# r = np.asarray(r, np.float64).reshape(-1, 3)
|
| 385 |
+
# th = np.linalg.norm(r, axis=1)
|
| 386 |
+
# R = np.zeros((len(r), 3, 3))
|
| 387 |
+
# nz = th > 1e-12
|
| 388 |
+
# R[~nz] = np.eye(3)
|
| 389 |
+
# k = r[nz] / th[nz, None]
|
| 390 |
+
# K = np.zeros((len(k), 3, 3))
|
| 391 |
+
# K[:, 0, 1], K[:, 0, 2], K[:, 1, 2] = -k[:, 2], k[:, 1], -k[:, 0]
|
| 392 |
+
# K[:, 1, 0], K[:, 2, 0], K[:, 2, 1] = k[:, 2], -k[:, 1], k[:, 0]
|
| 393 |
+
# s, c = np.sin(th[nz])[:, None, None], np.cos(th[nz])[:, None, None]
|
| 394 |
+
# R[nz] = np.eye(3) + s * K + (1 - c) * (K @ K)
|
| 395 |
+
# return R
|
| 396 |
+
#
|
| 397 |
+
#
|
| 398 |
+
# def _mano_chain(model, betas, pose):
|
| 399 |
+
# """返回 (v_shaped, J, Rs, G):G 为 16 个关节的全局变换(平移列 = 关节位置)。"""
|
| 400 |
+
# v = model["v_template"] + np.einsum("nkc,c->nk", model["shapedirs"], betas)
|
| 401 |
+
# J = model["J_regressor"] @ v
|
| 402 |
+
# Rs = rodrigues(np.asarray(pose, np.float64).reshape(16, 3))
|
| 403 |
+
# kt = model["kintree"]
|
| 404 |
+
# G = np.zeros((16, 4, 4))
|
| 405 |
+
# for j in range(16):
|
| 406 |
+
# p = kt[0, j] if j else -1
|
| 407 |
+
# loc = np.eye(4)
|
| 408 |
+
# loc[:3, :3] = Rs[j]
|
| 409 |
+
# loc[:3, 3] = J[j] - (J[p] if j else 0.0)
|
| 410 |
+
# G[j] = loc if not j else G[p] @ loc
|
| 411 |
+
# return v, J, Rs, G
|
| 412 |
+
#
|
| 413 |
+
#
|
| 414 |
+
# def mano_forward(model, betas, pose, transl):
|
| 415 |
+
# """MANO LBS 前向(经典蒙皮 M_j = G_j·G0_j⁻¹;对 hand_pose 21 关节实证 0.0 mm)。
|
| 416 |
+
# pose: 48 axis-angle([0:3] 全局);返回相机系米顶点 (778,3)。"""
|
| 417 |
+
# v, J, Rs, G = _mano_chain(model, betas, pose)
|
| 418 |
+
# lrot = (Rs[1:] - np.eye(3)).ravel()
|
| 419 |
+
# v_posed = v + np.einsum("nkc,c->nk", model["posedirs"], lrot)
|
| 420 |
+
# kt = model["kintree"]
|
| 421 |
+
# G0 = np.zeros((16, 4, 4))
|
| 422 |
+
# for j in range(16):
|
| 423 |
+
# p = kt[0, j] if j else -1
|
| 424 |
+
# loc = np.eye(4)
|
| 425 |
+
# loc[:3, 3] = J[j] - (J[p] if j else 0.0)
|
| 426 |
+
# G0[j] = loc if not j else G0[p] @ loc
|
| 427 |
+
# M = np.einsum("nj,jab->nab", model["weights"], G @ np.linalg.inv(G0))
|
| 428 |
+
# out = np.einsum("nab,nb->na", M[:, :3, :3], v_posed) + M[:, :3, 3]
|
| 429 |
+
# return out + np.asarray(transl, np.float64)
|
| 430 |
+
#
|
| 431 |
+
#
|
| 432 |
+
# def mano_chain_joints(model, betas, pose, transl):
|
| 433 |
+
# """16 个关节位置(相机系米)= 链平移列;自检用。"""
|
| 434 |
+
# _, _, _, G = _mano_chain(model, betas, pose)
|
| 435 |
+
# return G[:, :3, 3] + np.asarray(transl, np.float64)
|
| 436 |
+
#
|
| 437 |
+
#
|
| 438 |
+
# def rasterize(verts_cam, faces, labels, W, H, fx, fy, cx, cy):
|
| 439 |
+
# z = verts_cam[:, 2]
|
| 440 |
+
# P = faces
|
| 441 |
+
# ok = (z[P] > 0.02).all(1) # 任一顶点在相机后 → 丢弃该三角形
|
| 442 |
+
# P, labels = P[ok], labels[ok]
|
| 443 |
+
# if len(P) == 0:
|
| 444 |
+
# return np.zeros((H, W), np.uint16), np.zeros(0, np.int64)
|
| 445 |
+
# x = verts_cam[:, 0] / z * fx + cx
|
| 446 |
+
# y = verts_cam[:, 1] / z * fy + cy
|
| 447 |
+
# xa = np.maximum(0, np.minimum(np.floor(x[P[:, 0]]), np.minimum(
|
| 448 |
+
# np.floor(x[P[:, 1]]), np.floor(x[P[:, 2]]))).astype(np.int64))
|
| 449 |
+
# xb = np.minimum(W - 1, np.maximum(np.ceil(x[P[:, 0]]), np.maximum(
|
| 450 |
+
# np.ceil(x[P[:, 1]]), np.ceil(x[P[:, 2]]))).astype(np.int64))
|
| 451 |
+
# ya = np.maximum(0, np.minimum(np.floor(y[P[:, 0]]), np.minimum(
|
| 452 |
+
# np.floor(y[P[:, 1]]), np.floor(y[P[:, 2]]))).astype(np.int64))
|
| 453 |
+
# yb = np.minimum(H - 1, np.maximum(np.ceil(y[P[:, 0]]), np.maximum(
|
| 454 |
+
# np.ceil(y[P[:, 1]]), np.ceil(y[P[:, 2]]))).astype(np.int64))
|
| 455 |
+
# xa, ya = np.minimum(xa, xb), np.minimum(ya, yb) # 完全出画的三角形 → 空 bbox
|
| 456 |
+
# wdt, hgt = xb - xa + 1, yb - ya + 1
|
| 457 |
+
# cnt = wdt * hgt
|
| 458 |
+
# tot = int(cnt.sum())
|
| 459 |
+
# tri = np.repeat(np.arange(len(P)), cnt)
|
| 460 |
+
# k = np.arange(tot) - (np.cumsum(cnt) - cnt)[tri]
|
| 461 |
+
# px = xa[tri] + k % wdt[tri] + 0.5
|
| 462 |
+
# py = ya[tri] + k // wdt[tri] + 0.5
|
| 463 |
+
# ax, ay = x[P[tri, 0]], y[P[tri, 0]]
|
| 464 |
+
# bx, by = x[P[tri, 1]], y[P[tri, 1]]
|
| 465 |
+
# cx_, cy_ = x[P[tri, 2]], y[P[tri, 2]]
|
| 466 |
+
# area = ((x[P[:, 1]] - x[P[:, 0]]) * (y[P[:, 2]] - y[P[:, 0]])
|
| 467 |
+
# - (y[P[:, 1]] - y[P[:, 0]]) * (x[P[:, 2]] - x[P[:, 0]]))
|
| 468 |
+
# areat = area[tri]
|
| 469 |
+
# e0 = (bx - ax) * (py - ay) - (by - ay) * (px - ax)
|
| 470 |
+
# e1 = (cx_ - bx) * (py - by) - (cy_ - by) * (px - bx)
|
| 471 |
+
# e2 = (ax - cx_) * (py - cy_) - (ay - cy_) * (px - cx_)
|
| 472 |
+
# s = np.sign(areat)
|
| 473 |
+
# inside = (np.abs(areat) > 1e-9) & ((e0 * s >= 0) & (e1 * s >= 0) & (e2 * s >= 0))
|
| 474 |
+
# px, py, tri = px[inside], py[inside], tri[inside]
|
| 475 |
+
# at = areat[inside]
|
| 476 |
+
# w0, w1, w2 = e1[inside] / at, e2[inside] / at, e0[inside] / at
|
| 477 |
+
# zz = w0 * z[P[tri, 0]] + w1 * z[P[tri, 1]] + w2 * z[P[tri, 2]]
|
| 478 |
+
# pix = py.astype(np.int64) * W + px.astype(np.int64)
|
| 479 |
+
# order = np.lexsort((zz, pix)) # 同像素按深度升序 → 首条即最近
|
| 480 |
+
# pix, tri = pix[order], tri[order]
|
| 481 |
+
# first = np.unique(pix, return_index=True)[1]
|
| 482 |
+
# mask = np.zeros(H * W, np.uint16)
|
| 483 |
+
# win = tri[first]
|
| 484 |
+
# mask[pix[first]] = labels[win] + 1 # 临时标签 +1(0=背景)
|
| 485 |
+
# return mask.reshape(H, W), np.bincount(labels[win] + 1)
|
| 486 |
+
#
|
| 487 |
+
#
|
| 488 |
+
# # ============================================================================
|
| 489 |
+
# # ffmpeg 写出与核验(与 convert_dexycb.py 同构)
|
| 490 |
+
# # ============================================================================
|
| 491 |
+
# verts, faces_all, labels = [], [], []
|
| 492 |
+
# for ti, (tid, kind) in enumerate(tracks):
|
| 493 |
+
# if kind == "hand_left" and b["mano"][0] > 0.5:
|
| 494 |
+
# verts.append(mano_forward(mano_models["left"], b["mano"][52:62],
|
| 495 |
+
# b["mano"][4:52], b["mano"][1:4]))
|
| 496 |
+
# faces_all.append(mano_models["left"]["faces"])
|
| 497 |
+
# elif kind == "hand_right" and b["mano"][62] > 0.5:
|
| 498 |
+
# verts.append(mano_forward(mano_models["right"], b["mano"][114:124],
|
| 499 |
+
# b["mano"][66:114], b["mano"][63:66]))
|
| 500 |
+
# faces_all.append(mano_models["right"]["faces"])
|
| 501 |
+
# elif isinstance(kind, tuple) and int(b["objp"][0]) == kind[1]:
|
| 502 |
+
# M = np.asarray(b["objrt"][1:17], np.float64).reshape(4, 4)
|
| 503 |
+
# V0, F0 = meshes[kind[1]]
|
| 504 |
+
# verts.append(V0 @ M[:3, :3].T + M[:3, 3])
|
| 505 |
+
# faces_all.append(F0)
|
| 506 |
+
# else:
|
| 507 |
+
# continue
|
| 508 |
+
# labels.append(np.full(len(faces_all[-1]), ti))
|
| 509 |
+
# if verts:
|
| 510 |
+
# V = np.concatenate(verts)
|
| 511 |
+
# offs = np.cumsum([0] + [len(v) for v in verts[:-1]])
|
| 512 |
+
# F = np.concatenate([fa + o for fa, o in zip(faces_all, offs)])
|
| 513 |
+
# mask, counts = rasterize(V, F, np.concatenate(labels),
|
| 514 |
+
# IMG_W, IMG_H, fx, fy, cx, cy)
|
| 515 |
+
# else:
|
| 516 |
+
# mask, counts = np.zeros((IMG_H, IMG_W), np.uint16), np.zeros(0, np.int64)
|
| 517 |
+
# lut = np.zeros(n_tracks + 1, np.uint16)
|
| 518 |
+
# for ti in range(n_tracks):
|
| 519 |
+
# present = ti + 1 < len(counts) and counts[ti + 1] > 0
|
| 520 |
+
# if present:
|
| 521 |
+
# presence[tracks[ti][0]][f] = True
|
| 522 |
+
# if active_id[ti] is None:
|
| 523 |
+
# pid = next(i for i in range(1, 65535) if i not in used)
|
| 524 |
+
# used.add(pid)
|
| 525 |
+
# active_id[ti], seg_start[ti] = pid, f
|
| 526 |
+
# frame_maps[ti].append({"id": pid})
|
| 527 |
+
# lut[ti + 1] = active_id[ti]
|
| 528 |
+
# elif active_id[ti] is not None:
|
| 529 |
+
# frame_maps[ti][-1]["frames"] = [seg_start[ti], f - 1]
|
| 530 |
+
# segments[ti].append([seg_start[ti], f - 1])
|
| 531 |
+
# used.discard(active_id[ti])
|
| 532 |
+
# active_id[ti] = None
|
| 533 |
+
# mw.write(lut[mask])
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
# TODO(v2.0): 旧物体尺寸派生代码;v1.0 仅保留源物体关键点。
|
| 537 |
+
# pts = np.asarray(b["objp"][1:64], np.float64).reshape(21, 3)
|
| 538 |
+
# half = np.abs((pts[1:9] - pts[0]) @ M[:3, :3]).max(0)
|
| 539 |
+
# obj_recs.append({
|
| 540 |
+
# "track_id": f"o{classes.index(c)}", "frame": f,
|
| 541 |
+
# "mesh_ref": f"h2o/{OBJ_CLASSES[c]}.obj",
|
| 542 |
+
# "pose": {"quat": rotmat_to_quat_wxyz(M[:3, :3])[0].tolist(),
|
| 543 |
+
# "trans": M[:3, 3].tolist()},
|
| 544 |
+
# "bbox_center3d": pts[0].tolist(),
|
| 545 |
+
# "bbox_size": (2 * half).tolist()})
|
H2O/shared-v1.0/script/provenance/previous-run/script/convert_hoi4d_v1.0.py
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""HOI4D native observations and annotations → CONTRACT.md v1.0."""
|
| 3 |
+
from collections import Counter
|
| 4 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 5 |
+
from contextlib import ExitStack
|
| 6 |
+
from functools import lru_cache
|
| 7 |
+
import gzip
|
| 8 |
+
import io
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
import pickle
|
| 13 |
+
import re
|
| 14 |
+
import shutil
|
| 15 |
+
import shlex
|
| 16 |
+
import posixpath
|
| 17 |
+
import subprocess
|
| 18 |
+
import tempfile
|
| 19 |
+
import tarfile
|
| 20 |
+
import threading
|
| 21 |
+
import zipfile
|
| 22 |
+
|
| 23 |
+
# Each worker owns one Python thread; prevent native libraries spawning CPU pools.
|
| 24 |
+
for key in ('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS', 'NUMEXPR_NUM_THREADS'):
|
| 25 |
+
os.environ[key] = '1'
|
| 26 |
+
|
| 27 |
+
import numpy as np
|
| 28 |
+
from PIL import Image
|
| 29 |
+
from scipy.spatial.transform import Rotation
|
| 30 |
+
|
| 31 |
+
import torch
|
| 32 |
+
|
| 33 |
+
from warehouse_v1_0 import (View, build_record, check_mesh, decode_args, find_file, json_write, locator,
|
| 34 |
+
mano_models, model_profile, parser, probe, release, run, safe_member, sequence_dir)
|
| 35 |
+
|
| 36 |
+
CATEGORIES = {
|
| 37 |
+
1: dict(cad="rigid/ToyCar", groups=[("main", [1], "Toy Car", 1)],
|
| 38 |
+
hands={2: "right"}, objmap={"Toycar": "main"}),
|
| 39 |
+
2: dict(cad="rigid/Mug", groups=[("a", [1], "Mug", 2), ("b", [3], "Mug", 2)],
|
| 40 |
+
hands={2: "right"}, objmap={"Watercup": "a"}),
|
| 41 |
+
3: dict(cad="articulated/Laptop", groups=[("main", [1, 3], "Laptop", 3)],
|
| 42 |
+
hands={2: "right"},
|
| 43 |
+
objmap={"Laptopdisplay": "main", "Laptopkeyboard": "main"}),
|
| 44 |
+
4: dict(cad="articulated/StorageFurniture",
|
| 45 |
+
groups=[("main", [1, 3, 4], "Storage Furniture", 4),
|
| 46 |
+
("bottle", [5], "Bottle", 5)],
|
| 47 |
+
hands={2: "right"},
|
| 48 |
+
objmap={"Lockerbody": "main", "Lockersldingdoor": "main",
|
| 49 |
+
"Lockerdrawer": "main", "Safebox": "main"}),
|
| 50 |
+
5: dict(cad="rigid/Bottle", groups=[("main", [1], "Bottle", 5),
|
| 51 |
+
("mug", [3], "Mug", 2)],
|
| 52 |
+
hands={2: "right"}, objmap={"bottleddrinks": "main"}),
|
| 53 |
+
6: dict(cad="articulated/Safe", groups=[("main", [1, 3], "Safe", 6),
|
| 54 |
+
("bottle", [4], "Bottle", 5)],
|
| 55 |
+
hands={2: "right"}, objmap={"Safebox": "main", "Safedoor": "main"}),
|
| 56 |
+
7: dict(cad="rigid/Bowl", groups=[("main", [1], "Bowl", 7),
|
| 57 |
+
("ball", [3], "Ball", None)],
|
| 58 |
+
hands={2: "right"}, objmap={"bowl": "main"}),
|
| 59 |
+
8: dict(cad="articulated/Bucket",
|
| 60 |
+
groups=[("a", [1, 3], "Bucket", 8), ("b", [4, 5], "Bucket", 8)],
|
| 61 |
+
hands={2: "right", 6: "left"},
|
| 62 |
+
objmap={"bucket": "a", "Buckethandle": "a"}),
|
| 63 |
+
9: dict(cad="articulated/Scissors", groups=[("main", [1, 3], "Scissors", 9)],
|
| 64 |
+
hands={2: "right"},
|
| 65 |
+
objmap={"scissors": "main", "scissors2": None}), # scissors2:场景道具,无掩码
|
| 66 |
+
11: dict(cad="articulated/Pliers", groups=[("main", [1, 3], "Pliers", 11)],
|
| 67 |
+
hands={2: "right"}, objmap={"Pliersleft": "main", "Pliersright": "main"}),
|
| 68 |
+
12: dict(cad="rigid/Kettle", groups=[("main", [1], "Kettle", 12),
|
| 69 |
+
("mug", [3], "Mug", 2)],
|
| 70 |
+
hands={2: "right"}, objmap={"kettle": "main"}),
|
| 71 |
+
13: dict(cad="rigid/Knife", groups=[("main", [1], "Knife", 13),
|
| 72 |
+
("apple", [3], "Apple", None)],
|
| 73 |
+
hands={2: "right"}, objmap={"knife": "main"}),
|
| 74 |
+
14: dict(cad="articulated/TrashCan",
|
| 75 |
+
groups=[("main", [1, 3], "Trash Can", 14), ("bottle", [4], "Bottle", 5)],
|
| 76 |
+
hands={2: "right"}, objmap={"Dustbinbase": "main", "Dustbincover": "main"}),
|
| 77 |
+
17: dict(cad="articulated/Lamp", groups=[("main", [1, 3, 4, 5], "Lamp", 17)],
|
| 78 |
+
hands={2: "right", 6: "left"},
|
| 79 |
+
objmap={"Lampbase": "main", "Tablelampfirstjoint": "main",
|
| 80 |
+
"Tablelampsecondjoint": "main", "Thirdjointoftablelamp": "main"}),
|
| 81 |
+
18: dict(cad="articulated/Stapler",
|
| 82 |
+
groups=[("main", [1, 3, 4], "Stapler", 18), ("paper", [5], "Paper", None)],
|
| 83 |
+
hands={2: "right", 6: "left"}, # 6=左手:官方 label.csv 缺列,实测修正
|
| 84 |
+
objmap={"Staplerbase": "main", "Staplercover": "main"}),
|
| 85 |
+
20: dict(cad="rigid/Chair", groups=[("main", [1], "Chair", 20)],
|
| 86 |
+
hands={2: "right", 3: "left"}, objmap={"chair": "main"}),
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
# Official HOI4D definitions/motion segmentation/label.csv; no spatial side inference.
|
| 91 |
+
REGION_NAMES = {1: {1: 'Toy Car', 2: 'Right Hand'}, 2: {1: 'Mug', 2: 'Right Hand', 3: 'Mug'}, 3: {1: 'Screen', 2: 'Right Hand', 3: 'Keyboard'}, 4: {1: 'Door', 2: 'Right Hand', 3: 'Body of the Cabinet', 4: 'Drawer', 5: 'Bottle'}, 5: {1: 'Bottle', 2: 'Right Hand', 3: 'Mug'}, 6: {1: 'Body of the Safe', 2: 'Right Hand', 3: 'Door', 4: 'Bottle'}, 7: {1: 'Bowl', 2: 'Right Hand', 3: 'Ball'}, 8: {1: 'Body of the Bucket', 2: 'Right Hand', 3: 'Handle', 4: 'Body of the Bucket', 5: 'Handle', 6: 'Left Hand'}, 9: {1: 'Left Part of the Scissors', 2: 'Right Hand', 3: 'Right Part of the Scissors'}, 11: {1: 'Left Part of the Pliers', 2: 'Right Hand', 3: 'Right Part of the Pliers'}, 12: {1: 'Kettle', 2: 'Right Hand', 3: 'Mug'}, 13: {1: 'Knife', 2: 'Right Hand', 3: 'Apple'}, 14: {1: 'Body of the Trash Can', 2: 'Right Hand', 3: 'Lid', 4: 'Bottle'}, 17: {1: 'Base', 2: 'Right Hand', 3: 'Tube', 4: 'Top Link', 5: 'Bottom Link', 6: 'Left Hand'}, 18: {1: 'Base', 2: 'Right Hand', 3: 'Slot', 4: 'Lid', 5: 'Paper'}, 20: {1: 'Chair', 2: 'Right Hand', 3: 'Left Hand'}}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class SplitFiles(io.RawIOBase):
|
| 95 |
+
"""Read concatenated source gzip parts without concatenating 119 GB on disk."""
|
| 96 |
+
def __init__(self, paths):
|
| 97 |
+
self.paths = iter(paths)
|
| 98 |
+
self.current = None
|
| 99 |
+
|
| 100 |
+
def readable(self):
|
| 101 |
+
return True
|
| 102 |
+
|
| 103 |
+
def readinto(self, buffer):
|
| 104 |
+
while True:
|
| 105 |
+
if self.current is None:
|
| 106 |
+
path = next(self.paths, None)
|
| 107 |
+
if path is None:
|
| 108 |
+
return 0
|
| 109 |
+
self.current = path.open('rb')
|
| 110 |
+
n = self.current.readinto(buffer)
|
| 111 |
+
if n:
|
| 112 |
+
return n
|
| 113 |
+
self.current.close()
|
| 114 |
+
self.current = None
|
| 115 |
+
|
| 116 |
+
def close(self):
|
| 117 |
+
if self.current is not None:
|
| 118 |
+
self.current.close()
|
| 119 |
+
super().close()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def extract_depths(root, sequences, work):
|
| 123 |
+
directory = find_file(root, 'DEPTH')
|
| 124 |
+
if directory is None:
|
| 125 |
+
return {}, []
|
| 126 |
+
parts = sorted(directory.glob('HOI4D_depth_video.tar.gz*'), key=lambda p: int(p.name.split('.gz')[1] or 0))
|
| 127 |
+
if not parts:
|
| 128 |
+
return {}, []
|
| 129 |
+
wanted = {f'HOI4D_depth_video/{seq}/align_depth/depth_video.avi': seq for seq in sequences}
|
| 130 |
+
found = {}
|
| 131 |
+
with SplitFiles(parts) as joined, io.BufferedReader(joined) as inp, gzip.GzipFile(fileobj=inp) as gz:
|
| 132 |
+
with tarfile.open(fileobj=gz, mode='r|') as tf:
|
| 133 |
+
for member in tf:
|
| 134 |
+
if member.isfile() and member.name in wanted:
|
| 135 |
+
seq = wanted[member.name]
|
| 136 |
+
dest = work / (seq.replace('/', '_') + '.avi')
|
| 137 |
+
with tf.extractfile(member) as src, dest.open('wb') as dst:
|
| 138 |
+
shutil.copyfileobj(src, dst)
|
| 139 |
+
found[seq] = (dest, {'files': [str(p.resolve()) for p in parts], 'member': member.name})
|
| 140 |
+
if len(found) == len(wanted):
|
| 141 |
+
break
|
| 142 |
+
return found, parts
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def palette_mask(data):
|
| 146 |
+
with Image.open(io.BytesIO(data)) as im:
|
| 147 |
+
arr = np.asarray(im)
|
| 148 |
+
if arr.ndim == 2:
|
| 149 |
+
return arr.astype(np.uint16)
|
| 150 |
+
if arr.shape[-1] != 3:
|
| 151 |
+
raise ValueError('unsupported HOI4D mask representation')
|
| 152 |
+
# VOC's 256-color palette interleaves eight label bits into the high RGB bits.
|
| 153 |
+
# Invert it directly instead of sorting every pixel with np.unique.
|
| 154 |
+
if np.any(arr & np.array([31, 31, 63], dtype=np.uint8)):
|
| 155 |
+
raise ValueError('source mask has colors outside official VOC palette')
|
| 156 |
+
mask = np.zeros(arr.shape[:2], dtype=np.uint16)
|
| 157 |
+
for bit in range(8):
|
| 158 |
+
mask |= ((arr[..., bit % 3] >> (7 - bit // 3)) & 1).astype(np.uint16) << bit
|
| 159 |
+
return mask
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
# Four workers each reuse annotation and hand indices instead of rebuilding the ZIP directory.
|
| 163 |
+
@lru_cache(maxsize=8)
|
| 164 |
+
def index_frames(z):
|
| 165 |
+
index = {}
|
| 166 |
+
for name in z.namelist():
|
| 167 |
+
parent, _, filename = name.rpartition('/')
|
| 168 |
+
stem, dot, suffix = filename.rpartition('.')
|
| 169 |
+
if not dot or not stem.isdigit() or suffix not in ('png', 'json', 'pickle'):
|
| 170 |
+
continue
|
| 171 |
+
entries = index.setdefault((parent + '/', '.' + suffix), {})
|
| 172 |
+
f = int(stem)
|
| 173 |
+
if f in entries:
|
| 174 |
+
raise ValueError(f'duplicate frame number under {parent}')
|
| 175 |
+
entries[f] = name
|
| 176 |
+
return index
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def frame_members(z, prefix, suffix):
|
| 180 |
+
return index_frames(z).get((prefix, suffix), {})
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def convert_sequence(seq, args, target, rgbz, annz, hpz, calz, cadz, paths, models, depth):
|
| 184 |
+
# ponytail: cache only one sequence's encoded annotation bytes; no decoded masks or CAD cache.
|
| 185 |
+
@lru_cache(maxsize=None)
|
| 186 |
+
def read_annotation(archive, name):
|
| 187 |
+
return archive.read(name)
|
| 188 |
+
|
| 189 |
+
category = int(re.search(r'/C(\d+)/', seq)[1])
|
| 190 |
+
definition = CATEGORIES.get(category)
|
| 191 |
+
if definition is None:
|
| 192 |
+
raise ValueError(f'category mapping unavailable: {category}')
|
| 193 |
+
prefix = f'HOI4D_annotations/{seq}'
|
| 194 |
+
mask_members = frame_members(annz, prefix + '/2Dseg/mask/', '.png')
|
| 195 |
+
shifted = frame_members(annz, prefix + '/2Dseg/shift_mask/', '.png')
|
| 196 |
+
if not mask_members:
|
| 197 |
+
mask_members = shifted
|
| 198 |
+
pose_members = frame_members(annz, prefix + '/objpose/', '.json')
|
| 199 |
+
hand_members = {side: frame_members(hpz, f'Hand_pose/handpose_{side}_hand/{seq}/', '.pickle')
|
| 200 |
+
for side in ('left', 'right')} if hpz else {'left': {}, 'right': {}}
|
| 201 |
+
with tempfile.TemporaryDirectory(prefix='hoi4d-source-') as wd:
|
| 202 |
+
work = Path(wd)
|
| 203 |
+
member = f'HOI4D_release/{seq}/align_rgb/image.mp4'
|
| 204 |
+
video = work / 'rgb.mp4'
|
| 205 |
+
with rgbz.open(member) as src, video.open('wb') as dst:
|
| 206 |
+
shutil.copyfileobj(src, dst)
|
| 207 |
+
info = probe(video)
|
| 208 |
+
if 'nb_frames' not in info:
|
| 209 |
+
info['nb_frames'] = json.loads(run(['ffprobe', '-v', 'error', '-count_frames', '-select_streams', 'v:0',
|
| 210 |
+
'-show_entries', 'stream=nb_read_frames', '-of', 'json', str(video)], stdout=subprocess.PIPE).stdout)['streams'][0]['nb_read_frames']
|
| 211 |
+
n = int(info['nb_frames'])
|
| 212 |
+
if args.max_frames:
|
| 213 |
+
n = min(n, args.max_frames)
|
| 214 |
+
if shifted and mask_members != shifted and any(f not in mask_members and f in shifted for f in range(n)):
|
| 215 |
+
raise ValueError('shift_mask has frames absent from mask; correspondence unverified')
|
| 216 |
+
frames = []
|
| 217 |
+
for f in range(n):
|
| 218 |
+
sources = {}
|
| 219 |
+
if f in mask_members:
|
| 220 |
+
sources['segment'] = locator(paths['annotations'], mask_members[f], read_annotation(annz, mask_members[f]))
|
| 221 |
+
if f in pose_members:
|
| 222 |
+
sources['object'] = locator(paths['annotations'], pose_members[f], read_annotation(annz, pose_members[f]))
|
| 223 |
+
for side in ('left', 'right'):
|
| 224 |
+
if f in hand_members[side]:
|
| 225 |
+
sources['hand_' + side] = locator(paths['hand'], hand_members[side][f], read_annotation(hpz, hand_members[side][f]))
|
| 226 |
+
frames.append(dict(source_frame_id=f, source_locator=locator(paths['release'], member, frame=f),
|
| 227 |
+
component_sources=sources, annotation_matches={k: dict(source_frame_id=f, source_timestamp_ns=None,
|
| 228 |
+
clock_domain=None, match_method='index_map', delta_ns=None) for k in sources}))
|
| 229 |
+
view = View(target, 'HOI4D', args.release_id, seq.replace('/', '_'), 'ego', frames)
|
| 230 |
+
view.valid_rules = {
|
| 231 |
+
'mano': 'Matched side pickle contains poseCoeff, beta, trans and corresponding model available; zero angles are not missing',
|
| 232 |
+
'keypoints': 'Matched side pickle contains kps2D; independently provided source points, no visibility gate',
|
| 233 |
+
'pose': 'Matched source object record contains rotation and center; record identity retained',
|
| 234 |
+
'dimensions': 'Matched source object record contains dimensions; size/mesh relation remains source_unspecified',
|
| 235 |
+
'segment': 'Source mask or shift_mask present with verified palette codes and entity/part mapping',
|
| 236 |
+
}
|
| 237 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 238 |
+
view.meta['view_type'] = 'ego'
|
| 239 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'source_sequence': seq}
|
| 240 |
+
view.rgb([], locator(paths['release'], member), video=video, count=n)
|
| 241 |
+
intr_name = f'camera_params/{seq.split("/")[0]}/intrin.npy'
|
| 242 |
+
if calz and intr_name in calz.namelist():
|
| 243 |
+
view.camera(np.load(io.BytesIO(calz.read(intr_name))), locator(paths['camera'], intr_name))
|
| 244 |
+
extr_name = prefix + '/3Dseg/output.log'
|
| 245 |
+
if extr_name in annz.NameToInfo:
|
| 246 |
+
lines = [line for line in annz.read(extr_name).decode().splitlines() if line.strip()]
|
| 247 |
+
if len(lines) % 5:
|
| 248 |
+
raise ValueError('invalid Open3D camera trajectory')
|
| 249 |
+
extr, valid = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 250 |
+
for i in range(0, len(lines), 5):
|
| 251 |
+
idx = int(lines[i].split()[0])
|
| 252 |
+
if idx < n:
|
| 253 |
+
if valid[idx]:
|
| 254 |
+
raise ValueError('duplicate trajectory index')
|
| 255 |
+
extr[idx] = np.linalg.inv(np.loadtxt(io.StringIO('\n'.join(lines[i + 1:i + 5]))))
|
| 256 |
+
valid[idx] = True
|
| 257 |
+
view.tensor('extrinsic', 'transform/se3/v1', 'camera/extrinsic.pt', extr, valid,
|
| 258 |
+
['T', 'row', 'column'], locator(paths['annotations'], extr_name),
|
| 259 |
+
convention='T_camera_from_world', source_convention='Open3D LOG camera-to-world; inverted')
|
| 260 |
+
loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources'}
|
| 261 |
+
motion, mv = np.full((n, 2, 61), np.nan, np.float32), np.zeros((n, 2), bool)
|
| 262 |
+
points, pv = np.full((n, 2, 21, 2), np.nan, np.float32), np.zeros((n, 2, 21), bool)
|
| 263 |
+
for slot, side in enumerate(('left', 'right')):
|
| 264 |
+
for f, name in hand_members[side].items():
|
| 265 |
+
if f >= n:
|
| 266 |
+
continue
|
| 267 |
+
data = pickle.loads(read_annotation(hpz, name), encoding='latin1')
|
| 268 |
+
if all(k in data for k in ('poseCoeff', 'beta', 'trans')):
|
| 269 |
+
motion[f, slot] = np.r_[np.asarray(data['poseCoeff']).reshape(48),
|
| 270 |
+
np.asarray(data['beta']).reshape(10), np.asarray(data['trans']).reshape(3)]
|
| 271 |
+
mv[f, slot] = True # Zero angles are a valid pose, not a missing sentinel.
|
| 272 |
+
if 'kps2D' in data:
|
| 273 |
+
points[f, slot] = np.asarray(data['kps2D']).reshape(21, 2)
|
| 274 |
+
pv[f, slot] = True
|
| 275 |
+
if mv.any():
|
| 276 |
+
if all(side in models for slot, side in enumerate(('left', 'right')) if mv[:, slot].any()):
|
| 277 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 278 |
+
['T', 'hand', 'parameter'], loc, model_profile=model_profile(models))
|
| 279 |
+
else:
|
| 280 |
+
view.absent('mano', 'Source MANO exists; provide --mano-dir to fix model identity', 'dependency_missing')
|
| 281 |
+
if pv.any():
|
| 282 |
+
view.tensor('keypoints_uv', 'keypoints/uv/v1', 'annotation/keypoints/uv.pt', points, pv,
|
| 283 |
+
['T', 'hand', 'keypoint', 'coordinate'], loc, keypoint_schema='mano21/v1', unit='pixel',
|
| 284 |
+
source_method='Upstream fitted MANO projection already present in kps2D')
|
| 285 |
+
objects = {}
|
| 286 |
+
groups = {key: (vals, name, cls) for key, vals, name, cls in definition['groups']}
|
| 287 |
+
def ensure_object(key, source_loc, category_id=None, frame=None, source_id=None):
|
| 288 |
+
if key not in objects:
|
| 289 |
+
view.object(key, source_loc, scope='frame' if frame is not None else 'sequence',
|
| 290 |
+
scope_id=f'{seq}:{frame}' if frame is not None else None,
|
| 291 |
+
category_id=category_id, source_object_id=source_id)
|
| 292 |
+
objects[key] = {}
|
| 293 |
+
mappings = []
|
| 294 |
+
mask_valid = [f in mask_members for f in range(n)]
|
| 295 |
+
if any(mask_valid):
|
| 296 |
+
width, height = view.meta['camera']['image_size']
|
| 297 |
+
def masks():
|
| 298 |
+
for f in range(n):
|
| 299 |
+
labels = []
|
| 300 |
+
if f in mask_members:
|
| 301 |
+
mask = palette_mask(read_annotation(annz, mask_members[f]))
|
| 302 |
+
for value in np.unique(mask):
|
| 303 |
+
value = int(value)
|
| 304 |
+
if value in (0, 255):
|
| 305 |
+
if value == 255:
|
| 306 |
+
raise ValueError('HOI4D 255 region semantics unverified')
|
| 307 |
+
continue
|
| 308 |
+
if REGION_NAMES[category].get(value) in ('Left Hand', 'Right Hand'):
|
| 309 |
+
entity, part, cls = 'hand_' + REGION_NAMES[category][value].split()[0].lower(), None, 'hand'
|
| 310 |
+
else:
|
| 311 |
+
group = next((k for k, (vals, _, _) in groups.items() if value in vals), None)
|
| 312 |
+
entity = group or f'unknown_region_{value}'
|
| 313 |
+
cls = groups[group][2] if group else None
|
| 314 |
+
part = f'region_{value}' if group and len(groups[group][0]) > 1 else None
|
| 315 |
+
ensure_object(entity, frames[f]['component_sources']['segment'], cls)
|
| 316 |
+
if part:
|
| 317 |
+
objects[entity].setdefault('parts', {})[part] = {'part_id': part, 'parent_id': None,
|
| 318 |
+
'has_model': False, 'mesh_ref': None, 'source_region_code': value, 'name': REGION_NAMES[category].get(value)}
|
| 319 |
+
labels.append(dict(mask_value=value, category_id=cls, entity_id=entity,
|
| 320 |
+
part_id=part, source_instance_id=value,
|
| 321 |
+
source_attributes={'region_name': REGION_NAMES[category].get(value)}))
|
| 322 |
+
else:
|
| 323 |
+
mask = np.zeros((height, width), np.uint16)
|
| 324 |
+
mappings.append(dict(frame_index=f, labels=labels))
|
| 325 |
+
yield mask
|
| 326 |
+
view.raster('segment', masks(), mask_valid, loc, mappings)
|
| 327 |
+
view.meta['components']['segment']['coverage'] = {'kind': 'unknown'}
|
| 328 |
+
if any(label['part_id'] for row in mappings for label in row['labels']):
|
| 329 |
+
view.meta['components']['segment']['segmentation_type'] = 'part'
|
| 330 |
+
else:
|
| 331 |
+
view.absent('segment', 'No native segmentation for this source sequence')
|
| 332 |
+
records = {}
|
| 333 |
+
for f, name in pose_members.items():
|
| 334 |
+
if f >= n:
|
| 335 |
+
continue
|
| 336 |
+
data = json.loads(read_annotation(annz, name))
|
| 337 |
+
# isEffective is not used to erase existing numerical annotations.
|
| 338 |
+
source_records = data.get('dataList', data.get('objects'))
|
| 339 |
+
if source_records is None:
|
| 340 |
+
raise ValueError('unrecognized source object annotation structure')
|
| 341 |
+
if category == 2 and source_records and (len(source_records) != 1 or
|
| 342 |
+
source_records[0].get('id') != 1 or source_records[0].get('label') != 'Watercup'):
|
| 343 |
+
raise ValueError('C2 native pose differs from the verified one-object target; cannot map to mask region 1')
|
| 344 |
+
label_counts = Counter(record['label'] for record in source_records)
|
| 345 |
+
per_frame = set()
|
| 346 |
+
for record_index, record in enumerate(source_records):
|
| 347 |
+
label = record['label']
|
| 348 |
+
group = definition['objmap'].get(label)
|
| 349 |
+
# Pinned official ObjTracking reads dataList[0] with segmentation label 1.
|
| 350 |
+
source_primary = category == 2 and record_index == 0 and record.get('id') == 1 and group == 'a'
|
| 351 |
+
ambiguous = group is not None and sum(g[2] == groups[group][2] for g in groups.values()) > 1 and not source_primary
|
| 352 |
+
ambiguous = ambiguous or (label_counts[label] > 1 and not source_primary) or group is None
|
| 353 |
+
entity = f'pose_frame_{f}_{record_index}' if ambiguous else group
|
| 354 |
+
ensure_object(entity, locator(paths['annotations'], name, record=record_index),
|
| 355 |
+
groups[group][2] if group else None, frame=f if ambiguous else None, source_id=record.get('id'))
|
| 356 |
+
if ambiguous:
|
| 357 |
+
view.build['unresolved'].append({'component': entity, 'status': 'source_semantics_unverified',
|
| 358 |
+
'reason': 'Source pose retained with frame identity; no guessed association to same-class mask instances'})
|
| 359 |
+
label_key = (entity, label)
|
| 360 |
+
if label_key in per_frame:
|
| 361 |
+
raise ValueError(f'ambiguous repeated object label {label}; source identity must be resolved')
|
| 362 |
+
per_frame.add(label_key)
|
| 363 |
+
records.setdefault(label_key, {})[f] = (record, locator(paths['annotations'], name, record=record.get('id')))
|
| 364 |
+
if category == 2 and any(entity == 'a' for entity, _ in records):
|
| 365 |
+
view.build['validation'].append({'component': 'C2_source_pose_mask_identity',
|
| 366 |
+
'rule': 'Official ObjTracking process_data.py reads dataList[0] with semantic mask label 1',
|
| 367 |
+
'source_revision': 'afa7bf37b02b7e33cf245acd08b98c207ccc175c',
|
| 368 |
+
'source_pose_id': 1, 'mask_value': 1, 'matched_frames': sum(len(by_frame) for (entity, _), by_frame in records.items() if entity == 'a')})
|
| 369 |
+
for (entity, label), by_frame in records.items():
|
| 370 |
+
part_labels = [k[1] for k in records if k[0] == entity]
|
| 371 |
+
articulated = definition['cad'].startswith('articulated/') and entity == definition['groups'][0][0]
|
| 372 |
+
part = 'pose_' + re.sub(r'[^a-zA-Z0-9_]', '_', label) if articulated or len(part_labels) > 1 else None
|
| 373 |
+
base = f'annotation/object/{entity}'
|
| 374 |
+
if part:
|
| 375 |
+
base += '/parts/' + part
|
| 376 |
+
objects[entity].setdefault('parts', {})[part] = dict(part_id=part, parent_id=None,
|
| 377 |
+
has_model=False, mesh_ref=None, source_label=label)
|
| 378 |
+
poses, valid = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 379 |
+
dimensions = np.full((n, 3), np.nan, np.float32)
|
| 380 |
+
dv = np.zeros(n, bool)
|
| 381 |
+
for f, (record, _) in by_frame.items():
|
| 382 |
+
if all(k in record for k in ('rotation', 'center')):
|
| 383 |
+
poses[f] = np.eye(4)
|
| 384 |
+
poses[f, :3, :3] = Rotation.from_euler('XYZ', [record['rotation'][k] for k in ('x', 'y', 'z')]).as_matrix()
|
| 385 |
+
poses[f, :3, 3] = [record['center'][k] for k in ('x', 'y', 'z')]
|
| 386 |
+
valid[f] = True
|
| 387 |
+
if 'dimensions' in record:
|
| 388 |
+
dimensions[f] = [record['dimensions'][k] for k in ('length', 'width', 'height')]
|
| 389 |
+
dv[f] = True
|
| 390 |
+
key = entity + ('_' + part if part else '')
|
| 391 |
+
view.tensor('pose_' + key, 'transform/se3/v1' if part else 'object/rigid/v1', base + '/pose.pt', poses, valid,
|
| 392 |
+
['T', 'row', 'column'], loc, convention='T_camera_from_part' if part else 'T_camera_from_object',
|
| 393 |
+
unit='m', source_label=label, source_euler_order='XYZ',
|
| 394 |
+
definition='https://github.com/hoi4d/ObjTracking/blob/main/process_data.py')
|
| 395 |
+
if dv.any():
|
| 396 |
+
view.tensor('dimensions_' + key, 'object/dimensions/v1', base + '/dimensions.pt', dimensions, dv,
|
| 397 |
+
['T', 'dimension'], loc, dimensions_semantics='source_unspecified', unit='m', scale_applied_to_mesh=False)
|
| 398 |
+
if cadz:
|
| 399 |
+
primary = definition['groups'][0][0]
|
| 400 |
+
if category != 2 and sum(g[2] == category for g in groups.values()) > 1:
|
| 401 |
+
primary = 'source_cad_instance'
|
| 402 |
+
instance = int(re.search(r'/N(\d+)/', seq)[1])
|
| 403 |
+
mesh_prefix = f'HOI4D_CAD_Model_for_release/{definition["cad"]}/{instance:03d}'
|
| 404 |
+
candidates = [name for name in cadz.namelist() if not name.endswith('/') and
|
| 405 |
+
(name == mesh_prefix + '.obj' or name.startswith(mesh_prefix + '/'))]
|
| 406 |
+
if candidates:
|
| 407 |
+
# Retain OBJ material/texture dependencies beside their original names.
|
| 408 |
+
queue = list(candidates)
|
| 409 |
+
for name in queue:
|
| 410 |
+
if Path(name).suffix.lower() not in ('.obj', '.mtl'):
|
| 411 |
+
continue
|
| 412 |
+
for line in cadz.read(name).decode().splitlines():
|
| 413 |
+
fields = shlex.split(line, comments=True)
|
| 414 |
+
if not fields:
|
| 415 |
+
continue
|
| 416 |
+
refs = fields[1:] if fields[0] == 'mtllib' else ([fields[-1]] if
|
| 417 |
+
fields[0].startswith('map_') or fields[0] in ('bump', 'norm', 'disp', 'decal') else [])
|
| 418 |
+
for ref in refs:
|
| 419 |
+
dependency = posixpath.normpath(posixpath.join(posixpath.dirname(name), ref))
|
| 420 |
+
if dependency not in cadz.NameToInfo:
|
| 421 |
+
raise ValueError(f'missing CAD dependency: {dependency}')
|
| 422 |
+
if dependency not in candidates:
|
| 423 |
+
candidates.append(dependency)
|
| 424 |
+
queue.append(dependency)
|
| 425 |
+
ensure_object(primary, locator(paths['cad'], mesh_prefix), category)
|
| 426 |
+
asset_dir = view.path / f'annotation/object/{primary}/assets'
|
| 427 |
+
asset_refs = []
|
| 428 |
+
for name in candidates:
|
| 429 |
+
relative = posixpath.relpath(name, mesh_prefix if definition['cad'].startswith('articulated/') else posixpath.dirname(mesh_prefix))
|
| 430 |
+
dest = safe_member(asset_dir, relative)
|
| 431 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 432 |
+
dest.write_bytes(cadz.read(name))
|
| 433 |
+
ref = dest.relative_to(view.path).as_posix()
|
| 434 |
+
if dest.suffix.lower() == '.obj':
|
| 435 |
+
asset_key = re.sub(r'[^a-zA-Z0-9_]', '_', relative)
|
| 436 |
+
view.component('mesh_' + primary + '_' + asset_key, 'mesh/obj/v1', ref, ['vertex'],
|
| 437 |
+
locator(paths['cad'], name), unit='m', valid=True,
|
| 438 |
+
scale_applied_to_mesh=False, dimensions_semantics='source_unspecified')
|
| 439 |
+
asset_refs.append(ref)
|
| 440 |
+
if definition['cad'].startswith('articulated/'):
|
| 441 |
+
part_id = 'asset_' + asset_key
|
| 442 |
+
objects[primary].setdefault('parts', {})[part_id] = dict(part_id=part_id,
|
| 443 |
+
parent_id=None, has_model=True, mesh_ref=ref, source_asset=relative,
|
| 444 |
+
note='Source asset; correspondence to motion part labels remains unverified')
|
| 445 |
+
for asset_ref in asset_refs:
|
| 446 |
+
mesh_check = check_mesh(view.path / asset_ref, asset_dir)
|
| 447 |
+
view.build['validation'].append({'component': asset_ref, **mesh_check,
|
| 448 |
+
'unit_basis': 'official ObjTracking loads source canonical CAD without scaling in metre camera coordinates',
|
| 449 |
+
'geometric_acceptance': 'physical dimensions-to-mesh relation remains source_unspecified'})
|
| 450 |
+
metadata_path = view.path / f'annotation/object/{primary}/metainfo.json'
|
| 451 |
+
metadata = json.loads(metadata_path.read_text())
|
| 452 |
+
metadata.update(has_model=bool(asset_refs), asset_refs=asset_refs)
|
| 453 |
+
if definition['cad'].startswith('rigid/') and len(asset_refs) == 1:
|
| 454 |
+
metadata['mesh_ref'] = asset_refs[0]
|
| 455 |
+
json_write(metadata_path, metadata)
|
| 456 |
+
if definition['cad'].startswith('articulated/'):
|
| 457 |
+
view.build['unresolved'].append({'component': 'object_part_asset_association',
|
| 458 |
+
'status': 'source_semantics_unverified',
|
| 459 |
+
'reason': 'All source assets and motion labels retained, but no guessed correspondence or joint_state'})
|
| 460 |
+
for entity, info in objects.items():
|
| 461 |
+
if 'parts' in info:
|
| 462 |
+
ref = f'annotation/object/{entity}/articulation.json'
|
| 463 |
+
json_write(view.path / ref, {'parts': list(info['parts'].values()), 'joints': [],
|
| 464 |
+
'hierarchy_semantics': 'semantic_containment',
|
| 465 |
+
'note': 'Unassociated source region, motion and asset nodes; original CAD trees retained in assets'})
|
| 466 |
+
view.component('articulation_' + entity, 'object/articulated/v1', ref, [], loc)
|
| 467 |
+
meta_path = view.path / f'annotation/object/{entity}/metainfo.json'
|
| 468 |
+
metadata = json.loads(meta_path.read_text())
|
| 469 |
+
metadata['articulation_ref'] = ref
|
| 470 |
+
json_write(meta_path, metadata)
|
| 471 |
+
if depth is not None:
|
| 472 |
+
dpath, dloc = depth
|
| 473 |
+
dmeta = probe(dpath)
|
| 474 |
+
if [dmeta['width'], dmeta['height']] != view.meta['camera']['image_size']:
|
| 475 |
+
raise ValueError('HOI4D depth grid differs from RGB')
|
| 476 |
+
if dmeta['pix_fmt'] != 'gray16le':
|
| 477 |
+
raise ValueError('unexpected HOI4D depth pixel format')
|
| 478 |
+
width, height = view.meta['camera']['image_size']
|
| 479 |
+
raw = work / 'depth.raw'
|
| 480 |
+
limits = ['-frames:v', str(n)] if args.max_frames else []
|
| 481 |
+
run(decode_args(dpath, 'gray16le') + limits + ['-y', str(raw)])
|
| 482 |
+
if raw.stat().st_size != n * width * height * 2:
|
| 483 |
+
raise ValueError('depth/RGB frame count or grid mismatch')
|
| 484 |
+
def depths():
|
| 485 |
+
with raw.open('rb') as inp:
|
| 486 |
+
for _ in range(n):
|
| 487 |
+
yield np.frombuffer(inp.read(width * height * 2), '<u2').reshape(height, width).astype(np.float32) / 1000
|
| 488 |
+
view.raster('depth', depths(), None, dloc | {'conversion': 'registered millimetre camera-Z to metres'})
|
| 489 |
+
else:
|
| 490 |
+
if find_file(args.root, 'DEPTH'):
|
| 491 |
+
raise ValueError('DEPTH source exists, but no matching depth video was found')
|
| 492 |
+
view.absent('depth', 'Depth source not downloaded', 'not_downloaded')
|
| 493 |
+
return view.finish()
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
def main(argv=None):
|
| 497 |
+
p = parser('HOI4D', __doc__)
|
| 498 |
+
p.set_defaults(release_id='shared-v1.0')
|
| 499 |
+
# Four workers reached 21 observed OS threads including timing; stay below the 24-thread budget.
|
| 500 |
+
p.add_argument('--workers', type=int, choices=range(1, 5), default=1,
|
| 501 |
+
help='Independent views in parallel, 1..4; codec/BLAS threads fixed at 1')
|
| 502 |
+
p.add_argument('--tasks', help='Comma-separated substrings of source sequence paths')
|
| 503 |
+
p.add_argument('--sessions', help='Comma-separated sessions')
|
| 504 |
+
p.add_argument('--categories', help='Comma-separated category numbers')
|
| 505 |
+
args = p.parse_args(argv)
|
| 506 |
+
if args.views and args.views != 'ego':
|
| 507 |
+
p.error('HOI4D source camera ID is ego')
|
| 508 |
+
paths = {key: find_file(args.root, name) for key, name in {
|
| 509 |
+
'release': 'HOI4D_release.zip', 'annotations': 'HOI4D_annotations.zip', 'hand': 'HOI4D_Hand_pose.zip',
|
| 510 |
+
'camera': 'camera_params.zip', 'cad': 'HOI4D_CAD_Model_for_release.zip'}.items()}
|
| 511 |
+
if not paths['release'] or not paths['annotations']:
|
| 512 |
+
p.error('HOI4D release and annotation ZIPs are required')
|
| 513 |
+
out = release(args, 'HOI4D')
|
| 514 |
+
mapping = Path(__file__).resolve().parent.parent / 'docs/hoi4d-RAW_TO_SHARED.md'
|
| 515 |
+
published_mapping = out / 'doc/RAW_TO_SHARED.md'
|
| 516 |
+
if published_mapping.exists() and published_mapping.read_bytes() != mapping.read_bytes():
|
| 517 |
+
raise ValueError('RAW_TO_SHARED.md changed; choose a new release-id')
|
| 518 |
+
if not published_mapping.exists():
|
| 519 |
+
shutil.copyfile(mapping, published_mapping)
|
| 520 |
+
torch.set_num_threads(1)
|
| 521 |
+
models = mano_models(args.mano_dir)
|
| 522 |
+
with ExitStack() as stack, tempfile.TemporaryDirectory(prefix='hoi4d-depth-') as wd:
|
| 523 |
+
archives = {key: stack.enter_context(zipfile.ZipFile(path)) if path else None for key, path in paths.items()}
|
| 524 |
+
sequences = sorted(name.removeprefix('HOI4D_release/').removesuffix('/align_rgb/image.mp4')
|
| 525 |
+
for name in archives['release'].namelist() if name.endswith('/align_rgb/image.mp4'))
|
| 526 |
+
if args.tasks:
|
| 527 |
+
sequences = [s for s in sequences if any(token in s for token in args.tasks.split(','))]
|
| 528 |
+
if args.sessions:
|
| 529 |
+
sequences = [s for s in sequences if s.split('/')[0] in args.sessions.split(',')]
|
| 530 |
+
if args.categories:
|
| 531 |
+
sequences = [s for s in sequences if re.search(r'/C(\d+)/', s)[1] in args.categories.split(',')]
|
| 532 |
+
if args.limit:
|
| 533 |
+
sequences = sequences[:args.limit]
|
| 534 |
+
if not sequences:
|
| 535 |
+
p.error('no matching source sequences')
|
| 536 |
+
depths, _ = extract_depths(args.root, sequences, Path(wd))
|
| 537 |
+
worker = threading.local()
|
| 538 |
+
worker_stacks = []
|
| 539 |
+
def init_worker():
|
| 540 |
+
owned = ExitStack()
|
| 541 |
+
try:
|
| 542 |
+
# ZipFile.read mutates a shared seek position: never share a handle across workers.
|
| 543 |
+
worker.archives = {key: owned.enter_context(zipfile.ZipFile(path)) if path else None
|
| 544 |
+
for key, path in paths.items()}
|
| 545 |
+
index_frames(worker.archives['annotations'])
|
| 546 |
+
if worker.archives['hand']:
|
| 547 |
+
index_frames(worker.archives['hand'])
|
| 548 |
+
except BaseException:
|
| 549 |
+
owned.close()
|
| 550 |
+
raise
|
| 551 |
+
worker_stacks.append(owned)
|
| 552 |
+
def convert_one(seq):
|
| 553 |
+
source = archives if args.workers == 1 else worker.archives
|
| 554 |
+
name = seq.replace('/', '_')
|
| 555 |
+
with sequence_dir(out, name) as target:
|
| 556 |
+
report = convert_sequence(seq, args, target / 'ego', source['release'], source['annotations'],
|
| 557 |
+
source['hand'], source['camera'], source['cad'], paths, models, depths.get(seq))
|
| 558 |
+
build_record(out, name, {'ego': report})
|
| 559 |
+
return seq
|
| 560 |
+
if args.workers == 1:
|
| 561 |
+
for seq in map(convert_one, sequences):
|
| 562 |
+
print(f'Converted {seq}', flush=True)
|
| 563 |
+
else:
|
| 564 |
+
try:
|
| 565 |
+
with ThreadPoolExecutor(max_workers=args.workers, initializer=init_worker) as pool:
|
| 566 |
+
for seq in pool.map(convert_one, sequences):
|
| 567 |
+
print(f'Converted {seq}', flush=True)
|
| 568 |
+
finally:
|
| 569 |
+
for owned in worker_stacks:
|
| 570 |
+
owned.close()
|
| 571 |
+
return 0
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
if __name__ == '__main__':
|
| 575 |
+
raise SystemExit(main())
|
| 576 |
+
|
| 577 |
+
# TODO(v2.0): 旧 bbox IoU 实例重分配属于推断,注释保留,不在 v1.0 执行。
|
| 578 |
+
# # 同类多实例(C8 双桶 / C2 双杯):2dBox 可用时按 IoU 复核归属
|
| 579 |
+
# cls = next(x[3] for x in cat["groups"] if x[0] == gk)
|
| 580 |
+
# sibs = [g for g in cat["groups"]
|
| 581 |
+
# if g[0] != gk and cls is not None and g[3] == cls]
|
| 582 |
+
# box = (d.get("2dBox") or {}).get("camera1")
|
| 583 |
+
# box = (box[0][0], box[0][1], box[1][0], box[1][1]) \
|
| 584 |
+
# if box and len(box) == 2 else None
|
| 585 |
+
# if box is not None and sibs:
|
| 586 |
+
# gvals = next(x[1] for x in cat["groups"] if x[0] == gk)
|
| 587 |
+
# best, best_iou = gk, box_iou(box, bbox_of(mask, gvals))
|
| 588 |
+
# for s in sibs:
|
| 589 |
+
# if ("obj", s[0]) not in tid_of_group:
|
| 590 |
+
# continue
|
| 591 |
+
# i = box_iou(box, bbox_of(mask, s[1]))
|
| 592 |
+
# if i > best_iou + 0.1 and i > 0.15:
|
| 593 |
+
# best, best_iou = s[0], i
|
| 594 |
+
# if best != gk:
|
| 595 |
+
# gk, iou_fixups = best, iou_fixups + 1
|
H2O/shared-v1.0/script/provenance/previous-run/script/convert_visor_v1.0.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""VISOR source polygons and contact → CONTRACT.md v1.0, without rasterization or side inference."""
|
| 3 |
+
from collections import Counter
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
import re
|
| 7 |
+
import shutil
|
| 8 |
+
import tempfile
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import zipfile
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from warehouse_v1_0 import (View, build_record, find_file, jsonl_write, locator, parser,
|
| 16 |
+
release, roots, sequence_dir, source)
|
| 17 |
+
|
| 18 |
+
FRAME = re.compile(r'frame_(\d+)')
|
| 19 |
+
HAND = {300: 'left', 301: 'right'}
|
| 20 |
+
GLOVE = {303: 'left', 304: 'right'}
|
| 21 |
+
STATES = {'hand-not-in-contact': 'negative', 'glove-not-in-contact': 'negative',
|
| 22 |
+
'none-of-the-above': 'target_unannotated', 'inconclusive': 'unknown'}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def hand_side(ann):
|
| 26 |
+
if ann['class_id'] in HAND:
|
| 27 |
+
return HAND[ann['class_id']]
|
| 28 |
+
if ann['class_id'] not in (60, 303, 304):
|
| 29 |
+
return None
|
| 30 |
+
raw = ann.get('on_which_hand')
|
| 31 |
+
raw = raw if isinstance(raw, list) else [raw]
|
| 32 |
+
sides = set()
|
| 33 |
+
for item in raw:
|
| 34 |
+
if item == 'left hand':
|
| 35 |
+
sides.add('left')
|
| 36 |
+
if item in ('right hand', 'rigth hand'):
|
| 37 |
+
sides.add('right')
|
| 38 |
+
if len(sides) == 1:
|
| 39 |
+
return next(iter(sides))
|
| 40 |
+
if not sides and ann['class_id'] in GLOVE:
|
| 41 |
+
return GLOVE[ann['class_id']]
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def convert_video(video, split, annotation, ann_loc, rgb_zip, rgb_loc, mapping, args, target):
|
| 46 |
+
indexed = sorted(enumerate(annotation['video_annotations']), key=lambda row: int(FRAME.search(row[1]['image']['name'])[1]))
|
| 47 |
+
if args.max_frames:
|
| 48 |
+
indexed = indexed[:args.max_frames]
|
| 49 |
+
if len({row['image']['name'] for _, row in indexed}) != len(indexed):
|
| 50 |
+
raise ValueError('duplicate VISOR frame')
|
| 51 |
+
keys = lambda row, ann: (row['image']['subsequence'], ann['class_id'], ann['name'])
|
| 52 |
+
collisions = set()
|
| 53 |
+
for _, row in indexed:
|
| 54 |
+
collisions.update(key for key, number in Counter(keys(row, a) for a in row['annotations']).items() if number > 1)
|
| 55 |
+
frames, paths = [], []
|
| 56 |
+
with tempfile.TemporaryDirectory(prefix='visor-rgb-') as wd, zipfile.ZipFile(rgb_zip) as z:
|
| 57 |
+
work = Path(wd)
|
| 58 |
+
for original_index, row in indexed:
|
| 59 |
+
name = row['image']['name']
|
| 60 |
+
data = z.read(name)
|
| 61 |
+
path = work / Path(name).name
|
| 62 |
+
path.write_bytes(data)
|
| 63 |
+
paths.append(path)
|
| 64 |
+
loc = rgb_loc | {'nested_member': name, 'sha256': hashlib.sha256(data).hexdigest()}
|
| 65 |
+
frames.append(dict(source_frame_id=int(FRAME.search(name)[1]), source_locator=loc,
|
| 66 |
+
source_image=row['image'], original_frame_name=mapping.get(name),
|
| 67 |
+
annotation_matches={'segment': dict(source_frame_id=name, source_timestamp_ns=None,
|
| 68 |
+
clock_domain=None, match_method='index_map', delta_ns=None,
|
| 69 |
+
source_locator=ann_loc | {'record': f'video_annotations[{original_index}]'})}))
|
| 70 |
+
view = View(target, 'EPIC-KITCHENS-VISOR', args.release_id, video, 'ego', frames, sampling='sparse', split=split)
|
| 71 |
+
view.valid_rules = {
|
| 72 |
+
'segment': 'Selected sparse annotation frame present; all source polygons finite with at least three vertices and entity mapping valid',
|
| 73 |
+
'relations': 'At least one source in_contact_object value present; positive targets resolve in the same frame; unknown is an explicit usable status',
|
| 74 |
+
}
|
| 75 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 76 |
+
view.meta.update(view_type='ego', split_scheme='VISOR_GroundTruth_SparseAnnotations', split_source_locator=ann_loc)
|
| 77 |
+
view.meta['sampling']['selection'] = {'representation': 'official sparse annotations', 'max_frames': args.max_frames}
|
| 78 |
+
view.rgb(paths, rgb_loc)
|
| 79 |
+
entities = {}
|
| 80 |
+
polygons, mappings, relations, relation_valid = [], [], [], []
|
| 81 |
+
for f, (original_index, row) in enumerate(indexed):
|
| 82 |
+
frame_loc = ann_loc | {'record': f'video_annotations[{original_index}]'}
|
| 83 |
+
id_map, labels, polys = {}, [], []
|
| 84 |
+
for code, ann in enumerate(row['annotations'], 1):
|
| 85 |
+
if code >= 65535:
|
| 86 |
+
raise ValueError('too many source instances')
|
| 87 |
+
sid = ann['id']
|
| 88 |
+
if sid in id_map:
|
| 89 |
+
raise ValueError('duplicate source instance ID within a frame')
|
| 90 |
+
side = hand_side(ann)
|
| 91 |
+
if side is not None:
|
| 92 |
+
entity = 'hand_' + side
|
| 93 |
+
else:
|
| 94 |
+
key = keys(row, ann)
|
| 95 |
+
identity = key + (sid, row['image']['name']) if key in collisions else key
|
| 96 |
+
entity = 'object_' + hashlib.sha256(json.dumps(identity).encode()).hexdigest()[:20]
|
| 97 |
+
if entity not in entities:
|
| 98 |
+
scope = 'frame' if key in collisions else 'subsequence'
|
| 99 |
+
scope_id = f'{video}:{row["image"]["name"]}' if scope == 'frame' else f'{video}:{key[0]}'
|
| 100 |
+
view.object(entity, frame_loc | {'source_instance_id': sid}, scope, scope_id,
|
| 101 |
+
category_id=ann['class_id'], name=ann['name'],
|
| 102 |
+
association_basis='source_frame_instance' if scope == 'frame' else 'official_subsequence_entity_name')
|
| 103 |
+
entities[entity] = True
|
| 104 |
+
id_map[sid] = entity
|
| 105 |
+
for polygon in ann.get('segments', []):
|
| 106 |
+
p = np.asarray(polygon)
|
| 107 |
+
if p.ndim != 2 or p.shape[1] != 2 or len(p) < 3 or not np.isfinite(p).all():
|
| 108 |
+
raise ValueError(f'invalid source polygon {sid}')
|
| 109 |
+
polys.append(dict(mask_value=code, polygons=ann.get('segments', [])))
|
| 110 |
+
labels.append(dict(mask_value=code, category_id=ann['class_id'], entity_id=entity,
|
| 111 |
+
part_id=None, source_instance_id=sid,
|
| 112 |
+
source_attributes={k: v for k, v in ann.items() if k != 'segments'}))
|
| 113 |
+
rr = []
|
| 114 |
+
provided = False
|
| 115 |
+
for ann in row['annotations']:
|
| 116 |
+
raw = ann.get('in_contact_object')
|
| 117 |
+
values = raw if isinstance(raw, list) else [raw]
|
| 118 |
+
for value in values:
|
| 119 |
+
if value is None:
|
| 120 |
+
continue
|
| 121 |
+
provided = True
|
| 122 |
+
status = STATES.get(value)
|
| 123 |
+
obj = None
|
| 124 |
+
if status is None:
|
| 125 |
+
if value not in id_map:
|
| 126 |
+
raise ValueError(f'unresolved source contact target {value} in {video} frame {f}')
|
| 127 |
+
status, obj = 'positive', id_map[value]
|
| 128 |
+
rr.append(dict(relation_type='contact', subject_id=id_map[ann['id']], object_id=obj,
|
| 129 |
+
status=status, source_value=value, source_locator=frame_loc | {'source_instance_id': ann['id']},
|
| 130 |
+
provenance=source('Resolve source contact ID against instances in this frame')))
|
| 131 |
+
polygons.append(dict(frame_index=f, instances=polys))
|
| 132 |
+
mappings.append(dict(frame_index=f, labels=labels))
|
| 133 |
+
relations.append(dict(frame_index=f, relations=rr))
|
| 134 |
+
relation_valid.append(provided)
|
| 135 |
+
jsonl_write(view.path / 'annotation/segment/polygons.jsonl', polygons)
|
| 136 |
+
jsonl_write(view.path / 'annotation/segment/instances.jsonl', mappings)
|
| 137 |
+
torch.save(torch.ones(len(frames), dtype=torch.bool, device='cpu'), view.path / 'annotation/segment/mask_valid.pt')
|
| 138 |
+
view.component('segment', 'segment/instance_polygons/v1', 'annotation/segment/polygons.jsonl', ['T'], ann_loc,
|
| 139 |
+
valid_ref='annotation/segment/mask_valid.pt', valid_axes=['T'], segmentation_type='instance',
|
| 140 |
+
mapping_ref='annotation/segment/instances.jsonl', coverage={'kind': 'unknown', 'exhaustive_ref': 'annotation/segment/instances.jsonl'})
|
| 141 |
+
view.relations(relations, relation_valid, ann_loc)
|
| 142 |
+
for component in ('depth', 'mano', 'keypoints_uv', 'keypoints_xyz', 'intrinsic', 'extrinsic'):
|
| 143 |
+
view.absent(component, 'Not provided by VISOR sparse source annotations')
|
| 144 |
+
return view.finish()
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def main(argv=None):
|
| 148 |
+
p = parser('EPIC-KITCHENS-VISOR', __doc__)
|
| 149 |
+
p.add_argument('--videos', help='Comma-separated video names')
|
| 150 |
+
p.add_argument('--splits', default='train,val')
|
| 151 |
+
args = p.parse_args(argv)
|
| 152 |
+
wanted = set(args.videos.split(',')) if args.videos else None
|
| 153 |
+
splits = set(args.splits.split(','))
|
| 154 |
+
if not splits <= {'train', 'val'}:
|
| 155 |
+
p.error('only annotated train/val splits are available')
|
| 156 |
+
out = release(args, 'EPIC-KITCHENS-VISOR')
|
| 157 |
+
archive = find_file(args.root, 'EPIC-KITCHENS VISOR.zip')
|
| 158 |
+
with tempfile.TemporaryDirectory(prefix='visor-source-') as wd:
|
| 159 |
+
work = Path(wd)
|
| 160 |
+
if archive:
|
| 161 |
+
with zipfile.ZipFile(archive) as z:
|
| 162 |
+
suffix = 'GroundTruth-SparseAnnotations/annotations/'
|
| 163 |
+
members = [n for n in z.namelist() if suffix in n and n.endswith('.json')]
|
| 164 |
+
prefix = members[0].split(suffix)[0]
|
| 165 |
+
fm = json.loads(z.read(prefix + 'frame_mapping.json'))
|
| 166 |
+
done = 0
|
| 167 |
+
for member in sorted(members):
|
| 168 |
+
split, filename = member.split(suffix)[1].split('/')
|
| 169 |
+
video = Path(filename).stem
|
| 170 |
+
if split not in splits or wanted and video not in wanted:
|
| 171 |
+
continue
|
| 172 |
+
data = z.read(member)
|
| 173 |
+
rgb_member = prefix + f'GroundTruth-SparseAnnotations/rgb_frames/{split}/{video.split("_")[0]}/{video}.zip'
|
| 174 |
+
rgb_zip = work / (video + '.zip')
|
| 175 |
+
with z.open(rgb_member) as inp, rgb_zip.open('wb') as dest:
|
| 176 |
+
shutil.copyfileobj(inp, dest)
|
| 177 |
+
with sequence_dir(out, video) as dest:
|
| 178 |
+
report = convert_video(video, split, json.loads(data), locator(archive, member, data),
|
| 179 |
+
rgb_zip, locator(archive, rgb_member), fm.get(video, {}), args, dest / 'ego')
|
| 180 |
+
build_record(out, video, {'ego': report})
|
| 181 |
+
rgb_zip.unlink()
|
| 182 |
+
done += 1
|
| 183 |
+
print(f'Converted {video}', flush=True)
|
| 184 |
+
if args.limit and done >= args.limit:
|
| 185 |
+
break
|
| 186 |
+
else:
|
| 187 |
+
root = next((r for r in roots(args.root) if (r / 'GroundTruth-SparseAnnotations').is_dir()), None)
|
| 188 |
+
if root is None:
|
| 189 |
+
p.error('VISOR outer ZIP or extracted source directory not found')
|
| 190 |
+
fm = json.loads((root / 'frame_mapping.json').read_text()) if (root / 'frame_mapping.json').exists() else {}
|
| 191 |
+
done = 0
|
| 192 |
+
for split in sorted(splits):
|
| 193 |
+
for ann in sorted((root / 'GroundTruth-SparseAnnotations/annotations' / split).glob('*.json')):
|
| 194 |
+
video = ann.stem
|
| 195 |
+
if wanted and video not in wanted:
|
| 196 |
+
continue
|
| 197 |
+
rgb = root / f'GroundTruth-SparseAnnotations/rgb_frames/{split}/{video.split("_")[0]}/{video}.zip'
|
| 198 |
+
with sequence_dir(out, video) as dest:
|
| 199 |
+
report = convert_video(video, split, json.loads(ann.read_text()), locator(ann), rgb,
|
| 200 |
+
locator(rgb), fm.get(video, {}), args, dest / 'ego')
|
| 201 |
+
build_record(out, video, {'ego': report})
|
| 202 |
+
done += 1
|
| 203 |
+
if args.limit and done >= args.limit:
|
| 204 |
+
return 0
|
| 205 |
+
if not done:
|
| 206 |
+
p.error('no matching annotated videos found')
|
| 207 |
+
return 0
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
if __name__ == '__main__':
|
| 211 |
+
raise SystemExit(main())
|
| 212 |
+
|
| 213 |
+
# TODO(v2.0): 旧距离猜侧和单层掩码生成仅注释保留;v1.0 不执行。
|
| 214 |
+
# if side is None and len(frame_hands) == 1:
|
| 215 |
+
# # 空间门槛:脱下放在远处的手套不并入(实测双峰 0..25px / ≥44px)
|
| 216 |
+
# hb = frame_hands[0][1]
|
| 217 |
+
# gb = _bbox_of(polys)
|
| 218 |
+
# if hb and gb and _bbox_dist(gb, hb) <= GLOVE60_MERGE_BBOX_DIST:
|
| 219 |
+
# side = frame_hands[0][0]
|
| 220 |
+
# stats["glove60_merged_into_sole_hand"] += 1
|
| 221 |
+
# if side is None:
|
| 222 |
+
# stats["dropped_glove60_unresolved"] += 1
|
| 223 |
+
# id_disp[mid] = ("dropped", "glove60")
|
| 224 |
+
# continue
|
| 225 |
+
# def rasterize_and_encode(vdir, frames, frame_draw, zip_path, n, stats):
|
| 226 |
+
# """流式读 zip 内 jpg + 光栅化多边形 → rgb.mkv / mask.mkv;返回 (w, h)。"""
|
| 227 |
+
# from PIL import Image, ImageDraw
|
| 228 |
+
#
|
| 229 |
+
# with zipfile.ZipFile(zip_path) as zf:
|
| 230 |
+
# member_of = {}
|
| 231 |
+
# for nm in zf.namelist():
|
| 232 |
+
# member_of[os.path.basename(nm)] = nm
|
| 233 |
+
# names = [im["name"] for im in frames]
|
| 234 |
+
# missing = [nm for nm in names if nm not in member_of]
|
| 235 |
+
# if missing:
|
| 236 |
+
# raise RuntimeError(f"{len(missing)} annotated frames missing in zip, "
|
| 237 |
+
# f"e.g. {missing[:3]}")
|
| 238 |
+
# stats["zip_extra_members"] = len(member_of) - len(names)
|
| 239 |
+
#
|
| 240 |
+
# # 首帧定分辨率(官方 1920×1080,实测每帧校验)
|
| 241 |
+
# img0 = Image.open(io.BytesIO(zf.read(member_of[names[0]]))).convert("RGB")
|
| 242 |
+
# w, h = img0.size
|
| 243 |
+
#
|
| 244 |
+
# bin_img = Image.new("L", (w, h), 0)
|
| 245 |
+
# bin_draw = ImageDraw.Draw(bin_img)
|
| 246 |
+
# canvas = np.zeros((h, w), np.uint16)
|
| 247 |
+
# with VideoPipe(vdir / "mask.mkv", w, h, FPS, "mask") as mw, \
|
| 248 |
+
# VideoPipe(vdir / "rgb.mkv", w, h, FPS, "rgb") as rw:
|
| 249 |
+
# for f in range(n):
|
| 250 |
+
# canvas[:] = 0
|
| 251 |
+
# for pid, polys in frame_draw[f]:
|
| 252 |
+
# bin_draw.rectangle((0, 0, w, h), fill=0)
|
| 253 |
+
# for poly in polys:
|
| 254 |
+
# bin_draw.polygon([(float(x), float(y)) for x, y in poly], fill=255)
|
| 255 |
+
# arr = np.asarray(bin_img)
|
| 256 |
+
# canvas[arr > 0] = pid # 后画覆盖先画:物体→手(modal)
|
| 257 |
+
# mw.write(canvas)
|
| 258 |
+
# img = img0 if f == 0 else Image.open(
|
| 259 |
+
# io.BytesIO(zf.read(member_of[names[f]]))).convert("RGB")
|
| 260 |
+
# if img.size != (w, h):
|
| 261 |
+
# raise RuntimeError(f"frame {names[f]}: size {img.size} != {(w, h)}")
|
| 262 |
+
# rw.write(np.asarray(img))
|
| 263 |
+
# n_mask, n_rgb = mw.n, rw.n
|
| 264 |
+
# if (n_rgb, n_mask) != (n, n):
|
| 265 |
+
# raise RuntimeError(f"wrote rgb={n_rgb} mask={n_mask} != {n}")
|
| 266 |
+
# got = (count_frames(vdir / "rgb.mkv"), count_frames(vdir / "mask.mkv"))
|
| 267 |
+
# if got != (n, n):
|
| 268 |
+
# raise RuntimeError(f"encoded rgb={got[0]} mask={got[1]} != {n} (decode verify)")
|
| 269 |
+
# return w, h
|
| 270 |
+
#
|
| 271 |
+
#
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/h2o-benchmark-decode.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Benchmark full FFV1 decodes, PNG RGB decodes, and source depth PNG loading; preserve every byte."""
|
| 2 |
+
import hashlib
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import statistics
|
| 7 |
+
import subprocess
|
| 8 |
+
import time
|
| 9 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 10 |
+
import numpy as np
|
| 11 |
+
from PIL import Image
|
| 12 |
+
|
| 13 |
+
old = Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10')
|
| 14 |
+
bench = Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-decode-bench-20260930')
|
| 15 |
+
bench.mkdir(exist_ok=True)
|
| 16 |
+
media = next((old / 'H2O/shared-v1.0/data').glob('subject4_h1_0*/cam0/observation/rgb.mkv')).parent
|
| 17 |
+
inputs = bench / 'inputs'
|
| 18 |
+
inputs.mkdir(exist_ok=True)
|
| 19 |
+
for name in ('rgb.mkv', 'depth.mkv', 'depth_valid.mkv'):
|
| 20 |
+
dest = inputs / name
|
| 21 |
+
if not dest.exists():
|
| 22 |
+
os.link(media / name, dest)
|
| 23 |
+
source = next((old / 'scratch').glob('h2o-source-*/subject4/h1/0/cam0/rgb')).parent
|
| 24 |
+
for kind in ('rgb', 'depth'):
|
| 25 |
+
dest = inputs / kind
|
| 26 |
+
dest.mkdir(exist_ok=True)
|
| 27 |
+
for frame in sorted((source / kind).glob('*.png'))[:100]:
|
| 28 |
+
if not (dest / frame.name).exists():
|
| 29 |
+
os.link(frame, dest / frame.name)
|
| 30 |
+
records = []
|
| 31 |
+
expected = {}
|
| 32 |
+
def record(stage, threads, digest, size, seconds):
|
| 33 |
+
assert expected.setdefault(stage, (digest, size)) == (digest, size), stage
|
| 34 |
+
row = dict(stage=stage, threads=threads, seconds=seconds, sha256=digest, bytes=size)
|
| 35 |
+
records.append(row)
|
| 36 |
+
print(json.dumps(row), flush=True)
|
| 37 |
+
(bench / 'report.json').write_text(json.dumps(records, indent=2) + '\n')
|
| 38 |
+
def decode(stage, arguments, threads, pix_fmt):
|
| 39 |
+
cmd = ['ffmpeg','-v','error','-nostdin','-filter_threads',str(threads),'-threads',str(threads),
|
| 40 |
+
'-noautorotate',*arguments,'-map','0:v:0','-vsync','0','-threads',str(threads),
|
| 41 |
+
'-f','rawvideo','-pix_fmt',pix_fmt,'pipe:1']
|
| 42 |
+
digest = hashlib.sha256()
|
| 43 |
+
size = 0
|
| 44 |
+
start = time.monotonic()
|
| 45 |
+
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
|
| 46 |
+
while chunk := proc.stdout.read(1024*1024):
|
| 47 |
+
digest.update(chunk)
|
| 48 |
+
size += len(chunk)
|
| 49 |
+
stderr = proc.stderr.read()
|
| 50 |
+
assert proc.wait() == 0, stderr.decode()
|
| 51 |
+
record(stage, threads, digest.hexdigest(), size, time.monotonic()-start)
|
| 52 |
+
for threads in (1,10,10,1):
|
| 53 |
+
for name, pix in (('rgb','rgb24'),('depth','gray16le'),('depth_valid','gray')):
|
| 54 |
+
decode('ffv1_'+name, ['-i',str(inputs/(name+'.mkv'))], threads, pix)
|
| 55 |
+
decode('source_rgb_png_100', ['-framerate','30','-i',str(inputs/'rgb/%06d.png')], threads, 'rgb24')
|
| 56 |
+
files = sorted((inputs/'depth').glob('*.png'))
|
| 57 |
+
def read(path):
|
| 58 |
+
with Image.open(path) as im:
|
| 59 |
+
return np.asarray(im).astype(np.float32)/1000.0
|
| 60 |
+
for depth_threads in (1,2,4):
|
| 61 |
+
digest = hashlib.sha256()
|
| 62 |
+
start = time.monotonic()
|
| 63 |
+
size = 0
|
| 64 |
+
with ThreadPoolExecutor(max_workers=depth_threads) as pool:
|
| 65 |
+
# Bound decoded arrays to one small batch, as the production candidate would.
|
| 66 |
+
for begin in range(0,len(files),depth_threads):
|
| 67 |
+
for arr in pool.map(read,files[begin:begin+depth_threads]):
|
| 68 |
+
digest.update(arr.tobytes())
|
| 69 |
+
size += arr.nbytes
|
| 70 |
+
record('source_depth_png_100', depth_threads, digest.hexdigest(), size, time.monotonic()-start)
|
| 71 |
+
print('MEDIANS',flush=True)
|
| 72 |
+
for stage in expected:
|
| 73 |
+
for threads in sorted({r['threads'] for r in records if r['stage']==stage}):
|
| 74 |
+
print(stage,threads,statistics.median(r['seconds'] for r in records if r['stage']==stage and r['threads']==threads),flush=True)
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/h2o-prepare-d10.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Reuse only atomically published sequences; preserve previous runtime provenance."""
|
| 2 |
+
import datetime
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import shutil
|
| 7 |
+
|
| 8 |
+
old = Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10')
|
| 9 |
+
new = Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10')
|
| 10 |
+
snapshot = Path('/tmp/h2o-w4-c10-d10-recovery')
|
| 11 |
+
new.mkdir()
|
| 12 |
+
shutil.copytree(snapshot, new / 'frozen-code')
|
| 13 |
+
release = new / 'H2O/shared-v1.0'
|
| 14 |
+
for directory in ('data', 'doc/validation', 'script/provenance/previous-run', 'script/provenance/operations'):
|
| 15 |
+
(release / directory).mkdir(parents=True, exist_ok=True)
|
| 16 |
+
history = release / 'script/provenance/previous-run'
|
| 17 |
+
shutil.copytree(old / 'H2O/shared-v1.0/script', history / 'script')
|
| 18 |
+
shutil.copytree(old / 'frozen-code/docs', history / 'docs')
|
| 19 |
+
for name in ('full.log', 'full.status', 'run-full.sh'):
|
| 20 |
+
shutil.copy2(old / name, history / name)
|
| 21 |
+
records = []
|
| 22 |
+
for record in sorted((old / 'H2O/shared-v1.0/doc').glob('*.build.json')):
|
| 23 |
+
build = json.loads(record.read_text())
|
| 24 |
+
seq = build['sequence_id']
|
| 25 |
+
assert Path(seq).name == seq and seq not in ('.', '..')
|
| 26 |
+
assert set(build['views']) == {f'cam{i}' for i in range(5)}, seq
|
| 27 |
+
data = old / 'H2O/shared-v1.0/data' / seq
|
| 28 |
+
frames = {}
|
| 29 |
+
for cam in build['views']:
|
| 30 |
+
json.loads((data / cam / 'metainfo.json').read_text())
|
| 31 |
+
frames[cam] = sum(1 for _ in (data / cam / 'camera/frames.jsonl').open())
|
| 32 |
+
assert frames[cam] > 0
|
| 33 |
+
shutil.copytree(data, release / 'data' / seq, copy_function=os.link)
|
| 34 |
+
shutil.copy2(record, release / 'doc' / record.name)
|
| 35 |
+
records.append({'sequence_id': seq, 'frames_by_camera': frames,
|
| 36 |
+
'original_script_sha256': build['scripts']})
|
| 37 |
+
manifest = {'time': datetime.datetime.now().astimezone().isoformat(),
|
| 38 |
+
'source_run': str(old), 'destination_run': str(new),
|
| 39 |
+
'configuration': {'workers': 4, 'codec_threads': 10, 'decode_threads': 10,
|
| 40 |
+
'depth_threads': 4, 'cpu_limit': None},
|
| 41 |
+
'reuse': 'Hard-linked immutable completed views; source timeline/SHA256 still rechecked without staging published source frames',
|
| 42 |
+
'excluded': 'Unpublished .tmp directories; historical 62-sequence output',
|
| 43 |
+
'original_runtime_provenance': 'script/provenance/previous-run', 'sequences': records}
|
| 44 |
+
(release / 'doc/RESTART_PROVENANCE.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
| 45 |
+
operations = release / 'script/provenance/operations'
|
| 46 |
+
for name in ('h2o-prepare-d10.py', 'h2o-switch-d10.sh', 'h2o-benchmark-decode.py'):
|
| 47 |
+
shutil.copy2(Path('/tmp') / name, operations / name)
|
| 48 |
+
for src, dest in (('/tmp/h2o-run-d10.sh', new / 'run-full.sh'),
|
| 49 |
+
('/tmp/h2o-run-d10.sh', release / 'script/run-full.sh'),
|
| 50 |
+
('/tmp/h2o-decode-bench.log', release / 'doc/validation/DECODE_THREAD_BENCHMARK.log'),
|
| 51 |
+
('/data/xuzhefeng/Datasets/uni-hoi-h2o-decode-bench-20260930/report.json', release / 'doc/validation/DECODE_THREAD_BENCHMARK.json'),
|
| 52 |
+
('/tmp/h2o-d10-final-tests.log', operations / 'worker4-encode10-decode10-depth4-regression.log'),
|
| 53 |
+
('/tmp/h2o-io-sample.log', release / 'doc/validation/IO_SAMPLE.log')):
|
| 54 |
+
shutil.copy2(src, dest)
|
| 55 |
+
print(f'REUSED_SEQUENCES={len(records)} REUSED_VIEWS={sum(len(r["frames_by_camera"]) for r in records)}', flush=True)
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/h2o-switch-d10.sh
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
cd /home/xuzhefeng/Projects/uni-hoi-dataset
|
| 4 |
+
test "$(cat /tmp/h2o-d10-final-tests.exit)" = 0
|
| 5 |
+
test "$(cat /tmp/h2o-decode-bench.exit)" = 0
|
| 6 |
+
test ! -e /data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10
|
| 7 |
+
old=/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10
|
| 8 |
+
# Let the already nearly complete fifth camera publish, instead of discarding four completed cameras.
|
| 9 |
+
while test ! -s "$old/H2O/shared-v1.0/doc/subject4_h1_0.build.json"; do
|
| 10 |
+
test "$(systemctl --user show --no-pager h2o-full-w4c10-r2-20260930.scope -p ActiveState --value)" = active
|
| 11 |
+
sleep 20
|
| 12 |
+
done
|
| 13 |
+
printf '\nRECONFIGURE=%s REASON=decoder10_depth4_no_resume_png_writes\n' "$(date -Is)" >> "$old/full.status"
|
| 14 |
+
systemctl --user stop h2o-full-w4c10-r2-20260930.scope
|
| 15 |
+
.venv/bin/python /tmp/h2o-prepare-d10.py
|
| 16 |
+
systemd-run --user --scope --unit=h2o-full-d10-20260930 -p CPUAccounting=yes /bin/bash /data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10-d10/run-full.sh
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/worker4-encode10-decode10-depth4-regression.log
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Converted subject1/h1/0
|
| 2 |
+
Converted subject2/h1/0
|
| 3 |
+
Converted subject3/h1/0
|
| 4 |
+
Converted subject4/h1/0
|
| 5 |
+
Converted subject2/h1/0
|
| 6 |
+
Converted subject1/h1/0
|
| 7 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 8 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 9 |
+
Converted subject4/h1/0
|
| 10 |
+
Converted subject3/h1/0
|
| 11 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 12 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 13 |
+
Converted subject1/h1/0
|
| 14 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 15 |
+
Converted subject2/h1/0
|
| 16 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 17 |
+
Converted subject4/h1/0
|
| 18 |
+
Converted subject3/h1/0
|
| 19 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 20 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 21 |
+
Verified existing subject2/h1/0
|
| 22 |
+
Verified existing subject1/h1/0
|
| 23 |
+
Verified existing subject4/h1/0
|
| 24 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 25 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 26 |
+
Verified existing subject3/h1/0
|
| 27 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 28 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 29 |
+
Converted subject2/h1/0
|
| 30 |
+
Converted subject1/h1/0
|
| 31 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 32 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 33 |
+
Converted subject3/h1/0
|
| 34 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 35 |
+
Converted subject4/h1/0
|
| 36 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 37 |
+
PASS H2O four archive workers, codec/decode 1/4/10, ordered depth 1/2/4 and missing-depth preservation, no resume PNG writes, RGB FFV1-only, depth and persistent QC
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/operations/workspace-regression.log
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Converted subject1/h1/0
|
| 2 |
+
Converted subject2/h1/0
|
| 3 |
+
Converted subject3/h1/0
|
| 4 |
+
Converted subject4/h1/0
|
| 5 |
+
Converted subject1/h1/0
|
| 6 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 7 |
+
Converted subject2/h1/0
|
| 8 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 9 |
+
Converted subject3/h1/0
|
| 10 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 11 |
+
Converted subject4/h1/0
|
| 12 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 13 |
+
Converted subject1/h1/0
|
| 14 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 15 |
+
Converted subject3/h1/0
|
| 16 |
+
Converted subject2/h1/0
|
| 17 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 18 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 19 |
+
Converted subject4/h1/0
|
| 20 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 21 |
+
Verified existing subject4/h1/0
|
| 22 |
+
Verified existing subject3/h1/0
|
| 23 |
+
Verified existing subject1/h1/0
|
| 24 |
+
Verified existing subject2/h1/0
|
| 25 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 26 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 27 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 28 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 29 |
+
Converted subject1/h1/0
|
| 30 |
+
Archive subject1_v1_1.tar.gz: 1 sequences
|
| 31 |
+
Converted subject2/h1/0
|
| 32 |
+
Archive subject2_v1_1.tar.gz: 1 sequences
|
| 33 |
+
Converted subject3/h1/0
|
| 34 |
+
Archive subject3_v1_1.tar.gz: 1 sequences
|
| 35 |
+
Converted subject4/h1/0
|
| 36 |
+
Archive subject4_v1_1.tar.gz: 1 sequences
|
| 37 |
+
PASS H2O four archive workers, codec/decode 1/4/10, ordered depth 1/2/4 and missing-depth preservation, no resume PNG writes, RGB FFV1-only, depth and persistent QC
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/docs/CONTRACT.md
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 手物数据仓库统一约定 v1.0
|
| 2 |
+
|
| 3 |
+
格式版本:`hand-warehouse/1.0`。存储约定:`lossless-video-2026-09-18`。
|
| 4 |
+
|
| 5 |
+
范围限于手物交互重建。按本任务纳入的源模态转换,不要求每个数据集填满所有组件。缺失模态、尚未下载、语义未核实分别报告,不能互相替代。
|
| 6 |
+
|
| 7 |
+
本文定义各字段的含义与使用规则,机器可读注册表见 [schema.json](schema.json)。两者互相补充;如有冲突,应先核实并统一定义。
|
| 8 |
+
|
| 9 |
+
## 1. 目录
|
| 10 |
+
|
| 11 |
+
```text
|
| 12 |
+
hand-datasets/
|
| 13 |
+
<dataset_name>/
|
| 14 |
+
raw/
|
| 15 |
+
doc/ # 官方说明、来源与校验记录
|
| 16 |
+
script/ # 官方下载脚本、必要包装脚本
|
| 17 |
+
data/ # 保留原始包,不原地解压或改写
|
| 18 |
+
<dataset_version>/
|
| 19 |
+
doc/ # 发布说明、schema、来源清单
|
| 20 |
+
script/ # 转换、校验脚本及运行配置
|
| 21 |
+
data/
|
| 22 |
+
<sequence_id>/
|
| 23 |
+
<camera_id>/
|
| 24 |
+
metainfo.json
|
| 25 |
+
observation/
|
| 26 |
+
rgb.mkv
|
| 27 |
+
rgb_valid.pt
|
| 28 |
+
depth.mkv # float32 深度的可逆视频编码
|
| 29 |
+
depth_valid.mkv # 逐像素 bool 的无损视频编码
|
| 30 |
+
camera/
|
| 31 |
+
frames.jsonl
|
| 32 |
+
intrinsic.pt
|
| 33 |
+
intrinsic_valid.pt
|
| 34 |
+
extrinsic.pt
|
| 35 |
+
extrinsic_valid.pt
|
| 36 |
+
annotation/
|
| 37 |
+
mano/
|
| 38 |
+
motion.pt
|
| 39 |
+
motion_valid.pt
|
| 40 |
+
visibility.pt
|
| 41 |
+
keypoints/
|
| 42 |
+
uv.pt
|
| 43 |
+
uv_valid.pt
|
| 44 |
+
xyz.pt
|
| 45 |
+
xyz_valid.pt
|
| 46 |
+
visibility.pt # 源数据有时提供
|
| 47 |
+
object/
|
| 48 |
+
<object_id>/
|
| 49 |
+
assets/ # 该物体的网格、材质、纹理及部件资产
|
| 50 |
+
<mesh_id>.obj
|
| 51 |
+
pose.pt
|
| 52 |
+
pose_valid.pt
|
| 53 |
+
visibility.pt
|
| 54 |
+
metainfo.json # 物体身份、类别、mesh、尺寸与部件引用
|
| 55 |
+
articulation.json
|
| 56 |
+
keypoints/
|
| 57 |
+
vertex_part_ids.pt
|
| 58 |
+
joint_state.pt
|
| 59 |
+
joint_state_valid.pt
|
| 60 |
+
parts/<part_id>/pose.pt
|
| 61 |
+
parts/<part_id>/pose_valid.pt
|
| 62 |
+
segment/
|
| 63 |
+
mask.mkv
|
| 64 |
+
mask_valid.pt
|
| 65 |
+
instances.jsonl
|
| 66 |
+
contact/
|
| 67 |
+
relations.jsonl
|
| 68 |
+
<subject_id>__<object_id>/ # 对应实体间的距离/接触区域
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
目录展示可能存在的组件,不要求填满。具体文件、字段和缺省规则分别见后续对应小节。原始包的解压发生在临时工作区,raw 内原始包保持不变。
|
| 72 |
+
|
| 73 |
+
## 2. 相机视图的 metainfo.json
|
| 74 |
+
|
| 75 |
+
### 2.1 顶层字段与发布信息
|
| 76 |
+
|
| 77 |
+
每个相机视图必须有 `metainfo.json`。以下字段除另行说明外均为必填:
|
| 78 |
+
|
| 79 |
+
| 字段 | 填写内容 |
|
| 80 |
+
|---|---|
|
| 81 |
+
| schema_version | 结构版本,本版为 `hand-warehouse/1.0` |
|
| 82 |
+
| dataset_id | 数据集的逻辑标识 |
|
| 83 |
+
| release_id | 本次数据发布版本,对应目录中的 dataset_version |
|
| 84 |
+
| sequence_id | 所属序列或独立图片样本的标识 |
|
| 85 |
+
| camera_id | 当前相机视图标识 |
|
| 86 |
+
| sample_type | `image` 或 `video`,规则见 2.2 |
|
| 87 |
+
| num_frames | 当前视图帧数 T,所有随帧组件按同一时间轴组织 |
|
| 88 |
+
| hand_slots | 固定为 `["left", "right"]`;解剖学左右的使用规则见 5.1 |
|
| 89 |
+
| sampling | 采样类型、源 FPS、帧索引引用及选择策略,见 2.2 |
|
| 90 |
+
| camera | 当前相机模型与图像尺寸,见 2.3 |
|
| 91 |
+
| components | 实际提供的组件及其文件、schema、有效性和来源,见 2.5 |
|
| 92 |
+
| split | `train/val/test/unknown`,划分协议见 2.4 |
|
| 93 |
+
| view_type | 可选,`ego/exo/unknown` |
|
| 94 |
+
|
| 95 |
+
`dataset_version` 是数据发布版本;`schema_version` 是结构版本,两者独立。原始包校验摘要、官方来源和转换配置应记录在发布清单中。解压发生在临时工作区,原始包保持不变。
|
| 96 |
+
|
| 97 |
+
### 2.2 图片、视频与 sampling
|
| 98 |
+
|
| 99 |
+
`sample_type=image`:允许单图 T=1、`sampling.type=single`,也允许将独立图片批量装入一个视频容器,T>1 时 `sampling.type=independent`、`source_fps=null`。分片大小按数据集选择;FreiHAND 默认每片最多 4096 张,训练与评估分开,尾片不补帧。该数量不是其他数据集的强制要求;同批分辨率、相机模型类型及划分协议一致。每行 frames 必须有稳定且唯一的 `sample_id`、原始文件定位;内参、手形状等仍逐帧保留,不能因打包而共享错误的标定或身份。`sequence_id` 在这里仅是批次标识,不代表真实序列;不得按相邻帧推断跟踪、同步或接触延续。源 camera_id、image_variant、split 等随样本变化时放在 frames 的对应字段中。真实采集时间未知则 timestamp_ns=null。合成背景变体不视为真实多相机。
|
| 100 |
+
|
| 101 |
+
`sample_type=video`:`sampling.type=dense/sparse`;`source_fps` 是真实采集 FPS,未知为 null。非连续取样必须保留源帧号和已知源时间,不可用采样后索引除以 FPS 冒充源时间。可另记采样策略与步长。
|
| 102 |
+
|
| 103 |
+
shared 可以仅存所选 RGB 帧对应的数据。OakInk2 图像/动捕不同采样率时用 annotation_matches 明确映射;不要求将未采样动捕点硬塞进 T。多视角身份和源同步关系要保留;选择了哪些帧/相机及原因写在 sampling 中。
|
| 104 |
+
|
| 105 |
+
`sampling.frames_ref` 指向 `camera/frames.jsonl`。帧号、逐帧时间、同步与标注匹配记录的结构见 4.1;MKV 封装时间的约定见 3.1。
|
| 106 |
+
|
| 107 |
+
### 2.3 camera 模型声明
|
| 108 |
+
|
| 109 |
+
`camera` 至少包含 `model`、`schema_id`、`image_size:[W,H]`。模型未知使用 `unknown` 和 `null`,不猜成针孔。实际内参、畸变及外参数组放在 `camera/`,各模型的固定结构见第 4 节。
|
| 110 |
+
|
| 111 |
+
### 2.4 split 与划分协议
|
| 112 |
+
|
| 113 |
+
保留上游划分,不将同一采集序列的相邻帧随意拆到不同集合。
|
| 114 |
+
|
| 115 |
+
有官方划分时必填 split_scheme 和 split_source_locator,split_scheme 区分如 Dex-YCB s0/s1、ARCTIC P1/P2 等选定协议;不知道时 split=unknown 并给理由,不凭空分配。每发布可选择一种协议;存在逐帧差异时 frames 中的 split 覆盖视图默认值,并登记其来源。
|
| 116 |
+
|
| 117 |
+
### 2.5 components 组件登记
|
| 118 |
+
|
| 119 |
+
组件表的键是本发布内唯一名称,例如 `rgb`、`depth`、`mano`、`keypoints_uv`。每个已提供组件声明以下信息;模态特有参数在第 3–5 节对应小节中定义。
|
| 120 |
+
|
| 121 |
+
| 字段 | 约定 |
|
| 122 |
+
|---|---|
|
| 123 |
+
| available | 本发布是否提供该组件;缺省也表示未提供 |
|
| 124 |
+
| schema_id | 已登记的具体存储与语义类型,不得临时创造未登记名称 |
|
| 125 |
+
| data_ref | 数据文件路径,相对当前相机视图根目录,使用 POSIX 路径 |
|
| 126 |
+
| axes | 数组各维度的含义 |
|
| 127 |
+
| valid_ref / valid_axes | 有效性文件及其维度;语义由所属组件规定 |
|
| 128 |
+
| storage / valid_storage | 视频数据/视频有效性的存储配置;包含已登记 profile、实际 codec、pixel_format、encoded_size,见 3.1;非视频组件按原数组规则 |
|
| 129 |
+
| provenance | source / format_conversion / derived,以及转换或生成方法 |
|
| 130 |
+
| source_locator | 原文件、压缩包成员和记录/帧的定位信息 |
|
| 131 |
+
|
| 132 |
+
不存在的组件允许缺省或写作 `{ "available": false, "reason": "..." }`,不用引用不存在的文件。静态网格可声明标量有效性;具体见 5.4。观测的 valid 见第 3 节,标注的 valid 与 visibility 区分见 5.1。
|
| 133 |
+
|
| 134 |
+
`provenance.kind` 使用 source/format_conversion/derived,`method` 说明转换或生成方法;发布清单补充脚本版本、参数、输入摘要。`source_locator` 定位到原始文件/压缩包成员和记录、帧号;允许引用有完整溯源清单的前一发布,但链条最终应能回到 raw。不得仅写一个无法定位记录的数据集名字。
|
| 135 |
+
|
| 136 |
+
`.pt` 仅保存 CPU Tensor,不保存 Python 自定义对象;浮点默认 float32,有效性为 bool,浮点无效位置填 NaN。所有随帧数组保留首维 T,单帧也不 squeeze;静态资产按其 schema 单独声明。单位、坐标及固定形状见各组件小节。
|
| 137 |
+
|
| 138 |
+
机器注册表 `schema.json` 中,`components` 固定解码后的数据类型、形状、单位和语义;`storage_profiles` 固定视频内的编码/还原方式。不得临时创造未登记的 schema_id 或 storage.profile。同一语义允许选择其登记的不同无损存储 profile。
|
| 139 |
+
|
| 140 |
+
## 3. observation 观测数据
|
| 141 |
+
|
| 142 |
+
### 3.1 rgb.mkv 与 rgb_valid.pt
|
| 143 |
+
|
| 144 |
+
RGB、深度和栅格 mask 在 shared 中统一使用 MKV 视频容器,不展开为逐帧图片或图像 tar。MANO、关键点、位姿等数值标注仍用数组;分割的重叠多边形仍用 JSONL,不为了视频化而有损栅格化。单图可为一帧视频,独立图批量封装规则见 2.2。
|
| 145 |
+
|
| 146 |
+
**无损指共享层不增加信息损失。** 源 JPEG/H.264 等本身可能已是有损编码,原样保留并不恢复已丢失信息;不得重新以有损 JPEG、H.264、H.265、AV1 参数编码。源视频/图片的色彩、位深、分辨率和几何关系不得被静默改变。RGB schema `rgb/uint8/v1` 的统一读取结果是 `[T,H,W,3] uint8`、RGB 通道,有效性仍为 `rgb_valid.pt [T] bool`。超出该 schema 的高位深或 HDR 源必须报告并扩展定义,不能降到 8 位冒充无损。
|
| 147 |
+
|
| 148 |
+
#### 3.1.1 允许的 RGB 存储 profile
|
| 149 |
+
|
| 150 |
+
| storage.profile | 编码方式 | 适用规则 |
|
| 151 |
+
|---|---|---|
|
| 152 |
+
| mkv/mjpeg_copy/v1 | 源 JPEG 压缩帧直接封装成 MJPEG/MKV | 不解码重编码;保持每张 JPEG 码流字节;普通 8 位 JPEG 且 MKV/解码器支持时使用 |
|
| 153 |
+
| mkv/source_copy/v1 | 已有视频的 RGB 对应码流直接封装为 MKV | 仅源编码能被 MKV 和选定解码器支持时使用,不伪造帧;需维持正确的呈现顺序与依赖帧 |
|
| 154 |
+
| mkv/h264_rgb_lossless/v1 | libx264rgb 的真正无损模式 | 必须 RGB 路径、CRF=0,并通过全帧 RGB 字节比较;不能替换成默认 libx264 YUV420 路径 |
|
| 155 |
+
| mkv/ffv1_rgb/v1 | FFV1 的 RGB 可逆编码路径 | 作为通用候选;解码回 RGB 后必须逐字节相同,不做色度降采样 |
|
| 156 |
+
|
| 157 |
+
优先尝试源码流直接封装;不能封装或需要选择稀疏帧时,比较 FFV1 与无损 RGB H.264。对完整待发布片段,只在通过无损验收的候选中选择文件较小者,不假设某个编码器总最小;编码时间和随机读取代价记入构建记录。中间候选不作为 shared 多份常驻。H.264 跨帧压缩允许较长 GOP,必须记录 GOP/关键帧间隔,随机取帧需从前一关键帧正确解码,不能把 seek 返回的近似帧当目标帧。
|
| 158 |
+
|
| 159 |
+
普通源视频可以保留它已有的有损码流,但不允许新增有损重编码。源是 VRS 等记录容器时,先查明图像流实际编码:已有兼容 JPEG/视频包可直接提取封装,否则解码后使用真正无损编码;不把整个 VRS 改后缀当 MKV。PNG 不要求直接塞进 MKV,可选上表两种无损重编码方式。
|
| 160 |
+
|
| 161 |
+
#### 3.1.2 视频配置与校验
|
| 162 |
+
|
| 163 |
+
每个视频组件在 metainfo 中登记 `storage`,至少包含:
|
| 164 |
+
|
| 165 |
+
| 字段 | 内容 |
|
| 166 |
+
|---|---|
|
| 167 |
+
| profile | 上述登记的存储 profile;语义仍由组件 schema_id 指定 |
|
| 168 |
+
| codec | 文件中实际 codec,例如 mjpeg、h264、ffv1;source_copy 必须写实际 codec |
|
| 169 |
+
| pixel_format | 实际编码像素格式;不得仅凭编码器参数猜测 |
|
| 170 |
+
| encoded_size | 视频物理像素尺寸 `[width,height]`;深度可能不同于逻辑尺寸,见 3.2 |
|
| 171 |
+
| decoder | 解码器名称、版本,以及颜色矩阵/范围/旋转处理等实际像素解释配置;未知的源色彩声明 unknown,不擅自称为 sRGB |
|
| 172 |
+
| encoder_parameters | 重编码时的编码器、版本、无损模式和 GOP 等参数;直接封装时记录 stream_copy |
|
| 173 |
+
| source_lossy | 源是否已有损:true / false / unknown;不是共享层再有损编码的许可 |
|
| 174 |
+
|
| 175 |
+
无损重新编码的 RGB 必须使用同一固定解码配置,比较**全部帧**的统一 RGB 字节、数量及顺序。MJPEG-copy 不重新编码,生产校验采用 `jpeg-packets-all-rgb-sample16/v1`:从 MKV 逐包取回,对全部源 JPEG 的 SHA256、数量、顺序和图像尺寸进行精确核对;每视图另用同一固定解码配置比较最多 16 帧的源与目标 RGB 字节(含首尾与四分位位置,其余由固定种子抽取)。记录策略、实际索引、种子与结果;不足 16 帧时全查。试点与最终完整序列随机抽查,对选中视图的全部帧复核解码 RGB。历史已做全帧像素检查的证明继续保留。
|
| 176 |
+
|
| 177 |
+
逐包一致与像素抽查的范围必须分别声明,不能将抽查写成全量像素检查。不能用 PSNR 高、视觉相似、编码器参数称为 lossless 等替代精确检查。同时保留源编码的色彩标记和必要元数据;原图有 EXIF/色彩/方向等元数据时保留 raw 和必要来源信息;不能静默自动旋转图像而不更新像素对应与标定。以上加速策略仅适用于原 JPEG 码流直接封装,不适用于深度、标签或重新编码的 RGB。
|
| 178 |
+
|
| 179 |
+
所有共享视频的呈现帧顺序与统一 frame_index 一一对应,每个栅格组件恰好 T 帧。MKV 的 `storage_fps` 只服务封装,声明 `timebase_role=index_only`;source_copy 可以保留源 PTS 以避免改坏码流,但真实时间与标注对齐仍以 frames 为准。未知真实时间保留 null。缺失某帧组件时保留索引位置并使用该组件的无效占位/valid 标识,不删帧;不能以重复相邻图像冒充已知观测。
|
| 180 |
+
|
| 181 |
+
### 3.2 depth.mkv 与 depth_valid.mkv
|
| 182 |
+
|
| 183 |
+
深度语义仍是 `depth/z_float32/v1`:统一读取结果 `[T,H,W] float32`,米制相机 Z 分量,`depth_type=z`。有效深度有限且大于 0,无效位置为 NaN。`depth_origin=measured/rendered/unknown` 必填,来源不明时 unknown。默认与 RGB 共用像素网格及相机参考系,不处理未注册 RGB-D。射线距离必须依据源定义转换成 z,不能只改声明。
|
| 184 |
+
|
| 185 |
+
#### 3.2.1 float32 的可逆视频编码
|
| 186 |
+
|
| 187 |
+
采用 `mkv/depth_float32_bits/v1`:**不是把深度量化成 uint16**,而是将规范化后每个 IEEE-754 float32 的完整 32 位拆成两个 uint16,使用 FFV1 gray16le 保存。视频物理尺寸为 `[2W,H]`:每行前 W 列存原 float32 位串的低 16 位,后 W 列存高 16 位。读取时先合并为 uint32 位串,再按 float32 重新解释,不能数值 cast 成 float32。
|
| 188 |
+
|
| 189 |
+
```text
|
| 190 |
+
u = reinterpret_uint32(depth_float32)
|
| 191 |
+
encoded[:, :, :W] = uint16(u & 65535)
|
| 192 |
+
encoded[:, :, W:] = uint16(u >> 16)
|
| 193 |
+
u_restored = uint32(low) | (uint32(high) << 16)
|
| 194 |
+
depth_float32 = reinterpret_float32(u_restored)
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
统一采用 little-endian 原始字节接口。`camera.image_size` 始终是逻辑 RGB 尺寸 `[W,H]`,不能改成编���视频的 2W;`storage.encoded_size=[2W,H]`。包括 NaN 在内的 float32 位串必须全帧完全恢复,不允许改成 float16、整数毫米、归一化灰度或 RGB 伪彩色。这里的无损验收基准是完成既定米制/坐标转换后的标准 float32 数组,不声称消除 float64→float32 等原约定转换本身的舍入。
|
| 198 |
+
|
| 199 |
+
#### 3.2.2 逐像素有效性
|
| 200 |
+
|
| 201 |
+
`depth_valid.mkv` 使用 `mkv/bool_ffv1/v1`,FFV1 gray8(FFmpeg pixel_format=`gray`),物理尺寸 `[W,H]`。像素只能为 0 或 1,统一解码为 `[T,H,W] bool`,逐像素含义不变。这样不再把庞大的 bool 数组保存为未压缩 `.pt`;标注的帧级/手级 valid 仍保留原有小数组。
|
| 202 |
+
|
| 203 |
+
登记示例(W、H 以下取 640、480;decoder/encoder_parameters 的实际版本由转换器填写):
|
| 204 |
+
|
| 205 |
+
```json
|
| 206 |
+
{
|
| 207 |
+
"available": true,
|
| 208 |
+
"schema_id": "depth/z_float32/v1",
|
| 209 |
+
"data_ref": "observation/depth.mkv",
|
| 210 |
+
"axes": ["T", "height", "width"],
|
| 211 |
+
"valid_ref": "observation/depth_valid.mkv",
|
| 212 |
+
"valid_axes": ["T", "height", "width"],
|
| 213 |
+
"unit": "m",
|
| 214 |
+
"depth_type": "z",
|
| 215 |
+
"depth_origin": "measured",
|
| 216 |
+
"invalid_value": "NaN",
|
| 217 |
+
"storage": {
|
| 218 |
+
"profile": "mkv/depth_float32_bits/v1",
|
| 219 |
+
"codec": "ffv1",
|
| 220 |
+
"pixel_format": "gray16le",
|
| 221 |
+
"encoded_size": [1280, 480],
|
| 222 |
+
"source_lossy": false,
|
| 223 |
+
"decoder": {"name": "ffmpeg", "version": "填写实际版本"},
|
| 224 |
+
"encoder_parameters": {"name": "ffv1", "level": 3, "version": "填写实际版本"}
|
| 225 |
+
},
|
| 226 |
+
"valid_storage": {
|
| 227 |
+
"profile": "mkv/bool_ffv1/v1",
|
| 228 |
+
"codec": "ffv1",
|
| 229 |
+
"pixel_format": "gray",
|
| 230 |
+
"encoded_size": [640, 480],
|
| 231 |
+
"source_lossy": false,
|
| 232 |
+
"decoder": {"name": "ffmpeg", "version": "填写实际版本"},
|
| 233 |
+
"encoder_parameters": {"name": "ffv1", "version": "填写实际版本"}
|
| 234 |
+
},
|
| 235 |
+
"provenance": {"kind": "format_conversion", "method": "源深度转米制 z float32;逐位打包为 FFV1"},
|
| 236 |
+
"source_locator": {"file": "raw/data/depth.zip", "member": "depth/0001.png"}
|
| 237 |
+
}
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
深度和有效性视频都必须逐帧解码验收:float32 位串相同、bool 相同、T 相同,并检查 valid=true 的正有限值和 valid=false 的 NaN。读取器必须按 profile 还原,不能把 depth.mkv 的编码像素直接当深度值。
|
| 241 |
+
|
| 242 |
+
## 4. camera 相机、帧索引与标定
|
| 243 |
+
|
| 244 |
+
### 4.1 frames.jsonl:索引、时间与对应关系
|
| 245 |
+
|
| 246 |
+
`camera/frames.jsonl` 每行对应统一帧号 `frame_index=0..T-1`,是所有组件的唯一行索引。至少包含 `frame_index`、`timestamp_ns`、`clock_domain`、`source_locator`;原始帧号/文件名保存在 `source_frame_id`,不能被新帧号替代。每行还可有 `annotation_matches`,按组件键保存 `source_frame_id`、`source_timestamp_ns`、`clock_domain`、`match_method` 和 `delta_ns`;方法为 exact/index_map/nearest/interpolated,索引映射无时间依据时 delta_ns=null。nearest 必须记录允许误差;interpolated 必须记录两端源标识和权重。delta_ns 仅在同一时间域中计算为源标注时间减图像时间。多相机共享 `sequence_id`;已知同步关系必须用 `sync_id` 或明确的源帧/时间映射表达,不能仅凭相同数组索引认定同步。
|
| 247 |
+
|
| 248 |
+
每个视图必须提供此文件。源时间使用整数纳秒及 `clock_domain`,未知写 JSON `null`;不同时间域不能直接比较。逐帧 split 可以覆盖 metainfo 的视图默认划分,并保留来源,见 2.4。
|
| 249 |
+
|
| 250 |
+
### 4.2 坐标系与标定通则
|
| 251 |
+
|
| 252 |
+
| 项目 | 统一约定 |
|
| 253 |
+
|---|---|
|
| 254 |
+
| 相机坐标 | 右手系,X 向右、Y 向下、Z 向前,长度单位米 |
|
| 255 |
+
| 齐次变换 | 列向量,`p_target = T_target_from_source @ p_source` |
|
| 256 |
+
| 图像坐标 | `(u,v)`;左上像素中心为 `(0,0)`,u 向右、v 向下,单位 pixel |
|
| 257 |
+
| 固定标定 | 本版展开为 T 份,同一 schema 不混用静态与动态形状 |
|
| 258 |
+
| 分辨率或模型变化 | 分开存储为视图/片段,不在同一组件中混装 |
|
| 259 |
+
| 未知标定 | 相机内外参允许缺省,不填单位阵冒充已知标定 |
|
| 260 |
+
|
| 261 |
+
### 4.3 intrinsic.pt 与畸变参数
|
| 262 |
+
|
| 263 |
+
| model / schema_id | intrinsic.pt 的固定结构 |
|
| 264 |
+
|---|---|
|
| 265 |
+
| pinhole / camera/pinhole/v1 | `[T,3,3]`,标准 K,最后一行为 `[0,0,1]`;限无畸变或已校正图像 |
|
| 266 |
+
| fisheye624 / camera/fisheye624/v1 | `[T,15]`,`[f,cx,cy,k0,k1,k2,k3,k4,k5,p0,p1,s0,s1,s2,s3]`,采用 Project Aria Fisheye624 投影定义 |
|
| 267 |
+
| opencv_fisheye4 / camera/opencv_fisheye4/v1 | `intrinsic.pt [T,3,3]` 保存 K;同组件 `distortion_ref` 指向 `[T,4]`,顺序 `[k1,k2,k3,k4]`,使用 OpenCV fisheye 等距角度多项式;已由 ReInterHand 实际原始相机参数验证 |
|
| 268 |
+
| rational8 / camera/rational8/v1 | `intrinsic.pt [T,3,3]` 保存 K;同组件必需 `distortion_ref` 指向 `[T,8]`,顺序 `[k1,k2,p1,p2,k3,k4,k5,k6]` |
|
| 269 |
+
| unknown / null | 不提供可用 intrinsic,不声称可以投影 |
|
| 270 |
+
|
| 271 |
+
有畸变的其他模型必须注册新 schema,固定参数名、顺序和投影公式;不能塞进针孔 K 后遗失畸变项。`metainfo.camera.schema_id` 必须与 intrinsic 组件一致。同一模型的别名不可隐式改变参数布局。
|
| 272 |
+
|
| 273 |
+
`opencv_fisheye4`:对前方点令 `x=X/Z, y=Y/Z, r=sqrt(x²+y²), theta=atan(r)`,`theta_d=theta*(1+k1*theta²+k2*theta⁴+k3*theta⁶+k4*theta⁸)`;`u=fx*x*theta_d/r+cx, v=fy*y*theta_d/r+cy`。光轴 r=0 时使用连续极限 `theta_d/r=1`。四系数不能按普通径向畸变解释,也不能补零冒充 Fisheye624。
|
| 274 |
+
|
| 275 |
+
rational8 对归一化坐标 x=X/Z、y=Y/Z,令 r²=x²+y²,径向项为 `(1+k1*r²+k2*r⁴+k3*r⁶)/(1+k4*r²+k5*r⁴+k6*r⁶)`;再加 p1/p2 切向项并经 K 得到像素。`distortion_ref` 与 intrinsic 共用 `[T]` valid,保存到 camera/distortion.pt。不得把这种畸变三维坐标当作真实相机系 xyz 保存。
|
| 276 |
+
|
| 277 |
+
内参有效性为 `intrinsic_valid.pt [T] bool`;有畸变时使用对应 `distortion_ref`。同一模型的参数名和顺序固定。
|
| 278 |
+
|
| 279 |
+
### 4.4 extrinsic.pt 与 extrinsic_valid.pt
|
| 280 |
+
|
| 281 |
+
`extrinsic.pt` 为 `[T,4,4]`,schema `transform/se3/v1`,方向固定 `T_camera_from_world`,有效性 `[T]`。世界坐标含义及源坐标转换记录在 provenance 中;只有相机坐标标注不要求虚构世界坐标。旋转块须正交且 determinant≈1。
|
| 282 |
+
|
| 283 |
+
## 5. annotation 标注数据
|
| 284 |
+
|
| 285 |
+
### 5.1 标注通则:手槽、valid 与 visibility
|
| 286 |
+
|
| 287 |
+
手槽固定为 0=left、1=right,指解剖学左右,不按画面位置或可见性重排。本阶段只处理左右手两槽,不处理更多手。实体引用使用 `hand_left`、`hand_right`;手槽不证明跨采集片段的个人身份。
|
| 288 |
+
|
| 289 |
+
#### 5.1.1 valid:标注是否可用于监督
|
| 290 |
+
|
| 291 |
+
标注的 `valid=true` 表示:有对应实际标注、通过本 schema 数值检查,且通过来源明确提供并适用于该组件的有效性/QA 条件。`valid=false` 可由缺标注、无法建立帧对应、源无效占位或官方 QA 不通过导致;不等于画面没有手或手不可见。各组件独立判断,MANO 按 `[T,2]` 标记左右手,关键点按 `[T,2,K]` 标记。
|
| 292 |
+
|
| 293 |
+
**2026-09-20 将标注 valid 从“仅表示存在”修订为“可用于监督”,字段形状不变。** 公式为 `source_annotation_present AND numerical_checks_pass AND applicable_official_QA_pass`。没有官方 QA 时省略最后一项,不伪造 QA;不能把未知当成已通过已存在的 QA。适配器在组件 `valid_policy` 中记录具体规则、来源、聚合/广播作用域。缺失官方必需 QA 的记录须明确处理为未知或暂停验收,不能静默通过。无效浮点项仍填 NaN,原始数据保留在 raw;被排除原值可用于 doc 中明确标识的诊断渲染,不能冒充 shared 有效监督。
|
| 294 |
+
|
| 295 |
+
本地筛选须依据明确的规则,并在 `valid_policy.local_excluded_frame_indices`、排除原因和正式报告中记录。单个可疑投影作为问题记录,不直接硬编码排除该帧。已确认的曝光异常须明确作用范围,不能把一个序列的“前两帧有问题”套到所有序列。RGB 编码完好与几何监督可用是两件事,允许保留原图及帧索引而屏蔽对应标注;未发现问题不等于完成全部人工审核,试点待确认时不能作为已验收发布使用。
|
| 296 |
+
|
| 297 |
+
源字段必须按官方语义映射,不能直接按名字复制:
|
| 298 |
+
|
| 299 |
+
| 来源 | 官方含义 | 映射原则 |
|
| 300 |
+
|---|---|---|
|
| 301 |
+
| [H2O](https://github.com/taeinkwon/h2odataset) 的手标注首位 | 0 未标注、1 已标注 | 可作为对应手标注存在性的依据,不推断未标注原因 |
|
| 302 |
+
| [HOT3D](https://github.com/facebookresearch/hot3d#using-mask-files) 的 pose_available、visible、mask_qa_pass | 分别表达姿态存在、可见性、对画面中可见手物位姿的人工 QA | 逐手/物体记录决定存在性,再 AND 当前相机当前帧 QA;QA 是整帧聚合判定,保守排除该帧全部手物几何监督,不声称每个实体均有错误;源可见性基于位姿推导时,其自身 valid 同样受 QA 约束 |
|
| 303 |
+
| [Dex-YCB](https://github.com/NVlabs/dex-ycb-toolkit#loading-dataset-and-visualizing-samples) 的全零 pose_m、全 -1 joints | 不可见的手或缺标注共用占位表示 | 对应组件 valid=false;不能从该值判定 visibility=false,也不能声称原因是动捕缺失 |
|
| 304 |
+
| [ARCTIC](https://github.com/zc-alexfan/arctic/blob/master/docs/data/data_doc.md) 的 is_valid/left_valid/right_valid | 是否有效用于官方评估 | 核实每项筛选依据;不把可见性/评估选择直接等同 QA。本次原始 mano.npy 不含这些派生评估标记,按原记录与数值检查生成 valid,并声明没有额外官方 QA 输入 |
|
| 305 |
+
|
| 306 |
+
源 valid=false 若代表评估筛选或其他条件,应检查实际标注和源约定后映射;不能一律清空坐标。反之,占位零或 -1 只有在源官方明确规定时才判为缺失,不泛化成所有数据的判断规则。
|
| 307 |
+
|
| 308 |
+
`valid=true` 的标注应通过其 schema 的数值与形状检查;检查失败必须报告或修复,不能静默隐藏。QA 不通过应报告排除数量与原因,并保留可追溯信息;不能把这类无效称为缺标注。RGB、深度等观测有效性仍按各自 schema;手物 QA 不自动否定 RGB、静态相机内参或物体资产。相机外参是否过滤须依据其自身来源规则;HOT3D 本次保留源外参用于溯源和诊断,不能用其存在性证明 QA 失败帧的几何监督正确。
|
| 309 |
+
|
| 310 |
+
#### 5.1.2 visibility:可见性属性
|
| 311 |
+
|
| 312 |
+
附加质量属性只保留 `visibility`,存放在对应模态或标注集内,不设 quality 目录。同一份可见性仅存一次;uv 与 xyz 共用时引用同一个文件。
|
| 313 |
+
|
| 314 |
+
visibility 通过所属组件 attributes 登记 data_ref、axes、dtype、visibility_type、meaning、provenance、source_locator;未知值通过属性 valid_ref 标识,全已知可声明 valid=true。比例与布尔值不相互强转,也不按任意阈值二值化。没有 MANO 时,整手可见性挂在 keypoints 组件,使用独立的 whole_hand_visibility.pt,明确 meaning=whole_hand,不与逐关键点可见性混用。
|
| 315 |
+
|
| 316 |
+
`valid` 回答“这项标注能否用于监督”,`visibility` 回答“在当前图像中是否可见(或可见多少)”。不可见的手或关键点仍可有有效标注;不能因 visibility=0 就清空坐标。源没有 visibility 时缺省或标为未知,不由 valid 推断。
|
| 317 |
+
|
| 318 |
+
| 情况 | 手标注 valid | visibility |
|
| 319 |
+
|---|---|---|
|
| 320 |
+
| RGB 已开始录制,动捕尚未开始,没有其他对应手标注 | false | 以独立源可见性标注为准;没有则未知 |
|
| 321 |
+
| 手被遮挡,但源有标注且通过适用有效性检查 | true | 若源声明不可见,则 false 或源可见比例 |
|
| 322 |
+
| 手可见且有对应标注,通过适用 QA | true | 若源有此信息,则 true 或源可见比例 |
|
| 323 |
+
| 手可见,但该帧漏标或动捕中断 | false | 可以为 true,但必须有独立来源依据 |
|
| 324 |
+
| 有手部参数,但官方 QA 明确不通过 | false | 不据此断言不可见;源可见比例若基于不可靠位姿,其属性 valid 也为 false |
|
| 325 |
+
|
| 326 |
+
visibility 自己的 valid_ref 表示该可见性标注是否可用,不复用 MANO 或关键点坐标的 valid_ref;明确记录源存在性及适用的 QA 条件。上述例子不要求凭图像自动生成可见性。
|
| 327 |
+
|
| 328 |
+
不设 quality 组件或目录,不另存拟合误差、曝光、截断比例等通用质量数组。适用的官方 QA 合并进对应 valid,在 `valid_policy` 记录来源与规则;正式校验报告保留原始 QA 时间区间及排除统计。原始 QA 文件仍在 raw,官方 split 保留。
|
| 329 |
+
|
| 330 |
+
### 5.2 mano:参数与整手可见性
|
| 331 |
+
|
| 332 |
+
MANO schema `mano/axis_angle61/v1`:`motion.pt [T,2,61]`,顺序为完整 16 关节 axis-angle 48、shape betas 10、全局平移 3。姿态使用弧度,平移米,位于当前相机系。有效性 `[T,2]`;缺少一侧整槽 NaN。PCA 必须先按对应模型展开,不能将 PCA 系数直接填入 axis-angle。
|
| 333 |
+
|
| 334 |
+
`model_profile` 必须固定 MANO 版本、`flat_hand_mean=true`、左手 shapedirs 修正状态。平移表示模型输出顶点所加的全局平移,不是某个腕关节的坐标;源语义不同须转换。shape 无量纲。模型权重不作为共享数据附带上传。
|
| 335 |
+
|
| 336 |
+
`mano/visibility.pt [T,2]` 保存源整手可见比例时使用 float32 [0,1],`visibility_type=ratio`;只有实际采用 0–100 的百分比才除以100,不能只凭表头判断。HOT3D 的 `visibility_ratio[%]` 实值已经是0–1,官方读取器原样读取,必须保留原值。通过 MANO 组件 attributes 登记,使用独立有效性,不复用 motion_valid。
|
| 337 |
+
|
| 338 |
+
手部共享表示仅保留 MANO 参数与选定关键点,不发布独立手表面几何。需要渲染或接触计算时由 MANO 参数生成,几何引用使用固定 MANO 模型配置与顶点顺序;不影响 object 下的物体模型和材质资产。
|
| 339 |
+
|
| 340 |
+
### 5.3 keypoints:二维点、三维点与逐点可见性
|
| 341 |
+
|
| 342 |
+
关键点独立于 MANO 参数存在;没有 motion 也可有关键点。`uv.pt [T,2,K,2]` 与 `xyz.pt [T,2,K,3]`,有效性 `[T,2,K]`,分别采用 `keypoints/uv/v1` 和 `keypoints/xyz/v1`。K 由 `keypoint_schema` 固定,不能在同一数组中逐帧变化;同体系统一顺序。数值使用像素坐标或米制相机系。
|
| 343 |
+
|
| 344 |
+
| keypoint_schema | K 与固定索引 |
|
| 345 |
+
|---|---|
|
| 346 |
+
| mano21/v1 | 21;wrist 后依次 thumb/index/middle/ring/little,每指由近端至指尖 |
|
| 347 |
+
| rhd21/v1 | 21;保持 wrist,然后五指由近端至指尖;原始每指 tip→palm 反序。只统一顺序,不宣称解剖学位置等价于 MANO |
|
| 348 |
+
|
| 349 |
+
具体名称与源索引映射见 `schema.json`。当前只登记 MANO21 与 RHD21;不登记 MediaPipe、ReInterHand capture21 或 fit24 中间关键点。
|
| 350 |
+
|
| 351 |
+
每个发布中的每个视图只提供一套标准手关键点,直接放在 keypoints 下,不设 annotation_set_id 字段或目录。uv 与 xyz 是这套关键点的二维与三维表示,不是两套标注。provenance 分别记录二者来自原始标注还是计算结果;不要求已有 2D 必须由当前 xyz 重新投影覆盖。
|
| 352 |
+
|
| 353 |
+
ReInterHand 的 Original keypoints���Original fits keypoints 及带前臂关键点不纳入 shared;如需手关键点,从选定 MANO 参数生成 MANO21 并记录模型/指尖回归约定。其他数据集默认使用选定的官方关键点,不额外生成平行的 MANO 派生集合。后续主动更换生成方法或结果时发布新的 dataset_version,不在同一版本内增设方法分支。
|
| 354 |
+
|
| 355 |
+
manual/projection/fitting 只记录在 provenance,不作为目录或类型分支。不得通过坐标为零、是否出画或 visibility 判断标注是否存在。派生标注仅在实际生成并通过数值检查后声明 valid=true;没有生成的项为 false,不伪造坐标。
|
| 356 |
+
|
| 357 |
+
`keypoints/visibility.pt [T,2,K]` 保存源逐点可见性,布尔表示使用 `visibility_type=boolean`。uv 与 xyz 共用时引用同一份文件。整手比例属性没有 MANO 可挂载时使用 `whole_hand_visibility.pt [T,2]`,`meaning=whole_hand`;它与逐点可见性分开,通用登记规则见 5.1。
|
| 358 |
+
|
| 359 |
+
不使用 annotation_set_id;ReInterHand 中间关键点集合不进入 shared,raw 保留来源文件。
|
| 360 |
+
|
| 361 |
+
### 5.4 object:身份、资产、位姿与几何
|
| 362 |
+
|
| 363 |
+
#### 5.4.1 metainfo.json:物体身份与跟踪作用域
|
| 364 |
+
|
| 365 |
+
手用 `hand_left`、`hand_right` 及槽位 0、1 表示,不再另存 entities.json。物体身份登记在 `annotation/object/<object_id>/metainfo.json`,必填 `object_id`、`identity_scope`、`scope_id`、`source_locator`;可含 `category_id`、`source_object_id`、`mesh_ref`、`has_model`、部件引用。即使只有分割、没有 pose/mesh,也可只有这份物体元信息。
|
| 366 |
+
|
| 367 |
+
`identity_scope` 为 frame/subsequence/sequence,`scope_id` 指定具体作用域;跨相机共享身份只在已有源对应证据时使用。VISOR 按官方 subsequence 与实体名关联时记录 `association_basis=official_subsequence_entity_name`,不能声称这是全视频物理实例跟踪。无需与 object_id 一一对应的标准 track_id;官方独立轨迹标识存在时保留为 source_track_id,并声明作用域。手槽不证明跨采集片段的个人身份。
|
| 368 |
+
|
| 369 |
+
#### 5.4.2 assets:网格、材质与纹理
|
| 370 |
+
|
| 371 |
+
资产属于物体,统一存放在 `annotation/object/<object_id>/` 内,可用 `assets/` 子目录组织网格、材质、纹理和部件资产。序列层不设共享 assets。所有引用采用视图根目录为基准;其中物体资产组件的 `data_ref` 与部件的 `mesh_ref` 采用相对于当前视图目录的 POSIX 路径,例如 `annotation/object/cup_01/assets/cup.obj`,且必须指向所属物体目录内的资产。OBJ 内部的材质、纹理引用遵循文件格式自身的相对路径规则,依赖文件一并保留。不同相机视图允许各自保存物体资产,不要求跨视图去重;下载物体时包含其资产依赖。
|
| 372 |
+
|
| 373 |
+
网格 schema 为 `mesh/obj/v1`,顶点米制,静态有效性可直接声明标量 `valid`,或通过 `valid_ref` 指向标量 bool Tensor;不按 T 重复静态资产。由物体/部件通过引用关联,不仅凭文件名猜测。
|
| 374 |
+
|
| 375 |
+
#### 5.4.3 pose.pt、pose_valid.pt 与 visibility.pt
|
| 376 |
+
|
| 377 |
+
刚体 schema 为 `object/rigid/v1`,`pose.pt [T,4,4]` 固定为 `T_camera_from_object`,平移米制,有效性 `[T]`。物体坐标原点、轴向必须与 mesh 一致;旋转块为正交矩阵且 determinant≈1。
|
| 378 |
+
|
| 379 |
+
`object/<id>/visibility.pt [T]` 保存源物体可见比例,float32 [0,1],`visibility_type=ratio`。通过所属物体组件 attributes 登记,独立表达其有效性。
|
| 380 |
+
|
| 381 |
+
#### 5.4.4 articulation.json、部件位姿与 joint_state.pt
|
| 382 |
+
|
| 383 |
+
关节物体:schema `object/articulated/v1`,`articulation.json` 登记 `parts` 与 `joints`。每个 part 有 `part_id`、`parent_id`(根为 null)、`has_model`、`mesh_ref`;has_model=false 时 mesh_ref=null,结构节点允许没有网格。父链不得成环。每个 joint 有唯一 `joint_id`、`parent_part`、`child_part`、`type`;fixed 单位 null、revolute 弧度、prismatic 米。有源限位时保存 `limits:[lower,upper]`;没有时 null,不伪造上下限。部件姿态统一为 `T_camera_from_part [T,4,4]`,不与父局部变换混装。
|
| 384 |
+
|
| 385 |
+
若提供 `joint_state.pt [T,J]`,必须登记固定 joint_order、轴在父部件系的表达、零位变换与正方向,valid 为 `[T,J]`;缺少这些运动学定义时只发布部件位姿与已有来源信息,不伪造可驱动的关节模型。关节值与部件位姿同时存在时需验证一致性。
|
| 386 |
+
|
| 387 |
+
部件层级应声明语义:纯语义包含树允许 `joints=[]`,不将包含关系推断为机械关节。关节状态 schema 为 `object/joint_state/v1`;转动用弧度、移动用米,混合类型按 joint_order 对应的关节定义解释。
|
| 388 |
+
|
| 389 |
+
#### 5.4.5 dimensions、几何关键点与顶点部件标签
|
| 390 |
+
|
| 391 |
+
`dimensions.pt [T,3]` 采用 `object/dimensions/v1`,有效性为 `[T]`。
|
| 392 |
+
|
| 393 |
+
物体/部件 `dimensions` 为 `[length,width,height]` 米,轴顺序与该 mesh 的局部坐标关联,登记 `dimensions_semantics` 和来源。HOI4D dimensions 与 mesh 的具体尺度关���未验证前标为 source_unspecified,保留源值并暂停依赖该关系的几何验收,不能默认为待施加缩放。需要施加缩放时明确 scale_applied_to_mesh,禁止重复应用。
|
| 394 |
+
|
| 395 |
+
源物体关键点放 `object/<id>/keypoints/xyz.pt [T,K,3]`(相机系)或 `template_xyz.pt [K,3]`(物体系),schema 分别为 object_keypoints/camera/v1 和 object_keypoints/template/v1。明确 keypoint_schema、keypoint_names、单位及有效性;模板点配合 pose 可投影,无须重复生成全部帧。H2O 中心/角点/棱中点,以及 ARCTIC 部件点分别登记具体源顺序,不套用手的 21 点 schema。每个发布选择一套源几何点并记录选择,不另建方法分支。
|
| 396 |
+
|
| 397 |
+
`vertex_part_ids.pt [V] int64` 绑定 `mesh_ref` 与 topology_id,登记整数到 part_id 的映射;未知用 -1。ARCTIC 不同拓扑的资产分别绑定,不能共用未经转换的顶点标签。部件层级中 is_instance/has_model 等源属性保留,几何文件仍全部归 object。
|
| 398 |
+
|
| 399 |
+
### 5.5 segment:分割类别、编码与覆盖范围
|
| 400 |
+
|
| 401 |
+
每个发布选择一套任务使用的分割表示,不建立方法/标注集分支。没有分割就不创建 segment 目录,不为其他模态创建空的实体表。
|
| 402 |
+
|
| 403 |
+
| schema_id | 文件与数值语义 |
|
| 404 |
+
|---|---|
|
| 405 |
+
| segment/uint16_labels/v1 | mask.mkv;整数区域编号,通过 instances.jsonl 解释 |
|
| 406 |
+
| segment/instance_polygons/v1 | polygons.jsonl;实例多边形,可重叠;当前不支持孔洞拓扑 |
|
| 407 |
+
| segment/foreground_intensity/v1 | mask.mkv;0–255 前景强度,不是区域编号或经过校准的概率 |
|
| 408 |
+
|
| 409 |
+
#### 5.5.1 uint16 标签图与 instances.jsonl
|
| 410 |
+
|
| 411 |
+
组件声明 `segmentation_type=semantic/instance/part`;同一组件固定一种类型。`mask.mkv` 解码为 `[T,H,W] uint16`,schema `segment/uint16_labels/v1`,使用 `mkv/uint16_ffv1/v1`,FFV1 gray16le 无损;只有所有区域编码均 ≤255 时允许 gray8(pixel_format=gray),读取后转 uint16,数值不变。禁止调色板和有损编码。有效性 `[T]`,表示该帧有可用分割标注。数值 0 固定为 unassigned,65535 固定为 ignore,1–65534 为区域编码,不能直接等同 entity_id。
|
| 412 |
+
|
| 413 |
+
`instances.jsonl` 每帧一行,包含 `frame_index` 与 `labels`。每条标签包含 `mask_value`、`category_id`、`entity_id`、`part_id`;无意义或未知字段为 null。semantic 允许 entity_id=null;instance 必须引用 hand_left/hand_right 或登记的 object_id;part 还须关联登记部件。源实例 ID 和其他属性分别保存在 `source_instance_id`、`source_attributes`。mask 中每个非保留编码必须有且仅有一个映射。
|
| 414 |
+
|
| 415 |
+
FreiHAND 的试点按本任务需要,统一到手/背景类别,保留每个原生区域编码;不要求给原生细分区域猜测手指名称。需要细部件监督时,尚未核实的部件名称必须保持未知,不能因粗粒度手类别已核实便声称部件语义也已统一。
|
| 416 |
+
|
| 417 |
+
#### 5.5.2 重叠实例多边形
|
| 418 |
+
|
| 419 |
+
每发布选择一套任务使用的分割表示,不建立方法/标注集分支。VISOR 的实际试点存在重叠实例多边形,单层标签图不能无损表达。对此补充 `segment/instance_polygons/v1`:`segment/polygons.jsonl` 每帧包含 `frame_index` 和 `instances`,每实例包含 `mask_value` 与 `polygons`(列表,每个多边形为源图像像素坐标顶点序列,保留原始精度)。身份和类别仍由同一 `instances.jsonl` 映射,有效性仍为 `[T]`,通过 schema 区分物理编码。允许多实例重叠,不采用后画覆盖前画。消费者按需栅格化为独立实例二值 mask;不能声称合并的单层 mask 无损。
|
| 420 |
+
|
| 421 |
+
#### 5.5.3 灰度前景强度
|
| 422 |
+
|
| 423 |
+
ReInterHand 的官方渲染 mask 为双手合并的灰度前景掩码,实测存在 0–255 的中间值,不是左右手实例编号。登记 `segment/foreground_intensity/v1`:仍存 `segment/mask.mkv`,解码为 `[T,H,W] uint16`,使用 `mkv/uint16_ffv1/v1`,此类数据优先编码为 FFV1 gray8(pixel_format=gray),读取后转 uint16。有效值范围 0–255,归一化值为 `float32(value)/255`;0 为背景端点、255 为前景端点。组件声明 `foreground_category=hand`、`entity_id=null` 和双手合并语义,不使用区域编号映射。这里保留原始渲染 mask 强度,不把它称为经过校准的概率。若任务需要二值 mask,阈值化属于任务层派生操作,记录阈值;共享层不丢弃中间灰度。不同 schema 的数值含义不同,不能将该文件按整数类别图解码。
|
| 424 |
+
|
| 425 |
+
FreiHAND 训练集的 JPEG mask 使用 `segment/foreground_intensity/v1`,逐像素保留 JPEG 解码后的灰度,`entity_id=hand_right`。该 schema 不限定双手合并:单手或合并范围由 `entity_id` 与 `coverage` 明确声明。评估集整数区域图仍用 `segment/uint16_labels/v1`,两者不能仅凭文件名使用同一种解码语义。
|
| 426 |
+
|
| 427 |
+
#### 5.5.4 coverage 与有效性
|
| 428 |
+
|
| 429 |
+
`coverage.kind=full/selected_entities/partial/unknown`。full 指声明���标注范围完整;selected_entities 还应列出目标范围。无论哪种,0 本身不自动成为背景;背景要有明确类别映射,未标注区域不能用于构造负样本。保留源逐类/逐实例 exhaustive 信息,未知不可改写为完整。
|
| 430 |
+
|
| 431 |
+
三种表示的帧级有效性均为 `[T]`,表示该帧是否提供此分割标注;对应 valid_ref 在组件中登记,仍用小型 bool `.pt` 数组。栅格 mask 必须登记 storage,格式见 3.1.2,所有帧的整数编码或强度逐值完全相同。编码语义由 schema_id 决定,读取器不能仅依据 mask.mkv 文件名选择解码方式。
|
| 432 |
+
|
| 433 |
+
### 5.6 contact:接触、抓取、区域与距离
|
| 434 |
+
|
| 435 |
+
#### 5.6.1 relations.jsonl 与 relations_valid.pt
|
| 436 |
+
|
| 437 |
+
`annotation/contact/relations.jsonl`,schema contact/relations/v1,每帧一行含 frame_index、relations。每条记录含 relation_type(contact/grasp)、subject_id(手槽或登记实体)、object_id、status、source_locator、provenance。status 固定为 positive/negative/unknown/target_unannotated:positive 必须有可解析目标,negative 表示源明确否定该关系,unknown 为不确定,target_unannotated 为确有接触但目标未标注。非 positive 的 object_id 可 null,不能用 null 冒充“不接触”。稀疏源无记录的帧不自动补 negative。
|
| 438 |
+
|
| 439 |
+
VISOR 的对象 mask ID 必须先按同帧 source_instance_id 解析成 object_id;hand-not-in-contact、none-of-the-above、inconclusive 分别映射 negative、target_unannotated、unknown,保留原始字符串。Dex ycb_grasp_ind 通过 ycb_ids 映射到登记物体,以 relation_type=grasp 保存;不得当作逐顶点接触。
|
| 440 |
+
|
| 441 |
+
relations 组件的 valid_ref 指向 `relations_valid.pt [T] bool`,表示该帧是否有可用源关系标注。有效帧中可以存在 status=unknown 的明确不确定标注;无源标注的帧为 valid=false、relations=[]。组件仍声明 available/provenance/source_locator。
|
| 442 |
+
|
| 443 |
+
#### 5.6.2 实体对的顶点区域与距离
|
| 444 |
+
|
| 445 |
+
已发布的接触区域/距离按参与关系的 subject_id 与 object_id 组织,每对实体保留选定的一套结果,以精确 geometry_ref/topology_id 关联到手或物体/部件;不要求每套数据都有。顶点区域 schema contact/vertex_region/v1:bool `[T,V]` 加同形 valid;顶点距离 schema contact/vertex_distance/v1:float32 `[T,V]`、米、同形 valid,声明 source/target geometry_ref、distance_definition(signed/unsigned、测量到点集或表面等明确源定义)。geometry_ref 必须指向已登记 mesh 或由固定 MANO 模型配置确定的拓扑;拓扑/顶点数变化时按拓扑拆分片段。其他源区域表示只有在实际接入并登记 schema 后才可转换,不能随意栅格化宣称等价。
|
| 446 |
+
|
| 447 |
+
顶点区域/距离已有存储定义,但尚未完成真实输入试点;接入时必须提供源语义与几何验收证据,不因已经登记 schema 就视为通过。
|
| 448 |
+
|
| 449 |
+
## 附录:任务范围
|
| 450 |
+
|
| 451 |
+
不强制收录 2D bbox、完整高频动捕、动作程序、身体 SMPL-X、点云或网络特征。范围内的接触、visibility、选定手关键点、物体几何不能因不便处理而静默丢弃。分割采用的物理编码由第 5.5 节决定,存在重叠时不能以单层标签图声称无损。
|
| 452 |
+
|
| 453 |
+
不设置 entities_ref/segment/entities.json,不要求与 object_id 重复的 track_id。MediaPipe 不在当前关键点定义中;旧版本迁移必须保留可追溯关系,不能直接删表。手部共享表示不含独立 hand_mesh。
|
| 454 |
+
|
| 455 |
+
schema.json 是普通注册表,不是 JSON Schema 文档或可执行验收器;定义存在不代表真实数据已验证。验收须保留实测范围与未决项。
|
| 456 |
+
|
| 457 |
+
本存储约定只更新标准,不代表既有 FFV1/depth.pt 试点已迁移。新发布必须显式写 storage 配置;旧产物按其旧定义读取,不能只改文件后缀或版本标识伪装为合规。
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/docs/h2o-RAW_TO_SHARED.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# H2O raw → shared-v1.0
|
| 2 |
+
|
| 3 |
+
## 范围与来源
|
| 4 |
+
|
| 5 |
+
本版本仅转换 `raw/data/subject{1,2,3,4}_v1_1.tar.gz` 的真实五视角 (`cam0`–`cam4`) 序列;`h2o_CASA.tar` 是单独的扩展,不与标准序列混合。每个原始序列存于 `data/subjectN_<scene>_<sequence>/cam{0..4}/`。源压缩包保持不变,不合成源不存在的标注。输出仅在本地制作;完整序列试点及人工检查通过、更新全量预估之前,不启动全量。
|
| 6 |
+
|
| 7 |
+
| 源包/字段 | shared 文件/处理 |
|
| 8 |
+
| --- | --- |
|
| 9 |
+
| `subjectN_v1_1.tar.gz`: `camX/rgb/<frame>.png` | `observation/rgb.mkv`:逐帧源 RGB 解码为 RGB24,FFV1 直接编码;输出**每帧**解码与源 RGB 字节摘要完全一致。`rgb_valid.pt` 记录存在性,源帧号和每组件的包成员及 SHA256 写入 `camera/frames.jsonl`。不再额外编码未采用的 H.264 RGB 候选;FFV1 编码器进程失败时才尝试 H.264。 |
|
| 10 |
+
| 同包 `camX/depth/<frame>.png` | `observation/depth.mkv` 和 `depth_valid.mkv`;按源毫米单位除以 1000 转米,保留无效深度与全帧时间轴,深度位串以 FFV1 保真封装并逐帧校验。既不做 3 米裁剪也不造出缺失的深度。 |
|
| 11 |
+
| `camX/cam_intrinsics.txt`、`camX/cam_pose/<frame>.txt` | `camera/intrinsic.pt`、`extrinsic.pt`:保留源内参;逐帧源 `T_world_from_camera` 求逆后存 `T_camera_from_world`;声明变换约定与有效性。 |
|
| 12 |
+
| `camX/hand_pose_mano/<frame>.txt` | `annotation/mano/motion.pt`、`motion_valid.pt`:源左/右手标志各自判断有效性;姿态与平移保持源数值,声明 MANO 模型配置,缺模型则明确标依赖缺失,不伪造网格或掩码。 |
|
| 13 |
+
| `camX/hand_pose/<frame>.txt` | `annotation/keypoints/xyz.pt`、`xyz_valid.pt`:源双手 21 点,相机坐标系米制,与 MANO 有效性彼此独立。HTML 中的投影仅用于人工预览,不写回训练数据。 |
|
| 14 |
+
| `camX/obj_pose/<frame>.txt`、`obj_pose_rt/<frame>.txt` | `annotation/object/<name>/keypoints/xyz.pt`、`pose.pt`:按源类号关联 21 个物体点及物体→相机位姿;仅源存在时登记组件及有效性。 |
|
| 15 |
+
| `object.zip` | `annotation/object/<name>/assets/` 与源 OBJ、MTL、纹理;静态形状预览不等于所有帧网格位姿的投影证明。 |
|
| 16 |
+
| `label_split.zip` 的 `action_{train,val,test}.txt` | 序列元数据的官方划分及来源;未知映射明确记 `unknown`,不自行编排。 |
|
| 17 |
+
|
| 18 |
+
`cam4` 是 ego,`cam0`–`cam3` 是 exo。真实时间/FPS 缺乏可靠来源时使用 null,不把 MKV 封装帧率冒充采集时钟。源 `action_label`、`verb_label`、pose 任务帧列表和 `manolabel_v1.1.tar.gz` 保留在 raw;当前契约没有相应动作组件,本发布不宣称它们已转换。源没有像素分割,本版本不投影网格生成替代分割。
|
| 19 |
+
|
| 20 |
+
## 源资产文件名修复
|
| 21 |
+
|
| 22 |
+
源 `object/cocoa/cocoa.obj` 引用 `ovomaltine.mtl`,材质内写的是 `map_Kd cocoa.png`,但原 ZIP 只提供 `ovomaltine.png`。仅在临时解压目录为该已确认的纹理增加**字节相同**的 `cocoa.png` 别名,保留原 PNG、OBJ、MTL 不变;在网格 `source_locator.texture_aliases` 中记录别名、原始包成员和 SHA256。别名与已保留的旧 cocoa 资产一致,不替换图像、标注或网格。全部八类物体的材质依赖在读取大 subject 包之前预检,其他缺失/越界依赖仍报错。
|
| 23 |
+
|
| 24 |
+
## 加速与验收
|
| 25 |
+
|
| 26 |
+
四个互不依赖的 subject 压缩包可由 `--workers 1..4` 并行顺序读取,各 worker 一次只处理一个序列。数值库保持单线程;FFV1 编码支持 `--codec-threads 1|2|4|8|10`,当前全量按用户要求使用 10,逐帧解码校验仍保留。并发数由相同输入实测吞吐量决定,记录 OS 线程峰值和磁盘占用,不以 CPU 线程数本身作为提速证据。RGB 源为 PNG,不适用 ARCTIC/HOT3D 的 JPEG 包直封和 16 帧抽查:RGB、深度、有效性与数值模态仍逐帧精确校验。临时文件在 `/data` 上隔离放置,历史 62 条目录不复用、不覆盖;调整并发时,在新的运行目录复用本次全量已经原子发布的完整序列,并从源重新核对帧号及逐组件 SHA256。未完成的临时序列不复用,原运行的脚本、配置及 QC 保留用于溯源。
|
| 27 |
+
|
| 28 |
+
先运行不截帧的代表性完整序列试点,保存自动 QC、真实耗时和 `doc/validation/index.html`(RGB、深度、源 3D 关键点投影、原生物体网格和全组件数值/有效性)。试点由人工核查之后再决定全量;全量后再次抽样人工核查。报告须区分数据完整性、源未提供的模态与仅供人工判断的几何对齐。
|
| 29 |
+
|
| 30 |
+
2026-09-29 完整序列试点已获人工确认,用户已授权本地全量。2026-09-30 用户取消 CPU 使用量上限,指定 4 个独立压缩包 worker、每个 FFV1 编码器 10 线程;Python worker、读取及校验子进程不计入这最多 40 个编码线程,因此总线程数不固定为 40。该配置不代表已证明加速倍数。源包和旧产物保留;代码变化使用独立运行目录,已完��序列保留原始构建记录及生产脚本快照。
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/docs/schema.json
ADDED
|
@@ -0,0 +1,869 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": "hand-warehouse/1.0",
|
| 3 |
+
"validity_revision": "usable-annotation-2026-09-20",
|
| 4 |
+
"annotation_validity": {
|
| 5 |
+
"meaning": "annotation usable for supervision, not merely record presence",
|
| 6 |
+
"formula": "source_annotation_present AND numerical_checks_pass AND applicable_official_QA_pass AND NOT explicitly_reviewed_local_exclusion",
|
| 7 |
+
"without_official_qa": "omit QA term; declare source rules; do not fabricate QA",
|
| 8 |
+
"policy_field": "components.<name>.valid_policy",
|
| 9 |
+
"visibility_is_independent": true,
|
| 10 |
+
"invalid_float_value": "NaN",
|
| 11 |
+
"hot3d": "broadcast per-camera frame manual QA conservatively to hand/object labels and pose-derived visibility; retain RGB and source calibration; keep native QA in raw and review report",
|
| 12 |
+
"hot3d_visibility": "native visibility_ratio[%] already ranges from 0 to 1; do not divide by 100"
|
| 13 |
+
},
|
| 14 |
+
"hand_slots": [
|
| 15 |
+
"left",
|
| 16 |
+
"right"
|
| 17 |
+
],
|
| 18 |
+
"keypoints": {
|
| 19 |
+
"mano21/v1": {
|
| 20 |
+
"count": 21,
|
| 21 |
+
"names": [
|
| 22 |
+
"wrist",
|
| 23 |
+
"thumb_1",
|
| 24 |
+
"thumb_2",
|
| 25 |
+
"thumb_3",
|
| 26 |
+
"thumb_4",
|
| 27 |
+
"index_1",
|
| 28 |
+
"index_2",
|
| 29 |
+
"index_3",
|
| 30 |
+
"index_4",
|
| 31 |
+
"middle_1",
|
| 32 |
+
"middle_2",
|
| 33 |
+
"middle_3",
|
| 34 |
+
"middle_4",
|
| 35 |
+
"ring_1",
|
| 36 |
+
"ring_2",
|
| 37 |
+
"ring_3",
|
| 38 |
+
"ring_4",
|
| 39 |
+
"little_1",
|
| 40 |
+
"little_2",
|
| 41 |
+
"little_3",
|
| 42 |
+
"little_4"
|
| 43 |
+
],
|
| 44 |
+
"source_index_map": null,
|
| 45 |
+
"note": "adapter maps official MANO joint and fingertip convention"
|
| 46 |
+
},
|
| 47 |
+
"rhd21/v1": {
|
| 48 |
+
"count": 21,
|
| 49 |
+
"names": [
|
| 50 |
+
"wrist",
|
| 51 |
+
"thumb_1",
|
| 52 |
+
"thumb_2",
|
| 53 |
+
"thumb_3",
|
| 54 |
+
"thumb_4",
|
| 55 |
+
"index_1",
|
| 56 |
+
"index_2",
|
| 57 |
+
"index_3",
|
| 58 |
+
"index_4",
|
| 59 |
+
"middle_1",
|
| 60 |
+
"middle_2",
|
| 61 |
+
"middle_3",
|
| 62 |
+
"middle_4",
|
| 63 |
+
"ring_1",
|
| 64 |
+
"ring_2",
|
| 65 |
+
"ring_3",
|
| 66 |
+
"ring_4",
|
| 67 |
+
"little_1",
|
| 68 |
+
"little_2",
|
| 69 |
+
"little_3",
|
| 70 |
+
"little_4"
|
| 71 |
+
],
|
| 72 |
+
"source_index_map_per_hand": [
|
| 73 |
+
0,
|
| 74 |
+
4,
|
| 75 |
+
3,
|
| 76 |
+
2,
|
| 77 |
+
1,
|
| 78 |
+
8,
|
| 79 |
+
7,
|
| 80 |
+
6,
|
| 81 |
+
5,
|
| 82 |
+
12,
|
| 83 |
+
11,
|
| 84 |
+
10,
|
| 85 |
+
9,
|
| 86 |
+
16,
|
| 87 |
+
15,
|
| 88 |
+
14,
|
| 89 |
+
13,
|
| 90 |
+
20,
|
| 91 |
+
19,
|
| 92 |
+
18,
|
| 93 |
+
17
|
| 94 |
+
]
|
| 95 |
+
}
|
| 96 |
+
},
|
| 97 |
+
"camera": {
|
| 98 |
+
"opencv_fisheye4": {
|
| 99 |
+
"K": [
|
| 100 |
+
3,
|
| 101 |
+
3
|
| 102 |
+
],
|
| 103 |
+
"distortion": [
|
| 104 |
+
"k1",
|
| 105 |
+
"k2",
|
| 106 |
+
"k3",
|
| 107 |
+
"k4"
|
| 108 |
+
],
|
| 109 |
+
"projection": "theta=atan(r); theta_d=theta*(1+k1*theta^2+k2*theta^4+k3*theta^6+k4*theta^8); source ReInterHand"
|
| 110 |
+
},
|
| 111 |
+
"pinhole": {
|
| 112 |
+
"K": [
|
| 113 |
+
3,
|
| 114 |
+
3
|
| 115 |
+
]
|
| 116 |
+
},
|
| 117 |
+
"fisheye624": {
|
| 118 |
+
"parameters": [
|
| 119 |
+
"f",
|
| 120 |
+
"cx",
|
| 121 |
+
"cy",
|
| 122 |
+
"k0",
|
| 123 |
+
"k1",
|
| 124 |
+
"k2",
|
| 125 |
+
"k3",
|
| 126 |
+
"k4",
|
| 127 |
+
"k5",
|
| 128 |
+
"p0",
|
| 129 |
+
"p1",
|
| 130 |
+
"s0",
|
| 131 |
+
"s1",
|
| 132 |
+
"s2",
|
| 133 |
+
"s3"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
"rational8": {
|
| 137 |
+
"K": [
|
| 138 |
+
3,
|
| 139 |
+
3
|
| 140 |
+
],
|
| 141 |
+
"distortion": [
|
| 142 |
+
"k1",
|
| 143 |
+
"k2",
|
| 144 |
+
"p1",
|
| 145 |
+
"p2",
|
| 146 |
+
"k3",
|
| 147 |
+
"k4",
|
| 148 |
+
"k5",
|
| 149 |
+
"k6"
|
| 150 |
+
]
|
| 151 |
+
}
|
| 152 |
+
},
|
| 153 |
+
"segmentation": {
|
| 154 |
+
"segment/uint16_labels/v1": {
|
| 155 |
+
"storage": "mask.mkv",
|
| 156 |
+
"dtype": "uint16",
|
| 157 |
+
"mapping": "instances.jsonl",
|
| 158 |
+
"valid_shape": [
|
| 159 |
+
"T"
|
| 160 |
+
],
|
| 161 |
+
"required_metadata": [
|
| 162 |
+
"segmentation_type",
|
| 163 |
+
"coverage",
|
| 164 |
+
"mapping_ref",
|
| 165 |
+
"storage"
|
| 166 |
+
],
|
| 167 |
+
"shape": [
|
| 168 |
+
"T",
|
| 169 |
+
"H",
|
| 170 |
+
"W"
|
| 171 |
+
],
|
| 172 |
+
"reserved_codes": {
|
| 173 |
+
"0": "unassigned",
|
| 174 |
+
"65535": "ignore"
|
| 175 |
+
},
|
| 176 |
+
"region_codes": [
|
| 177 |
+
1,
|
| 178 |
+
65534
|
| 179 |
+
],
|
| 180 |
+
"allowed_storage_profiles": [
|
| 181 |
+
"mkv/uint16_ffv1/v1"
|
| 182 |
+
]
|
| 183 |
+
},
|
| 184 |
+
"segment/instance_polygons/v1": {
|
| 185 |
+
"storage": "polygons.jsonl",
|
| 186 |
+
"mapping": "instances.jsonl",
|
| 187 |
+
"frame_keys": [
|
| 188 |
+
"frame_index",
|
| 189 |
+
"instances"
|
| 190 |
+
],
|
| 191 |
+
"instance_keys": [
|
| 192 |
+
"mask_value",
|
| 193 |
+
"polygons"
|
| 194 |
+
],
|
| 195 |
+
"coordinate_unit": "pixel",
|
| 196 |
+
"overlap_allowed": true,
|
| 197 |
+
"valid_shape": [
|
| 198 |
+
"T"
|
| 199 |
+
],
|
| 200 |
+
"required_metadata": [
|
| 201 |
+
"segmentation_type",
|
| 202 |
+
"coverage",
|
| 203 |
+
"mapping_ref"
|
| 204 |
+
],
|
| 205 |
+
"polygon_shape": [
|
| 206 |
+
"N",
|
| 207 |
+
2
|
| 208 |
+
],
|
| 209 |
+
"holes_supported": false
|
| 210 |
+
},
|
| 211 |
+
"segment/foreground_intensity/v1": {
|
| 212 |
+
"storage": "mask.mkv",
|
| 213 |
+
"dtype": "uint16",
|
| 214 |
+
"value_range": [
|
| 215 |
+
0,
|
| 216 |
+
255
|
| 217 |
+
],
|
| 218 |
+
"normalization_scale": 0.00392156862745098,
|
| 219 |
+
"axes": [
|
| 220 |
+
"T",
|
| 221 |
+
"height",
|
| 222 |
+
"width"
|
| 223 |
+
],
|
| 224 |
+
"meaning": "native hand foreground intensity; individual hand or union declared in metadata; not instance codes or calibrated probability",
|
| 225 |
+
"zero": "background",
|
| 226 |
+
"full_scale": "foreground",
|
| 227 |
+
"mapping": "foreground_category in component metadata",
|
| 228 |
+
"valid_shape": [
|
| 229 |
+
"T"
|
| 230 |
+
],
|
| 231 |
+
"required_metadata": [
|
| 232 |
+
"segmentation_type",
|
| 233 |
+
"coverage",
|
| 234 |
+
"value_range",
|
| 235 |
+
"normalization_scale",
|
| 236 |
+
"foreground_category",
|
| 237 |
+
"entity_id",
|
| 238 |
+
"storage"
|
| 239 |
+
],
|
| 240 |
+
"shape": [
|
| 241 |
+
"T",
|
| 242 |
+
"H",
|
| 243 |
+
"W"
|
| 244 |
+
],
|
| 245 |
+
"allowed_storage_profiles": [
|
| 246 |
+
"mkv/uint16_ffv1/v1"
|
| 247 |
+
]
|
| 248 |
+
}
|
| 249 |
+
},
|
| 250 |
+
"note": "Registry for hand-warehouse/1.0. Read CONTRACT.md for field semantics. This is not a JSON Schema document or executable validator.",
|
| 251 |
+
"components": {
|
| 252 |
+
"mano/axis_angle61/v1": {
|
| 253 |
+
"storage": "pt",
|
| 254 |
+
"dtype": "float32",
|
| 255 |
+
"shape": [
|
| 256 |
+
"T",
|
| 257 |
+
2,
|
| 258 |
+
61
|
| 259 |
+
],
|
| 260 |
+
"valid_shape": [
|
| 261 |
+
"T",
|
| 262 |
+
2
|
| 263 |
+
],
|
| 264 |
+
"unit": "m",
|
| 265 |
+
"angle_unit": "rad",
|
| 266 |
+
"coordinate_frame": "camera",
|
| 267 |
+
"layout": {
|
| 268 |
+
"pose_axis_angle": [
|
| 269 |
+
0,
|
| 270 |
+
48
|
| 271 |
+
],
|
| 272 |
+
"shape": [
|
| 273 |
+
48,
|
| 274 |
+
58
|
| 275 |
+
],
|
| 276 |
+
"translation": [
|
| 277 |
+
58,
|
| 278 |
+
61
|
| 279 |
+
]
|
| 280 |
+
}
|
| 281 |
+
},
|
| 282 |
+
"keypoints/uv/v1": {
|
| 283 |
+
"storage": "pt",
|
| 284 |
+
"dtype": "float32",
|
| 285 |
+
"shape": [
|
| 286 |
+
"T",
|
| 287 |
+
2,
|
| 288 |
+
21,
|
| 289 |
+
2
|
| 290 |
+
],
|
| 291 |
+
"valid_shape": [
|
| 292 |
+
"T",
|
| 293 |
+
2,
|
| 294 |
+
21
|
| 295 |
+
],
|
| 296 |
+
"unit": "pixel",
|
| 297 |
+
"required_metadata": [
|
| 298 |
+
"keypoint_schema"
|
| 299 |
+
]
|
| 300 |
+
},
|
| 301 |
+
"keypoints/xyz/v1": {
|
| 302 |
+
"storage": "pt",
|
| 303 |
+
"dtype": "float32",
|
| 304 |
+
"shape": [
|
| 305 |
+
"T",
|
| 306 |
+
2,
|
| 307 |
+
21,
|
| 308 |
+
3
|
| 309 |
+
],
|
| 310 |
+
"valid_shape": [
|
| 311 |
+
"T",
|
| 312 |
+
2,
|
| 313 |
+
21
|
| 314 |
+
],
|
| 315 |
+
"unit": "m",
|
| 316 |
+
"required_metadata": [
|
| 317 |
+
"keypoint_schema"
|
| 318 |
+
]
|
| 319 |
+
},
|
| 320 |
+
"depth/z_float32/v1": {
|
| 321 |
+
"storage": "mkv",
|
| 322 |
+
"dtype": "float32",
|
| 323 |
+
"shape": [
|
| 324 |
+
"T",
|
| 325 |
+
"H",
|
| 326 |
+
"W"
|
| 327 |
+
],
|
| 328 |
+
"valid_shape": [
|
| 329 |
+
"T",
|
| 330 |
+
"H",
|
| 331 |
+
"W"
|
| 332 |
+
],
|
| 333 |
+
"unit": "m",
|
| 334 |
+
"depth_type": "z",
|
| 335 |
+
"pixel_grid": "current_rgb",
|
| 336 |
+
"coordinate_frame": "current_rgb_camera",
|
| 337 |
+
"valid_storage": "mkv",
|
| 338 |
+
"allowed_storage_profiles": [
|
| 339 |
+
"mkv/depth_float32_bits/v1"
|
| 340 |
+
],
|
| 341 |
+
"allowed_valid_storage_profiles": [
|
| 342 |
+
"mkv/bool_ffv1/v1"
|
| 343 |
+
],
|
| 344 |
+
"required_metadata": [
|
| 345 |
+
"storage",
|
| 346 |
+
"valid_storage",
|
| 347 |
+
"depth_origin"
|
| 348 |
+
],
|
| 349 |
+
"depth_origin_values": [
|
| 350 |
+
"measured",
|
| 351 |
+
"rendered",
|
| 352 |
+
"unknown"
|
| 353 |
+
]
|
| 354 |
+
},
|
| 355 |
+
"transform/se3/v1": {
|
| 356 |
+
"storage": "pt",
|
| 357 |
+
"dtype": "float32",
|
| 358 |
+
"shape": [
|
| 359 |
+
"T",
|
| 360 |
+
4,
|
| 361 |
+
4
|
| 362 |
+
],
|
| 363 |
+
"valid_shape": [
|
| 364 |
+
"T"
|
| 365 |
+
],
|
| 366 |
+
"unit": "m",
|
| 367 |
+
"required_metadata": [
|
| 368 |
+
"convention"
|
| 369 |
+
]
|
| 370 |
+
},
|
| 371 |
+
"object/rigid/v1": {
|
| 372 |
+
"storage": "pt",
|
| 373 |
+
"dtype": "float32",
|
| 374 |
+
"shape": [
|
| 375 |
+
"T",
|
| 376 |
+
4,
|
| 377 |
+
4
|
| 378 |
+
],
|
| 379 |
+
"valid_shape": [
|
| 380 |
+
"T"
|
| 381 |
+
],
|
| 382 |
+
"unit": "m",
|
| 383 |
+
"required_metadata": [
|
| 384 |
+
"convention"
|
| 385 |
+
]
|
| 386 |
+
},
|
| 387 |
+
"camera/pinhole/v1": {
|
| 388 |
+
"storage": "pt",
|
| 389 |
+
"dtype": "float32",
|
| 390 |
+
"shape": [
|
| 391 |
+
"T",
|
| 392 |
+
3,
|
| 393 |
+
3
|
| 394 |
+
],
|
| 395 |
+
"valid_shape": [
|
| 396 |
+
"T"
|
| 397 |
+
]
|
| 398 |
+
},
|
| 399 |
+
"camera/rational8/v1": {
|
| 400 |
+
"storage": "pt",
|
| 401 |
+
"dtype": "float32",
|
| 402 |
+
"shape": [
|
| 403 |
+
"T",
|
| 404 |
+
3,
|
| 405 |
+
3
|
| 406 |
+
],
|
| 407 |
+
"valid_shape": [
|
| 408 |
+
"T"
|
| 409 |
+
]
|
| 410 |
+
},
|
| 411 |
+
"camera/opencv_fisheye4/v1": {
|
| 412 |
+
"storage": "pt",
|
| 413 |
+
"dtype": "float32",
|
| 414 |
+
"shape": [
|
| 415 |
+
"T",
|
| 416 |
+
3,
|
| 417 |
+
3
|
| 418 |
+
],
|
| 419 |
+
"valid_shape": [
|
| 420 |
+
"T"
|
| 421 |
+
]
|
| 422 |
+
},
|
| 423 |
+
"camera/fisheye624/v1": {
|
| 424 |
+
"storage": "pt",
|
| 425 |
+
"dtype": "float32",
|
| 426 |
+
"shape": [
|
| 427 |
+
"T",
|
| 428 |
+
15
|
| 429 |
+
],
|
| 430 |
+
"valid_shape": [
|
| 431 |
+
"T"
|
| 432 |
+
]
|
| 433 |
+
},
|
| 434 |
+
"camera/distortion8/v1": {
|
| 435 |
+
"storage": "pt",
|
| 436 |
+
"dtype": "float32",
|
| 437 |
+
"shape": [
|
| 438 |
+
"T",
|
| 439 |
+
8
|
| 440 |
+
],
|
| 441 |
+
"valid_shape": [
|
| 442 |
+
"T"
|
| 443 |
+
]
|
| 444 |
+
},
|
| 445 |
+
"camera/fisheye4_distortion/v1": {
|
| 446 |
+
"storage": "pt",
|
| 447 |
+
"dtype": "float32",
|
| 448 |
+
"shape": [
|
| 449 |
+
"T",
|
| 450 |
+
4
|
| 451 |
+
],
|
| 452 |
+
"valid_shape": [
|
| 453 |
+
"T"
|
| 454 |
+
]
|
| 455 |
+
},
|
| 456 |
+
"object/joint_state/v1": {
|
| 457 |
+
"storage": "pt",
|
| 458 |
+
"dtype": "float32",
|
| 459 |
+
"shape": [
|
| 460 |
+
"T",
|
| 461 |
+
"J"
|
| 462 |
+
],
|
| 463 |
+
"valid_shape": [
|
| 464 |
+
"T",
|
| 465 |
+
"J"
|
| 466 |
+
],
|
| 467 |
+
"required_metadata": [
|
| 468 |
+
"joint_order"
|
| 469 |
+
],
|
| 470 |
+
"unit_rule": "revolute radians; prismatic metres; mixed types declared per joint"
|
| 471 |
+
},
|
| 472 |
+
"object_keypoints/camera/v1": {
|
| 473 |
+
"storage": "pt",
|
| 474 |
+
"dtype": "float32",
|
| 475 |
+
"shape": [
|
| 476 |
+
"T",
|
| 477 |
+
"K",
|
| 478 |
+
3
|
| 479 |
+
],
|
| 480 |
+
"valid_shape": [
|
| 481 |
+
"T",
|
| 482 |
+
"K"
|
| 483 |
+
],
|
| 484 |
+
"unit": "m",
|
| 485 |
+
"coordinate_frame": "camera",
|
| 486 |
+
"required_metadata": [
|
| 487 |
+
"keypoint_schema"
|
| 488 |
+
]
|
| 489 |
+
},
|
| 490 |
+
"object/dimensions/v1": {
|
| 491 |
+
"storage": "pt",
|
| 492 |
+
"dtype": "float32",
|
| 493 |
+
"shape": [
|
| 494 |
+
"T",
|
| 495 |
+
3
|
| 496 |
+
],
|
| 497 |
+
"valid_shape": [
|
| 498 |
+
"T"
|
| 499 |
+
],
|
| 500 |
+
"unit": "m",
|
| 501 |
+
"required_metadata": [
|
| 502 |
+
"dimensions_semantics"
|
| 503 |
+
],
|
| 504 |
+
"axis_order": [
|
| 505 |
+
"length",
|
| 506 |
+
"width",
|
| 507 |
+
"height"
|
| 508 |
+
],
|
| 509 |
+
"scale_rule": "do not apply to mesh without source-supported size/scale relation"
|
| 510 |
+
},
|
| 511 |
+
"object_keypoints/template/v1": {
|
| 512 |
+
"storage": "pt",
|
| 513 |
+
"dtype": "float32",
|
| 514 |
+
"shape": [
|
| 515 |
+
"K",
|
| 516 |
+
3
|
| 517 |
+
],
|
| 518 |
+
"valid_shape": [
|
| 519 |
+
"K"
|
| 520 |
+
],
|
| 521 |
+
"unit": "m",
|
| 522 |
+
"coordinate_frame": "object",
|
| 523 |
+
"static": true,
|
| 524 |
+
"required_metadata": [
|
| 525 |
+
"keypoint_schema"
|
| 526 |
+
]
|
| 527 |
+
},
|
| 528 |
+
"mesh/obj/v1": {
|
| 529 |
+
"storage": "obj",
|
| 530 |
+
"unit": "m",
|
| 531 |
+
"static": true,
|
| 532 |
+
"valid_shape": [],
|
| 533 |
+
"dependencies": "MTL and textures retained under owning object"
|
| 534 |
+
},
|
| 535 |
+
"rgb/uint8/v1": {
|
| 536 |
+
"storage": "mkv",
|
| 537 |
+
"dtype": "uint8",
|
| 538 |
+
"shape": [
|
| 539 |
+
"T",
|
| 540 |
+
"H",
|
| 541 |
+
"W",
|
| 542 |
+
3
|
| 543 |
+
],
|
| 544 |
+
"valid_shape": [
|
| 545 |
+
"T"
|
| 546 |
+
],
|
| 547 |
+
"color_order": "RGB",
|
| 548 |
+
"allowed_storage_profiles": [
|
| 549 |
+
"mkv/mjpeg_copy/v1",
|
| 550 |
+
"mkv/source_copy/v1",
|
| 551 |
+
"mkv/h264_rgb_lossless/v1",
|
| 552 |
+
"mkv/ffv1_rgb/v1"
|
| 553 |
+
],
|
| 554 |
+
"required_metadata": [
|
| 555 |
+
"storage"
|
| 556 |
+
]
|
| 557 |
+
},
|
| 558 |
+
"contact/relations/v1": {
|
| 559 |
+
"storage": "jsonl",
|
| 560 |
+
"valid_shape": [
|
| 561 |
+
"T"
|
| 562 |
+
],
|
| 563 |
+
"frame_keys": [
|
| 564 |
+
"frame_index",
|
| 565 |
+
"relations"
|
| 566 |
+
],
|
| 567 |
+
"absence_semantics": "no record is not a negative contact annotation"
|
| 568 |
+
},
|
| 569 |
+
"contact/vertex_region/v1": {
|
| 570 |
+
"storage": "pt",
|
| 571 |
+
"dtype": "bool",
|
| 572 |
+
"shape": [
|
| 573 |
+
"T",
|
| 574 |
+
"V"
|
| 575 |
+
],
|
| 576 |
+
"valid_shape": [
|
| 577 |
+
"T",
|
| 578 |
+
"V"
|
| 579 |
+
],
|
| 580 |
+
"required_metadata": [
|
| 581 |
+
"source_geometry_ref",
|
| 582 |
+
"target_geometry_ref",
|
| 583 |
+
"topology_id"
|
| 584 |
+
],
|
| 585 |
+
"pilot_status": "defined_not_empirically_validated"
|
| 586 |
+
},
|
| 587 |
+
"contact/vertex_distance/v1": {
|
| 588 |
+
"storage": "pt",
|
| 589 |
+
"dtype": "float32",
|
| 590 |
+
"shape": [
|
| 591 |
+
"T",
|
| 592 |
+
"V"
|
| 593 |
+
],
|
| 594 |
+
"valid_shape": [
|
| 595 |
+
"T",
|
| 596 |
+
"V"
|
| 597 |
+
],
|
| 598 |
+
"unit": "m",
|
| 599 |
+
"required_metadata": [
|
| 600 |
+
"source_geometry_ref",
|
| 601 |
+
"target_geometry_ref",
|
| 602 |
+
"topology_id",
|
| 603 |
+
"distance_definition"
|
| 604 |
+
],
|
| 605 |
+
"pilot_status": "defined_not_empirically_validated"
|
| 606 |
+
},
|
| 607 |
+
"object/articulated/v1": {
|
| 608 |
+
"storage": "json",
|
| 609 |
+
"required_keys": [
|
| 610 |
+
"parts",
|
| 611 |
+
"joints"
|
| 612 |
+
],
|
| 613 |
+
"part_keys": [
|
| 614 |
+
"part_id",
|
| 615 |
+
"parent_id",
|
| 616 |
+
"has_model",
|
| 617 |
+
"mesh_ref"
|
| 618 |
+
],
|
| 619 |
+
"hierarchy_semantics": "declare mechanical articulation or semantic containment; containment alone does not imply joints",
|
| 620 |
+
"acyclic": true
|
| 621 |
+
},
|
| 622 |
+
"segment/uint16_labels/v1": {
|
| 623 |
+
"storage": "mkv",
|
| 624 |
+
"dtype": "uint16",
|
| 625 |
+
"mapping": "instances.jsonl",
|
| 626 |
+
"valid_shape": [
|
| 627 |
+
"T"
|
| 628 |
+
],
|
| 629 |
+
"required_metadata": [
|
| 630 |
+
"segmentation_type",
|
| 631 |
+
"coverage",
|
| 632 |
+
"mapping_ref",
|
| 633 |
+
"storage"
|
| 634 |
+
],
|
| 635 |
+
"shape": [
|
| 636 |
+
"T",
|
| 637 |
+
"H",
|
| 638 |
+
"W"
|
| 639 |
+
],
|
| 640 |
+
"reserved_codes": {
|
| 641 |
+
"0": "unassigned",
|
| 642 |
+
"65535": "ignore"
|
| 643 |
+
},
|
| 644 |
+
"region_codes": [
|
| 645 |
+
1,
|
| 646 |
+
65534
|
| 647 |
+
],
|
| 648 |
+
"allowed_storage_profiles": [
|
| 649 |
+
"mkv/uint16_ffv1/v1"
|
| 650 |
+
]
|
| 651 |
+
},
|
| 652 |
+
"segment/instance_polygons/v1": {
|
| 653 |
+
"storage": "jsonl",
|
| 654 |
+
"mapping": "instances.jsonl",
|
| 655 |
+
"frame_keys": [
|
| 656 |
+
"frame_index",
|
| 657 |
+
"instances"
|
| 658 |
+
],
|
| 659 |
+
"instance_keys": [
|
| 660 |
+
"mask_value",
|
| 661 |
+
"polygons"
|
| 662 |
+
],
|
| 663 |
+
"coordinate_unit": "pixel",
|
| 664 |
+
"overlap_allowed": true,
|
| 665 |
+
"valid_shape": [
|
| 666 |
+
"T"
|
| 667 |
+
],
|
| 668 |
+
"required_metadata": [
|
| 669 |
+
"segmentation_type",
|
| 670 |
+
"coverage",
|
| 671 |
+
"mapping_ref"
|
| 672 |
+
],
|
| 673 |
+
"polygon_shape": [
|
| 674 |
+
"N",
|
| 675 |
+
2
|
| 676 |
+
],
|
| 677 |
+
"holes_supported": false
|
| 678 |
+
},
|
| 679 |
+
"segment/foreground_intensity/v1": {
|
| 680 |
+
"storage": "mkv",
|
| 681 |
+
"dtype": "uint16",
|
| 682 |
+
"value_range": [
|
| 683 |
+
0,
|
| 684 |
+
255
|
| 685 |
+
],
|
| 686 |
+
"normalization_scale": 0.00392156862745098,
|
| 687 |
+
"axes": [
|
| 688 |
+
"T",
|
| 689 |
+
"height",
|
| 690 |
+
"width"
|
| 691 |
+
],
|
| 692 |
+
"meaning": "native hand foreground intensity; individual hand or union declared in metadata; not instance codes or calibrated probability",
|
| 693 |
+
"zero": "background",
|
| 694 |
+
"full_scale": "foreground",
|
| 695 |
+
"mapping": "foreground_category in component metadata",
|
| 696 |
+
"valid_shape": [
|
| 697 |
+
"T"
|
| 698 |
+
],
|
| 699 |
+
"required_metadata": [
|
| 700 |
+
"segmentation_type",
|
| 701 |
+
"coverage",
|
| 702 |
+
"value_range",
|
| 703 |
+
"normalization_scale",
|
| 704 |
+
"foreground_category",
|
| 705 |
+
"entity_id",
|
| 706 |
+
"storage"
|
| 707 |
+
],
|
| 708 |
+
"shape": [
|
| 709 |
+
"T",
|
| 710 |
+
"H",
|
| 711 |
+
"W"
|
| 712 |
+
],
|
| 713 |
+
"allowed_storage_profiles": [
|
| 714 |
+
"mkv/uint16_ffv1/v1"
|
| 715 |
+
]
|
| 716 |
+
}
|
| 717 |
+
},
|
| 718 |
+
"storage_revision": "lossless-video-2026-09-18",
|
| 719 |
+
"sampling": {
|
| 720 |
+
"image": {
|
| 721 |
+
"single": {
|
| 722 |
+
"T": 1
|
| 723 |
+
},
|
| 724 |
+
"independent": {
|
| 725 |
+
"T": ">=2",
|
| 726 |
+
"required_frame_fields": [
|
| 727 |
+
"sample_id",
|
| 728 |
+
"source_locator"
|
| 729 |
+
],
|
| 730 |
+
"temporal_relationship": false
|
| 731 |
+
},
|
| 732 |
+
"source_fps": null
|
| 733 |
+
},
|
| 734 |
+
"video": {
|
| 735 |
+
"sampling_types": [
|
| 736 |
+
"dense",
|
| 737 |
+
"sparse"
|
| 738 |
+
]
|
| 739 |
+
}
|
| 740 |
+
},
|
| 741 |
+
"storage_profiles": {
|
| 742 |
+
"mkv/mjpeg_copy/v1": {
|
| 743 |
+
"container": "matroska",
|
| 744 |
+
"codec": "mjpeg",
|
| 745 |
+
"method": "stream_copy_from_source_jpeg",
|
| 746 |
+
"logical_dtype": "uint8",
|
| 747 |
+
"decoded_pixel_format": "rgb24",
|
| 748 |
+
"validation": [
|
| 749 |
+
"source_jpeg_packet_sha256_exact",
|
| 750 |
+
"all_packet_count_order_and_dimensions_exact",
|
| 751 |
+
"deterministic_decoded_rgb_sample_exact",
|
| 752 |
+
"pilot_and_final_selected_whole_sequences_decoded_rgb_exact"
|
| 753 |
+
],
|
| 754 |
+
"validation_policy": {
|
| 755 |
+
"id": "jpeg-packets-all-rgb-sample16/v1",
|
| 756 |
+
"sample_count_per_view": 16,
|
| 757 |
+
"short_views": "all_frames_if_T_less_than_16",
|
| 758 |
+
"fixed_indices": "0,T-1,T//4,T//2,3*T//4, deduplicated",
|
| 759 |
+
"remaining_indices": "sample without replacement to min(T,16) using Python random.Random(seed)",
|
| 760 |
+
"seed": "first 8 bytes of SHA256(sequence_id/camera_id/20260920), big-endian integer",
|
| 761 |
+
"report": "policy, exact selected frame indices, seed, separate packet and pixel coverage",
|
| 762 |
+
"legacy_all_frame_pixel_proofs": "still accepted; preserve historical evidence"
|
| 763 |
+
}
|
| 764 |
+
},
|
| 765 |
+
"mkv/source_copy/v1": {
|
| 766 |
+
"container": "matroska",
|
| 767 |
+
"codec": "source_codec_declared_in_metadata",
|
| 768 |
+
"method": "stream_copy_only",
|
| 769 |
+
"logical_dtype": "uint8",
|
| 770 |
+
"decoded_pixel_format": "rgb24",
|
| 771 |
+
"validation": [
|
| 772 |
+
"no_reencoding",
|
| 773 |
+
"all_decoded_rgb_frames_exact",
|
| 774 |
+
"presentation_frame_order_exact"
|
| 775 |
+
]
|
| 776 |
+
},
|
| 777 |
+
"mkv/h264_rgb_lossless/v1": {
|
| 778 |
+
"container": "matroska",
|
| 779 |
+
"codec": "h264",
|
| 780 |
+
"encoder": "libx264rgb",
|
| 781 |
+
"crf": 0,
|
| 782 |
+
"decoded_pixel_format": "rgb24",
|
| 783 |
+
"logical_dtype": "uint8",
|
| 784 |
+
"gop": "declared_in_encoder_parameters",
|
| 785 |
+
"validation": [
|
| 786 |
+
"all_decoded_rgb_frames_exact"
|
| 787 |
+
],
|
| 788 |
+
"forbidden": [
|
| 789 |
+
"lossy_rate_control",
|
| 790 |
+
"rgb_to_yuv420_subsampling"
|
| 791 |
+
]
|
| 792 |
+
},
|
| 793 |
+
"mkv/ffv1_rgb/v1": {
|
| 794 |
+
"container": "matroska",
|
| 795 |
+
"codec": "ffv1",
|
| 796 |
+
"decoded_pixel_format": "rgb24",
|
| 797 |
+
"logical_dtype": "uint8",
|
| 798 |
+
"validation": [
|
| 799 |
+
"all_decoded_rgb_frames_exact"
|
| 800 |
+
]
|
| 801 |
+
},
|
| 802 |
+
"mkv/depth_float32_bits/v1": {
|
| 803 |
+
"container": "matroska",
|
| 804 |
+
"codec": "ffv1",
|
| 805 |
+
"pixel_format": "gray16le",
|
| 806 |
+
"logical_dtype": "float32",
|
| 807 |
+
"logical_shape": [
|
| 808 |
+
"T",
|
| 809 |
+
"H",
|
| 810 |
+
"W"
|
| 811 |
+
],
|
| 812 |
+
"encoded_shape": [
|
| 813 |
+
"T",
|
| 814 |
+
"H",
|
| 815 |
+
"2*W"
|
| 816 |
+
],
|
| 817 |
+
"packing": "IEEE754 little-endian float32 bits; low uint16 in first W columns, high uint16 in last W columns",
|
| 818 |
+
"decode": "reinterpret_float32(uint32(low) | (uint32(high) << 16))",
|
| 819 |
+
"validation": [
|
| 820 |
+
"all_float32_bits_exact_including_nan"
|
| 821 |
+
]
|
| 822 |
+
},
|
| 823 |
+
"mkv/bool_ffv1/v1": {
|
| 824 |
+
"container": "matroska",
|
| 825 |
+
"codec": "ffv1",
|
| 826 |
+
"pixel_format": "gray",
|
| 827 |
+
"logical_dtype": "bool",
|
| 828 |
+
"stored_values": [
|
| 829 |
+
0,
|
| 830 |
+
1
|
| 831 |
+
],
|
| 832 |
+
"validation": [
|
| 833 |
+
"all_bool_values_exact"
|
| 834 |
+
]
|
| 835 |
+
},
|
| 836 |
+
"mkv/uint16_ffv1/v1": {
|
| 837 |
+
"container": "matroska",
|
| 838 |
+
"codec": "ffv1",
|
| 839 |
+
"pixel_formats": [
|
| 840 |
+
"gray",
|
| 841 |
+
"gray16le"
|
| 842 |
+
],
|
| 843 |
+
"logical_dtype": "uint16",
|
| 844 |
+
"gray_condition": "all values <=255; decode by exact uint8-to-uint16 promotion",
|
| 845 |
+
"validation": [
|
| 846 |
+
"all_integer_values_exact"
|
| 847 |
+
]
|
| 848 |
+
}
|
| 849 |
+
},
|
| 850 |
+
"video_metadata": {
|
| 851 |
+
"required": [
|
| 852 |
+
"profile",
|
| 853 |
+
"codec",
|
| 854 |
+
"pixel_format",
|
| 855 |
+
"encoded_size",
|
| 856 |
+
"decoder",
|
| 857 |
+
"encoder_parameters",
|
| 858 |
+
"source_lossy"
|
| 859 |
+
],
|
| 860 |
+
"source_lossy_values": [
|
| 861 |
+
true,
|
| 862 |
+
false,
|
| 863 |
+
"unknown"
|
| 864 |
+
],
|
| 865 |
+
"timebase_role": "index_only",
|
| 866 |
+
"lossless_reference": "source compressed packets or fixed-decoder source pixels; depth uses normalized standard float32 bits",
|
| 867 |
+
"selection": "choose smaller complete candidate only after exact roundtrip validation"
|
| 868 |
+
}
|
| 869 |
+
}
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/full.log
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Verified existing subject1/h1/0
|
| 2 |
+
Verified existing subject2/h1/0
|
| 3 |
+
Verified existing subject1/h1/6
|
| 4 |
+
Verified existing subject1/h1/3
|
| 5 |
+
Verified existing subject2/h1/6
|
| 6 |
+
Converted subject3/h1/0
|
| 7 |
+
Verified existing subject1/h1/7
|
| 8 |
+
Converted subject4/h1/0
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/full.status
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
START=2026-09-30T10:22:30+08:00
|
| 2 |
+
WORKERS=4 CODEC_THREADS=10 SUBJECTS=1,2,3,4 CASA=false
|
| 3 |
+
CPU_LIMIT=none
|
| 4 |
+
CGROUP=/user.slice/user-25044.slice/user@25044.service/app.slice/h2o-full-w4c10-r2-20260930.scope
|
| 5 |
+
CPU_MAX=max controller_disabled
|
| 6 |
+
|
| 7 |
+
RECONFIGURE=2026-09-30T11:03:03+08:00 REASON=decoder10_depth4_no_resume_png_writes
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/run-full.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -u
|
| 3 |
+
base="$HOME/Datasets/uni-hoi-h2o-full-20260930-w4-c10"
|
| 4 |
+
raw="$HOME/Datasets/Hand-Datasets-Raw/H2O"
|
| 5 |
+
cd "$HOME/Projects/uni-hoi-dataset" || exit 1
|
| 6 |
+
mkdir -p "$base/scratch"
|
| 7 |
+
export TMPDIR="$base/scratch" PYTHONUNBUFFERED=1
|
| 8 |
+
for n in 1 2 3 4; do test -s "$raw/raw/data/subject${n}_v1_1.tar.gz" || exit 2; done
|
| 9 |
+
test ! -e "$base/full.status" || exit 3
|
| 10 |
+
cg=$(awk -F: '$1=="0" {print $3}' /proc/self/cgroup)
|
| 11 |
+
if [[ -f "/sys/fs/cgroup$cg/cpu.max" ]]; then
|
| 12 |
+
read -r quota period < "/sys/fs/cgroup$cg/cpu.max"
|
| 13 |
+
else
|
| 14 |
+
quota=max
|
| 15 |
+
period=controller_disabled
|
| 16 |
+
fi
|
| 17 |
+
printf 'START=%s\nWORKERS=4 CODEC_THREADS=10 SUBJECTS=1,2,3,4 CASA=false\nCPU_LIMIT=none\nCGROUP=%s\nCPU_MAX=%s %s\n' "$(date -Is)" "$cg" "$quota" "$period" > "$base/full.status"
|
| 18 |
+
if [[ "$quota" != max ]]; then
|
| 19 |
+
printf 'EXIT=4 ERROR=UNEXPECTED_CPU_QUOTA\n' >> "$base/full.status"
|
| 20 |
+
exit 4
|
| 21 |
+
fi
|
| 22 |
+
/usr/bin/time -v .venv/bin/python "$base/frozen-code/scripts/convert_h2o_v1.0.py" --root "$raw" --out "$base" --release-id shared-v1.0 --workers 4 --codec-threads 10 --mano-dir "$HOME/Projects/WiLoR/mano_data" > "$base/full.log" 2>&1
|
| 23 |
+
code=$?
|
| 24 |
+
printf 'EXIT=%s END=%s\n' "$code" "$(date -Is)" >> "$base/full.status"
|
| 25 |
+
if [[ -f "/sys/fs/cgroup$cg/cpu.stat" ]]; then cat "/sys/fs/cgroup$cg/cpu.stat" >> "$base/full.status"; fi
|
| 26 |
+
exit "$code"
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/check_dexycb_projection.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Check saved Dex-YCB source 3D joints against saved source 2D joints in sampled views."""
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import torch
|
| 9 |
+
|
| 10 |
+
root = Path(sys.argv[1])
|
| 11 |
+
report = json.loads((root / 'doc/validation/STRUCTURAL_AUDIT.json').read_text())
|
| 12 |
+
checks = []
|
| 13 |
+
for name in report['sampled_views']:
|
| 14 |
+
view = root / name
|
| 15 |
+
load = lambda path: torch.load(view / path, weights_only=True, map_location='cpu').numpy()
|
| 16 |
+
k = load('camera/intrinsic.pt')
|
| 17 |
+
xyz = load('annotation/keypoints/xyz.pt')
|
| 18 |
+
uv = load('annotation/keypoints/uv.pt')
|
| 19 |
+
valid = load('annotation/keypoints/xyz_valid.pt') & load('annotation/keypoints/uv_valid.pt')
|
| 20 |
+
z = xyz[..., 2]
|
| 21 |
+
valid &= np.isfinite(xyz).all(axis=-1) & np.isfinite(uv).all(axis=-1) & (z > 0)
|
| 22 |
+
z = np.where(valid, z, 1)
|
| 23 |
+
pred = np.stack((k[:, 0, 0, None, None] * xyz[..., 0] / z + k[:, 0, 2, None, None],
|
| 24 |
+
k[:, 1, 1, None, None] * xyz[..., 1] / z + k[:, 1, 2, None, None]), axis=-1)
|
| 25 |
+
errors = np.linalg.norm(pred[valid] - uv[valid], axis=-1)
|
| 26 |
+
checks.append(dict(view=name, points=int(errors.size), median_px=float(np.median(errors)) if errors.size else None,
|
| 27 |
+
p95_px=float(np.percentile(errors, 95)) if errors.size else None))
|
| 28 |
+
(root / 'doc/validation/KEYPOINT_PROJECTION_QC.json').write_text(json.dumps({
|
| 29 |
+
'scope': 'Saved source 3D joints projected with saved color intrinsics vs saved source 2D joints; independent of hand mesh rendering.',
|
| 30 |
+
'views': checks}, ensure_ascii=False, indent=2) + '\n')
|
| 31 |
+
print(json.dumps(checks, ensure_ascii=False), flush=True)
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"root": "/home/xuzhefeng/Datasets/Hand-Datasets-Raw/H2O",
|
| 3 |
+
"out": "/home/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10",
|
| 4 |
+
"release_id": "shared-v1.0",
|
| 5 |
+
"limit": null,
|
| 6 |
+
"max_frames": null,
|
| 7 |
+
"mano_dir": "/home/xuzhefeng/Projects/WiLoR/mano_data",
|
| 8 |
+
"views": null,
|
| 9 |
+
"jpeg_full_check": false,
|
| 10 |
+
"workers": 4,
|
| 11 |
+
"codec_threads": 10,
|
| 12 |
+
"subjects": null,
|
| 13 |
+
"include_casa": false,
|
| 14 |
+
"archive": null
|
| 15 |
+
}
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_dexycb_v1.0.py
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Dex-YCB source annotations → CONTRACT.md v1.0. No derived annotations."""
|
| 3 |
+
import io
|
| 4 |
+
import re
|
| 5 |
+
import shutil
|
| 6 |
+
import tarfile
|
| 7 |
+
import tempfile
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
from PIL import Image
|
| 12 |
+
import yaml
|
| 13 |
+
|
| 14 |
+
from warehouse_v1_0 import (View, build_record, find_file, locator, mano_models, mesh_asset,
|
| 15 |
+
model_profile, parser, pca_to_axis_angle, release, roots, safe_member, sequence_dir)
|
| 16 |
+
|
| 17 |
+
IMG_W, IMG_H = 640, 480
|
| 18 |
+
|
| 19 |
+
class _Loader(yaml.SafeLoader):
|
| 20 |
+
pass
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_Loader.add_constructor("tag:yaml.org,2002:python/tuple",
|
| 24 |
+
lambda l, n: tuple(l.construct_sequence(n)))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def yaml_load_bytes(data: bytes):
|
| 28 |
+
return yaml.load(io.BytesIO(data), Loader=_Loader)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Calibration:
|
| 32 |
+
def __init__(self, dexycb_root: Path):
|
| 33 |
+
self.intrinsics = {} # serial -> {fx,fy,cx,cy,w,h}
|
| 34 |
+
self.extrinsics = {} # group -> {serial: [12] 行优先 3×4 cam→world}
|
| 35 |
+
self.betas = {} # mano_calib_name -> [10]
|
| 36 |
+
calib_dir = dexycb_root / "calibration"
|
| 37 |
+
if calib_dir.is_dir():
|
| 38 |
+
self._load((p.as_posix(), p.read_bytes())
|
| 39 |
+
for p in sorted(calib_dir.rglob("*")) if p.is_file())
|
| 40 |
+
else:
|
| 41 |
+
tar_path = dexycb_root / "calibration.tar.gz"
|
| 42 |
+
if not tar_path.exists():
|
| 43 |
+
raise FileNotFoundError(f"no calibration/ nor calibration.tar.gz in {dexycb_root}")
|
| 44 |
+
with tarfile.open(tar_path, "r:gz") as tf:
|
| 45 |
+
self._load((m.name, tf.extractfile(m).read()) for m in tf if m.isfile())
|
| 46 |
+
|
| 47 |
+
_RE_INTR = re.compile(r"(?:^|/)intrinsics/(\d+)_\d+x\d+\.yml$")
|
| 48 |
+
_RE_EXTRA = re.compile(r"(?:^|/)extrinsics_(\d{8}_\d{6})/extrinsics\.yml$")
|
| 49 |
+
_RE_MANO = re.compile(r"(?:^|/)mano_(\d{8}_\d{6}_subject-\d{2}_right)/mano\.yml$")
|
| 50 |
+
|
| 51 |
+
def _load(self, files):
|
| 52 |
+
for rel, data in files:
|
| 53 |
+
m = self._RE_INTR.search(rel)
|
| 54 |
+
if m:
|
| 55 |
+
c = yaml_load_bytes(data)["color"]
|
| 56 |
+
self.intrinsics[m.group(1)] = {"fx": float(c["fx"]), "fy": float(c["fy"]),
|
| 57 |
+
"cx": float(c["ppx"]), "cy": float(c["ppy"]),
|
| 58 |
+
"w": IMG_W, "h": IMG_H}
|
| 59 |
+
continue
|
| 60 |
+
m = self._RE_EXTRA.search(rel)
|
| 61 |
+
if m:
|
| 62 |
+
raw = yaml_load_bytes(data)["extrinsics"]
|
| 63 |
+
self.extrinsics[m.group(1)] = {
|
| 64 |
+
str(s): [float(x) for x in np.asarray(v).ravel()] for s, v in raw.items()}
|
| 65 |
+
continue
|
| 66 |
+
m = self._RE_MANO.search(rel)
|
| 67 |
+
if m:
|
| 68 |
+
self.betas[m.group(1)] = [float(b) for b in yaml_load_bytes(data)["betas"]]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def calibration_locator(path, member, **extra):
|
| 73 |
+
if path.is_dir():
|
| 74 |
+
return locator(path / member.removeprefix('calibration/'), **extra)
|
| 75 |
+
return locator(path, member, **extra)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def prepare_models(root, destination):
|
| 79 |
+
archive = find_file(root, 'models.tar.gz')
|
| 80 |
+
if archive is None:
|
| 81 |
+
return {}, None
|
| 82 |
+
pattern = re.compile(r'^models/(\d{3}_[a-z0-9_]+)/(textured_simple\.obj(?:\.mtl)?|texture_map\.png)$')
|
| 83 |
+
names = set()
|
| 84 |
+
with tarfile.open(archive, 'r|gz') as tf:
|
| 85 |
+
for member in tf:
|
| 86 |
+
match = pattern.fullmatch(member.name)
|
| 87 |
+
if member.isfile() and match:
|
| 88 |
+
names.add(match[1])
|
| 89 |
+
path = safe_member(destination, '/'.join(match.groups()))
|
| 90 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 91 |
+
path.write_bytes(tf.extractfile(member).read())
|
| 92 |
+
if len(names) != 21:
|
| 93 |
+
raise ValueError('expected all 21 source YCB model directories')
|
| 94 |
+
return {i: destination / name for i, name in enumerate(sorted(names), 1)}, archive
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def convert_view(path, args, seq, serial, frames, meta, meta_loc, calib, calib_path, models, assets, asset_archive):
|
| 98 |
+
total = int(meta.get('num_frames', max(frames) + 1))
|
| 99 |
+
ids = list(range(min(total, args.max_frames) if args.max_frames else total))
|
| 100 |
+
for f in ids:
|
| 101 |
+
frames.setdefault(f, {})
|
| 102 |
+
if not ids:
|
| 103 |
+
raise ValueError('no RGB frames')
|
| 104 |
+
source_rows = []
|
| 105 |
+
for f in ids:
|
| 106 |
+
row = frames[f]
|
| 107 |
+
source_rows.append(dict(source_frame_id=f, sync_id=f'{seq}:{f}',
|
| 108 |
+
source_locator=row['color'][1] if 'color' in row else (meta_loc | {'source_frame_id': f, 'missing_rgb': True}), annotation_matches={
|
| 109 |
+
'labels': {'source_frame_id': f, 'source_timestamp_ns': None, 'clock_domain': None,
|
| 110 |
+
'match_method': 'index_map', 'delta_ns': None, 'source_locator': row['labels'][1]}
|
| 111 |
+
for _ in [0] if 'labels' in row},
|
| 112 |
+
component_sources={k: v[1] for k, v in row.items()}))
|
| 113 |
+
view = View(path, 'dex-ycb', args.release_id, seq, serial, source_rows,
|
| 114 |
+
sampling='dense' if ids == list(range(ids[0], ids[-1] + 1)) else 'sparse')
|
| 115 |
+
view.valid_rules = {
|
| 116 |
+
'mano': 'Source pose_m present and not all zero; side model/calibration available',
|
| 117 |
+
'keypoints': 'Corresponding joint_2d/joint_3d present; whole-hand all -1 is missing, broadcast to its 21 points',
|
| 118 |
+
'pose': 'Source pose_y for this ycb_ids slot present and not an all-zero matrix',
|
| 119 |
+
'segment': 'Source seg array provided for this frame; region codes and entity references validated',
|
| 120 |
+
'relations': 'Source sequence ycb_grasp_ind resolves through ycb_ids; broadcast sequence grasp to selected frames',
|
| 121 |
+
}
|
| 122 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 123 |
+
view.meta['view_type'] = 'exo'
|
| 124 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'views': args.views}
|
| 125 |
+
subject = re.search(r'subject-(\d+)', seq)
|
| 126 |
+
if subject and 1 <= int(subject[1]) <= 10:
|
| 127 |
+
index = int(subject[1])
|
| 128 |
+
view.meta.update(split='val' if index == 7 else 'test' if index in (8, 9) else 'train',
|
| 129 |
+
split_scheme='Dex-YCB/s1', split_source_locator={
|
| 130 |
+
'url': 'https://github.com/NVlabs/dex-ycb-toolkit/blob/master/dex_ycb_toolkit/dex_ycb.py',
|
| 131 |
+
'rule': 's1 unseen-subject: 01-06/10 train, 07 val, 08-09 test'})
|
| 132 |
+
view.meta.pop('split_reason', None)
|
| 133 |
+
view.rgb([frames[f]['color'][0] if 'color' in frames[f] else None for f in ids], {'frames_ref': 'camera/frames.jsonl'})
|
| 134 |
+
n = len(ids)
|
| 135 |
+
intr = calib.intrinsics.get(serial)
|
| 136 |
+
K = None if intr is None else np.array([[intr['fx'], 0, intr['cx']], [0, intr['fy'], intr['cy']], [0, 0, 1]])
|
| 137 |
+
ext = calib.extrinsics.get(str(meta['extrinsics']), {}).get(serial)
|
| 138 |
+
E = None
|
| 139 |
+
if ext is not None:
|
| 140 |
+
E = np.eye(4)
|
| 141 |
+
E[:3] = np.asarray(ext).reshape(3, 4)
|
| 142 |
+
E = np.linalg.inv(E)
|
| 143 |
+
view.camera(K, calibration_locator(calib_path, f'calibration/intrinsics/{serial}_640x480.yml'), E,
|
| 144 |
+
calibration_locator(calib_path, f'calibration/extrinsics_{meta["extrinsics"]}/extrinsics.yml',
|
| 145 |
+
conversion='inverse of source T_world_from_camera'))
|
| 146 |
+
sides = meta.get('mano_sides')
|
| 147 |
+
if sides not in (['left'], ['right']):
|
| 148 |
+
raise ValueError(f'expected exactly one anatomical source hand: {sides}')
|
| 149 |
+
side = sides[0]
|
| 150 |
+
slot = ['left', 'right'].index(side)
|
| 151 |
+
cal_name = meta['mano_calib'][0] if isinstance(meta['mano_calib'], list) else meta['mano_calib']
|
| 152 |
+
labels = [dict(np.load(frames[f]['labels'][0])) if 'labels' in frames[f] else {} for f in ids]
|
| 153 |
+
label_loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources.labels'}
|
| 154 |
+
motion = np.full((n, 2, 61), np.nan, np.float32)
|
| 155 |
+
mv = np.zeros((n, 2), bool)
|
| 156 |
+
if side in models and any('pose_m' in lab for lab in labels):
|
| 157 |
+
for i, lab in enumerate(labels):
|
| 158 |
+
if 'pose_m' not in lab:
|
| 159 |
+
continue
|
| 160 |
+
pose = np.asarray(lab['pose_m']).reshape(51)
|
| 161 |
+
if not np.any(pose): # Official Dex-YCB missing-pose sentinel, independent of joints/seg.
|
| 162 |
+
continue
|
| 163 |
+
motion[i, slot] = np.r_[pose[:3], pca_to_axis_angle(pose[3:48], models[side]),
|
| 164 |
+
calib.betas[cal_name], pose[48:51]]
|
| 165 |
+
mv[i, slot] = True
|
| 166 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 167 |
+
['T', 'hand', 'parameter'], label_loc, model_profile=model_profile(models),
|
| 168 |
+
calibration_source=calibration_locator(calib_path, f'calibration/mano_{cal_name}/mano.yml'),
|
| 169 |
+
provenance={'kind': 'format_conversion', 'method': 'source PCA @ hands_components + hands_mean; explicit axis-angle consumed with flat_hand_mean=true'})
|
| 170 |
+
elif any('pose_m' in lab for lab in labels):
|
| 171 |
+
view.absent('mano', 'Source PCA exists; provide --mano-dir to expand it', 'dependency_missing')
|
| 172 |
+
else:
|
| 173 |
+
view.absent('mano', 'No source pose_m field')
|
| 174 |
+
for source_key, key, dim, unit in [('joint_2d', 'uv', 2, 'pixel'), ('joint_3d', 'xyz', 3, 'm')]:
|
| 175 |
+
if not any(source_key in x for x in labels):
|
| 176 |
+
view.absent('keypoints_' + key, 'No source ' + source_key)
|
| 177 |
+
continue
|
| 178 |
+
points = np.full((n, 2, 21, dim), np.nan, np.float32)
|
| 179 |
+
valid = np.zeros((n, 2, 21), bool)
|
| 180 |
+
for i, lab in enumerate(labels):
|
| 181 |
+
if source_key not in lab:
|
| 182 |
+
continue
|
| 183 |
+
p = np.asarray(lab[source_key]).reshape(21, dim)
|
| 184 |
+
points[i, slot] = p
|
| 185 |
+
valid[i, slot] = not np.all(p == -1) # Official sentinel covers the whole source hand.
|
| 186 |
+
# An individual off-image point (-1, -1) is not evidence of missing annotation.
|
| 187 |
+
view.tensor('keypoints_' + key, f'keypoints/{key}/v1', f'annotation/keypoints/{key}.pt',
|
| 188 |
+
points, valid, ['T', 'hand', 'keypoint', 'coordinate'], label_loc,
|
| 189 |
+
keypoint_schema='mano21/v1', unit=unit)
|
| 190 |
+
ycb_ids = [int(x) for x in meta['ycb_ids']]
|
| 191 |
+
for j, oid in enumerate(ycb_ids):
|
| 192 |
+
entity = f'ycb_{oid:02d}'
|
| 193 |
+
view.object(entity, meta_loc, source_object_id=oid, category_id=oid)
|
| 194 |
+
poses = np.full((n, 4, 4), np.nan, np.float32)
|
| 195 |
+
valid = np.zeros(n, bool)
|
| 196 |
+
for i, lab in enumerate(labels):
|
| 197 |
+
if 'pose_y' in lab:
|
| 198 |
+
pose = np.asarray(lab['pose_y'])
|
| 199 |
+
if pose.shape != (len(ycb_ids), 3, 4):
|
| 200 |
+
raise ValueError('pose_y shape differs from ycb_ids')
|
| 201 |
+
if np.any(pose[j]): # Official all-zero missing object pose sentinel.
|
| 202 |
+
poses[i] = np.eye(4)
|
| 203 |
+
poses[i, :3] = pose[j]
|
| 204 |
+
valid[i] = True
|
| 205 |
+
if any('pose_y' in lab for lab in labels):
|
| 206 |
+
view.tensor('pose_' + entity, 'object/rigid/v1', f'annotation/object/{entity}/pose.pt',
|
| 207 |
+
poses, valid, ['T', 'row', 'column'], label_loc,
|
| 208 |
+
convention='T_camera_from_object', unit='m')
|
| 209 |
+
else:
|
| 210 |
+
view.absent('pose_' + entity, 'No source pose_y field')
|
| 211 |
+
if oid in assets:
|
| 212 |
+
mesh_asset(view, entity, assets[oid], assets[oid] / 'textured_simple.obj',
|
| 213 |
+
locator(asset_archive, f'models/{assets[oid].name}/textured_simple.obj'))
|
| 214 |
+
else:
|
| 215 |
+
view.absent('mesh_' + entity, 'models.tar.gz unavailable', 'not_downloaded')
|
| 216 |
+
if any('seg' in lab for lab in labels):
|
| 217 |
+
mask_rows = []
|
| 218 |
+
width, height = view.meta['camera']['image_size']
|
| 219 |
+
for i, lab in enumerate(labels):
|
| 220 |
+
values = np.unique(lab.get('seg', np.zeros((height, width), np.uint8)))
|
| 221 |
+
mappings = []
|
| 222 |
+
for value in values:
|
| 223 |
+
value = int(value)
|
| 224 |
+
if value == 0:
|
| 225 |
+
continue
|
| 226 |
+
if value != 255 and value not in ycb_ids:
|
| 227 |
+
raise ValueError(f'unknown Dex-YCB region value {value}')
|
| 228 |
+
mappings.append(dict(mask_value=value, category_id='hand' if value == 255 else value,
|
| 229 |
+
entity_id='hand_' + side if value == 255 else f'ycb_{value:02d}', part_id=None,
|
| 230 |
+
source_instance_id=value))
|
| 231 |
+
mask_rows.append(dict(frame_index=i, labels=mappings))
|
| 232 |
+
view.raster('segment', (lab.get('seg', np.zeros((height, width), np.uint16)) for lab in labels),
|
| 233 |
+
['seg' in lab for lab in labels], label_loc, mask_rows)
|
| 234 |
+
view.meta['components']['segment'].update(coverage={'kind': 'selected_entities',
|
| 235 |
+
'entities': ['hand_' + side] + [f'ycb_{o:02d}' for o in ycb_ids]}, source_zero_meaning='background')
|
| 236 |
+
else:
|
| 237 |
+
view.absent('segment', 'No source seg field')
|
| 238 |
+
if any('aligned_depth_to_color' in frames[f] for f in ids):
|
| 239 |
+
def depths():
|
| 240 |
+
width, height = view.meta['camera']['image_size']
|
| 241 |
+
for f in ids:
|
| 242 |
+
item = frames[f].get('aligned_depth_to_color')
|
| 243 |
+
if item is None:
|
| 244 |
+
yield np.full((height, width), np.nan, np.float32)
|
| 245 |
+
else:
|
| 246 |
+
with Image.open(item[0]) as im:
|
| 247 |
+
yield np.asarray(im).astype(np.float32) / 1000.0
|
| 248 |
+
view.raster('depth', depths(), None, {'frames_ref': 'camera/frames.jsonl',
|
| 249 |
+
'source_field': 'component_sources.aligned_depth_to_color', 'conversion': 'millimetres to metres'})
|
| 250 |
+
else:
|
| 251 |
+
view.absent('depth', 'No source aligned_depth_to_color frames')
|
| 252 |
+
grasp = meta.get('ycb_grasp_ind')
|
| 253 |
+
if grasp is not None:
|
| 254 |
+
if not 0 <= int(grasp) < len(ycb_ids):
|
| 255 |
+
raise ValueError('invalid ycb_grasp_ind')
|
| 256 |
+
relation = dict(relation_type='grasp', subject_id='hand_' + side,
|
| 257 |
+
object_id=f'ycb_{ycb_ids[int(grasp)]:02d}', status='positive', source_locator=meta_loc,
|
| 258 |
+
provenance={'kind': 'source', 'method': 'sequence ycb_grasp_ind resolved through ycb_ids; not per-frame contact'})
|
| 259 |
+
view.relations([{'frame_index': i, 'relations': [relation]} for i in range(n)], np.ones(n, bool), meta_loc)
|
| 260 |
+
else:
|
| 261 |
+
view.absent('relations', 'No source grasp/contact relation')
|
| 262 |
+
return view.finish()
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
MEMBER = re.compile(r'^([^/]+)/(\d{8}_\d{6})/(meta\.yml|(\d{12})/(color|labels|aligned_depth_to_color)_(\d+)\.(jpg|npz|png))$')
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def convert_archive(archive, args, out, calib, calib_path, models, assets, asset_archive):
|
| 269 |
+
selected_views = set(args.views.split(',')) if args.views else None
|
| 270 |
+
done = 0
|
| 271 |
+
current, meta, meta_loc, rows = None, None, None, {}
|
| 272 |
+
with tempfile.TemporaryDirectory(prefix='dex-source-') as wd:
|
| 273 |
+
work = Path(wd)
|
| 274 |
+
def flush():
|
| 275 |
+
nonlocal done
|
| 276 |
+
if not rows:
|
| 277 |
+
return
|
| 278 |
+
seq = archive.name.split('.tar')[0] + '_' + current
|
| 279 |
+
reports = {}
|
| 280 |
+
with sequence_dir(out, seq) as target:
|
| 281 |
+
for serial, frames in sorted(rows.items()):
|
| 282 |
+
reports[serial] = convert_view(target / serial, args, seq, serial, frames, meta,
|
| 283 |
+
meta_loc, calib, calib_path, models, assets, asset_archive)
|
| 284 |
+
build_record(out, seq, reports)
|
| 285 |
+
for staged in list(work.iterdir()):
|
| 286 |
+
if staged.is_dir():
|
| 287 |
+
shutil.rmtree(staged)
|
| 288 |
+
else:
|
| 289 |
+
staged.unlink()
|
| 290 |
+
done += 1
|
| 291 |
+
print(f'Converted {seq}', flush=True)
|
| 292 |
+
with tarfile.open(archive, 'r|gz') as tf:
|
| 293 |
+
for member in tf:
|
| 294 |
+
match = MEMBER.fullmatch(member.name)
|
| 295 |
+
if not member.isfile() or not match:
|
| 296 |
+
continue
|
| 297 |
+
seq = match[2]
|
| 298 |
+
if seq != current:
|
| 299 |
+
flush()
|
| 300 |
+
if args.limit and done >= args.limit:
|
| 301 |
+
break
|
| 302 |
+
current, meta, meta_loc, rows = seq, None, None, {}
|
| 303 |
+
data_kind = match[3]
|
| 304 |
+
if data_kind == 'meta.yml':
|
| 305 |
+
data = tf.extractfile(member).read()
|
| 306 |
+
meta = yaml_load_bytes(data)
|
| 307 |
+
meta_loc = locator(archive, member.name, data)
|
| 308 |
+
continue
|
| 309 |
+
serial, kind, f = match[4], match[5], int(match[6])
|
| 310 |
+
if selected_views and serial not in selected_views or args.max_frames and f >= args.max_frames:
|
| 311 |
+
continue
|
| 312 |
+
data = tf.extractfile(member).read()
|
| 313 |
+
dest = safe_member(work, member.name)
|
| 314 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 315 |
+
dest.write_bytes(data)
|
| 316 |
+
row = rows.setdefault(serial, {}).setdefault(f, {})
|
| 317 |
+
if kind in row:
|
| 318 |
+
raise ValueError('duplicate archive frame')
|
| 319 |
+
row[kind] = (dest, locator(archive, member.name, data))
|
| 320 |
+
else:
|
| 321 |
+
flush()
|
| 322 |
+
return done
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def main(argv=None):
|
| 326 |
+
p = parser('dex-ycb', __doc__)
|
| 327 |
+
p.add_argument('--subjects')
|
| 328 |
+
args = p.parse_args(argv)
|
| 329 |
+
archives = sorted({a for r in roots(args.root) for a in r.glob('*-subject-*.tar.gz')})
|
| 330 |
+
if args.subjects:
|
| 331 |
+
subjects = {s.strip().zfill(2) for s in args.subjects.split(',')}
|
| 332 |
+
archives = [a for a in archives if re.search(r'subject-(\d+)', a.name)[1] in subjects]
|
| 333 |
+
if not archives:
|
| 334 |
+
p.error('no Dex-YCB subject archives found')
|
| 335 |
+
cp = find_file(args.root, 'calibration.tar.gz') or find_file(args.root, 'calibration')
|
| 336 |
+
if cp is None:
|
| 337 |
+
p.error('calibration source missing')
|
| 338 |
+
calib = Calibration(cp.parent)
|
| 339 |
+
models = mano_models(args.mano_dir)
|
| 340 |
+
out = release(args, 'dex-ycb')
|
| 341 |
+
with tempfile.TemporaryDirectory(prefix='dex-models-') as wd:
|
| 342 |
+
assets, asset_archive = prepare_models(args.root, Path(wd))
|
| 343 |
+
for archive in archives:
|
| 344 |
+
convert_archive(archive, args, out, calib, cp, models, assets, asset_archive)
|
| 345 |
+
return 0
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
if __name__ == '__main__':
|
| 349 |
+
raise SystemExit(main())
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_h2o_v1.0.py
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""H2O native RGB-D, MANO, joints and objects → CONTRACT.md v1.0 (no rendered masks)."""
|
| 3 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
import shutil
|
| 8 |
+
import tarfile
|
| 9 |
+
import tempfile
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
import zipfile
|
| 12 |
+
|
| 13 |
+
# Bound native libraries before loading NumPy/Torch; each worker still uses independent FFmpeg processes.
|
| 14 |
+
for key in ('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS', 'NUMEXPR_NUM_THREADS'):
|
| 15 |
+
os.environ[key] = '1'
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
from PIL import Image
|
| 19 |
+
import torch
|
| 20 |
+
|
| 21 |
+
from warehouse_v1_0 import (View, build_record, check_mesh, find_file, locator, mano_models, mesh_asset,
|
| 22 |
+
model_profile, parser, release, roots, safe_member, sequence_dir, sha256)
|
| 23 |
+
|
| 24 |
+
OBJECTS = {1: 'book', 2: 'espresso', 3: 'lotion', 4: 'spray',
|
| 25 |
+
5: 'milk', 6: 'cocoa', 7: 'chips', 8: 'cappuccino'}
|
| 26 |
+
MEMBER = re.compile(r'^(?:h2o_CASA/)?(subject\d+)/([^/]+)/(\d+)/(cam\d)/(.+)$')
|
| 27 |
+
FRAME = re.compile(r'(rgb|depth|cam_pose|hand_pose|hand_pose_mano|obj_pose|obj_pose_rt)/(\d+)\.(png|jpg|txt)$')
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def load_splits(root):
|
| 31 |
+
archive = find_file(root, 'label_split.zip')
|
| 32 |
+
result = {}
|
| 33 |
+
if archive is not None:
|
| 34 |
+
with zipfile.ZipFile(archive) as z:
|
| 35 |
+
for split in ('train', 'val', 'test'):
|
| 36 |
+
member = f'label_split/action_{split}.txt'
|
| 37 |
+
for line_no, line in enumerate(z.read(member).decode().splitlines(), 1):
|
| 38 |
+
fields = line.split()
|
| 39 |
+
if len(fields) < 2 or fields[1] == 'path':
|
| 40 |
+
continue
|
| 41 |
+
key = fields[1]
|
| 42 |
+
if key in result and result[key][0] != split:
|
| 43 |
+
raise ValueError('conflicting official splits')
|
| 44 |
+
result[key] = (split, locator(archive, member, record=line_no))
|
| 45 |
+
return result
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def load_assets(root, work):
|
| 49 |
+
archive = find_file(root, 'object.zip')
|
| 50 |
+
if archive is None:
|
| 51 |
+
return {}, None
|
| 52 |
+
with zipfile.ZipFile(archive) as z:
|
| 53 |
+
for member in z.infolist():
|
| 54 |
+
if member.is_dir():
|
| 55 |
+
continue
|
| 56 |
+
path = safe_member(work, member.filename)
|
| 57 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 58 |
+
path.write_bytes(z.read(member))
|
| 59 |
+
result = {}
|
| 60 |
+
for oid, name in OBJECTS.items():
|
| 61 |
+
directory = work / 'object' / name
|
| 62 |
+
aliases = []
|
| 63 |
+
# Source cocoa.obj -> ovomaltine.mtl -> cocoa.png, but the ZIP names the
|
| 64 |
+
# supplied texture ovomaltine.png. Keep all originals and add a byte-identical alias.
|
| 65 |
+
if name == 'cocoa' and not (directory / 'cocoa.png').exists():
|
| 66 |
+
mtl = directory / 'ovomaltine.mtl'
|
| 67 |
+
if mtl.is_file() and 'map_Kd cocoa.png' in mtl.read_text().splitlines():
|
| 68 |
+
texture = directory / 'ovomaltine.png'
|
| 69 |
+
shutil.copyfile(texture, directory / 'cocoa.png')
|
| 70 |
+
aliases.append({'file': 'cocoa.png', 'sha256': sha256(texture),
|
| 71 |
+
'source': locator(archive, 'object/cocoa/ovomaltine.png')})
|
| 72 |
+
candidates = list(directory.glob('*.obj'))
|
| 73 |
+
if len(candidates) != 1:
|
| 74 |
+
raise ValueError(f'expected one source OBJ for {name}')
|
| 75 |
+
check_mesh(candidates[0], directory) # Fail before decoding any large subject archive.
|
| 76 |
+
result[oid] = (directory, candidates[0], aliases)
|
| 77 |
+
return result, archive
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def convert_view(path, args, seq, cam, rows, intr, splits, models, assets, asset_archive):
|
| 81 |
+
codec_threads = getattr(args, 'codec_threads', 1)
|
| 82 |
+
ids = list(range(min(rows), max(rows) + 1))
|
| 83 |
+
for f in ids:
|
| 84 |
+
rows.setdefault(f, {})
|
| 85 |
+
n = len(ids)
|
| 86 |
+
if not n:
|
| 87 |
+
raise ValueError('no RGB frames')
|
| 88 |
+
split, split_loc = splits.get(seq, ('unknown', None))
|
| 89 |
+
frame_rows = [dict(source_frame_id=f, sync_id=f'{seq}:{f}', source_locator=rows[f]['rgb'][1] if 'rgb' in rows[f] else {'sequence': seq, 'camera': cam, 'source_frame_id': f, 'missing_rgb': True},
|
| 90 |
+
component_sources={k: item[1] for k, item in rows[f].items()},
|
| 91 |
+
annotation_matches={k: dict(source_frame_id=f, source_timestamp_ns=None,
|
| 92 |
+
clock_domain=None, match_method='index_map', delta_ns=None)
|
| 93 |
+
for k in rows[f] if k != 'rgb'}) for f in ids]
|
| 94 |
+
view = View(path, 'H2O', args.release_id, seq.replace('/', '_'), cam, frame_rows, split=split)
|
| 95 |
+
view.valid_rules = {
|
| 96 |
+
'mano': 'Per-hand hand_pose_mano flag equals 1; corresponding side model available',
|
| 97 |
+
'keypoints': "Per-hand hand_pose flag equals 1, broadcast to that hand's 21 source points independently of MANO",
|
| 98 |
+
'pose': 'Source obj_pose_rt class equals this nonzero object class',
|
| 99 |
+
'points': 'Source obj_pose class equals this nonzero object class, broadcast to its 21 points',
|
| 100 |
+
}
|
| 101 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 102 |
+
view.meta['view_type'] = 'ego' if cam == 'cam4' else 'exo' if cam in ('cam0', 'cam1', 'cam2', 'cam3') else 'unknown'
|
| 103 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'views': args.views}
|
| 104 |
+
if split_loc:
|
| 105 |
+
view.meta.update(split_scheme='official_action_split', split_source_locator=split_loc)
|
| 106 |
+
# In the measured 275 H2O views, exact FFV1 was always smaller than exact H.264.
|
| 107 |
+
view.rgb([rows[f]['rgb'][0] if 'rgb' in rows[f] else None for f in ids],
|
| 108 |
+
{'frames_ref': 'camera/frames.jsonl'}, ffv1_first=True, codec_threads=codec_threads)
|
| 109 |
+
loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources'}
|
| 110 |
+
if intr is not None:
|
| 111 |
+
fx, fy, cx, cy, width, height = np.loadtxt(intr[0]).ravel()
|
| 112 |
+
if [int(width), int(height)] != view.meta['camera']['image_size']:
|
| 113 |
+
raise ValueError('source intrinsics resolution mismatch')
|
| 114 |
+
K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
|
| 115 |
+
view.camera(K, intr[1])
|
| 116 |
+
camps = np.full((n, 4, 4), np.nan, np.float32)
|
| 117 |
+
cv = np.zeros(n, bool)
|
| 118 |
+
data = []
|
| 119 |
+
for i, f in enumerate(ids):
|
| 120 |
+
lab = {k: np.loadtxt(item[0]).ravel() for k, item in rows[f].items() if k not in ('rgb', 'depth')}
|
| 121 |
+
data.append(lab)
|
| 122 |
+
if 'cam_pose' in lab:
|
| 123 |
+
camps[i] = np.linalg.inv(lab['cam_pose'].reshape(4, 4))
|
| 124 |
+
cv[i] = True
|
| 125 |
+
if cv.any():
|
| 126 |
+
view.tensor('extrinsic', 'transform/se3/v1', 'camera/extrinsic.pt', camps, cv,
|
| 127 |
+
['T', 'row', 'column'], loc, convention='T_camera_from_world',
|
| 128 |
+
source_convention='T_world_from_camera')
|
| 129 |
+
motion, mv = np.full((n, 2, 61), np.nan, np.float32), np.zeros((n, 2), bool)
|
| 130 |
+
points, pv = np.full((n, 2, 21, 3), np.nan, np.float32), np.zeros((n, 2, 21), bool)
|
| 131 |
+
object_ids = set()
|
| 132 |
+
for i, lab in enumerate(data):
|
| 133 |
+
if 'hand_pose_mano' in lab:
|
| 134 |
+
hands = lab['hand_pose_mano'].reshape(2, 62)
|
| 135 |
+
for side, row in enumerate(hands):
|
| 136 |
+
if row[0] not in (0, 1):
|
| 137 |
+
raise ValueError('unexpected H2O MANO presence flag')
|
| 138 |
+
if row[0] == 1:
|
| 139 |
+
motion[i, side] = np.r_[row[4:52], row[52:62], row[1:4]]
|
| 140 |
+
mv[i, side] = True
|
| 141 |
+
if 'hand_pose' in lab:
|
| 142 |
+
hands = lab['hand_pose'].reshape(2, 64)
|
| 143 |
+
for side, row in enumerate(hands):
|
| 144 |
+
if row[0] not in (0, 1):
|
| 145 |
+
raise ValueError('unexpected H2O keypoint presence flag')
|
| 146 |
+
if row[0] == 1:
|
| 147 |
+
points[i, side] = row[1:].reshape(21, 3)
|
| 148 |
+
pv[i, side] = True
|
| 149 |
+
for key in ('obj_pose', 'obj_pose_rt'):
|
| 150 |
+
if key in lab and lab[key][0] != 0:
|
| 151 |
+
object_ids.add(int(lab[key][0]))
|
| 152 |
+
if any('hand_pose_mano' in lab for lab in data):
|
| 153 |
+
if len(models) == 2:
|
| 154 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 155 |
+
['T', 'hand', 'parameter'], loc, model_profile=model_profile(models))
|
| 156 |
+
else:
|
| 157 |
+
view.absent('mano', 'Source parameters exist; --mano-dir must identify both model profiles', 'dependency_missing')
|
| 158 |
+
if any('hand_pose' in lab for lab in data):
|
| 159 |
+
view.tensor('keypoints_xyz', 'keypoints/xyz/v1', 'annotation/keypoints/xyz.pt', points, pv,
|
| 160 |
+
['T', 'hand', 'keypoint', 'coordinate'], loc, keypoint_schema='mano21/v1', unit='m')
|
| 161 |
+
for oid in sorted(object_ids):
|
| 162 |
+
if oid not in OBJECTS:
|
| 163 |
+
raise ValueError(f'unknown H2O object class {oid}')
|
| 164 |
+
entity = OBJECTS[oid]
|
| 165 |
+
view.object(entity, loc, category_id=oid, source_object_id=oid)
|
| 166 |
+
poses, ov = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 167 |
+
pts, kv = np.full((n, 21, 3), np.nan, np.float32), np.zeros((n, 21), bool)
|
| 168 |
+
for i, lab in enumerate(data):
|
| 169 |
+
if 'obj_pose_rt' in lab and lab['obj_pose_rt'][0] == oid:
|
| 170 |
+
poses[i] = lab['obj_pose_rt'][1:].reshape(4, 4)
|
| 171 |
+
ov[i] = True
|
| 172 |
+
if 'obj_pose' in lab and lab['obj_pose'][0] == oid:
|
| 173 |
+
pts[i] = lab['obj_pose'][1:].reshape(21, 3)
|
| 174 |
+
kv[i] = True
|
| 175 |
+
if ov.any():
|
| 176 |
+
view.tensor('pose_' + entity, 'object/rigid/v1', f'annotation/object/{entity}/pose.pt',
|
| 177 |
+
poses, ov, ['T', 'row', 'column'], loc, convention='T_camera_from_object', unit='m')
|
| 178 |
+
if kv.any():
|
| 179 |
+
view.tensor('points_' + entity, 'object_keypoints/camera/v1',
|
| 180 |
+
f'annotation/object/{entity}/keypoints/xyz.pt', pts, kv,
|
| 181 |
+
['T', 'keypoint', 'coordinate'], loc, keypoint_schema='H2O_official_object21',
|
| 182 |
+
keypoint_names=['center'] + [f'corner_{i}' for i in range(8)] + [f'edge_midpoint_{i}' for i in range(12)],
|
| 183 |
+
source_order='official obj_point_order.jpg: center, 8 corners, 12 edge midpoints', unit='m')
|
| 184 |
+
if oid in assets:
|
| 185 |
+
directory, obj, aliases = assets[oid]
|
| 186 |
+
asset_loc = locator(asset_archive, f'object/{entity}/{obj.name}')
|
| 187 |
+
if aliases:
|
| 188 |
+
asset_loc['texture_aliases'] = aliases
|
| 189 |
+
mesh_asset(view, entity, directory, obj, asset_loc)
|
| 190 |
+
else:
|
| 191 |
+
view.absent('mesh_' + entity, 'Source object.zip unavailable', 'not_downloaded')
|
| 192 |
+
if any('depth' in rows[f] for f in ids):
|
| 193 |
+
width, height = view.meta['camera']['image_size']
|
| 194 |
+
def depths():
|
| 195 |
+
for f in ids:
|
| 196 |
+
item = rows[f].get('depth')
|
| 197 |
+
if item:
|
| 198 |
+
with Image.open(item[0]) as im:
|
| 199 |
+
yield np.asarray(im).astype(np.float32) / 1000.0
|
| 200 |
+
else:
|
| 201 |
+
yield np.full((height, width), np.nan, np.float32)
|
| 202 |
+
view.raster('depth', depths(), None, loc | {'source_field': 'component_sources.depth',
|
| 203 |
+
'definition': 'https://github.com/taeinkwon/h2oplayer/blob/main/utils.py',
|
| 204 |
+
'conversion': 'registered millimetre camera-Z to metres; no viewer range clipping'},
|
| 205 |
+
codec_threads=codec_threads)
|
| 206 |
+
else:
|
| 207 |
+
view.absent('depth', 'No source depth frames')
|
| 208 |
+
view.absent('segment', 'H2O provides no native segmentation; rendering deferred to v2.0')
|
| 209 |
+
view.absent('relations', 'No source contact/grasp annotation')
|
| 210 |
+
return view.finish()
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def convert_archive(archive, args, out, splits, models, assets, asset_archive):
|
| 214 |
+
selected_views = set(args.views.split(',')) if args.views else None
|
| 215 |
+
subjects = {'subject' + s.strip() for s in args.subjects.split(',')} if args.subjects else None
|
| 216 |
+
current, rows, intrinsics, done = None, {}, {}, 0
|
| 217 |
+
with tempfile.TemporaryDirectory(prefix='h2o-source-') as wd:
|
| 218 |
+
work = Path(wd)
|
| 219 |
+
def flush():
|
| 220 |
+
nonlocal done
|
| 221 |
+
if not rows:
|
| 222 |
+
return
|
| 223 |
+
seq = '/'.join(current)
|
| 224 |
+
reports, pending = {}, {}
|
| 225 |
+
for cam, frames in sorted(rows.items()):
|
| 226 |
+
existing = out / 'data' / seq.replace('/', '_') / cam
|
| 227 |
+
if (existing / 'metainfo.json').is_file():
|
| 228 |
+
old_frames = [json.loads(line) for line in (existing / 'camera/frames.jsonl').read_text().splitlines()]
|
| 229 |
+
if [f['source_frame_id'] for f in old_frames] != list(range(min(frames), max(frames) + 1)):
|
| 230 |
+
raise ValueError('existing view has different sampling; choose a new release-id')
|
| 231 |
+
for frame in old_frames:
|
| 232 |
+
incoming = frames.get(frame['source_frame_id'], {})
|
| 233 |
+
previous = frame.get('component_sources', {})
|
| 234 |
+
if set(previous) != set(incoming) or any(previous[k].get('sha256') != v[1].get('sha256') for k, v in incoming.items()):
|
| 235 |
+
raise ValueError('duplicate H2O view differs from the published source; choose a new release-id')
|
| 236 |
+
else:
|
| 237 |
+
pending[cam] = frames
|
| 238 |
+
if pending:
|
| 239 |
+
with sequence_dir(out, seq.replace('/', '_')) as target:
|
| 240 |
+
for cam, frames in pending.items():
|
| 241 |
+
reports[cam] = convert_view(target / cam, args, seq, cam, frames,
|
| 242 |
+
intrinsics.get(cam), splits, models, assets, asset_archive)
|
| 243 |
+
build_record(out, seq.replace('/', '_'), reports)
|
| 244 |
+
for staged in list(work.iterdir()):
|
| 245 |
+
if staged.is_dir():
|
| 246 |
+
shutil.rmtree(staged)
|
| 247 |
+
else:
|
| 248 |
+
staged.unlink()
|
| 249 |
+
done += 1
|
| 250 |
+
print(f'{"Converted" if pending else "Verified existing"} {seq}', flush=True)
|
| 251 |
+
# Uncompressed CASA supports seeking over large frames; gzip is single-pass.
|
| 252 |
+
mode = 'r:' if archive.suffix == '.tar' else 'r|gz'
|
| 253 |
+
with tarfile.open(archive, mode) as tf:
|
| 254 |
+
for member in tf:
|
| 255 |
+
match = MEMBER.fullmatch(member.name)
|
| 256 |
+
if not member.isfile() or not match:
|
| 257 |
+
continue
|
| 258 |
+
subj, scene, seq, cam, tail = match.groups()
|
| 259 |
+
if subjects and subj not in subjects:
|
| 260 |
+
continue
|
| 261 |
+
key = (subj, scene, seq)
|
| 262 |
+
if key != current:
|
| 263 |
+
flush()
|
| 264 |
+
if args.limit and done >= args.limit:
|
| 265 |
+
break
|
| 266 |
+
current, rows, intrinsics = key, {}, {}
|
| 267 |
+
if selected_views and cam not in selected_views:
|
| 268 |
+
continue
|
| 269 |
+
frame = FRAME.fullmatch(tail)
|
| 270 |
+
if tail != 'cam_intrinsics.txt' and not frame:
|
| 271 |
+
continue
|
| 272 |
+
if frame and args.max_frames and int(frame[2]) >= args.max_frames:
|
| 273 |
+
continue
|
| 274 |
+
data = tf.extractfile(member).read()
|
| 275 |
+
dest = safe_member(work, member.name)
|
| 276 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 277 |
+
dest.write_bytes(data)
|
| 278 |
+
item = (dest, locator(archive, member.name, data))
|
| 279 |
+
if tail == 'cam_intrinsics.txt':
|
| 280 |
+
intrinsics[cam] = item
|
| 281 |
+
else:
|
| 282 |
+
kind, f = frame[1], int(frame[2])
|
| 283 |
+
row = rows.setdefault(cam, {}).setdefault(f, {})
|
| 284 |
+
if kind in row:
|
| 285 |
+
raise ValueError('duplicate H2O frame')
|
| 286 |
+
row[kind] = item
|
| 287 |
+
else:
|
| 288 |
+
flush()
|
| 289 |
+
return done
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def main(argv=None):
|
| 293 |
+
p = parser('H2O', __doc__)
|
| 294 |
+
p.set_defaults(release_id='shared-v1.0')
|
| 295 |
+
p.add_argument('--workers', type=int, choices=range(1, 5), default=1,
|
| 296 |
+
help='Independent subject archives in parallel, 1..4; benchmark before using >2')
|
| 297 |
+
p.add_argument('--codec-threads', type=int, choices=(1, 2, 4, 8, 10), default=4,
|
| 298 |
+
help='FFV1 slice threads per encode; default 4, use 10 for the current full run')
|
| 299 |
+
p.add_argument('--subjects')
|
| 300 |
+
p.add_argument('--include-casa', action='store_true')
|
| 301 |
+
p.add_argument('--archive', type=Path, help='Convert one explicit source archive')
|
| 302 |
+
args = p.parse_args(argv)
|
| 303 |
+
if args.include_casa and args.workers != 1:
|
| 304 |
+
p.error('CASA can share sequence IDs with subject archives; convert it sequentially in a separate release')
|
| 305 |
+
archives = [args.archive.expanduser()] if args.archive else sorted(
|
| 306 |
+
{a for root in roots(args.root) for a in root.glob('subject*_v1_1.tar.gz')})
|
| 307 |
+
if args.subjects and not args.archive:
|
| 308 |
+
requested = {'subject' + s.strip() for s in args.subjects.split(',')}
|
| 309 |
+
archives = [arc for arc in archives if arc.name.split('_', 1)[0] in requested]
|
| 310 |
+
if args.include_casa:
|
| 311 |
+
casa = find_file(args.root, 'h2o_CASA.tar')
|
| 312 |
+
if casa:
|
| 313 |
+
archives.append(casa)
|
| 314 |
+
if not archives:
|
| 315 |
+
p.error('no H2O archives found')
|
| 316 |
+
out = release(args, 'H2O')
|
| 317 |
+
source_mapping = next(p for p in (Path(__file__).resolve().parents[1] / 'docs/h2o-RAW_TO_SHARED.md',
|
| 318 |
+
Path(__file__).resolve().parents[1] / 'doc/RAW_TO_SHARED.md',
|
| 319 |
+
out / 'doc/RAW_TO_SHARED.md') if p.is_file())
|
| 320 |
+
mapping = out / 'doc/RAW_TO_SHARED.md'
|
| 321 |
+
if mapping.exists() and mapping.read_bytes() != source_mapping.read_bytes():
|
| 322 |
+
raise ValueError('RAW_TO_SHARED.md changed; choose a new release-id')
|
| 323 |
+
if not mapping.exists():
|
| 324 |
+
shutil.copyfile(source_mapping, mapping)
|
| 325 |
+
torch.set_num_threads(1)
|
| 326 |
+
models, splits = mano_models(args.mano_dir), load_splits(args.root)
|
| 327 |
+
with tempfile.TemporaryDirectory(prefix='h2o-assets-') as wd:
|
| 328 |
+
assets, asset_archive = load_assets(args.root, Path(wd))
|
| 329 |
+
def convert_one(archive):
|
| 330 |
+
return convert_archive(archive, args, out, splits, models, assets, asset_archive)
|
| 331 |
+
if args.workers == 1:
|
| 332 |
+
for archive in archives:
|
| 333 |
+
convert_one(archive)
|
| 334 |
+
else:
|
| 335 |
+
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 336 |
+
for archive, count in zip(archives, pool.map(convert_one, archives), strict=True):
|
| 337 |
+
print(f'Archive {archive.name}: {count} sequences', flush=True)
|
| 338 |
+
return 0
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
if __name__ == '__main__':
|
| 342 |
+
raise SystemExit(main())
|
| 343 |
+
|
| 344 |
+
# TODO(v2.0): 以下旧 MANO 网格和渲染分割代码仅保留备查;v1.0 不生成标注。
|
| 345 |
+
# def load_mano_model(path: Path):
|
| 346 |
+
# """MPI MANO pkl → numpy 字典。shapedirs 在 pkl 内为 chumpy Select(对 (778,3,20) 基
|
| 347 |
+
# 底 flat 选取前 10 个 shape 分量;idxs 已核实等价于 base[:,:,:10])。"""
|
| 348 |
+
# with open(path, "rb") as f:
|
| 349 |
+
# d = _ManoUnpickler(f, encoding="latin1").load()
|
| 350 |
+
# sd = d["shapedirs"]
|
| 351 |
+
# base = np.asarray(sd.a.x, np.float64) # (778, 3, 20)
|
| 352 |
+
# shapedirs = base.reshape(-1)[np.asarray(sd.idxs)].reshape(base.shape[0], 3, -1)
|
| 353 |
+
# jreg = d["J_regressor"]
|
| 354 |
+
# jreg = np.asarray(jreg.todense()) if hasattr(jreg, "todense") else np.asarray(jreg)
|
| 355 |
+
# return {"v_template": np.asarray(d["v_template"], np.float64),
|
| 356 |
+
# "shapedirs": shapedirs,
|
| 357 |
+
# "posedirs": np.asarray(d["posedirs"], np.float64),
|
| 358 |
+
# "weights": np.asarray(d["weights"], np.float64),
|
| 359 |
+
# "J_regressor": np.asarray(jreg, np.float64),
|
| 360 |
+
# "kintree": np.asarray(d["kintree_table"], np.int64),
|
| 361 |
+
# "faces": np.asarray(d["f"], np.int64)}
|
| 362 |
+
#
|
| 363 |
+
#
|
| 364 |
+
# def rodrigues(r):
|
| 365 |
+
# """axis-angle (N,3) → 旋转矩阵 (N,3,3)。公式 I + sinθ·K + (1−cosθ)·K²(已对 scipy 核验)。"""
|
| 366 |
+
# r = np.asarray(r, np.float64).reshape(-1, 3)
|
| 367 |
+
# th = np.linalg.norm(r, axis=1)
|
| 368 |
+
# R = np.zeros((len(r), 3, 3))
|
| 369 |
+
# nz = th > 1e-12
|
| 370 |
+
# R[~nz] = np.eye(3)
|
| 371 |
+
# k = r[nz] / th[nz, None]
|
| 372 |
+
# K = np.zeros((len(k), 3, 3))
|
| 373 |
+
# K[:, 0, 1], K[:, 0, 2], K[:, 1, 2] = -k[:, 2], k[:, 1], -k[:, 0]
|
| 374 |
+
# K[:, 1, 0], K[:, 2, 0], K[:, 2, 1] = k[:, 2], -k[:, 1], k[:, 0]
|
| 375 |
+
# s, c = np.sin(th[nz])[:, None, None], np.cos(th[nz])[:, None, None]
|
| 376 |
+
# R[nz] = np.eye(3) + s * K + (1 - c) * (K @ K)
|
| 377 |
+
# return R
|
| 378 |
+
#
|
| 379 |
+
#
|
| 380 |
+
# def _mano_chain(model, betas, pose):
|
| 381 |
+
# """返回 (v_shaped, J, Rs, G):G 为 16 个关节的全��变换(平移列 = 关节位置)。"""
|
| 382 |
+
# v = model["v_template"] + np.einsum("nkc,c->nk", model["shapedirs"], betas)
|
| 383 |
+
# J = model["J_regressor"] @ v
|
| 384 |
+
# Rs = rodrigues(np.asarray(pose, np.float64).reshape(16, 3))
|
| 385 |
+
# kt = model["kintree"]
|
| 386 |
+
# G = np.zeros((16, 4, 4))
|
| 387 |
+
# for j in range(16):
|
| 388 |
+
# p = kt[0, j] if j else -1
|
| 389 |
+
# loc = np.eye(4)
|
| 390 |
+
# loc[:3, :3] = Rs[j]
|
| 391 |
+
# loc[:3, 3] = J[j] - (J[p] if j else 0.0)
|
| 392 |
+
# G[j] = loc if not j else G[p] @ loc
|
| 393 |
+
# return v, J, Rs, G
|
| 394 |
+
#
|
| 395 |
+
#
|
| 396 |
+
# def mano_forward(model, betas, pose, transl):
|
| 397 |
+
# """MANO LBS 前向(经典蒙皮 M_j = G_j·G0_j⁻¹;对 hand_pose 21 关节实证 0.0 mm)。
|
| 398 |
+
# pose: 48 axis-angle([0:3] 全局);返回相机系米顶点 (778,3)。"""
|
| 399 |
+
# v, J, Rs, G = _mano_chain(model, betas, pose)
|
| 400 |
+
# lrot = (Rs[1:] - np.eye(3)).ravel()
|
| 401 |
+
# v_posed = v + np.einsum("nkc,c->nk", model["posedirs"], lrot)
|
| 402 |
+
# kt = model["kintree"]
|
| 403 |
+
# G0 = np.zeros((16, 4, 4))
|
| 404 |
+
# for j in range(16):
|
| 405 |
+
# p = kt[0, j] if j else -1
|
| 406 |
+
# loc = np.eye(4)
|
| 407 |
+
# loc[:3, 3] = J[j] - (J[p] if j else 0.0)
|
| 408 |
+
# G0[j] = loc if not j else G0[p] @ loc
|
| 409 |
+
# M = np.einsum("nj,jab->nab", model["weights"], G @ np.linalg.inv(G0))
|
| 410 |
+
# out = np.einsum("nab,nb->na", M[:, :3, :3], v_posed) + M[:, :3, 3]
|
| 411 |
+
# return out + np.asarray(transl, np.float64)
|
| 412 |
+
#
|
| 413 |
+
#
|
| 414 |
+
# def mano_chain_joints(model, betas, pose, transl):
|
| 415 |
+
# """16 个关节位置(相机系米)= 链平移列;自检用。"""
|
| 416 |
+
# _, _, _, G = _mano_chain(model, betas, pose)
|
| 417 |
+
# return G[:, :3, 3] + np.asarray(transl, np.float64)
|
| 418 |
+
#
|
| 419 |
+
#
|
| 420 |
+
# def rasterize(verts_cam, faces, labels, W, H, fx, fy, cx, cy):
|
| 421 |
+
# z = verts_cam[:, 2]
|
| 422 |
+
# P = faces
|
| 423 |
+
# ok = (z[P] > 0.02).all(1) # 任一顶点在相机后 → 丢弃该三角形
|
| 424 |
+
# P, labels = P[ok], labels[ok]
|
| 425 |
+
# if len(P) == 0:
|
| 426 |
+
# return np.zeros((H, W), np.uint16), np.zeros(0, np.int64)
|
| 427 |
+
# x = verts_cam[:, 0] / z * fx + cx
|
| 428 |
+
# y = verts_cam[:, 1] / z * fy + cy
|
| 429 |
+
# xa = np.maximum(0, np.minimum(np.floor(x[P[:, 0]]), np.minimum(
|
| 430 |
+
# np.floor(x[P[:, 1]]), np.floor(x[P[:, 2]]))).astype(np.int64))
|
| 431 |
+
# xb = np.minimum(W - 1, np.maximum(np.ceil(x[P[:, 0]]), np.maximum(
|
| 432 |
+
# np.ceil(x[P[:, 1]]), np.ceil(x[P[:, 2]]))).astype(np.int64))
|
| 433 |
+
# ya = np.maximum(0, np.minimum(np.floor(y[P[:, 0]]), np.minimum(
|
| 434 |
+
# np.floor(y[P[:, 1]]), np.floor(y[P[:, 2]]))).astype(np.int64))
|
| 435 |
+
# yb = np.minimum(H - 1, np.maximum(np.ceil(y[P[:, 0]]), np.maximum(
|
| 436 |
+
# np.ceil(y[P[:, 1]]), np.ceil(y[P[:, 2]]))).astype(np.int64))
|
| 437 |
+
# xa, ya = np.minimum(xa, xb), np.minimum(ya, yb) # 完全出画的三角形 → 空 bbox
|
| 438 |
+
# wdt, hgt = xb - xa + 1, yb - ya + 1
|
| 439 |
+
# cnt = wdt * hgt
|
| 440 |
+
# tot = int(cnt.sum())
|
| 441 |
+
# tri = np.repeat(np.arange(len(P)), cnt)
|
| 442 |
+
# k = np.arange(tot) - (np.cumsum(cnt) - cnt)[tri]
|
| 443 |
+
# px = xa[tri] + k % wdt[tri] + 0.5
|
| 444 |
+
# py = ya[tri] + k // wdt[tri] + 0.5
|
| 445 |
+
# ax, ay = x[P[tri, 0]], y[P[tri, 0]]
|
| 446 |
+
# bx, by = x[P[tri, 1]], y[P[tri, 1]]
|
| 447 |
+
# cx_, cy_ = x[P[tri, 2]], y[P[tri, 2]]
|
| 448 |
+
# area = ((x[P[:, 1]] - x[P[:, 0]]) * (y[P[:, 2]] - y[P[:, 0]])
|
| 449 |
+
# - (y[P[:, 1]] - y[P[:, 0]]) * (x[P[:, 2]] - x[P[:, 0]]))
|
| 450 |
+
# areat = area[tri]
|
| 451 |
+
# e0 = (bx - ax) * (py - ay) - (by - ay) * (px - ax)
|
| 452 |
+
# e1 = (cx_ - bx) * (py - by) - (cy_ - by) * (px - bx)
|
| 453 |
+
# e2 = (ax - cx_) * (py - cy_) - (ay - cy_) * (px - cx_)
|
| 454 |
+
# s = np.sign(areat)
|
| 455 |
+
# inside = (np.abs(areat) > 1e-9) & ((e0 * s >= 0) & (e1 * s >= 0) & (e2 * s >= 0))
|
| 456 |
+
# px, py, tri = px[inside], py[inside], tri[inside]
|
| 457 |
+
# at = areat[inside]
|
| 458 |
+
# w0, w1, w2 = e1[inside] / at, e2[inside] / at, e0[inside] / at
|
| 459 |
+
# zz = w0 * z[P[tri, 0]] + w1 * z[P[tri, 1]] + w2 * z[P[tri, 2]]
|
| 460 |
+
# pix = py.astype(np.int64) * W + px.astype(np.int64)
|
| 461 |
+
# order = np.lexsort((zz, pix)) # 同像素按深度升序 → 首条即最近
|
| 462 |
+
# pix, tri = pix[order], tri[order]
|
| 463 |
+
# first = np.unique(pix, return_index=True)[1]
|
| 464 |
+
# mask = np.zeros(H * W, np.uint16)
|
| 465 |
+
# win = tri[first]
|
| 466 |
+
# mask[pix[first]] = labels[win] + 1 # 临时标签 +1(0=背景)
|
| 467 |
+
# return mask.reshape(H, W), np.bincount(labels[win] + 1)
|
| 468 |
+
#
|
| 469 |
+
#
|
| 470 |
+
# # ============================================================================
|
| 471 |
+
# # ffmpeg 写出与核验(与 convert_dexycb.py 同构)
|
| 472 |
+
# # ============================================================================
|
| 473 |
+
# verts, faces_all, labels = [], [], []
|
| 474 |
+
# for ti, (tid, kind) in enumerate(tracks):
|
| 475 |
+
# if kind == "hand_left" and b["mano"][0] > 0.5:
|
| 476 |
+
# verts.append(mano_forward(mano_models["left"], b["mano"][52:62],
|
| 477 |
+
# b["mano"][4:52], b["mano"][1:4]))
|
| 478 |
+
# faces_all.append(mano_models["left"]["faces"])
|
| 479 |
+
# elif kind == "hand_right" and b["mano"][62] > 0.5:
|
| 480 |
+
# verts.append(mano_forward(mano_models["right"], b["mano"][114:124],
|
| 481 |
+
# b["mano"][66:114], b["mano"][63:66]))
|
| 482 |
+
# faces_all.append(mano_models["right"]["faces"])
|
| 483 |
+
# elif isinstance(kind, tuple) and int(b["objp"][0]) == kind[1]:
|
| 484 |
+
# M = np.asarray(b["objrt"][1:17], np.float64).reshape(4, 4)
|
| 485 |
+
# V0, F0 = meshes[kind[1]]
|
| 486 |
+
# verts.append(V0 @ M[:3, :3].T + M[:3, 3])
|
| 487 |
+
# faces_all.append(F0)
|
| 488 |
+
# else:
|
| 489 |
+
# continue
|
| 490 |
+
# labels.append(np.full(len(faces_all[-1]), ti))
|
| 491 |
+
# if verts:
|
| 492 |
+
# V = np.concatenate(verts)
|
| 493 |
+
# offs = np.cumsum([0] + [len(v) for v in verts[:-1]])
|
| 494 |
+
# F = np.concatenate([fa + o for fa, o in zip(faces_all, offs)])
|
| 495 |
+
# mask, counts = rasterize(V, F, np.concatenate(labels),
|
| 496 |
+
# IMG_W, IMG_H, fx, fy, cx, cy)
|
| 497 |
+
# else:
|
| 498 |
+
# mask, counts = np.zeros((IMG_H, IMG_W), np.uint16), np.zeros(0, np.int64)
|
| 499 |
+
# lut = np.zeros(n_tracks + 1, np.uint16)
|
| 500 |
+
# for ti in range(n_tracks):
|
| 501 |
+
# present = ti + 1 < len(counts) and counts[ti + 1] > 0
|
| 502 |
+
# if present:
|
| 503 |
+
# presence[tracks[ti][0]][f] = True
|
| 504 |
+
# if active_id[ti] is None:
|
| 505 |
+
# pid = next(i for i in range(1, 65535) if i not in used)
|
| 506 |
+
# used.add(pid)
|
| 507 |
+
# active_id[ti], seg_start[ti] = pid, f
|
| 508 |
+
# frame_maps[ti].append({"id": pid})
|
| 509 |
+
# lut[ti + 1] = active_id[ti]
|
| 510 |
+
# elif active_id[ti] is not None:
|
| 511 |
+
# frame_maps[ti][-1]["frames"] = [seg_start[ti], f - 1]
|
| 512 |
+
# segments[ti].append([seg_start[ti], f - 1])
|
| 513 |
+
# used.discard(active_id[ti])
|
| 514 |
+
# active_id[ti] = None
|
| 515 |
+
# mw.write(lut[mask])
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
# TODO(v2.0): 旧物体尺寸派生代码;v1.0 仅保留源物体关键点。
|
| 519 |
+
# pts = np.asarray(b["objp"][1:64], np.float64).reshape(21, 3)
|
| 520 |
+
# half = np.abs((pts[1:9] - pts[0]) @ M[:3, :3]).max(0)
|
| 521 |
+
# obj_recs.append({
|
| 522 |
+
# "track_id": f"o{classes.index(c)}", "frame": f,
|
| 523 |
+
# "mesh_ref": f"h2o/{OBJ_CLASSES[c]}.obj",
|
| 524 |
+
# "pose": {"quat": rotmat_to_quat_wxyz(M[:3, :3])[0].tolist(),
|
| 525 |
+
# "trans": M[:3, 3].tolist()},
|
| 526 |
+
# "bbox_center3d": pts[0].tolist(),
|
| 527 |
+
# "bbox_size": (2 * half).tolist()})
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_hoi4d_v1.0.py
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""HOI4D native observations and annotations → CONTRACT.md v1.0."""
|
| 3 |
+
from collections import Counter
|
| 4 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 5 |
+
from contextlib import ExitStack
|
| 6 |
+
from functools import lru_cache
|
| 7 |
+
import gzip
|
| 8 |
+
import io
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
import pickle
|
| 13 |
+
import re
|
| 14 |
+
import shutil
|
| 15 |
+
import shlex
|
| 16 |
+
import posixpath
|
| 17 |
+
import subprocess
|
| 18 |
+
import tempfile
|
| 19 |
+
import tarfile
|
| 20 |
+
import threading
|
| 21 |
+
import zipfile
|
| 22 |
+
|
| 23 |
+
# Each worker owns one Python thread; prevent native libraries spawning CPU pools.
|
| 24 |
+
for key in ('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS', 'NUMEXPR_NUM_THREADS'):
|
| 25 |
+
os.environ[key] = '1'
|
| 26 |
+
|
| 27 |
+
import numpy as np
|
| 28 |
+
from PIL import Image
|
| 29 |
+
from scipy.spatial.transform import Rotation
|
| 30 |
+
|
| 31 |
+
import torch
|
| 32 |
+
|
| 33 |
+
from warehouse_v1_0 import (View, build_record, check_mesh, decode_args, find_file, json_write, locator,
|
| 34 |
+
mano_models, model_profile, parser, probe, release, run, safe_member, sequence_dir)
|
| 35 |
+
|
| 36 |
+
CATEGORIES = {
|
| 37 |
+
1: dict(cad="rigid/ToyCar", groups=[("main", [1], "Toy Car", 1)],
|
| 38 |
+
hands={2: "right"}, objmap={"Toycar": "main"}),
|
| 39 |
+
2: dict(cad="rigid/Mug", groups=[("a", [1], "Mug", 2), ("b", [3], "Mug", 2)],
|
| 40 |
+
hands={2: "right"}, objmap={"Watercup": "a"}),
|
| 41 |
+
3: dict(cad="articulated/Laptop", groups=[("main", [1, 3], "Laptop", 3)],
|
| 42 |
+
hands={2: "right"},
|
| 43 |
+
objmap={"Laptopdisplay": "main", "Laptopkeyboard": "main"}),
|
| 44 |
+
4: dict(cad="articulated/StorageFurniture",
|
| 45 |
+
groups=[("main", [1, 3, 4], "Storage Furniture", 4),
|
| 46 |
+
("bottle", [5], "Bottle", 5)],
|
| 47 |
+
hands={2: "right"},
|
| 48 |
+
objmap={"Lockerbody": "main", "Lockersldingdoor": "main",
|
| 49 |
+
"Lockerdrawer": "main", "Safebox": "main"}),
|
| 50 |
+
5: dict(cad="rigid/Bottle", groups=[("main", [1], "Bottle", 5),
|
| 51 |
+
("mug", [3], "Mug", 2)],
|
| 52 |
+
hands={2: "right"}, objmap={"bottleddrinks": "main"}),
|
| 53 |
+
6: dict(cad="articulated/Safe", groups=[("main", [1, 3], "Safe", 6),
|
| 54 |
+
("bottle", [4], "Bottle", 5)],
|
| 55 |
+
hands={2: "right"}, objmap={"Safebox": "main", "Safedoor": "main"}),
|
| 56 |
+
7: dict(cad="rigid/Bowl", groups=[("main", [1], "Bowl", 7),
|
| 57 |
+
("ball", [3], "Ball", None)],
|
| 58 |
+
hands={2: "right"}, objmap={"bowl": "main"}),
|
| 59 |
+
8: dict(cad="articulated/Bucket",
|
| 60 |
+
groups=[("a", [1, 3], "Bucket", 8), ("b", [4, 5], "Bucket", 8)],
|
| 61 |
+
hands={2: "right", 6: "left"},
|
| 62 |
+
objmap={"bucket": "a", "Buckethandle": "a"}),
|
| 63 |
+
9: dict(cad="articulated/Scissors", groups=[("main", [1, 3], "Scissors", 9)],
|
| 64 |
+
hands={2: "right"},
|
| 65 |
+
objmap={"scissors": "main", "scissors2": None}), # scissors2:场景道具,无掩码
|
| 66 |
+
11: dict(cad="articulated/Pliers", groups=[("main", [1, 3], "Pliers", 11)],
|
| 67 |
+
hands={2: "right"}, objmap={"Pliersleft": "main", "Pliersright": "main"}),
|
| 68 |
+
12: dict(cad="rigid/Kettle", groups=[("main", [1], "Kettle", 12),
|
| 69 |
+
("mug", [3], "Mug", 2)],
|
| 70 |
+
hands={2: "right"}, objmap={"kettle": "main"}),
|
| 71 |
+
13: dict(cad="rigid/Knife", groups=[("main", [1], "Knife", 13),
|
| 72 |
+
("apple", [3], "Apple", None)],
|
| 73 |
+
hands={2: "right"}, objmap={"knife": "main"}),
|
| 74 |
+
14: dict(cad="articulated/TrashCan",
|
| 75 |
+
groups=[("main", [1, 3], "Trash Can", 14), ("bottle", [4], "Bottle", 5)],
|
| 76 |
+
hands={2: "right"}, objmap={"Dustbinbase": "main", "Dustbincover": "main"}),
|
| 77 |
+
17: dict(cad="articulated/Lamp", groups=[("main", [1, 3, 4, 5], "Lamp", 17)],
|
| 78 |
+
hands={2: "right", 6: "left"},
|
| 79 |
+
objmap={"Lampbase": "main", "Tablelampfirstjoint": "main",
|
| 80 |
+
"Tablelampsecondjoint": "main", "Thirdjointoftablelamp": "main"}),
|
| 81 |
+
18: dict(cad="articulated/Stapler",
|
| 82 |
+
groups=[("main", [1, 3, 4], "Stapler", 18), ("paper", [5], "Paper", None)],
|
| 83 |
+
hands={2: "right", 6: "left"}, # 6=左手:官方 label.csv 缺列,实测修正
|
| 84 |
+
objmap={"Staplerbase": "main", "Staplercover": "main"}),
|
| 85 |
+
20: dict(cad="rigid/Chair", groups=[("main", [1], "Chair", 20)],
|
| 86 |
+
hands={2: "right", 3: "left"}, objmap={"chair": "main"}),
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
# Official HOI4D definitions/motion segmentation/label.csv; no spatial side inference.
|
| 91 |
+
REGION_NAMES = {1: {1: 'Toy Car', 2: 'Right Hand'}, 2: {1: 'Mug', 2: 'Right Hand', 3: 'Mug'}, 3: {1: 'Screen', 2: 'Right Hand', 3: 'Keyboard'}, 4: {1: 'Door', 2: 'Right Hand', 3: 'Body of the Cabinet', 4: 'Drawer', 5: 'Bottle'}, 5: {1: 'Bottle', 2: 'Right Hand', 3: 'Mug'}, 6: {1: 'Body of the Safe', 2: 'Right Hand', 3: 'Door', 4: 'Bottle'}, 7: {1: 'Bowl', 2: 'Right Hand', 3: 'Ball'}, 8: {1: 'Body of the Bucket', 2: 'Right Hand', 3: 'Handle', 4: 'Body of the Bucket', 5: 'Handle', 6: 'Left Hand'}, 9: {1: 'Left Part of the Scissors', 2: 'Right Hand', 3: 'Right Part of the Scissors'}, 11: {1: 'Left Part of the Pliers', 2: 'Right Hand', 3: 'Right Part of the Pliers'}, 12: {1: 'Kettle', 2: 'Right Hand', 3: 'Mug'}, 13: {1: 'Knife', 2: 'Right Hand', 3: 'Apple'}, 14: {1: 'Body of the Trash Can', 2: 'Right Hand', 3: 'Lid', 4: 'Bottle'}, 17: {1: 'Base', 2: 'Right Hand', 3: 'Tube', 4: 'Top Link', 5: 'Bottom Link', 6: 'Left Hand'}, 18: {1: 'Base', 2: 'Right Hand', 3: 'Slot', 4: 'Lid', 5: 'Paper'}, 20: {1: 'Chair', 2: 'Right Hand', 3: 'Left Hand'}}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class SplitFiles(io.RawIOBase):
|
| 95 |
+
"""Read concatenated source gzip parts without concatenating 119 GB on disk."""
|
| 96 |
+
def __init__(self, paths):
|
| 97 |
+
self.paths = iter(paths)
|
| 98 |
+
self.current = None
|
| 99 |
+
|
| 100 |
+
def readable(self):
|
| 101 |
+
return True
|
| 102 |
+
|
| 103 |
+
def readinto(self, buffer):
|
| 104 |
+
while True:
|
| 105 |
+
if self.current is None:
|
| 106 |
+
path = next(self.paths, None)
|
| 107 |
+
if path is None:
|
| 108 |
+
return 0
|
| 109 |
+
self.current = path.open('rb')
|
| 110 |
+
n = self.current.readinto(buffer)
|
| 111 |
+
if n:
|
| 112 |
+
return n
|
| 113 |
+
self.current.close()
|
| 114 |
+
self.current = None
|
| 115 |
+
|
| 116 |
+
def close(self):
|
| 117 |
+
if self.current is not None:
|
| 118 |
+
self.current.close()
|
| 119 |
+
super().close()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def extract_depths(root, sequences, work):
|
| 123 |
+
directory = find_file(root, 'DEPTH')
|
| 124 |
+
if directory is None:
|
| 125 |
+
return {}, []
|
| 126 |
+
parts = sorted(directory.glob('HOI4D_depth_video.tar.gz*'), key=lambda p: int(p.name.split('.gz')[1] or 0))
|
| 127 |
+
if not parts:
|
| 128 |
+
return {}, []
|
| 129 |
+
wanted = {f'HOI4D_depth_video/{seq}/align_depth/depth_video.avi': seq for seq in sequences}
|
| 130 |
+
found = {}
|
| 131 |
+
with SplitFiles(parts) as joined, io.BufferedReader(joined) as inp, gzip.GzipFile(fileobj=inp) as gz:
|
| 132 |
+
with tarfile.open(fileobj=gz, mode='r|') as tf:
|
| 133 |
+
for member in tf:
|
| 134 |
+
if member.isfile() and member.name in wanted:
|
| 135 |
+
seq = wanted[member.name]
|
| 136 |
+
dest = work / (seq.replace('/', '_') + '.avi')
|
| 137 |
+
with tf.extractfile(member) as src, dest.open('wb') as dst:
|
| 138 |
+
shutil.copyfileobj(src, dst)
|
| 139 |
+
found[seq] = (dest, {'files': [str(p.resolve()) for p in parts], 'member': member.name})
|
| 140 |
+
if len(found) == len(wanted):
|
| 141 |
+
break
|
| 142 |
+
return found, parts
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def palette_mask(data):
|
| 146 |
+
with Image.open(io.BytesIO(data)) as im:
|
| 147 |
+
arr = np.asarray(im)
|
| 148 |
+
if arr.ndim == 2:
|
| 149 |
+
return arr.astype(np.uint16)
|
| 150 |
+
if arr.shape[-1] != 3:
|
| 151 |
+
raise ValueError('unsupported HOI4D mask representation')
|
| 152 |
+
# VOC's 256-color palette interleaves eight label bits into the high RGB bits.
|
| 153 |
+
# Invert it directly instead of sorting every pixel with np.unique.
|
| 154 |
+
if np.any(arr & np.array([31, 31, 63], dtype=np.uint8)):
|
| 155 |
+
raise ValueError('source mask has colors outside official VOC palette')
|
| 156 |
+
mask = np.zeros(arr.shape[:2], dtype=np.uint16)
|
| 157 |
+
for bit in range(8):
|
| 158 |
+
mask |= ((arr[..., bit % 3] >> (7 - bit // 3)) & 1).astype(np.uint16) << bit
|
| 159 |
+
return mask
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
# Four workers each reuse annotation and hand indices instead of rebuilding the ZIP directory.
|
| 163 |
+
@lru_cache(maxsize=8)
|
| 164 |
+
def index_frames(z):
|
| 165 |
+
index = {}
|
| 166 |
+
for name in z.namelist():
|
| 167 |
+
parent, _, filename = name.rpartition('/')
|
| 168 |
+
stem, dot, suffix = filename.rpartition('.')
|
| 169 |
+
if not dot or not stem.isdigit() or suffix not in ('png', 'json', 'pickle'):
|
| 170 |
+
continue
|
| 171 |
+
entries = index.setdefault((parent + '/', '.' + suffix), {})
|
| 172 |
+
f = int(stem)
|
| 173 |
+
if f in entries:
|
| 174 |
+
raise ValueError(f'duplicate frame number under {parent}')
|
| 175 |
+
entries[f] = name
|
| 176 |
+
return index
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def frame_members(z, prefix, suffix):
|
| 180 |
+
return index_frames(z).get((prefix, suffix), {})
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def convert_sequence(seq, args, target, rgbz, annz, hpz, calz, cadz, paths, models, depth):
|
| 184 |
+
# ponytail: cache only one sequence's encoded annotation bytes; no decoded masks or CAD cache.
|
| 185 |
+
@lru_cache(maxsize=None)
|
| 186 |
+
def read_annotation(archive, name):
|
| 187 |
+
return archive.read(name)
|
| 188 |
+
|
| 189 |
+
category = int(re.search(r'/C(\d+)/', seq)[1])
|
| 190 |
+
definition = CATEGORIES.get(category)
|
| 191 |
+
if definition is None:
|
| 192 |
+
raise ValueError(f'category mapping unavailable: {category}')
|
| 193 |
+
prefix = f'HOI4D_annotations/{seq}'
|
| 194 |
+
mask_members = frame_members(annz, prefix + '/2Dseg/mask/', '.png')
|
| 195 |
+
shifted = frame_members(annz, prefix + '/2Dseg/shift_mask/', '.png')
|
| 196 |
+
if not mask_members:
|
| 197 |
+
mask_members = shifted
|
| 198 |
+
pose_members = frame_members(annz, prefix + '/objpose/', '.json')
|
| 199 |
+
hand_members = {side: frame_members(hpz, f'Hand_pose/handpose_{side}_hand/{seq}/', '.pickle')
|
| 200 |
+
for side in ('left', 'right')} if hpz else {'left': {}, 'right': {}}
|
| 201 |
+
with tempfile.TemporaryDirectory(prefix='hoi4d-source-') as wd:
|
| 202 |
+
work = Path(wd)
|
| 203 |
+
member = f'HOI4D_release/{seq}/align_rgb/image.mp4'
|
| 204 |
+
video = work / 'rgb.mp4'
|
| 205 |
+
with rgbz.open(member) as src, video.open('wb') as dst:
|
| 206 |
+
shutil.copyfileobj(src, dst)
|
| 207 |
+
info = probe(video)
|
| 208 |
+
if 'nb_frames' not in info:
|
| 209 |
+
info['nb_frames'] = json.loads(run(['ffprobe', '-v', 'error', '-count_frames', '-select_streams', 'v:0',
|
| 210 |
+
'-show_entries', 'stream=nb_read_frames', '-of', 'json', str(video)], stdout=subprocess.PIPE).stdout)['streams'][0]['nb_read_frames']
|
| 211 |
+
n = int(info['nb_frames'])
|
| 212 |
+
if args.max_frames:
|
| 213 |
+
n = min(n, args.max_frames)
|
| 214 |
+
if shifted and mask_members != shifted and any(f not in mask_members and f in shifted for f in range(n)):
|
| 215 |
+
raise ValueError('shift_mask has frames absent from mask; correspondence unverified')
|
| 216 |
+
frames = []
|
| 217 |
+
for f in range(n):
|
| 218 |
+
sources = {}
|
| 219 |
+
if f in mask_members:
|
| 220 |
+
sources['segment'] = locator(paths['annotations'], mask_members[f], read_annotation(annz, mask_members[f]))
|
| 221 |
+
if f in pose_members:
|
| 222 |
+
sources['object'] = locator(paths['annotations'], pose_members[f], read_annotation(annz, pose_members[f]))
|
| 223 |
+
for side in ('left', 'right'):
|
| 224 |
+
if f in hand_members[side]:
|
| 225 |
+
sources['hand_' + side] = locator(paths['hand'], hand_members[side][f], read_annotation(hpz, hand_members[side][f]))
|
| 226 |
+
frames.append(dict(source_frame_id=f, source_locator=locator(paths['release'], member, frame=f),
|
| 227 |
+
component_sources=sources, annotation_matches={k: dict(source_frame_id=f, source_timestamp_ns=None,
|
| 228 |
+
clock_domain=None, match_method='index_map', delta_ns=None) for k in sources}))
|
| 229 |
+
view = View(target, 'HOI4D', args.release_id, seq.replace('/', '_'), 'ego', frames)
|
| 230 |
+
view.valid_rules = {
|
| 231 |
+
'mano': 'Matched side pickle contains poseCoeff, beta, trans and corresponding model available; zero angles are not missing',
|
| 232 |
+
'keypoints': 'Matched side pickle contains kps2D; independently provided source points, no visibility gate',
|
| 233 |
+
'pose': 'Matched source object record contains rotation and center; record identity retained',
|
| 234 |
+
'dimensions': 'Matched source object record contains dimensions; size/mesh relation remains source_unspecified',
|
| 235 |
+
'segment': 'Source mask or shift_mask present with verified palette codes and entity/part mapping',
|
| 236 |
+
}
|
| 237 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 238 |
+
view.meta['view_type'] = 'ego'
|
| 239 |
+
view.meta['sampling']['selection'] = {'max_frames': args.max_frames, 'source_sequence': seq}
|
| 240 |
+
view.rgb([], locator(paths['release'], member), video=video, count=n)
|
| 241 |
+
intr_name = f'camera_params/{seq.split("/")[0]}/intrin.npy'
|
| 242 |
+
if calz and intr_name in calz.namelist():
|
| 243 |
+
view.camera(np.load(io.BytesIO(calz.read(intr_name))), locator(paths['camera'], intr_name))
|
| 244 |
+
extr_name = prefix + '/3Dseg/output.log'
|
| 245 |
+
if extr_name in annz.NameToInfo:
|
| 246 |
+
lines = [line for line in annz.read(extr_name).decode().splitlines() if line.strip()]
|
| 247 |
+
if len(lines) % 5:
|
| 248 |
+
raise ValueError('invalid Open3D camera trajectory')
|
| 249 |
+
extr, valid = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 250 |
+
for i in range(0, len(lines), 5):
|
| 251 |
+
idx = int(lines[i].split()[0])
|
| 252 |
+
if idx < n:
|
| 253 |
+
if valid[idx]:
|
| 254 |
+
raise ValueError('duplicate trajectory index')
|
| 255 |
+
extr[idx] = np.linalg.inv(np.loadtxt(io.StringIO('\n'.join(lines[i + 1:i + 5]))))
|
| 256 |
+
valid[idx] = True
|
| 257 |
+
view.tensor('extrinsic', 'transform/se3/v1', 'camera/extrinsic.pt', extr, valid,
|
| 258 |
+
['T', 'row', 'column'], locator(paths['annotations'], extr_name),
|
| 259 |
+
convention='T_camera_from_world', source_convention='Open3D LOG camera-to-world; inverted')
|
| 260 |
+
loc = {'frames_ref': 'camera/frames.jsonl', 'source_field': 'component_sources'}
|
| 261 |
+
motion, mv = np.full((n, 2, 61), np.nan, np.float32), np.zeros((n, 2), bool)
|
| 262 |
+
points, pv = np.full((n, 2, 21, 2), np.nan, np.float32), np.zeros((n, 2, 21), bool)
|
| 263 |
+
for slot, side in enumerate(('left', 'right')):
|
| 264 |
+
for f, name in hand_members[side].items():
|
| 265 |
+
if f >= n:
|
| 266 |
+
continue
|
| 267 |
+
data = pickle.loads(read_annotation(hpz, name), encoding='latin1')
|
| 268 |
+
if all(k in data for k in ('poseCoeff', 'beta', 'trans')):
|
| 269 |
+
motion[f, slot] = np.r_[np.asarray(data['poseCoeff']).reshape(48),
|
| 270 |
+
np.asarray(data['beta']).reshape(10), np.asarray(data['trans']).reshape(3)]
|
| 271 |
+
mv[f, slot] = True # Zero angles are a valid pose, not a missing sentinel.
|
| 272 |
+
if 'kps2D' in data:
|
| 273 |
+
points[f, slot] = np.asarray(data['kps2D']).reshape(21, 2)
|
| 274 |
+
pv[f, slot] = True
|
| 275 |
+
if mv.any():
|
| 276 |
+
if all(side in models for slot, side in enumerate(('left', 'right')) if mv[:, slot].any()):
|
| 277 |
+
view.tensor('mano', 'mano/axis_angle61/v1', 'annotation/mano/motion.pt', motion, mv,
|
| 278 |
+
['T', 'hand', 'parameter'], loc, model_profile=model_profile(models))
|
| 279 |
+
else:
|
| 280 |
+
view.absent('mano', 'Source MANO exists; provide --mano-dir to fix model identity', 'dependency_missing')
|
| 281 |
+
if pv.any():
|
| 282 |
+
view.tensor('keypoints_uv', 'keypoints/uv/v1', 'annotation/keypoints/uv.pt', points, pv,
|
| 283 |
+
['T', 'hand', 'keypoint', 'coordinate'], loc, keypoint_schema='mano21/v1', unit='pixel',
|
| 284 |
+
source_method='Upstream fitted MANO projection already present in kps2D')
|
| 285 |
+
objects = {}
|
| 286 |
+
groups = {key: (vals, name, cls) for key, vals, name, cls in definition['groups']}
|
| 287 |
+
def ensure_object(key, source_loc, category_id=None, frame=None, source_id=None):
|
| 288 |
+
if key not in objects:
|
| 289 |
+
view.object(key, source_loc, scope='frame' if frame is not None else 'sequence',
|
| 290 |
+
scope_id=f'{seq}:{frame}' if frame is not None else None,
|
| 291 |
+
category_id=category_id, source_object_id=source_id)
|
| 292 |
+
objects[key] = {}
|
| 293 |
+
mappings = []
|
| 294 |
+
mask_valid = [f in mask_members for f in range(n)]
|
| 295 |
+
if any(mask_valid):
|
| 296 |
+
width, height = view.meta['camera']['image_size']
|
| 297 |
+
def masks():
|
| 298 |
+
for f in range(n):
|
| 299 |
+
labels = []
|
| 300 |
+
if f in mask_members:
|
| 301 |
+
mask = palette_mask(read_annotation(annz, mask_members[f]))
|
| 302 |
+
for value in np.unique(mask):
|
| 303 |
+
value = int(value)
|
| 304 |
+
if value in (0, 255):
|
| 305 |
+
if value == 255:
|
| 306 |
+
raise ValueError('HOI4D 255 region semantics unverified')
|
| 307 |
+
continue
|
| 308 |
+
if REGION_NAMES[category].get(value) in ('Left Hand', 'Right Hand'):
|
| 309 |
+
entity, part, cls = 'hand_' + REGION_NAMES[category][value].split()[0].lower(), None, 'hand'
|
| 310 |
+
else:
|
| 311 |
+
group = next((k for k, (vals, _, _) in groups.items() if value in vals), None)
|
| 312 |
+
entity = group or f'unknown_region_{value}'
|
| 313 |
+
cls = groups[group][2] if group else None
|
| 314 |
+
part = f'region_{value}' if group and len(groups[group][0]) > 1 else None
|
| 315 |
+
ensure_object(entity, frames[f]['component_sources']['segment'], cls)
|
| 316 |
+
if part:
|
| 317 |
+
objects[entity].setdefault('parts', {})[part] = {'part_id': part, 'parent_id': None,
|
| 318 |
+
'has_model': False, 'mesh_ref': None, 'source_region_code': value, 'name': REGION_NAMES[category].get(value)}
|
| 319 |
+
labels.append(dict(mask_value=value, category_id=cls, entity_id=entity,
|
| 320 |
+
part_id=part, source_instance_id=value,
|
| 321 |
+
source_attributes={'region_name': REGION_NAMES[category].get(value)}))
|
| 322 |
+
else:
|
| 323 |
+
mask = np.zeros((height, width), np.uint16)
|
| 324 |
+
mappings.append(dict(frame_index=f, labels=labels))
|
| 325 |
+
yield mask
|
| 326 |
+
view.raster('segment', masks(), mask_valid, loc, mappings)
|
| 327 |
+
view.meta['components']['segment']['coverage'] = {'kind': 'unknown'}
|
| 328 |
+
if any(label['part_id'] for row in mappings for label in row['labels']):
|
| 329 |
+
view.meta['components']['segment']['segmentation_type'] = 'part'
|
| 330 |
+
else:
|
| 331 |
+
view.absent('segment', 'No native segmentation for this source sequence')
|
| 332 |
+
records = {}
|
| 333 |
+
for f, name in pose_members.items():
|
| 334 |
+
if f >= n:
|
| 335 |
+
continue
|
| 336 |
+
data = json.loads(read_annotation(annz, name))
|
| 337 |
+
# isEffective is not used to erase existing numerical annotations.
|
| 338 |
+
source_records = data.get('dataList', data.get('objects'))
|
| 339 |
+
if source_records is None:
|
| 340 |
+
raise ValueError('unrecognized source object annotation structure')
|
| 341 |
+
if category == 2 and source_records and (len(source_records) != 1 or
|
| 342 |
+
source_records[0].get('id') != 1 or source_records[0].get('label') != 'Watercup'):
|
| 343 |
+
raise ValueError('C2 native pose differs from the verified one-object target; cannot map to mask region 1')
|
| 344 |
+
label_counts = Counter(record['label'] for record in source_records)
|
| 345 |
+
per_frame = set()
|
| 346 |
+
for record_index, record in enumerate(source_records):
|
| 347 |
+
label = record['label']
|
| 348 |
+
group = definition['objmap'].get(label)
|
| 349 |
+
# Pinned official ObjTracking reads dataList[0] with segmentation label 1.
|
| 350 |
+
source_primary = category == 2 and record_index == 0 and record.get('id') == 1 and group == 'a'
|
| 351 |
+
ambiguous = group is not None and sum(g[2] == groups[group][2] for g in groups.values()) > 1 and not source_primary
|
| 352 |
+
ambiguous = ambiguous or (label_counts[label] > 1 and not source_primary) or group is None
|
| 353 |
+
entity = f'pose_frame_{f}_{record_index}' if ambiguous else group
|
| 354 |
+
ensure_object(entity, locator(paths['annotations'], name, record=record_index),
|
| 355 |
+
groups[group][2] if group else None, frame=f if ambiguous else None, source_id=record.get('id'))
|
| 356 |
+
if ambiguous:
|
| 357 |
+
view.build['unresolved'].append({'component': entity, 'status': 'source_semantics_unverified',
|
| 358 |
+
'reason': 'Source pose retained with frame identity; no guessed association to same-class mask instances'})
|
| 359 |
+
label_key = (entity, label)
|
| 360 |
+
if label_key in per_frame:
|
| 361 |
+
raise ValueError(f'ambiguous repeated object label {label}; source identity must be resolved')
|
| 362 |
+
per_frame.add(label_key)
|
| 363 |
+
records.setdefault(label_key, {})[f] = (record, locator(paths['annotations'], name, record=record.get('id')))
|
| 364 |
+
if category == 2 and any(entity == 'a' for entity, _ in records):
|
| 365 |
+
view.build['validation'].append({'component': 'C2_source_pose_mask_identity',
|
| 366 |
+
'rule': 'Official ObjTracking process_data.py reads dataList[0] with semantic mask label 1',
|
| 367 |
+
'source_revision': 'afa7bf37b02b7e33cf245acd08b98c207ccc175c',
|
| 368 |
+
'source_pose_id': 1, 'mask_value': 1, 'matched_frames': sum(len(by_frame) for (entity, _), by_frame in records.items() if entity == 'a')})
|
| 369 |
+
for (entity, label), by_frame in records.items():
|
| 370 |
+
part_labels = [k[1] for k in records if k[0] == entity]
|
| 371 |
+
articulated = definition['cad'].startswith('articulated/') and entity == definition['groups'][0][0]
|
| 372 |
+
part = 'pose_' + re.sub(r'[^a-zA-Z0-9_]', '_', label) if articulated or len(part_labels) > 1 else None
|
| 373 |
+
base = f'annotation/object/{entity}'
|
| 374 |
+
if part:
|
| 375 |
+
base += '/parts/' + part
|
| 376 |
+
objects[entity].setdefault('parts', {})[part] = dict(part_id=part, parent_id=None,
|
| 377 |
+
has_model=False, mesh_ref=None, source_label=label)
|
| 378 |
+
poses, valid = np.full((n, 4, 4), np.nan, np.float32), np.zeros(n, bool)
|
| 379 |
+
dimensions = np.full((n, 3), np.nan, np.float32)
|
| 380 |
+
dv = np.zeros(n, bool)
|
| 381 |
+
for f, (record, _) in by_frame.items():
|
| 382 |
+
if all(k in record for k in ('rotation', 'center')):
|
| 383 |
+
poses[f] = np.eye(4)
|
| 384 |
+
poses[f, :3, :3] = Rotation.from_euler('XYZ', [record['rotation'][k] for k in ('x', 'y', 'z')]).as_matrix()
|
| 385 |
+
poses[f, :3, 3] = [record['center'][k] for k in ('x', 'y', 'z')]
|
| 386 |
+
valid[f] = True
|
| 387 |
+
if 'dimensions' in record:
|
| 388 |
+
dimensions[f] = [record['dimensions'][k] for k in ('length', 'width', 'height')]
|
| 389 |
+
dv[f] = True
|
| 390 |
+
key = entity + ('_' + part if part else '')
|
| 391 |
+
view.tensor('pose_' + key, 'transform/se3/v1' if part else 'object/rigid/v1', base + '/pose.pt', poses, valid,
|
| 392 |
+
['T', 'row', 'column'], loc, convention='T_camera_from_part' if part else 'T_camera_from_object',
|
| 393 |
+
unit='m', source_label=label, source_euler_order='XYZ',
|
| 394 |
+
definition='https://github.com/hoi4d/ObjTracking/blob/main/process_data.py')
|
| 395 |
+
if dv.any():
|
| 396 |
+
view.tensor('dimensions_' + key, 'object/dimensions/v1', base + '/dimensions.pt', dimensions, dv,
|
| 397 |
+
['T', 'dimension'], loc, dimensions_semantics='source_unspecified', unit='m', scale_applied_to_mesh=False)
|
| 398 |
+
if cadz:
|
| 399 |
+
primary = definition['groups'][0][0]
|
| 400 |
+
if category != 2 and sum(g[2] == category for g in groups.values()) > 1:
|
| 401 |
+
primary = 'source_cad_instance'
|
| 402 |
+
instance = int(re.search(r'/N(\d+)/', seq)[1])
|
| 403 |
+
mesh_prefix = f'HOI4D_CAD_Model_for_release/{definition["cad"]}/{instance:03d}'
|
| 404 |
+
candidates = [name for name in cadz.namelist() if not name.endswith('/') and
|
| 405 |
+
(name == mesh_prefix + '.obj' or name.startswith(mesh_prefix + '/'))]
|
| 406 |
+
if candidates:
|
| 407 |
+
# Retain OBJ material/texture dependencies beside their original names.
|
| 408 |
+
queue = list(candidates)
|
| 409 |
+
for name in queue:
|
| 410 |
+
if Path(name).suffix.lower() not in ('.obj', '.mtl'):
|
| 411 |
+
continue
|
| 412 |
+
for line in cadz.read(name).decode().splitlines():
|
| 413 |
+
fields = shlex.split(line, comments=True)
|
| 414 |
+
if not fields:
|
| 415 |
+
continue
|
| 416 |
+
refs = fields[1:] if fields[0] == 'mtllib' else ([fields[-1]] if
|
| 417 |
+
fields[0].startswith('map_') or fields[0] in ('bump', 'norm', 'disp', 'decal') else [])
|
| 418 |
+
for ref in refs:
|
| 419 |
+
dependency = posixpath.normpath(posixpath.join(posixpath.dirname(name), ref))
|
| 420 |
+
if dependency not in cadz.NameToInfo:
|
| 421 |
+
raise ValueError(f'missing CAD dependency: {dependency}')
|
| 422 |
+
if dependency not in candidates:
|
| 423 |
+
candidates.append(dependency)
|
| 424 |
+
queue.append(dependency)
|
| 425 |
+
ensure_object(primary, locator(paths['cad'], mesh_prefix), category)
|
| 426 |
+
asset_dir = view.path / f'annotation/object/{primary}/assets'
|
| 427 |
+
asset_refs = []
|
| 428 |
+
for name in candidates:
|
| 429 |
+
relative = posixpath.relpath(name, mesh_prefix if definition['cad'].startswith('articulated/') else posixpath.dirname(mesh_prefix))
|
| 430 |
+
dest = safe_member(asset_dir, relative)
|
| 431 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 432 |
+
dest.write_bytes(cadz.read(name))
|
| 433 |
+
ref = dest.relative_to(view.path).as_posix()
|
| 434 |
+
if dest.suffix.lower() == '.obj':
|
| 435 |
+
asset_key = re.sub(r'[^a-zA-Z0-9_]', '_', relative)
|
| 436 |
+
view.component('mesh_' + primary + '_' + asset_key, 'mesh/obj/v1', ref, ['vertex'],
|
| 437 |
+
locator(paths['cad'], name), unit='m', valid=True,
|
| 438 |
+
scale_applied_to_mesh=False, dimensions_semantics='source_unspecified')
|
| 439 |
+
asset_refs.append(ref)
|
| 440 |
+
if definition['cad'].startswith('articulated/'):
|
| 441 |
+
part_id = 'asset_' + asset_key
|
| 442 |
+
objects[primary].setdefault('parts', {})[part_id] = dict(part_id=part_id,
|
| 443 |
+
parent_id=None, has_model=True, mesh_ref=ref, source_asset=relative,
|
| 444 |
+
note='Source asset; correspondence to motion part labels remains unverified')
|
| 445 |
+
for asset_ref in asset_refs:
|
| 446 |
+
mesh_check = check_mesh(view.path / asset_ref, asset_dir)
|
| 447 |
+
view.build['validation'].append({'component': asset_ref, **mesh_check,
|
| 448 |
+
'unit_basis': 'official ObjTracking loads source canonical CAD without scaling in metre camera coordinates',
|
| 449 |
+
'geometric_acceptance': 'physical dimensions-to-mesh relation remains source_unspecified'})
|
| 450 |
+
metadata_path = view.path / f'annotation/object/{primary}/metainfo.json'
|
| 451 |
+
metadata = json.loads(metadata_path.read_text())
|
| 452 |
+
metadata.update(has_model=bool(asset_refs), asset_refs=asset_refs)
|
| 453 |
+
if definition['cad'].startswith('rigid/') and len(asset_refs) == 1:
|
| 454 |
+
metadata['mesh_ref'] = asset_refs[0]
|
| 455 |
+
json_write(metadata_path, metadata)
|
| 456 |
+
if definition['cad'].startswith('articulated/'):
|
| 457 |
+
view.build['unresolved'].append({'component': 'object_part_asset_association',
|
| 458 |
+
'status': 'source_semantics_unverified',
|
| 459 |
+
'reason': 'All source assets and motion labels retained, but no guessed correspondence or joint_state'})
|
| 460 |
+
for entity, info in objects.items():
|
| 461 |
+
if 'parts' in info:
|
| 462 |
+
ref = f'annotation/object/{entity}/articulation.json'
|
| 463 |
+
json_write(view.path / ref, {'parts': list(info['parts'].values()), 'joints': [],
|
| 464 |
+
'hierarchy_semantics': 'semantic_containment',
|
| 465 |
+
'note': 'Unassociated source region, motion and asset nodes; original CAD trees retained in assets'})
|
| 466 |
+
view.component('articulation_' + entity, 'object/articulated/v1', ref, [], loc)
|
| 467 |
+
meta_path = view.path / f'annotation/object/{entity}/metainfo.json'
|
| 468 |
+
metadata = json.loads(meta_path.read_text())
|
| 469 |
+
metadata['articulation_ref'] = ref
|
| 470 |
+
json_write(meta_path, metadata)
|
| 471 |
+
if depth is not None:
|
| 472 |
+
dpath, dloc = depth
|
| 473 |
+
dmeta = probe(dpath)
|
| 474 |
+
if [dmeta['width'], dmeta['height']] != view.meta['camera']['image_size']:
|
| 475 |
+
raise ValueError('HOI4D depth grid differs from RGB')
|
| 476 |
+
if dmeta['pix_fmt'] != 'gray16le':
|
| 477 |
+
raise ValueError('unexpected HOI4D depth pixel format')
|
| 478 |
+
width, height = view.meta['camera']['image_size']
|
| 479 |
+
raw = work / 'depth.raw'
|
| 480 |
+
limits = ['-frames:v', str(n)] if args.max_frames else []
|
| 481 |
+
run(decode_args(dpath, 'gray16le') + limits + ['-y', str(raw)])
|
| 482 |
+
if raw.stat().st_size != n * width * height * 2:
|
| 483 |
+
raise ValueError('depth/RGB frame count or grid mismatch')
|
| 484 |
+
def depths():
|
| 485 |
+
with raw.open('rb') as inp:
|
| 486 |
+
for _ in range(n):
|
| 487 |
+
yield np.frombuffer(inp.read(width * height * 2), '<u2').reshape(height, width).astype(np.float32) / 1000
|
| 488 |
+
view.raster('depth', depths(), None, dloc | {'conversion': 'registered millimetre camera-Z to metres'})
|
| 489 |
+
else:
|
| 490 |
+
if find_file(args.root, 'DEPTH'):
|
| 491 |
+
raise ValueError('DEPTH source exists, but no matching depth video was found')
|
| 492 |
+
view.absent('depth', 'Depth source not downloaded', 'not_downloaded')
|
| 493 |
+
return view.finish()
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
def main(argv=None):
|
| 497 |
+
p = parser('HOI4D', __doc__)
|
| 498 |
+
p.set_defaults(release_id='shared-v1.0')
|
| 499 |
+
# Four workers reached 21 observed OS threads including timing; stay below the 24-thread budget.
|
| 500 |
+
p.add_argument('--workers', type=int, choices=range(1, 5), default=1,
|
| 501 |
+
help='Independent views in parallel, 1..4; codec/BLAS threads fixed at 1')
|
| 502 |
+
p.add_argument('--tasks', help='Comma-separated substrings of source sequence paths')
|
| 503 |
+
p.add_argument('--sessions', help='Comma-separated sessions')
|
| 504 |
+
p.add_argument('--categories', help='Comma-separated category numbers')
|
| 505 |
+
args = p.parse_args(argv)
|
| 506 |
+
if args.views and args.views != 'ego':
|
| 507 |
+
p.error('HOI4D source camera ID is ego')
|
| 508 |
+
paths = {key: find_file(args.root, name) for key, name in {
|
| 509 |
+
'release': 'HOI4D_release.zip', 'annotations': 'HOI4D_annotations.zip', 'hand': 'HOI4D_Hand_pose.zip',
|
| 510 |
+
'camera': 'camera_params.zip', 'cad': 'HOI4D_CAD_Model_for_release.zip'}.items()}
|
| 511 |
+
if not paths['release'] or not paths['annotations']:
|
| 512 |
+
p.error('HOI4D release and annotation ZIPs are required')
|
| 513 |
+
out = release(args, 'HOI4D')
|
| 514 |
+
mapping = Path(__file__).resolve().parent.parent / 'docs/hoi4d-RAW_TO_SHARED.md'
|
| 515 |
+
published_mapping = out / 'doc/RAW_TO_SHARED.md'
|
| 516 |
+
if published_mapping.exists() and published_mapping.read_bytes() != mapping.read_bytes():
|
| 517 |
+
raise ValueError('RAW_TO_SHARED.md changed; choose a new release-id')
|
| 518 |
+
if not published_mapping.exists():
|
| 519 |
+
shutil.copyfile(mapping, published_mapping)
|
| 520 |
+
torch.set_num_threads(1)
|
| 521 |
+
models = mano_models(args.mano_dir)
|
| 522 |
+
with ExitStack() as stack, tempfile.TemporaryDirectory(prefix='hoi4d-depth-') as wd:
|
| 523 |
+
archives = {key: stack.enter_context(zipfile.ZipFile(path)) if path else None for key, path in paths.items()}
|
| 524 |
+
sequences = sorted(name.removeprefix('HOI4D_release/').removesuffix('/align_rgb/image.mp4')
|
| 525 |
+
for name in archives['release'].namelist() if name.endswith('/align_rgb/image.mp4'))
|
| 526 |
+
if args.tasks:
|
| 527 |
+
sequences = [s for s in sequences if any(token in s for token in args.tasks.split(','))]
|
| 528 |
+
if args.sessions:
|
| 529 |
+
sequences = [s for s in sequences if s.split('/')[0] in args.sessions.split(',')]
|
| 530 |
+
if args.categories:
|
| 531 |
+
sequences = [s for s in sequences if re.search(r'/C(\d+)/', s)[1] in args.categories.split(',')]
|
| 532 |
+
if args.limit:
|
| 533 |
+
sequences = sequences[:args.limit]
|
| 534 |
+
if not sequences:
|
| 535 |
+
p.error('no matching source sequences')
|
| 536 |
+
depths, _ = extract_depths(args.root, sequences, Path(wd))
|
| 537 |
+
worker = threading.local()
|
| 538 |
+
worker_stacks = []
|
| 539 |
+
def init_worker():
|
| 540 |
+
owned = ExitStack()
|
| 541 |
+
try:
|
| 542 |
+
# ZipFile.read mutates a shared seek position: never share a handle across workers.
|
| 543 |
+
worker.archives = {key: owned.enter_context(zipfile.ZipFile(path)) if path else None
|
| 544 |
+
for key, path in paths.items()}
|
| 545 |
+
index_frames(worker.archives['annotations'])
|
| 546 |
+
if worker.archives['hand']:
|
| 547 |
+
index_frames(worker.archives['hand'])
|
| 548 |
+
except BaseException:
|
| 549 |
+
owned.close()
|
| 550 |
+
raise
|
| 551 |
+
worker_stacks.append(owned)
|
| 552 |
+
def convert_one(seq):
|
| 553 |
+
source = archives if args.workers == 1 else worker.archives
|
| 554 |
+
name = seq.replace('/', '_')
|
| 555 |
+
with sequence_dir(out, name) as target:
|
| 556 |
+
report = convert_sequence(seq, args, target / 'ego', source['release'], source['annotations'],
|
| 557 |
+
source['hand'], source['camera'], source['cad'], paths, models, depths.get(seq))
|
| 558 |
+
build_record(out, name, {'ego': report})
|
| 559 |
+
return seq
|
| 560 |
+
if args.workers == 1:
|
| 561 |
+
for seq in map(convert_one, sequences):
|
| 562 |
+
print(f'Converted {seq}', flush=True)
|
| 563 |
+
else:
|
| 564 |
+
try:
|
| 565 |
+
with ThreadPoolExecutor(max_workers=args.workers, initializer=init_worker) as pool:
|
| 566 |
+
for seq in pool.map(convert_one, sequences):
|
| 567 |
+
print(f'Converted {seq}', flush=True)
|
| 568 |
+
finally:
|
| 569 |
+
for owned in worker_stacks:
|
| 570 |
+
owned.close()
|
| 571 |
+
return 0
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
if __name__ == '__main__':
|
| 575 |
+
raise SystemExit(main())
|
| 576 |
+
|
| 577 |
+
# TODO(v2.0): 旧 bbox IoU 实例重分配属于推断,注释保留,不在 v1.0 执行。
|
| 578 |
+
# # 同类多实例(C8 双桶 / C2 双杯):2dBox 可用时按 IoU 复核归属
|
| 579 |
+
# cls = next(x[3] for x in cat["groups"] if x[0] == gk)
|
| 580 |
+
# sibs = [g for g in cat["groups"]
|
| 581 |
+
# if g[0] != gk and cls is not None and g[3] == cls]
|
| 582 |
+
# box = (d.get("2dBox") or {}).get("camera1")
|
| 583 |
+
# box = (box[0][0], box[0][1], box[1][0], box[1][1]) \
|
| 584 |
+
# if box and len(box) == 2 else None
|
| 585 |
+
# if box is not None and sibs:
|
| 586 |
+
# gvals = next(x[1] for x in cat["groups"] if x[0] == gk)
|
| 587 |
+
# best, best_iou = gk, box_iou(box, bbox_of(mask, gvals))
|
| 588 |
+
# for s in sibs:
|
| 589 |
+
# if ("obj", s[0]) not in tid_of_group:
|
| 590 |
+
# continue
|
| 591 |
+
# i = box_iou(box, bbox_of(mask, s[1]))
|
| 592 |
+
# if i > best_iou + 0.1 and i > 0.15:
|
| 593 |
+
# best, best_iou = s[0], i
|
| 594 |
+
# if best != gk:
|
| 595 |
+
# gk, iou_fixups = best, iou_fixups + 1
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/convert_visor_v1.0.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""VISOR source polygons and contact → CONTRACT.md v1.0, without rasterization or side inference."""
|
| 3 |
+
from collections import Counter
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
import re
|
| 7 |
+
import shutil
|
| 8 |
+
import tempfile
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import zipfile
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from warehouse_v1_0 import (View, build_record, find_file, jsonl_write, locator, parser,
|
| 16 |
+
release, roots, sequence_dir, source)
|
| 17 |
+
|
| 18 |
+
FRAME = re.compile(r'frame_(\d+)')
|
| 19 |
+
HAND = {300: 'left', 301: 'right'}
|
| 20 |
+
GLOVE = {303: 'left', 304: 'right'}
|
| 21 |
+
STATES = {'hand-not-in-contact': 'negative', 'glove-not-in-contact': 'negative',
|
| 22 |
+
'none-of-the-above': 'target_unannotated', 'inconclusive': 'unknown'}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def hand_side(ann):
|
| 26 |
+
if ann['class_id'] in HAND:
|
| 27 |
+
return HAND[ann['class_id']]
|
| 28 |
+
if ann['class_id'] not in (60, 303, 304):
|
| 29 |
+
return None
|
| 30 |
+
raw = ann.get('on_which_hand')
|
| 31 |
+
raw = raw if isinstance(raw, list) else [raw]
|
| 32 |
+
sides = set()
|
| 33 |
+
for item in raw:
|
| 34 |
+
if item == 'left hand':
|
| 35 |
+
sides.add('left')
|
| 36 |
+
if item in ('right hand', 'rigth hand'):
|
| 37 |
+
sides.add('right')
|
| 38 |
+
if len(sides) == 1:
|
| 39 |
+
return next(iter(sides))
|
| 40 |
+
if not sides and ann['class_id'] in GLOVE:
|
| 41 |
+
return GLOVE[ann['class_id']]
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def convert_video(video, split, annotation, ann_loc, rgb_zip, rgb_loc, mapping, args, target):
|
| 46 |
+
indexed = sorted(enumerate(annotation['video_annotations']), key=lambda row: int(FRAME.search(row[1]['image']['name'])[1]))
|
| 47 |
+
if args.max_frames:
|
| 48 |
+
indexed = indexed[:args.max_frames]
|
| 49 |
+
if len({row['image']['name'] for _, row in indexed}) != len(indexed):
|
| 50 |
+
raise ValueError('duplicate VISOR frame')
|
| 51 |
+
keys = lambda row, ann: (row['image']['subsequence'], ann['class_id'], ann['name'])
|
| 52 |
+
collisions = set()
|
| 53 |
+
for _, row in indexed:
|
| 54 |
+
collisions.update(key for key, number in Counter(keys(row, a) for a in row['annotations']).items() if number > 1)
|
| 55 |
+
frames, paths = [], []
|
| 56 |
+
with tempfile.TemporaryDirectory(prefix='visor-rgb-') as wd, zipfile.ZipFile(rgb_zip) as z:
|
| 57 |
+
work = Path(wd)
|
| 58 |
+
for original_index, row in indexed:
|
| 59 |
+
name = row['image']['name']
|
| 60 |
+
data = z.read(name)
|
| 61 |
+
path = work / Path(name).name
|
| 62 |
+
path.write_bytes(data)
|
| 63 |
+
paths.append(path)
|
| 64 |
+
loc = rgb_loc | {'nested_member': name, 'sha256': hashlib.sha256(data).hexdigest()}
|
| 65 |
+
frames.append(dict(source_frame_id=int(FRAME.search(name)[1]), source_locator=loc,
|
| 66 |
+
source_image=row['image'], original_frame_name=mapping.get(name),
|
| 67 |
+
annotation_matches={'segment': dict(source_frame_id=name, source_timestamp_ns=None,
|
| 68 |
+
clock_domain=None, match_method='index_map', delta_ns=None,
|
| 69 |
+
source_locator=ann_loc | {'record': f'video_annotations[{original_index}]'})}))
|
| 70 |
+
view = View(target, 'EPIC-KITCHENS-VISOR', args.release_id, video, 'ego', frames, sampling='sparse', split=split)
|
| 71 |
+
view.valid_rules = {
|
| 72 |
+
'segment': 'Selected sparse annotation frame present; all source polygons finite with at least three vertices and entity mapping valid',
|
| 73 |
+
'relations': 'At least one source in_contact_object value present; positive targets resolve in the same frame; unknown is an explicit usable status',
|
| 74 |
+
}
|
| 75 |
+
view.full_jpeg = getattr(args, 'jpeg_full_check', False)
|
| 76 |
+
view.meta.update(view_type='ego', split_scheme='VISOR_GroundTruth_SparseAnnotations', split_source_locator=ann_loc)
|
| 77 |
+
view.meta['sampling']['selection'] = {'representation': 'official sparse annotations', 'max_frames': args.max_frames}
|
| 78 |
+
view.rgb(paths, rgb_loc)
|
| 79 |
+
entities = {}
|
| 80 |
+
polygons, mappings, relations, relation_valid = [], [], [], []
|
| 81 |
+
for f, (original_index, row) in enumerate(indexed):
|
| 82 |
+
frame_loc = ann_loc | {'record': f'video_annotations[{original_index}]'}
|
| 83 |
+
id_map, labels, polys = {}, [], []
|
| 84 |
+
for code, ann in enumerate(row['annotations'], 1):
|
| 85 |
+
if code >= 65535:
|
| 86 |
+
raise ValueError('too many source instances')
|
| 87 |
+
sid = ann['id']
|
| 88 |
+
if sid in id_map:
|
| 89 |
+
raise ValueError('duplicate source instance ID within a frame')
|
| 90 |
+
side = hand_side(ann)
|
| 91 |
+
if side is not None:
|
| 92 |
+
entity = 'hand_' + side
|
| 93 |
+
else:
|
| 94 |
+
key = keys(row, ann)
|
| 95 |
+
identity = key + (sid, row['image']['name']) if key in collisions else key
|
| 96 |
+
entity = 'object_' + hashlib.sha256(json.dumps(identity).encode()).hexdigest()[:20]
|
| 97 |
+
if entity not in entities:
|
| 98 |
+
scope = 'frame' if key in collisions else 'subsequence'
|
| 99 |
+
scope_id = f'{video}:{row["image"]["name"]}' if scope == 'frame' else f'{video}:{key[0]}'
|
| 100 |
+
view.object(entity, frame_loc | {'source_instance_id': sid}, scope, scope_id,
|
| 101 |
+
category_id=ann['class_id'], name=ann['name'],
|
| 102 |
+
association_basis='source_frame_instance' if scope == 'frame' else 'official_subsequence_entity_name')
|
| 103 |
+
entities[entity] = True
|
| 104 |
+
id_map[sid] = entity
|
| 105 |
+
for polygon in ann.get('segments', []):
|
| 106 |
+
p = np.asarray(polygon)
|
| 107 |
+
if p.ndim != 2 or p.shape[1] != 2 or len(p) < 3 or not np.isfinite(p).all():
|
| 108 |
+
raise ValueError(f'invalid source polygon {sid}')
|
| 109 |
+
polys.append(dict(mask_value=code, polygons=ann.get('segments', [])))
|
| 110 |
+
labels.append(dict(mask_value=code, category_id=ann['class_id'], entity_id=entity,
|
| 111 |
+
part_id=None, source_instance_id=sid,
|
| 112 |
+
source_attributes={k: v for k, v in ann.items() if k != 'segments'}))
|
| 113 |
+
rr = []
|
| 114 |
+
provided = False
|
| 115 |
+
for ann in row['annotations']:
|
| 116 |
+
raw = ann.get('in_contact_object')
|
| 117 |
+
values = raw if isinstance(raw, list) else [raw]
|
| 118 |
+
for value in values:
|
| 119 |
+
if value is None:
|
| 120 |
+
continue
|
| 121 |
+
provided = True
|
| 122 |
+
status = STATES.get(value)
|
| 123 |
+
obj = None
|
| 124 |
+
if status is None:
|
| 125 |
+
if value not in id_map:
|
| 126 |
+
raise ValueError(f'unresolved source contact target {value} in {video} frame {f}')
|
| 127 |
+
status, obj = 'positive', id_map[value]
|
| 128 |
+
rr.append(dict(relation_type='contact', subject_id=id_map[ann['id']], object_id=obj,
|
| 129 |
+
status=status, source_value=value, source_locator=frame_loc | {'source_instance_id': ann['id']},
|
| 130 |
+
provenance=source('Resolve source contact ID against instances in this frame')))
|
| 131 |
+
polygons.append(dict(frame_index=f, instances=polys))
|
| 132 |
+
mappings.append(dict(frame_index=f, labels=labels))
|
| 133 |
+
relations.append(dict(frame_index=f, relations=rr))
|
| 134 |
+
relation_valid.append(provided)
|
| 135 |
+
jsonl_write(view.path / 'annotation/segment/polygons.jsonl', polygons)
|
| 136 |
+
jsonl_write(view.path / 'annotation/segment/instances.jsonl', mappings)
|
| 137 |
+
torch.save(torch.ones(len(frames), dtype=torch.bool, device='cpu'), view.path / 'annotation/segment/mask_valid.pt')
|
| 138 |
+
view.component('segment', 'segment/instance_polygons/v1', 'annotation/segment/polygons.jsonl', ['T'], ann_loc,
|
| 139 |
+
valid_ref='annotation/segment/mask_valid.pt', valid_axes=['T'], segmentation_type='instance',
|
| 140 |
+
mapping_ref='annotation/segment/instances.jsonl', coverage={'kind': 'unknown', 'exhaustive_ref': 'annotation/segment/instances.jsonl'})
|
| 141 |
+
view.relations(relations, relation_valid, ann_loc)
|
| 142 |
+
for component in ('depth', 'mano', 'keypoints_uv', 'keypoints_xyz', 'intrinsic', 'extrinsic'):
|
| 143 |
+
view.absent(component, 'Not provided by VISOR sparse source annotations')
|
| 144 |
+
return view.finish()
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def main(argv=None):
|
| 148 |
+
p = parser('EPIC-KITCHENS-VISOR', __doc__)
|
| 149 |
+
p.add_argument('--videos', help='Comma-separated video names')
|
| 150 |
+
p.add_argument('--splits', default='train,val')
|
| 151 |
+
args = p.parse_args(argv)
|
| 152 |
+
wanted = set(args.videos.split(',')) if args.videos else None
|
| 153 |
+
splits = set(args.splits.split(','))
|
| 154 |
+
if not splits <= {'train', 'val'}:
|
| 155 |
+
p.error('only annotated train/val splits are available')
|
| 156 |
+
out = release(args, 'EPIC-KITCHENS-VISOR')
|
| 157 |
+
archive = find_file(args.root, 'EPIC-KITCHENS VISOR.zip')
|
| 158 |
+
with tempfile.TemporaryDirectory(prefix='visor-source-') as wd:
|
| 159 |
+
work = Path(wd)
|
| 160 |
+
if archive:
|
| 161 |
+
with zipfile.ZipFile(archive) as z:
|
| 162 |
+
suffix = 'GroundTruth-SparseAnnotations/annotations/'
|
| 163 |
+
members = [n for n in z.namelist() if suffix in n and n.endswith('.json')]
|
| 164 |
+
prefix = members[0].split(suffix)[0]
|
| 165 |
+
fm = json.loads(z.read(prefix + 'frame_mapping.json'))
|
| 166 |
+
done = 0
|
| 167 |
+
for member in sorted(members):
|
| 168 |
+
split, filename = member.split(suffix)[1].split('/')
|
| 169 |
+
video = Path(filename).stem
|
| 170 |
+
if split not in splits or wanted and video not in wanted:
|
| 171 |
+
continue
|
| 172 |
+
data = z.read(member)
|
| 173 |
+
rgb_member = prefix + f'GroundTruth-SparseAnnotations/rgb_frames/{split}/{video.split("_")[0]}/{video}.zip'
|
| 174 |
+
rgb_zip = work / (video + '.zip')
|
| 175 |
+
with z.open(rgb_member) as inp, rgb_zip.open('wb') as dest:
|
| 176 |
+
shutil.copyfileobj(inp, dest)
|
| 177 |
+
with sequence_dir(out, video) as dest:
|
| 178 |
+
report = convert_video(video, split, json.loads(data), locator(archive, member, data),
|
| 179 |
+
rgb_zip, locator(archive, rgb_member), fm.get(video, {}), args, dest / 'ego')
|
| 180 |
+
build_record(out, video, {'ego': report})
|
| 181 |
+
rgb_zip.unlink()
|
| 182 |
+
done += 1
|
| 183 |
+
print(f'Converted {video}', flush=True)
|
| 184 |
+
if args.limit and done >= args.limit:
|
| 185 |
+
break
|
| 186 |
+
else:
|
| 187 |
+
root = next((r for r in roots(args.root) if (r / 'GroundTruth-SparseAnnotations').is_dir()), None)
|
| 188 |
+
if root is None:
|
| 189 |
+
p.error('VISOR outer ZIP or extracted source directory not found')
|
| 190 |
+
fm = json.loads((root / 'frame_mapping.json').read_text()) if (root / 'frame_mapping.json').exists() else {}
|
| 191 |
+
done = 0
|
| 192 |
+
for split in sorted(splits):
|
| 193 |
+
for ann in sorted((root / 'GroundTruth-SparseAnnotations/annotations' / split).glob('*.json')):
|
| 194 |
+
video = ann.stem
|
| 195 |
+
if wanted and video not in wanted:
|
| 196 |
+
continue
|
| 197 |
+
rgb = root / f'GroundTruth-SparseAnnotations/rgb_frames/{split}/{video.split("_")[0]}/{video}.zip'
|
| 198 |
+
with sequence_dir(out, video) as dest:
|
| 199 |
+
report = convert_video(video, split, json.loads(ann.read_text()), locator(ann), rgb,
|
| 200 |
+
locator(rgb), fm.get(video, {}), args, dest / 'ego')
|
| 201 |
+
build_record(out, video, {'ego': report})
|
| 202 |
+
done += 1
|
| 203 |
+
if args.limit and done >= args.limit:
|
| 204 |
+
return 0
|
| 205 |
+
if not done:
|
| 206 |
+
p.error('no matching annotated videos found')
|
| 207 |
+
return 0
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
if __name__ == '__main__':
|
| 211 |
+
raise SystemExit(main())
|
| 212 |
+
|
| 213 |
+
# TODO(v2.0): 旧距离猜侧和单层掩码生成仅注释保留;v1.0 不执行。
|
| 214 |
+
# if side is None and len(frame_hands) == 1:
|
| 215 |
+
# # 空间门槛:脱下放在远处的手套不并入(实测双峰 0..25px / ≥44px)
|
| 216 |
+
# hb = frame_hands[0][1]
|
| 217 |
+
# gb = _bbox_of(polys)
|
| 218 |
+
# if hb and gb and _bbox_dist(gb, hb) <= GLOVE60_MERGE_BBOX_DIST:
|
| 219 |
+
# side = frame_hands[0][0]
|
| 220 |
+
# stats["glove60_merged_into_sole_hand"] += 1
|
| 221 |
+
# if side is None:
|
| 222 |
+
# stats["dropped_glove60_unresolved"] += 1
|
| 223 |
+
# id_disp[mid] = ("dropped", "glove60")
|
| 224 |
+
# continue
|
| 225 |
+
# def rasterize_and_encode(vdir, frames, frame_draw, zip_path, n, stats):
|
| 226 |
+
# """流式读 zip 内 jpg + 光栅化多边形 → rgb.mkv / mask.mkv;返回 (w, h)。"""
|
| 227 |
+
# from PIL import Image, ImageDraw
|
| 228 |
+
#
|
| 229 |
+
# with zipfile.ZipFile(zip_path) as zf:
|
| 230 |
+
# member_of = {}
|
| 231 |
+
# for nm in zf.namelist():
|
| 232 |
+
# member_of[os.path.basename(nm)] = nm
|
| 233 |
+
# names = [im["name"] for im in frames]
|
| 234 |
+
# missing = [nm for nm in names if nm not in member_of]
|
| 235 |
+
# if missing:
|
| 236 |
+
# raise RuntimeError(f"{len(missing)} annotated frames missing in zip, "
|
| 237 |
+
# f"e.g. {missing[:3]}")
|
| 238 |
+
# stats["zip_extra_members"] = len(member_of) - len(names)
|
| 239 |
+
#
|
| 240 |
+
# # 首帧定分辨率(官方 1920×1080,实测每帧校验)
|
| 241 |
+
# img0 = Image.open(io.BytesIO(zf.read(member_of[names[0]]))).convert("RGB")
|
| 242 |
+
# w, h = img0.size
|
| 243 |
+
#
|
| 244 |
+
# bin_img = Image.new("L", (w, h), 0)
|
| 245 |
+
# bin_draw = ImageDraw.Draw(bin_img)
|
| 246 |
+
# canvas = np.zeros((h, w), np.uint16)
|
| 247 |
+
# with VideoPipe(vdir / "mask.mkv", w, h, FPS, "mask") as mw, \
|
| 248 |
+
# VideoPipe(vdir / "rgb.mkv", w, h, FPS, "rgb") as rw:
|
| 249 |
+
# for f in range(n):
|
| 250 |
+
# canvas[:] = 0
|
| 251 |
+
# for pid, polys in frame_draw[f]:
|
| 252 |
+
# bin_draw.rectangle((0, 0, w, h), fill=0)
|
| 253 |
+
# for poly in polys:
|
| 254 |
+
# bin_draw.polygon([(float(x), float(y)) for x, y in poly], fill=255)
|
| 255 |
+
# arr = np.asarray(bin_img)
|
| 256 |
+
# canvas[arr > 0] = pid # 后画覆盖先画:物体→手(modal)
|
| 257 |
+
# mw.write(canvas)
|
| 258 |
+
# img = img0 if f == 0 else Image.open(
|
| 259 |
+
# io.BytesIO(zf.read(member_of[names[f]]))).convert("RGB")
|
| 260 |
+
# if img.size != (w, h):
|
| 261 |
+
# raise RuntimeError(f"frame {names[f]}: size {img.size} != {(w, h)}")
|
| 262 |
+
# rw.write(np.asarray(img))
|
| 263 |
+
# n_mask, n_rgb = mw.n, rw.n
|
| 264 |
+
# if (n_rgb, n_mask) != (n, n):
|
| 265 |
+
# raise RuntimeError(f"wrote rgb={n_rgb} mask={n_mask} != {n}")
|
| 266 |
+
# got = (count_frames(vdir / "rgb.mkv"), count_frames(vdir / "mask.mkv"))
|
| 267 |
+
# if got != (n, n):
|
| 268 |
+
# raise RuntimeError(f"encoded rgb={got[0]} mask={got[1]} != {n} (decode verify)")
|
| 269 |
+
# return w, h
|
| 270 |
+
#
|
| 271 |
+
#
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/provenance/operations/prepare-w4-c10.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Preserve completed r1 sequences without re-encoding or touching source files."""
|
| 2 |
+
import datetime
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import shutil
|
| 7 |
+
|
| 8 |
+
old = Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260929-r1')
|
| 9 |
+
new = Path('/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10')
|
| 10 |
+
snapshot = Path('/tmp/h2o-w4-c10-recovery')
|
| 11 |
+
new.mkdir()
|
| 12 |
+
shutil.copytree(snapshot / 'scripts', new / 'frozen-code/scripts')
|
| 13 |
+
shutil.copytree(snapshot / 'docs', new / 'frozen-code/docs')
|
| 14 |
+
shutil.copytree(snapshot / 'tests', new / 'frozen-code/tests')
|
| 15 |
+
release = new / 'H2O/shared-v1.0'
|
| 16 |
+
for directory in ('data', 'doc', 'script', 'script/provenance/r1', 'script/provenance/operations'):
|
| 17 |
+
(release / directory).mkdir(parents=True, exist_ok=True)
|
| 18 |
+
history = release / 'script/provenance/r1'
|
| 19 |
+
shutil.copytree(old / 'H2O/shared-v1.0/script', history / 'script')
|
| 20 |
+
shutil.copytree(old / 'frozen-code/docs', history / 'docs')
|
| 21 |
+
for name in ('full.log', 'full.status', 'run-full.sh'):
|
| 22 |
+
shutil.copy2(old / name, history / name)
|
| 23 |
+
records = []
|
| 24 |
+
for record in sorted((old / 'H2O/shared-v1.0/doc').glob('*.build.json')):
|
| 25 |
+
build = json.loads(record.read_text())
|
| 26 |
+
seq = build['sequence_id']
|
| 27 |
+
assert Path(seq).name == seq and seq not in ('.', '..')
|
| 28 |
+
assert set(build['views']) == {f'cam{i}' for i in range(5)}, seq
|
| 29 |
+
data = old / 'H2O/shared-v1.0/data' / seq
|
| 30 |
+
frames = {}
|
| 31 |
+
for cam in build['views']:
|
| 32 |
+
meta = json.loads((data / cam / 'metainfo.json').read_text())
|
| 33 |
+
frames[cam] = sum(1 for _ in (data / cam / 'camera/frames.jsonl').open())
|
| 34 |
+
assert frames[cam] > 0
|
| 35 |
+
shutil.copytree(data, release / 'data' / seq, copy_function=os.link)
|
| 36 |
+
shutil.copy2(record, release / 'doc' / record.name)
|
| 37 |
+
records.append({'sequence_id': seq, 'frames_by_camera': frames,
|
| 38 |
+
'original_script_sha256': build['scripts']})
|
| 39 |
+
manifest = {'time': datetime.datetime.now().astimezone().isoformat(),
|
| 40 |
+
'source_run': str(old), 'destination_run': str(new),
|
| 41 |
+
'reason': 'User requested four archive workers, ten threads per encoder, no CPU quota',
|
| 42 |
+
'reuse': 'Hard-linked immutable completed views; frames and component source SHA256 rechecked during resume',
|
| 43 |
+
'excluded': 'Unpublished .tmp directories; historical 62-sequence output; failed initial full run',
|
| 44 |
+
'original_runtime_provenance': 'script/provenance/r1', 'sequences': records}
|
| 45 |
+
(release / 'doc/RESTART_PROVENANCE.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
| 46 |
+
for source, target in (('/tmp/h2o-prepare-w4-c10.py', 'provenance/operations/prepare-w4-c10.py'),
|
| 47 |
+
('/tmp/h2o-reconfigure-w4-c10.sh', 'reconfigure-w4-c10.sh'),
|
| 48 |
+
('/tmp/h2o-run-w4-c10.sh', 'run-full.sh')):
|
| 49 |
+
shutil.copy2(source, release / 'script' / target)
|
| 50 |
+
shutil.copy2('/tmp/h2o-run-w4-c10.sh', new / 'run-full.sh')
|
| 51 |
+
shutil.copy2('/tmp/h2o-w4-c10-frozen-tests.log', history.parent / 'worker4-codec10-regression.log')
|
| 52 |
+
print(f'REUSED_SEQUENCES={len(records)} REUSED_VIEWS={sum(len(r["frames_by_camera"]) for r in records)}', flush=True)
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/provenance/operations/retry-w4-c10.sh
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
base=/data/xuzhefeng/Datasets/uni-hoi-h2o-full-20260930-w4-c10
|
| 4 |
+
script="$base/H2O/shared-v1.0/script"
|
| 5 |
+
mkdir -p "$script/provenance/operations" "$script/provenance/startup-failure"
|
| 6 |
+
mv "$script/prepare-w4-c10.py" "$script/provenance/startup-failure/prepare-w4-c10.py"
|
| 7 |
+
cp /tmp/h2o-prepare-w4-c10.py "$script/provenance/operations/prepare-w4-c10.py"
|
| 8 |
+
mv "$base/full.status" "$script/provenance/startup-failure/full.status"
|
| 9 |
+
mv "$base/full.log" "$script/provenance/startup-failure/full.log"
|
| 10 |
+
cp /tmp/h2o-retry-w4-c10.sh "$script/provenance/operations/retry-w4-c10.sh"
|
| 11 |
+
systemd-run --user --scope --unit=h2o-full-w4c10-r2-20260930 -p CPUAccounting=yes /bin/bash "$base/run-full.sh"
|
H2O/shared-v1.0/script/provenance/previous-run/script/provenance/previous-run/script/provenance/r1/docs/CONTRACT.md
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 手物数据仓库统一约定 v1.0
|
| 2 |
+
|
| 3 |
+
格式版本:`hand-warehouse/1.0`。存储约定:`lossless-video-2026-09-18`。
|
| 4 |
+
|
| 5 |
+
范围限于手物交互重建。按本任务纳入的源模态转换,不要求每个数据集填满所有组件。缺失模态、尚未下载、语义未核实分别报告,不能互相替代。
|
| 6 |
+
|
| 7 |
+
本文定义各字段的含义与使用规则,机器可读注册表见 [schema.json](schema.json)。两者互相补充;如有冲突,应先核实并统一定义。
|
| 8 |
+
|
| 9 |
+
## 1. 目录
|
| 10 |
+
|
| 11 |
+
```text
|
| 12 |
+
hand-datasets/
|
| 13 |
+
<dataset_name>/
|
| 14 |
+
raw/
|
| 15 |
+
doc/ # 官方说明、来源与校验记录
|
| 16 |
+
script/ # 官方下载脚本、必要包装脚本
|
| 17 |
+
data/ # 保留原始包,不原地解压或改写
|
| 18 |
+
<dataset_version>/
|
| 19 |
+
doc/ # 发布说明、schema、来源清单
|
| 20 |
+
script/ # 转换、校验脚本及运行配置
|
| 21 |
+
data/
|
| 22 |
+
<sequence_id>/
|
| 23 |
+
<camera_id>/
|
| 24 |
+
metainfo.json
|
| 25 |
+
observation/
|
| 26 |
+
rgb.mkv
|
| 27 |
+
rgb_valid.pt
|
| 28 |
+
depth.mkv # float32 深度的可逆视频编码
|
| 29 |
+
depth_valid.mkv # 逐像素 bool 的无损视频编码
|
| 30 |
+
camera/
|
| 31 |
+
frames.jsonl
|
| 32 |
+
intrinsic.pt
|
| 33 |
+
intrinsic_valid.pt
|
| 34 |
+
extrinsic.pt
|
| 35 |
+
extrinsic_valid.pt
|
| 36 |
+
annotation/
|
| 37 |
+
mano/
|
| 38 |
+
motion.pt
|
| 39 |
+
motion_valid.pt
|
| 40 |
+
visibility.pt
|
| 41 |
+
keypoints/
|
| 42 |
+
uv.pt
|
| 43 |
+
uv_valid.pt
|
| 44 |
+
xyz.pt
|
| 45 |
+
xyz_valid.pt
|
| 46 |
+
visibility.pt # 源数据有时提供
|
| 47 |
+
object/
|
| 48 |
+
<object_id>/
|
| 49 |
+
assets/ # 该物体的网格、材质、纹理及部件资产
|
| 50 |
+
<mesh_id>.obj
|
| 51 |
+
pose.pt
|
| 52 |
+
pose_valid.pt
|
| 53 |
+
visibility.pt
|
| 54 |
+
metainfo.json # 物体身份、类别、mesh、尺寸与部件引用
|
| 55 |
+
articulation.json
|
| 56 |
+
keypoints/
|
| 57 |
+
vertex_part_ids.pt
|
| 58 |
+
joint_state.pt
|
| 59 |
+
joint_state_valid.pt
|
| 60 |
+
parts/<part_id>/pose.pt
|
| 61 |
+
parts/<part_id>/pose_valid.pt
|
| 62 |
+
segment/
|
| 63 |
+
mask.mkv
|
| 64 |
+
mask_valid.pt
|
| 65 |
+
instances.jsonl
|
| 66 |
+
contact/
|
| 67 |
+
relations.jsonl
|
| 68 |
+
<subject_id>__<object_id>/ # 对应实体间的距离/接触区域
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
目录展示可能存在的组件,不要求填满。具体文件、字段和缺省规则分别见后续对应小节。原始包的解压发生在临时工作区,raw 内原始包保持不变。
|
| 72 |
+
|
| 73 |
+
## 2. 相机视图的 metainfo.json
|
| 74 |
+
|
| 75 |
+
### 2.1 顶层字段与发布信息
|
| 76 |
+
|
| 77 |
+
每个相机视图必须有 `metainfo.json`。以下字段除另行说明外均为必填:
|
| 78 |
+
|
| 79 |
+
| 字段 | 填写内容 |
|
| 80 |
+
|---|---|
|
| 81 |
+
| schema_version | 结构版本,本版为 `hand-warehouse/1.0` |
|
| 82 |
+
| dataset_id | 数据集的逻辑标识 |
|
| 83 |
+
| release_id | 本次数据发布版本,对应目录中的 dataset_version |
|
| 84 |
+
| sequence_id | 所属序列或独立图片样本的标识 |
|
| 85 |
+
| camera_id | 当前相机视图标识 |
|
| 86 |
+
| sample_type | `image` 或 `video`,规则见 2.2 |
|
| 87 |
+
| num_frames | 当前视图帧数 T,所有随帧组件按同一时间轴组织 |
|
| 88 |
+
| hand_slots | 固定为 `["left", "right"]`;解剖学左右的使用规则见 5.1 |
|
| 89 |
+
| sampling | 采样类型、源 FPS、帧索引引用及选择策略,见 2.2 |
|
| 90 |
+
| camera | 当前相机模型与图像尺寸,见 2.3 |
|
| 91 |
+
| components | 实际提供的组件及其文件、schema、有效性和来源,见 2.5 |
|
| 92 |
+
| split | `train/val/test/unknown`,划分协议见 2.4 |
|
| 93 |
+
| view_type | 可选,`ego/exo/unknown` |
|
| 94 |
+
|
| 95 |
+
`dataset_version` 是数据发布版本;`schema_version` 是结构版本,两者独立。原始包校验摘要、官方来源和转换配置应记录在发布清单中。解压发生在临时工作区,原始包保持不变。
|
| 96 |
+
|
| 97 |
+
### 2.2 图片、视频与 sampling
|
| 98 |
+
|
| 99 |
+
`sample_type=image`:允许单图 T=1、`sampling.type=single`,也允许将独立图片批量装入一个视频容器,T>1 时 `sampling.type=independent`、`source_fps=null`。分片大小按数据集选择;FreiHAND 默认每片最多 4096 张,训练与评估分开,尾片不补帧。该数量不是其他数据集的强制要求;同批分辨率、相机模型类型及划分协议一致。每行 frames 必须有稳定且唯一的 `sample_id`、原始文件定位;内参、手形状等仍逐帧保留,不能因打包而共享错误的标定或身份。`sequence_id` 在这里仅是批次标识,不代表真实序列;不得按相邻帧推断跟踪、同步或接触延续。源 camera_id、image_variant、split 等随样本变化时放在 frames 的对应字段中。真实采集时间未知则 timestamp_ns=null。合成背景变体不视为真实多相机。
|
| 100 |
+
|
| 101 |
+
`sample_type=video`:`sampling.type=dense/sparse`;`source_fps` 是真实采集 FPS,未知为 null。非连续取样必须保留源帧号和已知源时间,不可用采样后索引除以 FPS 冒充源时间。可另记采样策略与步长。
|
| 102 |
+
|
| 103 |
+
shared 可以仅存所选 RGB 帧对应的数据。OakInk2 图像/动捕不同采样率时用 annotation_matches 明确映射;不要求将未采样动捕点硬塞进 T。多视角身份和源同步关系要保留;选择了哪些帧/相机及原因写在 sampling 中。
|
| 104 |
+
|
| 105 |
+
`sampling.frames_ref` 指向 `camera/frames.jsonl`。帧号、逐帧时间、同步与标注匹配记录的结构见 4.1;MKV 封装时间的约定见 3.1。
|
| 106 |
+
|
| 107 |
+
### 2.3 camera 模型声明
|
| 108 |
+
|
| 109 |
+
`camera` 至少包含 `model`、`schema_id`、`image_size:[W,H]`。模型未知使用 `unknown` 和 `null`,不猜成针孔。实际内参、畸变及外参数组放在 `camera/`,各模型的固定结构见第 4 节。
|
| 110 |
+
|
| 111 |
+
### 2.4 split 与划分协议
|
| 112 |
+
|
| 113 |
+
保留上游划分,不将同一采集序列的相邻帧随意拆到不同集合。
|
| 114 |
+
|
| 115 |
+
有官方划分时必填 split_scheme 和 split_source_locator,split_scheme 区分如 Dex-YCB s0/s1、ARCTIC P1/P2 等选定协议;不知道时 split=unknown 并给理由,不凭空分配。每发布可选择一种协议;存在逐帧差异时 frames 中的 split 覆盖视图默认值,并登记其来源。
|
| 116 |
+
|
| 117 |
+
### 2.5 components 组件登记
|
| 118 |
+
|
| 119 |
+
组件表的键是本发布内唯一名称,例如 `rgb`、`depth`、`mano`、`keypoints_uv`。每个已提供组件声明以下信息;模态特有参数在第 3–5 节对应小节中定义。
|
| 120 |
+
|
| 121 |
+
| 字段 | 约定 |
|
| 122 |
+
|---|---|
|
| 123 |
+
| available | 本发布是否提供该组件;缺省也表示未提供 |
|
| 124 |
+
| schema_id | 已登记的具体存储与语义类型,不得临时创造未登记名称 |
|
| 125 |
+
| data_ref | 数据文件路径,相对当前相机视图根目录,使用 POSIX 路径 |
|
| 126 |
+
| axes | 数组各维度的含义 |
|
| 127 |
+
| valid_ref / valid_axes | 有效性文件及其维度;语义由所属组件规定 |
|
| 128 |
+
| storage / valid_storage | 视频数据/视频有效性的存储配置;包含已登记 profile、实际 codec、pixel_format、encoded_size,见 3.1;非视频组件按原数组规则 |
|
| 129 |
+
| provenance | source / format_conversion / derived,以及转换或生成方法 |
|
| 130 |
+
| source_locator | 原文件、压缩包成员和记录/帧的定位信息 |
|
| 131 |
+
|
| 132 |
+
不存在的组件允许缺省或写作 `{ "available": false, "reason": "..." }`,不用引用不存在的文件。静态网格可声明标量有效性;具体见 5.4。观测的 valid 见第 3 节,标注的 valid 与 visibility 区分见 5.1。
|
| 133 |
+
|
| 134 |
+
`provenance.kind` 使用 source/format_conversion/derived,`method` 说明转换或生成方法;发布清单补充脚本版本、参数、输入摘要。`source_locator` 定位到原始文件/压缩包成员和记录、帧号;允许引用有完整溯源清单的前一发布,但链条最终应能回到 raw。不得仅写一个无法定位记录的数据集名字。
|
| 135 |
+
|
| 136 |
+
`.pt` 仅保存 CPU Tensor,不保存 Python 自定义对象;浮点默认 float32,有效性为 bool,浮点无效位置填 NaN。所有随帧数组保留首维 T,单帧也不 squeeze;静态资产按其 schema 单独声明。单位、坐标及固定形状见各组件小节。
|
| 137 |
+
|
| 138 |
+
机器注册表 `schema.json` 中,`components` 固定解码后的数据类型、形状、单位和语义;`storage_profiles` 固定视频内的编码/还原方式。不得临时创造未登记的 schema_id 或 storage.profile。同一语义允许选择其登记的不同无损存储 profile。
|
| 139 |
+
|
| 140 |
+
## 3. observation 观测数据
|
| 141 |
+
|
| 142 |
+
### 3.1 rgb.mkv 与 rgb_valid.pt
|
| 143 |
+
|
| 144 |
+
RGB、深度和栅格 mask 在 shared 中统一使用 MKV 视频容器,不展开为逐帧图片或图像 tar。MANO、关键点、位姿等数值标注仍用数组;分割的重叠多边形仍用 JSONL,不为了视频化而有损栅格化。单图可为一帧视频,独立图批量封装规则见 2.2。
|
| 145 |
+
|
| 146 |
+
**无损指共享层不增加信息损失。** 源 JPEG/H.264 等本身可能已是有损编码,原样保留并不恢复已丢失信息;不得重新以有损 JPEG、H.264、H.265、AV1 参数编码。源视频/图片的色彩、位深、分辨率和几何关系不得被静默改变。RGB schema `rgb/uint8/v1` 的统一读取结果是 `[T,H,W,3] uint8`、RGB 通道,有效性仍为 `rgb_valid.pt [T] bool`。超出该 schema 的高位深或 HDR 源必须报告并扩展定义,不能降到 8 位冒充无损。
|
| 147 |
+
|
| 148 |
+
#### 3.1.1 允许的 RGB 存储 profile
|
| 149 |
+
|
| 150 |
+
| storage.profile | 编码方式 | 适用规则 |
|
| 151 |
+
|---|---|---|
|
| 152 |
+
| mkv/mjpeg_copy/v1 | 源 JPEG 压缩帧直接封装成 MJPEG/MKV | 不解码重编码;保持每张 JPEG 码流字节;普通 8 位 JPEG 且 MKV/解码器支持时使用 |
|
| 153 |
+
| mkv/source_copy/v1 | 已有视频的 RGB 对应码流直接封装为 MKV | 仅源编码能被 MKV 和选定解码器支持时使用,不伪造帧;需维持正确的呈现顺序与依赖帧 |
|
| 154 |
+
| mkv/h264_rgb_lossless/v1 | libx264rgb 的真正无损模式 | 必须 RGB 路径、CRF=0,并通过全帧 RGB 字节比较;不能替换成默认 libx264 YUV420 路径 |
|
| 155 |
+
| mkv/ffv1_rgb/v1 | FFV1 的 RGB 可逆编码路径 | 作为通用候选;解码回 RGB 后必须逐字节相同,不做色度降采样 |
|
| 156 |
+
|
| 157 |
+
优先尝试源码流直接封装;不能封装或需要选择稀疏帧时,比较 FFV1 与无损 RGB H.264。对完整待发布片段,只在通过无损验收的候选中选择文件较小者,不假设某个编码器总最小;编码时间和随机读取代价记入构建记录。中间候选不作为 shared 多份常驻。H.264 跨帧压缩允许较长 GOP,必须记录 GOP/关键帧间隔,随机取帧需从前一关键帧正确解码,不能把 seek 返回的近似帧当目标帧。
|
| 158 |
+
|
| 159 |
+
普通源视频可以保留它已有的有损码流,但不允许新增有损重编码。源是 VRS 等记录容器时,先查明图像流实际编码:已有兼容 JPEG/视频包可直接提取封装,否则解码后使用真正无损编码;不把整个 VRS 改后缀当 MKV。PNG 不要求直接塞进 MKV,可选上表两种无损重编码方式。
|
| 160 |
+
|
| 161 |
+
#### 3.1.2 视频配置与校验
|
| 162 |
+
|
| 163 |
+
每个视频组件在 metainfo 中登记 `storage`,至少包含:
|
| 164 |
+
|
| 165 |
+
| 字段 | 内容 |
|
| 166 |
+
|---|---|
|
| 167 |
+
| profile | 上述登记的存储 profile;语义仍由组件 schema_id 指定 |
|
| 168 |
+
| codec | 文件中实际 codec,例如 mjpeg、h264、ffv1;source_copy 必须写实际 codec |
|
| 169 |
+
| pixel_format | 实际编码像素格式;不得仅凭编码器参数猜测 |
|
| 170 |
+
| encoded_size | 视频物理像素尺寸 `[width,height]`;深度可能不同于逻辑尺寸,见 3.2 |
|
| 171 |
+
| decoder | 解码器名称、版本,以及颜色矩阵/范围/旋转处理等实际像素解释配置;未知的源色彩声明 unknown,不擅自称为 sRGB |
|
| 172 |
+
| encoder_parameters | 重编码时的编码器、版本、无损模式和 GOP 等参数;直接封装时记录 stream_copy |
|
| 173 |
+
| source_lossy | 源是否已有损:true / false / unknown;不是共享层再有损编码的许可 |
|
| 174 |
+
|
| 175 |
+
无损重新编码的 RGB 必须使用同一固定解码配置,比较**全部帧**的统一 RGB 字节、数量及顺序。MJPEG-copy 不重新编码,生产校验采用 `jpeg-packets-all-rgb-sample16/v1`:从 MKV 逐包取回,对全部源 JPEG 的 SHA256、数量、顺序和图像尺寸进行精确核对;每视图另用同一固定解码配置比较最多 16 帧的源与目标 RGB 字节(含首尾与四分位位置,其余由固定种子抽取)。记录策略、实际索引、种子与结果;不足 16 帧时全查。试点与最终完整序列随机抽查,对选中视图的全部帧复核解码 RGB。历史已做全帧像素检查的证明继续保留。
|
| 176 |
+
|
| 177 |
+
逐包一致与像素抽查的范围必须分别声明,不能将抽查写成全量像素检查。不能用 PSNR 高、视觉相似、编码器参数称为 lossless 等替代精确检查。同时保留源编码的色彩标记和必要元数据;原图有 EXIF/色彩/方向等元数据时保留 raw 和必要来源信息;不能静默自动旋转图像而不更新像素对应与标定。以上加速策略仅适用于原 JPEG 码流直接封装,不适用于深度、标签或重新编码的 RGB。
|
| 178 |
+
|
| 179 |
+
所有共享视频的呈现帧顺序与统一 frame_index 一一对应,每个栅格组件恰好 T 帧。MKV 的 `storage_fps` 只服务封装,声明 `timebase_role=index_only`;source_copy 可以保留源 PTS 以避免改坏码流,但真实时间与标注对齐仍以 frames 为准。未知真实时间保留 null。缺失某帧组件时保留索引位置并使用该组件的无效占位/valid 标识,不删帧;不能以重复相邻图像冒充已知观测。
|
| 180 |
+
|
| 181 |
+
### 3.2 depth.mkv 与 depth_valid.mkv
|
| 182 |
+
|
| 183 |
+
深度语义仍是 `depth/z_float32/v1`:统一读取结果 `[T,H,W] float32`,米制相机 Z 分量,`depth_type=z`。有效深度有限且大于 0,无效位置为 NaN。`depth_origin=measured/rendered/unknown` 必填,来源不明时 unknown。默认与 RGB 共用像素网格及相机参考系,不处理未注册 RGB-D。射线距离必须依据源定义转换成 z,不能只改声明。
|
| 184 |
+
|
| 185 |
+
#### 3.2.1 float32 的可逆视频编码
|
| 186 |
+
|
| 187 |
+
采用 `mkv/depth_float32_bits/v1`:**不是把深度量化成 uint16**,而是将规范化后每个 IEEE-754 float32 的完整 32 位拆成两个 uint16,使用 FFV1 gray16le 保存。视频物理尺寸为 `[2W,H]`:每行前 W 列存原 float32 位串的低 16 位,后 W 列存高 16 位。读取时先合并为 uint32 位串,再按 float32 重新解释,不能数值 cast 成 float32。
|
| 188 |
+
|
| 189 |
+
```text
|
| 190 |
+
u = reinterpret_uint32(depth_float32)
|
| 191 |
+
encoded[:, :, :W] = uint16(u & 65535)
|
| 192 |
+
encoded[:, :, W:] = uint16(u >> 16)
|
| 193 |
+
u_restored = uint32(low) | (uint32(high) << 16)
|
| 194 |
+
depth_float32 = reinterpret_float32(u_restored)
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
统一采用 little-endian 原始字节接口。`camera.image_size` 始终是逻辑 RGB 尺寸 `[W,H]`,不能改成编���视频的 2W;`storage.encoded_size=[2W,H]`。包括 NaN 在内的 float32 位串必须全帧完全恢复,不允许改成 float16、整数毫米、归一化灰度或 RGB 伪彩色。这里的无损验收基准是完成既定米制/坐标转换后的标准 float32 数组,不声称消除 float64→float32 等原约定转换本身的舍入。
|
| 198 |
+
|
| 199 |
+
#### 3.2.2 逐像素有效性
|
| 200 |
+
|
| 201 |
+
`depth_valid.mkv` 使用 `mkv/bool_ffv1/v1`,FFV1 gray8(FFmpeg pixel_format=`gray`),物理尺寸 `[W,H]`。像素只能为 0 或 1,统一解码为 `[T,H,W] bool`,逐像素含义不变。这样不再把庞大的 bool 数组保存为未压缩 `.pt`;标注的帧级/手级 valid 仍保留原有小数组。
|
| 202 |
+
|
| 203 |
+
登记示例(W、H 以下取 640、480;decoder/encoder_parameters 的实际版本由转换器填写):
|
| 204 |
+
|
| 205 |
+
```json
|
| 206 |
+
{
|
| 207 |
+
"available": true,
|
| 208 |
+
"schema_id": "depth/z_float32/v1",
|
| 209 |
+
"data_ref": "observation/depth.mkv",
|
| 210 |
+
"axes": ["T", "height", "width"],
|
| 211 |
+
"valid_ref": "observation/depth_valid.mkv",
|
| 212 |
+
"valid_axes": ["T", "height", "width"],
|
| 213 |
+
"unit": "m",
|
| 214 |
+
"depth_type": "z",
|
| 215 |
+
"depth_origin": "measured",
|
| 216 |
+
"invalid_value": "NaN",
|
| 217 |
+
"storage": {
|
| 218 |
+
"profile": "mkv/depth_float32_bits/v1",
|
| 219 |
+
"codec": "ffv1",
|
| 220 |
+
"pixel_format": "gray16le",
|
| 221 |
+
"encoded_size": [1280, 480],
|
| 222 |
+
"source_lossy": false,
|
| 223 |
+
"decoder": {"name": "ffmpeg", "version": "填写实际版本"},
|
| 224 |
+
"encoder_parameters": {"name": "ffv1", "level": 3, "version": "填写实际版本"}
|
| 225 |
+
},
|
| 226 |
+
"valid_storage": {
|
| 227 |
+
"profile": "mkv/bool_ffv1/v1",
|
| 228 |
+
"codec": "ffv1",
|
| 229 |
+
"pixel_format": "gray",
|
| 230 |
+
"encoded_size": [640, 480],
|
| 231 |
+
"source_lossy": false,
|
| 232 |
+
"decoder": {"name": "ffmpeg", "version": "填写实际版本"},
|
| 233 |
+
"encoder_parameters": {"name": "ffv1", "version": "填写实际版本"}
|
| 234 |
+
},
|
| 235 |
+
"provenance": {"kind": "format_conversion", "method": "源深度转米制 z float32;逐位打包为 FFV1"},
|
| 236 |
+
"source_locator": {"file": "raw/data/depth.zip", "member": "depth/0001.png"}
|
| 237 |
+
}
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
深度和有效性视频都必须逐帧解码验收:float32 位串相同、bool 相同、T 相同,并检查 valid=true 的正有限值和 valid=false 的 NaN。读取器必须按 profile 还原,不能把 depth.mkv 的编码像素直接当深度值。
|
| 241 |
+
|
| 242 |
+
## 4. camera 相机、帧索引与标定
|
| 243 |
+
|
| 244 |
+
### 4.1 frames.jsonl:索引、时间与对应关系
|
| 245 |
+
|
| 246 |
+
`camera/frames.jsonl` 每行对应统一帧号 `frame_index=0..T-1`,是所有组件的唯一行索引。至少包含 `frame_index`、`timestamp_ns`、`clock_domain`、`source_locator`;原始帧号/文件名保存在 `source_frame_id`,不能被新帧号替代。每行还可有 `annotation_matches`,按组件键保存 `source_frame_id`、`source_timestamp_ns`、`clock_domain`、`match_method` 和 `delta_ns`;方法为 exact/index_map/nearest/interpolated,索引映射无时间依据时 delta_ns=null。nearest 必须记录允许误差;interpolated 必须记录两端源标识和权重。delta_ns 仅在同一时间域中计算为源标注时间减图像时间。多相机共享 `sequence_id`;已知同步关系必须用 `sync_id` 或明确的源帧/时间映射表达,不能仅凭相同数组索引认定同步。
|
| 247 |
+
|
| 248 |
+
每个视图必须提供此文件。源时间使用整数纳秒及 `clock_domain`,未知写 JSON `null`;不同时间域不能直接比较。逐帧 split 可以覆盖 metainfo 的视图默认划分,并保留来源,见 2.4。
|
| 249 |
+
|
| 250 |
+
### 4.2 坐标系与标定通则
|
| 251 |
+
|
| 252 |
+
| 项目 | 统一约定 |
|
| 253 |
+
|---|---|
|
| 254 |
+
| 相机坐标 | 右手系,X 向右、Y 向下、Z 向前,长度单位米 |
|
| 255 |
+
| 齐次变换 | 列向量,`p_target = T_target_from_source @ p_source` |
|
| 256 |
+
| 图像坐标 | `(u,v)`;左上像素中心为 `(0,0)`,u 向右、v 向下,单位 pixel |
|
| 257 |
+
| 固定标定 | 本版展开为 T 份,同一 schema 不混用静态与动态形状 |
|
| 258 |
+
| 分辨率或模型变化 | 分开存储为视图/片段,不在同一组件中混装 |
|
| 259 |
+
| 未知标定 | 相机内外参允许缺省,不填单位阵冒充已知标定 |
|
| 260 |
+
|
| 261 |
+
### 4.3 intrinsic.pt 与畸变参数
|
| 262 |
+
|
| 263 |
+
| model / schema_id | intrinsic.pt 的固定结构 |
|
| 264 |
+
|---|---|
|
| 265 |
+
| pinhole / camera/pinhole/v1 | `[T,3,3]`,标准 K,最后一行为 `[0,0,1]`;限无畸变或已校正图像 |
|
| 266 |
+
| fisheye624 / camera/fisheye624/v1 | `[T,15]`,`[f,cx,cy,k0,k1,k2,k3,k4,k5,p0,p1,s0,s1,s2,s3]`,采用 Project Aria Fisheye624 投影定义 |
|
| 267 |
+
| opencv_fisheye4 / camera/opencv_fisheye4/v1 | `intrinsic.pt [T,3,3]` 保存 K;同组件 `distortion_ref` 指向 `[T,4]`,顺序 `[k1,k2,k3,k4]`,使用 OpenCV fisheye 等距角度多项式;已由 ReInterHand 实际原始相机参数验证 |
|
| 268 |
+
| rational8 / camera/rational8/v1 | `intrinsic.pt [T,3,3]` 保存 K;同组件必需 `distortion_ref` 指向 `[T,8]`,顺序 `[k1,k2,p1,p2,k3,k4,k5,k6]` |
|
| 269 |
+
| unknown / null | 不提供可用 intrinsic,不声称可以投影 |
|
| 270 |
+
|
| 271 |
+
有畸变的其他模型必须注册新 schema,固定参数名、顺序和投影公式;不能塞进针孔 K 后遗失畸变项。`metainfo.camera.schema_id` 必须与 intrinsic 组件一致。同一模型的别名不可隐式改变参数布局。
|
| 272 |
+
|
| 273 |
+
`opencv_fisheye4`:对前方点令 `x=X/Z, y=Y/Z, r=sqrt(x²+y²), theta=atan(r)`,`theta_d=theta*(1+k1*theta²+k2*theta⁴+k3*theta⁶+k4*theta⁸)`;`u=fx*x*theta_d/r+cx, v=fy*y*theta_d/r+cy`。光轴 r=0 时使用连续极限 `theta_d/r=1`。四系数不能按普通径向畸变解释,也不能补零冒充 Fisheye624。
|
| 274 |
+
|
| 275 |
+
rational8 对归一化坐标 x=X/Z、y=Y/Z,令 r²=x²+y²,径向项为 `(1+k1*r²+k2*r⁴+k3*r⁶)/(1+k4*r²+k5*r⁴+k6*r⁶)`;再加 p1/p2 切向项并经 K 得到像素。`distortion_ref` 与 intrinsic 共用 `[T]` valid,保存到 camera/distortion.pt。不得把这种畸变三维坐标当作真实相机系 xyz 保存。
|
| 276 |
+
|
| 277 |
+
内参有效性为 `intrinsic_valid.pt [T] bool`;有畸变时使用对应 `distortion_ref`。同一模型的参数名和顺序固定。
|
| 278 |
+
|
| 279 |
+
### 4.4 extrinsic.pt 与 extrinsic_valid.pt
|
| 280 |
+
|
| 281 |
+
`extrinsic.pt` 为 `[T,4,4]`,schema `transform/se3/v1`,方向固定 `T_camera_from_world`,有效性 `[T]`。世界坐标含义及源坐标转换记录在 provenance 中;只有相机坐标标注不要求虚构世界坐标。旋转块须正交且 determinant≈1。
|
| 282 |
+
|
| 283 |
+
## 5. annotation 标注数据
|
| 284 |
+
|
| 285 |
+
### 5.1 标注通则:手槽、valid 与 visibility
|
| 286 |
+
|
| 287 |
+
手槽固定为 0=left、1=right,指解剖学左右,不按画面位置或可见性重排。本阶段只处理左右手两槽,不处理更多手。实体引用使用 `hand_left`、`hand_right`;手槽不证明跨采集片段的个人身份。
|
| 288 |
+
|
| 289 |
+
#### 5.1.1 valid:标注是否可用于监督
|
| 290 |
+
|
| 291 |
+
标注的 `valid=true` 表示:有对应实际标注、通过本 schema 数值检查,且通过来源明确提供并适用于该组件的有效性/QA 条件。`valid=false` 可由缺标注、无法建立帧对应、源无效占位或官方 QA 不通过导致;不等于画面没有手或手不可见。各组件独立判断,MANO 按 `[T,2]` 标记左右手,关键点按 `[T,2,K]` 标记。
|
| 292 |
+
|
| 293 |
+
**2026-09-20 将标注 valid 从“仅表示存在”修订为“可用于监督”,字段形状不变。** 公式为 `source_annotation_present AND numerical_checks_pass AND applicable_official_QA_pass`。没有官方 QA 时省略最后一项,不伪造 QA;不能把未知当成已通过已存在的 QA。适配器在组件 `valid_policy` 中记录具体规则、来源、聚合/广播作用域。缺失官方必需 QA 的记录须明确处理为未知或暂停验收,不能静默通过。无效浮点项仍填 NaN,原始数据保留在 raw;被排除原值可用于 doc 中明确标识的诊断渲染,不能冒充 shared 有效监督。
|
| 294 |
+
|
| 295 |
+
本地筛选须依据明确的规则,并在 `valid_policy.local_excluded_frame_indices`、排除原因和正式报告中记录。单个可疑投影作为问题记录,不直接硬编码排除该帧。已确认的曝光异常须明确作用范围,不能把一个序列的“前两帧有问题”套到所有序列。RGB 编码完好与几何监督可用是两件事,允许保留原图及帧索引而屏蔽对应标注;未发现问题不等于完成全部人工审核,试点待确认时不能作为已验收发布使用。
|
| 296 |
+
|
| 297 |
+
源字段必须按官方语义映射,不能直接按名字复制:
|
| 298 |
+
|
| 299 |
+
| 来源 | 官方含义 | 映射原则 |
|
| 300 |
+
|---|---|---|
|
| 301 |
+
| [H2O](https://github.com/taeinkwon/h2odataset) 的手标注首位 | 0 未标注、1 已标注 | 可作为对应手标注存在性的依据,不推断未标注原因 |
|
| 302 |
+
| [HOT3D](https://github.com/facebookresearch/hot3d#using-mask-files) 的 pose_available、visible、mask_qa_pass | 分别表达姿态存在、可见性、对画面中可见手物位姿的人工 QA | 逐手/物体记录决定存在性,再 AND 当前相机当前帧 QA;QA 是整帧聚合判定,保守排除该帧全部手物几何监督,不声称每个实体均有错误;源可见性基于位姿推导时,其自身 valid 同样受 QA 约束 |
|
| 303 |
+
| [Dex-YCB](https://github.com/NVlabs/dex-ycb-toolkit#loading-dataset-and-visualizing-samples) 的全零 pose_m、全 -1 joints | 不可见的手或缺标注共用占位表示 | 对应组件 valid=false;不能从该值判定 visibility=false,也不能声称原因是动捕缺失 |
|
| 304 |
+
| [ARCTIC](https://github.com/zc-alexfan/arctic/blob/master/docs/data/data_doc.md) 的 is_valid/left_valid/right_valid | 是否有效用于官方评估 | 核实每项筛选依据;不把可见性/评估选择直接等同 QA。本次原始 mano.npy 不含这些派生评估标记,按原记录与数值检查生成 valid,并声明没有额外官方 QA 输入 |
|
| 305 |
+
|
| 306 |
+
源 valid=false 若代表评估筛选或其他条件,应检查实际标注和源约定后映射;不能一律清空坐标。反之,占位零或 -1 只有在源官方明确规定时才判为缺失,不泛化成所有数据的判断规则。
|
| 307 |
+
|
| 308 |
+
`valid=true` 的标注应通过其 schema 的数值与形状检查;检查失败必须报告或修复,不能静默隐藏。QA 不通过应报告排除数量与原因,并保留可追溯信息;不能把这类无效称为缺标注。RGB、深度等观测有效性仍按各自 schema;手物 QA 不自动否定 RGB、静态相机内参或物体资产。相机外参是否过滤须依据其自身来源规则;HOT3D 本次保留源外参用于溯源和诊断,不能用其存在性证明 QA 失败帧的几何监督正确。
|
| 309 |
+
|
| 310 |
+
#### 5.1.2 visibility:可见性属性
|
| 311 |
+
|
| 312 |
+
附加质量属性只保留 `visibility`,存放在对应模态或标注集内,不设 quality 目录。同一份可见性仅存一次;uv 与 xyz 共用时引用同一个文件。
|
| 313 |
+
|
| 314 |
+
visibility 通过所属组件 attributes 登记 data_ref、axes、dtype、visibility_type、meaning、provenance、source_locator;未知值通过属性 valid_ref 标识,全已知可声明 valid=true。比例与布尔值不相互强转,也不按任意阈值二值化。没有 MANO 时,整手可见性挂在 keypoints 组件,使用独立的 whole_hand_visibility.pt,明确 meaning=whole_hand,不与逐关键点可见性混用。
|
| 315 |
+
|
| 316 |
+
`valid` 回答“这项标注能否用于监督”,`visibility` 回答“在当前图像中是否可见(或可见多少)”。不可见的手或关键点仍可有有效标注;不能因 visibility=0 就清空坐标。源没有 visibility 时缺省或标为未知,不由 valid 推断。
|
| 317 |
+
|
| 318 |
+
| 情况 | 手标注 valid | visibility |
|
| 319 |
+
|---|---|---|
|
| 320 |
+
| RGB 已开始录制,动捕尚未开始,没有其他对应手标注 | false | 以独立源可见性标注为准;没有则未知 |
|
| 321 |
+
| 手被遮挡,但源有标注且通过适用有效性检查 | true | 若源声明不可见,则 false 或源可见比例 |
|
| 322 |
+
| 手可见且有对应标注,通过适用 QA | true | 若源有此信息,则 true 或源可见比例 |
|
| 323 |
+
| 手可见,但该帧漏标或动捕中断 | false | 可以为 true,但必须有独立来源依据 |
|
| 324 |
+
| 有手部参数,但官方 QA 明确不通过 | false | 不据此断言不可见;源可见比例若基于不可靠位姿,其属性 valid 也为 false |
|
| 325 |
+
|
| 326 |
+
visibility 自己的 valid_ref 表示该可见性标注是否可用,不复用 MANO 或关键点坐标的 valid_ref;明确记录源存在性及适用的 QA 条件。上述例子不要求凭图像自动生成可见性。
|
| 327 |
+
|
| 328 |
+
不设 quality 组件或目录,不另存拟合误差、曝光、截断比例等通用质量数组。适用的官方 QA 合并进对应 valid,在 `valid_policy` 记录来源与规则;正式校验报告保留原始 QA 时间区间及排除统计。原始 QA 文件仍在 raw,官方 split 保留。
|
| 329 |
+
|
| 330 |
+
### 5.2 mano:参数与整手可见性
|
| 331 |
+
|
| 332 |
+
MANO schema `mano/axis_angle61/v1`:`motion.pt [T,2,61]`,顺序为完整 16 关节 axis-angle 48、shape betas 10、全局平移 3。姿态使用弧度,平移米,位于当前相机系。有效性 `[T,2]`;缺少一侧整槽 NaN。PCA 必须先按对应模型展开,不能将 PCA 系数直接填入 axis-angle。
|
| 333 |
+
|
| 334 |
+
`model_profile` 必须固定 MANO 版本、`flat_hand_mean=true`、左手 shapedirs 修正状态。平移表示模型输出顶点所加的全局平移,不是某个腕关节的坐标;源语义不同须转换。shape 无量纲。模型权重不作为共享数据附带上传。
|
| 335 |
+
|
| 336 |
+
`mano/visibility.pt [T,2]` 保存源整手可见比例时使用 float32 [0,1],`visibility_type=ratio`;只有实际采用 0–100 的百分比才除以100,不能只凭表头判断。HOT3D 的 `visibility_ratio[%]` 实值已经是0–1,官方读取器原样读取,必须保留原值。通过 MANO 组件 attributes 登记,使用独立有效性,不复用 motion_valid。
|
| 337 |
+
|
| 338 |
+
手部共享表示仅保留 MANO 参数与选定关键点,不发布独立手表面几何。需要渲染或接触计算时由 MANO 参数生成,几何引用使用固定 MANO 模型配置与顶点顺序;不影响 object 下的物体模型和材质资产。
|
| 339 |
+
|
| 340 |
+
### 5.3 keypoints:二维点、三维点与逐点可见性
|
| 341 |
+
|
| 342 |
+
关键点独立于 MANO 参数存在;没有 motion 也可有关键点。`uv.pt [T,2,K,2]` 与 `xyz.pt [T,2,K,3]`,有效性 `[T,2,K]`,分别采用 `keypoints/uv/v1` 和 `keypoints/xyz/v1`。K 由 `keypoint_schema` 固定,不能在同一数组中逐帧变化;同体系统一顺序。数值使用像素坐标或米制相机系。
|
| 343 |
+
|
| 344 |
+
| keypoint_schema | K 与固定索引 |
|
| 345 |
+
|---|---|
|
| 346 |
+
| mano21/v1 | 21;wrist 后依次 thumb/index/middle/ring/little,每指由近端至指尖 |
|
| 347 |
+
| rhd21/v1 | 21;保持 wrist,然后五指由近端至指尖;原始每指 tip→palm 反序。只统一顺序,不宣称解剖学位置等价于 MANO |
|
| 348 |
+
|
| 349 |
+
具体名称与源索引映射见 `schema.json`。当前只登记 MANO21 与 RHD21;不登记 MediaPipe、ReInterHand capture21 或 fit24 中间关键点。
|
| 350 |
+
|
| 351 |
+
每个发布中的每个视图只提供一套标准手关键点,直接放在 keypoints 下,不设 annotation_set_id 字段或目录。uv 与 xyz 是这套关键点的二维与三维表示,不是两套标注。provenance 分别记录二者来自原始标注还是计算结果;不要求已有 2D 必须由当前 xyz 重新投影覆盖。
|
| 352 |
+
|
| 353 |
+
ReInterHand 的 Original keypoints���Original fits keypoints 及带前臂关键点不纳入 shared;如需手关键点,从选定 MANO 参数生成 MANO21 并记录模型/指尖回归约定。其他数据集默认使用选定的官方关键点,不额外生成平行的 MANO 派生集合。后续主动更换生成方法或结果时发布新的 dataset_version,不在同一版本内增设方法分支。
|
| 354 |
+
|
| 355 |
+
manual/projection/fitting 只记录在 provenance,不作为目录或类型分支。不得通过坐标为零、是否出画或 visibility 判断标注是否存在。派生标注仅在实际生成并通过数值检查后声明 valid=true;没有生成的项为 false,不伪造坐标。
|
| 356 |
+
|
| 357 |
+
`keypoints/visibility.pt [T,2,K]` 保存源逐点可见性,布尔表示使用 `visibility_type=boolean`。uv 与 xyz 共用时引用同一份文件。整手比例属性没有 MANO 可挂载时使用 `whole_hand_visibility.pt [T,2]`,`meaning=whole_hand`;它与逐点可见性分开,通用登记规则见 5.1。
|
| 358 |
+
|
| 359 |
+
不使用 annotation_set_id;ReInterHand 中间关键点集合不进入 shared,raw 保留来源文件。
|
| 360 |
+
|
| 361 |
+
### 5.4 object:身份、资产、位姿与几何
|
| 362 |
+
|
| 363 |
+
#### 5.4.1 metainfo.json:物体身份与跟踪作用域
|
| 364 |
+
|
| 365 |
+
手用 `hand_left`、`hand_right` 及槽位 0、1 表示,不再另存 entities.json。物体身份登记在 `annotation/object/<object_id>/metainfo.json`,必填 `object_id`、`identity_scope`、`scope_id`、`source_locator`;可含 `category_id`、`source_object_id`、`mesh_ref`、`has_model`、部件引用。即使只有分割、没有 pose/mesh,也可只有这份物体元信息。
|
| 366 |
+
|
| 367 |
+
`identity_scope` 为 frame/subsequence/sequence,`scope_id` 指定具体作用域;跨相机共享身份只在已有源对应证据时使用。VISOR 按官方 subsequence 与实体名关联时记录 `association_basis=official_subsequence_entity_name`,不能声称这是全视频物理实例跟踪。无需与 object_id 一一对应的标准 track_id;官方独立轨迹标识存在时保留为 source_track_id,并声明作用域。手槽不证明跨采集片段的个人身份。
|
| 368 |
+
|
| 369 |
+
#### 5.4.2 assets:网格、材质与纹理
|
| 370 |
+
|
| 371 |
+
资产属于物体,统一存放在 `annotation/object/<object_id>/` 内,可用 `assets/` 子目录组织网格、材质、纹理和部件资产。序列层不设共享 assets。所有引用采用视图根目录为基准;其中物体资产组件的 `data_ref` 与部件的 `mesh_ref` 采用相对于当前视图目录的 POSIX 路径,例如 `annotation/object/cup_01/assets/cup.obj`,且必须指向所属物体目录内的资产。OBJ 内部的材质、纹理引用遵循文件格式自身的相对路径规则,依赖文件一并保留。不同相机视图允许各自保存物体资产,不要求跨视图去重;下载物体时包含其资产依赖。
|
| 372 |
+
|
| 373 |
+
网格 schema 为 `mesh/obj/v1`,顶点米制,静态有效性可直接声明标量 `valid`,或通过 `valid_ref` 指向标量 bool Tensor;不按 T 重复静态资产。由物体/部件通过引用关联,不仅凭文件名猜测。
|
| 374 |
+
|
| 375 |
+
#### 5.4.3 pose.pt、pose_valid.pt 与 visibility.pt
|
| 376 |
+
|
| 377 |
+
刚体 schema 为 `object/rigid/v1`,`pose.pt [T,4,4]` 固定为 `T_camera_from_object`,平移米制,有效性 `[T]`。物体坐标原点、轴向必须与 mesh 一致;旋转块为正交矩阵且 determinant≈1。
|
| 378 |
+
|
| 379 |
+
`object/<id>/visibility.pt [T]` 保存源物体可见比例,float32 [0,1],`visibility_type=ratio`。通过所属物体组件 attributes 登记,独立表达其有效性。
|
| 380 |
+
|
| 381 |
+
#### 5.4.4 articulation.json、部件位姿与 joint_state.pt
|
| 382 |
+
|
| 383 |
+
关节物体:schema `object/articulated/v1`,`articulation.json` 登记 `parts` 与 `joints`。每个 part 有 `part_id`、`parent_id`(根为 null)、`has_model`、`mesh_ref`;has_model=false 时 mesh_ref=null,结构节点允许没有网格。父链不得成环。每个 joint 有唯一 `joint_id`、`parent_part`、`child_part`、`type`;fixed 单位 null、revolute 弧度、prismatic 米。有源限位时保存 `limits:[lower,upper]`;没有时 null,不伪造上下限。部件姿态统一为 `T_camera_from_part [T,4,4]`,不与父局部变换混装。
|
| 384 |
+
|
| 385 |
+
若提供 `joint_state.pt [T,J]`,必须登记固定 joint_order、轴在父部件系的表达、零位变换与正方向,valid 为 `[T,J]`;缺少这些运动学定义时只发布部件位姿与已有来源信息,不伪造可驱动的关节模型。关节值与部件位姿同时存在时需验证一致性。
|
| 386 |
+
|
| 387 |
+
部件层级应声明语义:纯语义包含树允许 `joints=[]`,不将包含关系推断为机械关节。关节状态 schema 为 `object/joint_state/v1`;转动用弧度、移动用米,混合类型按 joint_order 对应的关节定义解释。
|
| 388 |
+
|
| 389 |
+
#### 5.4.5 dimensions、几何关键点与顶点部件标签
|
| 390 |
+
|
| 391 |
+
`dimensions.pt [T,3]` 采用 `object/dimensions/v1`,有效性为 `[T]`。
|
| 392 |
+
|
| 393 |
+
物体/部件 `dimensions` 为 `[length,width,height]` 米,轴顺序与该 mesh 的局部坐标关联,登记 `dimensions_semantics` 和来源。HOI4D dimensions 与 mesh 的具体尺度关���未验证前标为 source_unspecified,保留源值并暂停依赖该关系的几何验收,不能默认为待施加缩放。需要施加缩放时明确 scale_applied_to_mesh,禁止重复应用。
|
| 394 |
+
|
| 395 |
+
源物体关键点放 `object/<id>/keypoints/xyz.pt [T,K,3]`(相机系)或 `template_xyz.pt [K,3]`(物体系),schema 分别为 object_keypoints/camera/v1 和 object_keypoints/template/v1。明确 keypoint_schema、keypoint_names、单位及有效性;模板点配合 pose 可投影,无须重复生成全部帧。H2O 中心/角点/棱中点,以及 ARCTIC 部件点分别登记具体源顺序,不套用手的 21 点 schema。每个发布选择一套源几何点并记录选择,不另建方法分支。
|
| 396 |
+
|
| 397 |
+
`vertex_part_ids.pt [V] int64` 绑定 `mesh_ref` 与 topology_id,登记整数到 part_id 的映射;未知用 -1。ARCTIC 不同拓扑的资产分别绑定,不能共用未经转换的顶点标签。部件层级中 is_instance/has_model 等源属性保留,几何文件仍全部归 object。
|
| 398 |
+
|
| 399 |
+
### 5.5 segment:分割类别、编码与覆盖范围
|
| 400 |
+
|
| 401 |
+
每个发布选择一套任务使用的分割表示,不建立方法/标注集分支。没有分割就不创建 segment 目录,不为其他模态创建空的实体表。
|
| 402 |
+
|
| 403 |
+
| schema_id | 文件与数值语义 |
|
| 404 |
+
|---|---|
|
| 405 |
+
| segment/uint16_labels/v1 | mask.mkv;整数区域编号,通过 instances.jsonl 解释 |
|
| 406 |
+
| segment/instance_polygons/v1 | polygons.jsonl;实例多边形,可重叠;当前不支持孔洞拓扑 |
|
| 407 |
+
| segment/foreground_intensity/v1 | mask.mkv;0–255 前景强度,不是区域编号或经过校准的概率 |
|
| 408 |
+
|
| 409 |
+
#### 5.5.1 uint16 标签图与 instances.jsonl
|
| 410 |
+
|
| 411 |
+
组件声明 `segmentation_type=semantic/instance/part`;同一组件固定一种类型。`mask.mkv` 解码为 `[T,H,W] uint16`,schema `segment/uint16_labels/v1`,使用 `mkv/uint16_ffv1/v1`,FFV1 gray16le 无损;只有所有区域编码均 ≤255 时允许 gray8(pixel_format=gray),读取后转 uint16,数值不变。禁止调色板和有损编码。有效性 `[T]`,表示该帧有可用分割标注。数值 0 固定为 unassigned,65535 固定为 ignore,1–65534 为区域编码,不能直接等同 entity_id。
|
| 412 |
+
|
| 413 |
+
`instances.jsonl` 每帧一行,包含 `frame_index` 与 `labels`。每条标签包含 `mask_value`、`category_id`、`entity_id`、`part_id`;无意义或未知字段为 null。semantic 允许 entity_id=null;instance 必须引用 hand_left/hand_right 或登记的 object_id;part 还须关联登记部件。源实例 ID 和其他属性分别保存在 `source_instance_id`、`source_attributes`。mask 中每个非保留编码必须有且仅有一个映射。
|
| 414 |
+
|
| 415 |
+
FreiHAND 的试点按本任务需要,统一到手/背景类别,保留每个原生区域编码;不要求给原生细分区域猜测手指名称。需要细部件监督时,尚未核实的部件名称必须保持未知,不能因粗粒度手类别已核实便声称部件语义也已统一。
|
| 416 |
+
|
| 417 |
+
#### 5.5.2 重叠实例多边形
|
| 418 |
+
|
| 419 |
+
每发布选择一套任务使用的分割表示,不建立方法/标注集分支。VISOR 的实际试点存在重叠实例多边形,单层标签图不能无损表达。对此补充 `segment/instance_polygons/v1`:`segment/polygons.jsonl` 每帧包含 `frame_index` 和 `instances`,每实例包含 `mask_value` 与 `polygons`(列表,每个多边形为源图像像素坐标顶点序列,保留原始精度)。身份和类别仍由同一 `instances.jsonl` 映射,有效性仍为 `[T]`,通过 schema 区分物理编码。允许多实例重叠,不采用后画覆盖前画。消费者按需栅格化为独立实例二值 mask;不能声称合并的单层 mask 无损。
|
| 420 |
+
|
| 421 |
+
#### 5.5.3 灰度前景强度
|
| 422 |
+
|
| 423 |
+
ReInterHand 的官方渲染 mask 为双手合并的灰度前景掩码,实测存在 0–255 的中间值,不是左右手实例编号。登记 `segment/foreground_intensity/v1`:仍存 `segment/mask.mkv`,解码为 `[T,H,W] uint16`,使用 `mkv/uint16_ffv1/v1`,此类数据优先编码为 FFV1 gray8(pixel_format=gray),读取后转 uint16。有效值范围 0–255,归一化值为 `float32(value)/255`;0 为背景端点、255 为前景端点。组件声明 `foreground_category=hand`、`entity_id=null` 和双手合并语义,不使用区域编号映射。这里保留原始渲染 mask 强度,不把它称为经过校准的概率。若任务需要二值 mask,阈值化属于任务层派生操作,记录阈值;共享层不丢弃中间灰度。不同 schema 的数值含义不同,不能将该文件按整数类别图解码。
|
| 424 |
+
|
| 425 |
+
FreiHAND 训练集的 JPEG mask 使用 `segment/foreground_intensity/v1`,逐像素保留 JPEG 解码后的灰度,`entity_id=hand_right`。该 schema 不限定双手合并:单手或合并范围由 `entity_id` 与 `coverage` 明确声明。评估集整数区域图仍用 `segment/uint16_labels/v1`,两者不能仅凭文件名使用同一种解码语义。
|
| 426 |
+
|
| 427 |
+
#### 5.5.4 coverage 与有效性
|
| 428 |
+
|
| 429 |
+
`coverage.kind=full/selected_entities/partial/unknown`。full 指声明���标注范围完整;selected_entities 还应列出目标范围。无论哪种,0 本身不自动成为背景;背景要有明确类别映射,未标注区域不能用于构造负样本。保留源逐类/逐实例 exhaustive 信息,未知不可改写为完整。
|
| 430 |
+
|
| 431 |
+
三种表示的帧级有效性均为 `[T]`,表示该帧是否提供此分割标注;对应 valid_ref 在组件中登记,仍用小型 bool `.pt` 数组。栅格 mask 必须登记 storage,格式见 3.1.2,所有帧的整数编码或强度逐值完全相同。编码语义由 schema_id 决定,读取器不能仅依据 mask.mkv 文件名选择解码方式。
|
| 432 |
+
|
| 433 |
+
### 5.6 contact:接触、抓取、区域与距离
|
| 434 |
+
|
| 435 |
+
#### 5.6.1 relations.jsonl 与 relations_valid.pt
|
| 436 |
+
|
| 437 |
+
`annotation/contact/relations.jsonl`,schema contact/relations/v1,每帧一行含 frame_index、relations。每条记录含 relation_type(contact/grasp)、subject_id(手槽或登记实体)、object_id、status、source_locator、provenance。status 固定为 positive/negative/unknown/target_unannotated:positive 必须有可解析目标,negative 表示源明确否定该关系,unknown 为不确定,target_unannotated 为确有接触但目标未标注。非 positive 的 object_id 可 null,不能用 null 冒充“不接触”。稀疏源无记录的帧不自动补 negative。
|
| 438 |
+
|
| 439 |
+
VISOR 的对象 mask ID 必须先按同帧 source_instance_id 解析成 object_id;hand-not-in-contact、none-of-the-above、inconclusive 分别映射 negative、target_unannotated、unknown,保留原始字符串。Dex ycb_grasp_ind 通过 ycb_ids 映射到登记物体,以 relation_type=grasp 保存;不得当作逐顶点接触。
|
| 440 |
+
|
| 441 |
+
relations 组件的 valid_ref 指向 `relations_valid.pt [T] bool`,表示该帧是否有可用源关系标注。有效帧中可以存在 status=unknown 的明确不确定标注;无源标注的帧为 valid=false、relations=[]。组件仍声明 available/provenance/source_locator。
|
| 442 |
+
|
| 443 |
+
#### 5.6.2 实体对的顶点区域与距离
|
| 444 |
+
|
| 445 |
+
已发布的接触区域/距离按参与关系的 subject_id 与 object_id 组织,每对实体保留选定的一套结果,以精确 geometry_ref/topology_id 关联到手或物体/部件;不要求每套数据都有。顶点区域 schema contact/vertex_region/v1:bool `[T,V]` 加同形 valid;顶点距离 schema contact/vertex_distance/v1:float32 `[T,V]`、米、同形 valid,声明 source/target geometry_ref、distance_definition(signed/unsigned、测量到点集或表面等明确源定义)。geometry_ref 必须指向已登记 mesh 或由固定 MANO 模型配置确定的拓扑;拓扑/顶点数变化时按拓扑拆分片段。其他源区域表示只有在实际接入并登记 schema 后才可转换,不能随意栅格化宣称等价。
|
| 446 |
+
|
| 447 |
+
顶点区域/距离已有存储定义,但尚未完成真实输入试点;接入时必须提供源语义与几何验收证据,不因已经登记 schema 就视为通过。
|
| 448 |
+
|
| 449 |
+
## 附录:任务范围
|
| 450 |
+
|
| 451 |
+
不强制收录 2D bbox、完整高频动捕、动作程序、身体 SMPL-X、点云或网络特征。范围内的接触、visibility、选定手关键点、物体几何不能因不便处理而静默丢弃。分割采用的物理编码由第 5.5 节决定,存在重叠时不能以单层标签图声称无损。
|
| 452 |
+
|
| 453 |
+
不设置 entities_ref/segment/entities.json,不要求与 object_id 重复的 track_id。MediaPipe 不在当前关键点定义中;旧版本迁移必须保留可追溯关系,不能直接删表。手部共享表示不含独立 hand_mesh。
|
| 454 |
+
|
| 455 |
+
schema.json 是普通注册表,不是 JSON Schema 文档或可执行验收器;定义存在不代表真实数据已验证。验收须保留实测范围与未决项。
|
| 456 |
+
|
| 457 |
+
本存储约定只更新标准,不代表既有 FFV1/depth.pt 试点已迁移。新发布必须显式写 storage 配置;旧产物按其旧定义读取,不能只改文件后缀或版本标识伪装为合规。
|