forked from longtao.wu/droboticflow
🐛 Pair Qwen PTS by explicit reference and Capture identity
This commit is contained in:
parent
c892e9f038
commit
c9ac1b05ed
@ -213,6 +213,9 @@ def _pts_candidates(
|
||||
original_pts = pathlib.PurePosixPath(original_video_name).stem + "_pts.csv"
|
||||
blurred_pts = "blurred_" + original_pts
|
||||
paired = blur_item.get("pairedFiles") if isinstance(blur_item.get("pairedFiles"), dict) else {}
|
||||
exact_refs = [item for item in inputs if paired.get("pts") and str(item.get("path") or "") == str(paired["pts"])]
|
||||
if exact_refs:
|
||||
return exact_refs, []
|
||||
paired_pts = _basename(paired.get("pts"))
|
||||
names = [paired_pts, blurred_pts, original_pts]
|
||||
artifacts: list[dict[str, Any]] = []
|
||||
@ -1380,21 +1383,57 @@ def _port(artifact: dict[str, Any]) -> str:
|
||||
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
|
||||
|
||||
|
||||
def _match_video_pts(video: dict[str, Any], timestamps: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
name = _basename(video.get("name") or video.get("path"))
|
||||
original = name[len("blurred_"):] if name.lower().startswith("blurred_") else name
|
||||
stem = pathlib.PurePosixPath(original).stem
|
||||
data = video.get("data") if isinstance(video.get("data"), dict) else {}
|
||||
paired = data.get("pairedFiles") if isinstance(data.get("pairedFiles"), dict) else {}
|
||||
explicit = str(paired.get("pts") or "")
|
||||
|
||||
def unique(candidates):
|
||||
distinct = {}
|
||||
for item in candidates:
|
||||
identity = str(item.get("path") or item.get("id") or item.get("name"))
|
||||
distinct.setdefault(identity, item)
|
||||
if len(distinct) > 1:
|
||||
raise RuntimeError(f"Qwen PTS 匹配不唯一: {name}: {[item.get('path') or item.get('name') for item in distinct.values()]}")
|
||||
return next(iter(distinct.values()), None)
|
||||
|
||||
# Only use references that actually arrived through the timestamps input.
|
||||
if explicit:
|
||||
matched = unique([item for item in timestamps if str(item.get("path") or "") == explicit])
|
||||
if matched is None:
|
||||
raise RuntimeError(f"Qwen 明确关联的 PTS 未传入: {name}: {explicit}")
|
||||
identity = re.match(r"^(.*_camera_(?:left|right)_part\d+)(?:_|$)", stem, re.IGNORECASE)
|
||||
pts_stem = pathlib.PurePosixPath(_basename(matched.get("name") or matched.get("path"))).stem
|
||||
if identity and not pts_stem.lower().startswith(identity.group(1).lower() + "_"):
|
||||
raise RuntimeError(f"Qwen 明确关联的 PTS 与相机或 part 不一致: {name}")
|
||||
return matched
|
||||
|
||||
for expected in (stem + "_pts.csv", "blurred_" + stem + "_pts.csv"):
|
||||
matched = unique([item for item in timestamps if _basename(item.get("name") or item.get("path")).lower() == expected.lower()])
|
||||
if matched is not None:
|
||||
return matched
|
||||
identity = re.fullmatch(r"(.*_camera_(?:left|right)_part\d+)(?:_[a-z0-9_]+)?", stem, re.IGNORECASE)
|
||||
if identity:
|
||||
expected = identity.group(1) + "_pts.csv"
|
||||
matched = unique([item for item in timestamps if _basename(item.get("name") or item.get("path")).lower() == expected.lower()])
|
||||
if matched is not None:
|
||||
return matched
|
||||
raise RuntimeError(f"Qwen 未收到同采集、同相机、同 part 的 PTS: {name}")
|
||||
|
||||
|
||||
def _multiport_inputs(inputs: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
videos = [item for item in inputs if _port(item) == "videos" or pathlib.PurePosixPath(str(item.get("name", ""))).suffix.lower() in VIDEO_SUFFIXES]
|
||||
timestamps = [item for item in inputs if _port(item) == "timestamps" or str(item.get("name", "")).lower().endswith("_pts.csv")]
|
||||
if not videos:
|
||||
raise RuntimeError("Qwen 行为粗切多端口路径需要 videos 视频集合")
|
||||
pts_by_stem = {
|
||||
pathlib.PurePosixPath(str(item.get("name", ""))).stem.removesuffix("_pts"): item
|
||||
for item in timestamps
|
||||
if str(item.get("name", ""))
|
||||
}
|
||||
blur_items: list[dict[str, Any]] = []
|
||||
for artifact in videos:
|
||||
sanitized = _basename(artifact.get("name") or artifact.get("path"))
|
||||
original = sanitized[len("blurred_") :] if sanitized.startswith("blurred_") else sanitized
|
||||
pts = pts_by_stem.get(pathlib.PurePosixPath(original).stem)
|
||||
pts = _match_video_pts(artifact, timestamps)
|
||||
blur_items.append(
|
||||
{
|
||||
"sanitizedFilename": sanitized,
|
||||
|
||||
@ -213,6 +213,9 @@ def _pts_candidates(
|
||||
original_pts = pathlib.PurePosixPath(original_video_name).stem + "_pts.csv"
|
||||
blurred_pts = "blurred_" + original_pts
|
||||
paired = blur_item.get("pairedFiles") if isinstance(blur_item.get("pairedFiles"), dict) else {}
|
||||
exact_refs = [item for item in inputs if paired.get("pts") and str(item.get("path") or "") == str(paired["pts"])]
|
||||
if exact_refs:
|
||||
return exact_refs, []
|
||||
paired_pts = _basename(paired.get("pts"))
|
||||
names = [paired_pts, blurred_pts, original_pts]
|
||||
artifacts: list[dict[str, Any]] = []
|
||||
@ -1380,21 +1383,57 @@ def _port(artifact: dict[str, Any]) -> str:
|
||||
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
|
||||
|
||||
|
||||
def _match_video_pts(video: dict[str, Any], timestamps: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
name = _basename(video.get("name") or video.get("path"))
|
||||
original = name[len("blurred_"):] if name.lower().startswith("blurred_") else name
|
||||
stem = pathlib.PurePosixPath(original).stem
|
||||
data = video.get("data") if isinstance(video.get("data"), dict) else {}
|
||||
paired = data.get("pairedFiles") if isinstance(data.get("pairedFiles"), dict) else {}
|
||||
explicit = str(paired.get("pts") or "")
|
||||
|
||||
def unique(candidates):
|
||||
distinct = {}
|
||||
for item in candidates:
|
||||
identity = str(item.get("path") or item.get("id") or item.get("name"))
|
||||
distinct.setdefault(identity, item)
|
||||
if len(distinct) > 1:
|
||||
raise RuntimeError(f"Qwen PTS 匹配不唯一: {name}: {[item.get('path') or item.get('name') for item in distinct.values()]}")
|
||||
return next(iter(distinct.values()), None)
|
||||
|
||||
# Only use references that actually arrived through the timestamps input.
|
||||
if explicit:
|
||||
matched = unique([item for item in timestamps if str(item.get("path") or "") == explicit])
|
||||
if matched is None:
|
||||
raise RuntimeError(f"Qwen 明确关联的 PTS 未传入: {name}: {explicit}")
|
||||
identity = re.match(r"^(.*_camera_(?:left|right)_part\d+)(?:_|$)", stem, re.IGNORECASE)
|
||||
pts_stem = pathlib.PurePosixPath(_basename(matched.get("name") or matched.get("path"))).stem
|
||||
if identity and not pts_stem.lower().startswith(identity.group(1).lower() + "_"):
|
||||
raise RuntimeError(f"Qwen 明确关联的 PTS 与相机或 part 不一致: {name}")
|
||||
return matched
|
||||
|
||||
for expected in (stem + "_pts.csv", "blurred_" + stem + "_pts.csv"):
|
||||
matched = unique([item for item in timestamps if _basename(item.get("name") or item.get("path")).lower() == expected.lower()])
|
||||
if matched is not None:
|
||||
return matched
|
||||
identity = re.fullmatch(r"(.*_camera_(?:left|right)_part\d+)(?:_[a-z0-9_]+)?", stem, re.IGNORECASE)
|
||||
if identity:
|
||||
expected = identity.group(1) + "_pts.csv"
|
||||
matched = unique([item for item in timestamps if _basename(item.get("name") or item.get("path")).lower() == expected.lower()])
|
||||
if matched is not None:
|
||||
return matched
|
||||
raise RuntimeError(f"Qwen 未收到同采集、同相机、同 part 的 PTS: {name}")
|
||||
|
||||
|
||||
def _multiport_inputs(inputs: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
videos = [item for item in inputs if _port(item) == "videos" or pathlib.PurePosixPath(str(item.get("name", ""))).suffix.lower() in VIDEO_SUFFIXES]
|
||||
timestamps = [item for item in inputs if _port(item) == "timestamps" or str(item.get("name", "")).lower().endswith("_pts.csv")]
|
||||
if not videos:
|
||||
raise RuntimeError("Qwen 行为粗切多端口路径需要 videos 视频集合")
|
||||
pts_by_stem = {
|
||||
pathlib.PurePosixPath(str(item.get("name", ""))).stem.removesuffix("_pts"): item
|
||||
for item in timestamps
|
||||
if str(item.get("name", ""))
|
||||
}
|
||||
blur_items: list[dict[str, Any]] = []
|
||||
for artifact in videos:
|
||||
sanitized = _basename(artifact.get("name") or artifact.get("path"))
|
||||
original = sanitized[len("blurred_") :] if sanitized.startswith("blurred_") else sanitized
|
||||
pts = pts_by_stem.get(pathlib.PurePosixPath(original).stem)
|
||||
pts = _match_video_pts(artifact, timestamps)
|
||||
blur_items.append(
|
||||
{
|
||||
"sanitizedFilename": sanitized,
|
||||
|
||||
@ -405,7 +405,8 @@ def test_qwen_v58_emits_only_timestamp_windows(tmp_path):
|
||||
try:
|
||||
artifacts = qwen_operator.run(
|
||||
"run-qwen-v58", "qwen", tmp_path, {"outputs": outputs},
|
||||
[{"name": "blurred_left.mp4", "path": "bos://test/blurred_left.mp4", "type": "video", "portId": "videos"}],
|
||||
[{"name": "blurred_left.mp4", "path": "bos://test/blurred_left.mp4", "type": "video", "portId": "videos"},
|
||||
{"name": "left_pts.csv", "path": "bos://test/left_pts.csv", "portId": "timestamps"}],
|
||||
{"output_binding": output_binding, "write_json_artifact": write},
|
||||
)
|
||||
finally:
|
||||
|
||||
46
tests/backend/test_qwen_pts_pairing.py
Normal file
46
tests/backend/test_qwen_pts_pairing.py
Normal file
@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
from backend.operators.builtin.qwen_behavior_rough_cut import operator as qwen
|
||||
|
||||
C = "FYLX_S16_AZEC86400VY_19700101_000402"
|
||||
|
||||
def pts(side="left", part="part0006", suffix="", prefix="bos://bucket/input/"):
|
||||
name=f"{C}_camera_{side}_{part}{suffix}_pts.csv"
|
||||
return {"name":name,"path":prefix+name,"portId":"videoPts"}
|
||||
|
||||
def video(part="part0006"):
|
||||
name=f"blurred_{C}_camera_left_{part}_silent_480p_wm.mp4"
|
||||
return {"name":name,"path":"bos://bucket/output/"+name,"portId":"blurredVideos"}
|
||||
|
||||
def test_qwen_pairs_transcoded_name_with_original_pts_per_camera_and_part():
|
||||
candidates=[pts("right"),pts(part="part0005"),pts()]
|
||||
v=video()
|
||||
generated=qwen._multiport_inputs([v,*candidates])
|
||||
item=generated[0]["data"]["items"][0]
|
||||
assert item["pairedFiles"]["pts"]==candidates[2]["path"]
|
||||
artifacts, entries=qwen._pts_candidates(generated,[],item,item["sourceVideo"])
|
||||
assert artifacts==[candidates[2]] and entries==[]
|
||||
|
||||
def test_qwen_prefers_video_specific_pts_and_rejects_duplicates():
|
||||
specific=pts(suffix="_silent_480p_wm")
|
||||
assert qwen._match_video_pts(video(),[pts(),specific])==specific
|
||||
with pytest.raises(RuntimeError,match="不唯一"):
|
||||
qwen._match_video_pts(video(),[pts(),pts(prefix="bos://other/input/")])
|
||||
|
||||
@pytest.mark.parametrize("candidates",[[],[pts("right")],[pts(part="part0060")],[pts(part="part0005")]])
|
||||
def test_qwen_never_uses_another_camera_or_part(candidates):
|
||||
with pytest.raises(RuntimeError,match="同采集、同相机、同 part"):
|
||||
qwen._match_video_pts(video(),candidates)
|
||||
|
||||
def test_explicit_reference_is_used_without_basename_substitution():
|
||||
a,b=pts(),pts(prefix="bos://other/input/")
|
||||
v=video();v["data"]={"pairedFiles":{"pts":b["path"]}}
|
||||
assert qwen._match_video_pts(v,[a,b])==b
|
||||
item={"pairedFiles":{"pts":b["path"]}}
|
||||
assert qwen._pts_candidates([a,b],[],item,"unused.mp4")[0]==[b]
|
||||
v["data"]["pairedFiles"]["pts"]=pts("right")["path"]
|
||||
with pytest.raises(RuntimeError,match="不一致"):
|
||||
qwen._match_video_pts(v,[pts("right")])
|
||||
|
||||
def test_legacy_exact_pairing_is_retained():
|
||||
v={"name":"blurred_legacy.mp4"};p={"name":"legacy_pts.csv","path":"/tmp/legacy_pts.csv"}
|
||||
assert qwen._match_video_pts(v,[p])==p
|
||||
Loading…
x
Reference in New Issue
Block a user