fix: 修正ACT相机采样质量判定
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import queue
|
||||
import threading
|
||||
import time
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
@@ -29,6 +30,7 @@ from xr_rm_teleop.act_episode_recorder import (
|
||||
next_episode_index,
|
||||
publish_without_overwrite,
|
||||
recover_partial_files,
|
||||
sample_frame_metrics,
|
||||
select_camera_pair,
|
||||
select_frame,
|
||||
validate_episode,
|
||||
@@ -296,6 +298,34 @@ def test_camera_buffer_is_bounded_and_counts_dropped_frames():
|
||||
assert stats.fps == pytest.approx(800.0)
|
||||
|
||||
|
||||
def test_camera_buffer_counts_frame_number_regressions():
|
||||
buffer = CameraBuffer(maxlen=4)
|
||||
for frame_number in (100, 101, 1, 2):
|
||||
buffer.push(
|
||||
CameraFrame(
|
||||
_image(frame_number),
|
||||
frame_number,
|
||||
float(frame_number),
|
||||
time.monotonic_ns(),
|
||||
)
|
||||
)
|
||||
|
||||
stats = buffer.stats()
|
||||
|
||||
assert stats.frame_number_regression_count == 1
|
||||
assert stats.dropped_frames == 0
|
||||
|
||||
|
||||
def test_sample_frame_metrics_separate_repeats_skips_and_regressions():
|
||||
repeat, skip, regression = sample_frame_metrics(
|
||||
np.asarray((986, 986, 988), dtype=np.uint64)
|
||||
)
|
||||
|
||||
assert repeat == pytest.approx(0.5)
|
||||
assert skip == pytest.approx(0.5)
|
||||
assert regression == 0
|
||||
|
||||
|
||||
requires_h5py = pytest.mark.skipif(
|
||||
h5py is None,
|
||||
reason="h5py is not installed",
|
||||
@@ -506,6 +536,8 @@ def _valid_episode(tmp_path):
|
||||
root.attrs["camera_right_wrist_fps"] = 30.0
|
||||
root.attrs["camera_high_drop_ratio"] = 0.0
|
||||
root.attrs["camera_right_wrist_drop_ratio"] = 0.0
|
||||
root.attrs["camera_high_frame_number_regression_count"] = 0
|
||||
root.attrs["camera_right_wrist_frame_number_regression_count"] = 0
|
||||
return path
|
||||
|
||||
|
||||
@@ -518,6 +550,19 @@ def test_validate_episode_accepts_valid_file(tmp_path):
|
||||
assert report.metrics["control_hz"] == pytest.approx(30.0, rel=1e-5)
|
||||
|
||||
|
||||
@requires_h5py
|
||||
def test_validate_episode_accepts_async_camera_phase_drift(tmp_path):
|
||||
path = _valid_episode(tmp_path)
|
||||
with h5py.File(path, "r+") as root:
|
||||
root["debug/cameras/cam_high_frame_number"][:] = (986, 986, 988)
|
||||
|
||||
report = validate_episode(path, _quality_limits())
|
||||
|
||||
assert report.accepted
|
||||
assert report.metrics["cam_high_sample_repeat_ratio"] == pytest.approx(0.5)
|
||||
assert report.metrics["cam_high_sample_skip_ratio"] == pytest.approx(0.5)
|
||||
|
||||
|
||||
def _mutate_episode(path, mutation):
|
||||
with h5py.File(path, "r+") as root:
|
||||
if mutation == "short_episode":
|
||||
@@ -547,6 +592,8 @@ def _mutate_episode(path, mutation):
|
||||
root.attrs["camera_high_fps"] = 20.0
|
||||
elif mutation == "camera_drop":
|
||||
root.attrs["camera_right_wrist_drop_ratio"] = 0.02
|
||||
elif mutation == "camera_frame_regression":
|
||||
root.attrs["camera_high_frame_number_regression_count"] = 1
|
||||
elif mutation == "camera_age":
|
||||
root["debug/timestamps/cam_high_age_ms"][1] = 60.0
|
||||
elif mutation == "camera_skew":
|
||||
@@ -571,6 +618,7 @@ def _mutate_episode(path, mutation):
|
||||
("control_fault", "control_fault"),
|
||||
("camera_fps", "camera_fps"),
|
||||
("camera_drop", "camera_drop_ratio"),
|
||||
("camera_frame_regression", "camera_frame_number_regression"),
|
||||
("camera_age", "camera_frame_too_old"),
|
||||
("camera_skew", "camera_skew"),
|
||||
("final_gripper_closed", "final_gripper_not_open"),
|
||||
|
||||
Reference in New Issue
Block a user