feat(perception): split vegetation evidence layers
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import shutil
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
from PIL import Image
|
||||
|
||||
import k1link.laboratory.vegetation_policy_review as policy_review_module
|
||||
import k1link.laboratory.vegetation_policy_video as policy_video_module
|
||||
import k1link.laboratory.vegetation_shadow_lab as vegetation_lab_module
|
||||
from k1link.laboratory import LaboratoryEvidenceRegistry
|
||||
from k1link.laboratory.evidence_report import verify_laboratory_evidence_result
|
||||
@@ -21,6 +25,45 @@ from k1link.web.vegetation_shadow_lab_api import build_vegetation_shadow_lab_rou
|
||||
REPOSITORY_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_coarse_policy_masks_mark_every_outside_fov_pixel_undefined(
|
||||
tmp_path: Path,
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(policy_video_module, "FRAME_COUNT", 1)
|
||||
monkeypatch.setattr(
|
||||
policy_video_module,
|
||||
"fine_to_policy_lut",
|
||||
lambda _taxonomy, _provider_map: np.full(256, 4, dtype=np.uint8),
|
||||
)
|
||||
source = tmp_path / "fine.zip"
|
||||
fine_buffer = io.BytesIO()
|
||||
Image.new("L", (800, 600), color=1).save(fine_buffer, format="PNG")
|
||||
with zipfile.ZipFile(source, "w") as archive:
|
||||
archive.writestr("masks/frame-000001.png", fine_buffer.getvalue())
|
||||
|
||||
valid_fov = np.zeros((600, 800), dtype=np.uint8)
|
||||
valid_fov[:, :400] = 255
|
||||
valid_fov_path = tmp_path / "valid-fov.png"
|
||||
Image.fromarray(valid_fov, mode="L").save(valid_fov_path)
|
||||
destination = tmp_path / "coarse.zip"
|
||||
counts = policy_video_module.build_policy_mask_archive(
|
||||
source_archive=source,
|
||||
destination_archive=destination,
|
||||
fine_taxonomy={},
|
||||
provider_label_map={},
|
||||
valid_fov_mask=valid_fov_path,
|
||||
)
|
||||
with (
|
||||
zipfile.ZipFile(destination) as archive,
|
||||
Image.open(io.BytesIO(archive.read("masks/frame-000001.png"))) as image,
|
||||
):
|
||||
coarse = np.asarray(image.convert("L"))
|
||||
assert np.all(coarse[:, :400] == 4)
|
||||
assert np.all(coarse[:, 400:] == 9)
|
||||
assert counts[4] == 600 * 400
|
||||
assert counts[9] == 600 * 400
|
||||
|
||||
|
||||
def _sha256(path: Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
@@ -290,9 +333,12 @@ def test_policy_review_reuses_sealed_video_and_links_yolox_tgs(
|
||||
|
||||
def fake_policy_archive(**kwargs) -> list[int]:
|
||||
shutil.copyfile(kwargs["source_archive"], kwargs["destination_archive"])
|
||||
return [4489 * 800 * 600, *([0] * 8)]
|
||||
assert kwargs["valid_fov_mask"].is_file()
|
||||
return [4489 * 800 * 600, *([0] * 9)]
|
||||
|
||||
monkeypatch.setattr(policy_review_module, "build_policy_mask_archive", fake_policy_archive)
|
||||
valid_fov_mask = tmp_path / "valid-fov-mask.png"
|
||||
Image.new("L", (800, 600), color=255).save(valid_fov_mask)
|
||||
result_root = seal_vegetation_policy_review(
|
||||
base_lab_root=base_root,
|
||||
mission_policy_path=REPOSITORY_ROOT
|
||||
@@ -300,6 +346,7 @@ def test_policy_review_reuses_sealed_video_and_links_yolox_tgs(
|
||||
provider_label_map_path=REPOSITORY_ROOT
|
||||
/ "config/perception/lab-v1-vegetation-provider-label-map-v1.json",
|
||||
m49_tgs_full_shadow_root=tmp_path / "sealed-tgs",
|
||||
valid_fov_mask_path=valid_fov_mask,
|
||||
output_root=tmp_path / "results",
|
||||
created_at_utc="2026-08-28T08:00:00+00:00",
|
||||
)
|
||||
@@ -312,8 +359,9 @@ def test_policy_review_reuses_sealed_video_and_links_yolox_tgs(
|
||||
assert route["taxonomy"]["schema_version"] == (
|
||||
"missioncore.lab-v1-terrain-policy-taxonomy/v1"
|
||||
)
|
||||
assert len(route["taxonomy"]["classes"]) == 9
|
||||
assert len(manifest["artifacts"]) == 79
|
||||
assert len(route["taxonomy"]["classes"]) == 10
|
||||
assert route["valid_fov"]["outside_valid_fov_class_id"] == 9
|
||||
assert len(manifest["artifacts"]) == 80
|
||||
assert manifest["authority"]["commands_enabled"] is False
|
||||
assert manifest["decision"]["multilayer_policy_review_ready"] is True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user