Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion examples/egosuite_evaluation/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
)

SCHEMA_VERSION = 1
PROJECTED_HAND_LABEL_TYPE = "projected-hand-joints"
EXPECTED_HAND_JOINT_COUNT = 21
DEFAULT_RUNS_DIRECTORY = Path("data/egosuite-evaluation/runs")
DEFAULT_LABELS_DIRECTORY = Path("data/egosuite-evaluation/labels")
Expand Down Expand Up @@ -151,6 +152,22 @@ def load_projected_hand_label_report(
) from error
if not isinstance(report_payload, dict):
raise ValueError(f"projected-hand label report {report_path} must contain a JSON object")
schema_version = report_payload.get("schema_version")
if (
not isinstance(schema_version, int)
or isinstance(schema_version, bool)
or schema_version != SCHEMA_VERSION

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve unknown label-report envelope versions

When a label report comes from a newer producer with an unknown schema version, this exact-version check raises during pipeline.py module initialization, preventing the pipeline from starting. The repository's forward-compatibility guidance requires unknown values to retain their raw representation in an explicit Unknown* variant, emit a warning, and be ignored gracefully rather than raising, so handle future versions through that path while still rejecting malformed known values.

AGENTS.md reference: AGENTS.md:L1-L1

Useful? React with 👍 / 👎.

):
raise ValueError(
f"projected-hand label report {report_path} field 'schema_version' has value "
f"{schema_version!r}; supported value is {SCHEMA_VERSION}"
)
label_type = report_payload.get("label_type")
if not isinstance(label_type, str) or label_type != PROJECTED_HAND_LABEL_TYPE:
raise ValueError(
f"projected-hand label report {report_path} field 'label_type' has value "
f"{label_type!r}; supported value is {PROJECTED_HAND_LABEL_TYPE!r}"
)
raw_frame_records = report_payload.get("frames")
if not isinstance(raw_frame_records, list):
raise ValueError(f"projected-hand label report {report_path} must contain a 'frames' array")
Expand Down Expand Up @@ -889,7 +906,7 @@ def write_label_report(
all_labels = [label for labels in labels_by_source.values() for label in labels]
report = {
"schema_version": SCHEMA_VERSION,
"label_type": "projected-hand-joints",
"label_type": PROJECTED_HAND_LABEL_TYPE,
"camera_view": camera_view.value,
"frame_stride": frame_stride,
"limit_per_episode": limit_per_episode,
Expand Down
116 changes: 98 additions & 18 deletions examples/egosuite_evaluation/tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
select_episode_paths,
select_stratified_labels,
summarize_evaluation_results,
write_label_report,
)
from examples.egosuite_evaluation.geometry import (
CameraPoseInWorld,
Expand Down Expand Up @@ -268,25 +269,30 @@ def test_pipeline_registers_projected_hand_visibility_as_an_hflow_check() -> Non
def test_saved_label_report_selects_exact_frames_for_a_canonical_episode(tmp_path: Path) -> None:
source_path = tmp_path / "episode-123.mcap"
report_path = tmp_path / "labels.json"
report_path.write_text(
json.dumps(
{
"frames": [
{
"source_path": str(source_path),
"source_episode": "episode-123",
"camera_view": "head-left",
"frame_index": frame_index,
"left_in_frame_joint_count": 21,
"right_in_frame_joint_count": 21 if frame_index == 8 else 0,
"expected_hand_count": 2 if frame_index == 8 else 1,
"left_hand_issue_reasons": [],
"right_hand_issue_reasons": ["occlusion"] if frame_index == 8 else [],
}
for frame_index in (8, 3)
]
}
labels = [
ProjectedHandFrameLabel(
source_path=source_path,
source_episode="episode-123",
camera_view=CameraView.HEAD_LEFT,
frame_index=frame_index,
left_in_frame_joint_count=21,
right_in_frame_joint_count=21 if frame_index == 8 else 0,
expected_hand_count=2 if frame_index == 8 else 1,
left_hand_issue_reasons=(),
right_hand_issue_reasons=("occlusion",) if frame_index == 8 else (),
)
for frame_index in (8, 3)
]
write_label_report(
{source_path: labels},
camera_view=CameraView.HEAD_LEFT,
frame_stride=30,
limit_per_episode=None,
episode_count=None,
samples_per_episode=None,
samples_per_hand_count=None,
sample_seed=42,
output_path=report_path,
)

labels_by_source_episode = load_projected_hand_label_report(report_path)
Expand All @@ -299,6 +305,80 @@ def test_saved_label_report_selects_exact_frames_for_a_canonical_episode(tmp_pat
assert selected_labels[1].right_hand_issue_reasons == ("occlusion",)


@pytest.mark.parametrize(
("envelope", "field_name", "found_value", "supported_value"),
[
pytest.param(
{"label_type": "projected-hand-joints"},
"schema_version",
"None",
"1",
id="missing-schema-version",
),
pytest.param(
{"schema_version": "1", "label_type": "projected-hand-joints"},
"schema_version",
"'1'",
"1",
id="non-integer-schema-version",
),
pytest.param(
{"schema_version": 0, "label_type": "projected-hand-joints"},
"schema_version",
"0",
"1",
id="older-schema-version",
),
pytest.param(
{"schema_version": 2, "label_type": "projected-hand-joints"},
"schema_version",
"2",
"1",
id="future-schema-version",
),
pytest.param(
{"schema_version": 1},
"label_type",
"None",
"'projected-hand-joints'",
id="missing-label-type",
),
pytest.param(
{"schema_version": 1, "label_type": 1},
"label_type",
"1",
"'projected-hand-joints'",
id="non-string-label-type",
),
pytest.param(
{"schema_version": 1, "label_type": "bounding-boxes"},
"label_type",
"'bounding-boxes'",
"'projected-hand-joints'",
id="unsupported-label-type",
),
],
)
def test_saved_label_report_rejects_unsupported_envelope_before_frames(
tmp_path: Path,
envelope: dict[str, object],
field_name: str,
found_value: str,
supported_value: str,
) -> None:
report_path = tmp_path / "labels.json"
report_path.write_text(json.dumps({**envelope, "frames": [None]}))

with pytest.raises(ValueError) as error:
load_projected_hand_label_report(report_path)

message = str(error.value)
assert str(report_path) in message
assert repr(field_name) in message
assert f"value {found_value}" in message
assert f"supported value is {supported_value}" in message


def test_pipeline_records_agreement_output_validity_and_frame_intervals() -> None:
source_path = Path("episode.mcap")
labels = [
Expand Down
Loading