Support suffixed mask pairing

This commit is contained in:
2026-07-01 11:24:43 +08:00
parent afd6bd39ec
commit 9d66f65212
2 changed files with 29 additions and 6 deletions

View File

@@ -31,7 +31,7 @@ def test_validate_dataset_and_generate_yolo_yaml(tmp_path, monkeypatch):
image = np.zeros((32, 32, 3), dtype=np.uint8)
mask = np.zeros((32, 32), dtype=np.uint8)
cv2.imwrite(str(root / "images" / "sample.png"), image)
cv2.imwrite(str(root / "masks" / "sample.png"), mask)
cv2.imwrite(str(root / "masks" / "sample-mask.png"), mask)
(root / "labels" / "sample.txt").write_text("0 0.25 0.25 0.75 0.25 0.75 0.75 0.25 0.75\n", encoding="utf-8")
validation = validate_dataset("case_yolo")
@@ -57,6 +57,7 @@ def test_upload_zip_extracts_matching_dataset_kind(tmp_path, monkeypatch):
image_zip = io.BytesIO()
with zipfile.ZipFile(image_zip, "w") as archive:
archive.writestr("bundle/images/sample.png", b"image")
archive.writestr("bundle/images/manifest.csv", b"name\nsample.png\n")
archive.writestr("bundle/masks/sample.png", b"mask")
image_zip.seek(0)
image_upload = UploadFile(filename="images.zip", file=image_zip)
@@ -65,13 +66,13 @@ def test_upload_zip_extracts_matching_dataset_kind(tmp_path, monkeypatch):
mask_zip = io.BytesIO()
with zipfile.ZipFile(mask_zip, "w") as archive:
archive.writestr("bundle/images/sample.png", b"image")
archive.writestr("bundle/masks/sample.png", b"mask")
archive.writestr("bundle/masks/sample-mask.png", b"mask")
mask_zip.seek(0)
mask_upload = UploadFile(filename="masks.zip", file=mask_zip)
mask_result = asyncio.run(save_upload("case_zip", "masks", [mask_upload]))
assert [item["relative_path"] for item in image_result["saved"]] == ["var/uploads/datasets/case_zip/images/sample.png"]
assert [item["relative_path"] for item in mask_result["saved"]] == ["var/uploads/datasets/case_zip/masks/sample.png"]
assert [item["relative_path"] for item in mask_result["saved"]] == ["var/uploads/datasets/case_zip/masks/sample-mask.png"]
described = describe_dataset("case_zip")
assert described["counts"]["images"] == 1
assert described["counts"]["masks"] == 1