Spaces:
Sleeping
Sleeping
Download src/training/guard.py from farrell236/OCT_Segmentation_a1: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/farrell236/OCT_Segmentation_a1/resolve/main/src/training/guard.py
- Command line
-
hf download hf://spaces/farrell236/OCT_Segmentation_a1/src/training/guard.py
-
curl -L -o guard.py https://huggingface.co/spaces/farrell236/OCT_Segmentation_a1/resolve/main/src/training/guard.py
1.49 kB
| """Metadata-only split checks before development payload access. | |
| The frozen discovery audit establishes pairing. These checks independently reject | |
| a mislabeled manifest participant before reading any image/segmentation payload. | |
| This module is never imported by label-free inference. | |
| """ | |
| import pydicom | |
| from src.io import safe_path | |
| from src.protocol import split_for | |
| def check_development_identity(row, root, expected_split): | |
| participant = str(row["participant_id"]) | |
| if ( | |
| expected_split not in ["train", "validation"] | |
| or split_for(participant) != expected_split | |
| ): | |
| raise ValueError("Development manifest split violation") | |
| classes = [ | |
| ("oct_paths", "1.2.840.10008.5.1.4.1.1.77.1.5.4"), | |
| ("segmentation_paths", "1.2.840.10008.5.1.4.1.1.66.8"), | |
| ] | |
| for field, sop_class in classes: | |
| for relative in row[field]: | |
| header = pydicom.dcmread( | |
| safe_path(root, relative), | |
| stop_before_pixels=True, | |
| specific_tags=["PatientID", "SOPClassUID"], | |
| ) | |
| actual = str(header.get("PatientID", "")) | |
| if actual != participant or split_for(actual) != expected_split: | |
| raise ValueError( | |
| "DICOM participant identity/split differs from frozen manifest" | |
| ) | |
| if str(header.get("SOPClassUID", "")) != sop_class: | |
| raise ValueError("Unexpected development source object class") | |