Spaces:
Sleeping
Sleeping
Download engine/validate_tiling.py from MesserMMP/syntax-video-infer: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/MesserMMP/syntax-video-infer/resolve/main/engine/validate_tiling.py
- Command line
-
hf download hf://spaces/MesserMMP/syntax-video-infer/engine/validate_tiling.py
-
curl -L -o validate_tiling.py https://huggingface.co/spaces/MesserMMP/syntax-video-infer/resolve/main/engine/validate_tiling.py
2.19 kB
| """Check temporal tiling using real published weights and a supplied public cine.""" | |
| import argparse | |
| import json | |
| import time | |
| from pathlib import Path | |
| import numpy as np | |
| import torch | |
| from .architecture import artery_model, classifier_stream | |
| from .dicom import read_video | |
| from .preprocessing import preprocess_classifier, to_uint8 | |
| from .runtime import _device, _load | |
| from .weights import MANIFEST | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--dicom", required=True, type=Path) | |
| parser.add_argument("--output", required=True, type=Path) | |
| args = parser.parse_args() | |
| source = to_uint8(read_video(args.dicom)) | |
| # An in-memory repeated fixture crosses multiple temporal tiles without | |
| # changing any source DICOM or claiming this is a new clinical study. | |
| video = np.concatenate([source] * ((195 + len(source) - 1) // len(source)))[:195] | |
| device = _device() | |
| started = time.monotonic() | |
| with torch.inference_mode(): | |
| model = _load(artery_model, MANIFEST["classifier"], device, None) | |
| whole_clip = preprocess_classifier(video).unsqueeze(0).to(device) | |
| whole = model(whole_clip) | |
| del whole_clip | |
| tiled = classifier_stream(model, len(video), lambda a, b: preprocess_classifier(video[a:b]), device) | |
| torch.testing.assert_close(whole, tiled, rtol=2e-5, atol=2e-5) | |
| result = {"frames": len(video), "fixture": "repeated source frames in memory; original DICOM unchanged", | |
| "whole_logit": float(whole.cpu()[0, 0]), "tiled_logit": float(tiled.cpu()[0, 0]), | |
| "absolute_logit_difference": float(abs(whole - tiled).cpu()[0, 0]), | |
| "whole_probability_right": float(whole.sigmoid().cpu()[0, 0]), | |
| "tiled_probability_right": float(tiled.sigmoid().cpu()[0, 0]), | |
| "classifier_sha256": MANIFEST["classifier"]["sha256"], | |
| "classifier_preprocessing": MANIFEST["preprocessing"]["classifier"], | |
| "seconds": time.monotonic() - started, "pass": True} | |
| args.output.write_text(json.dumps(result, indent=2)) | |
| print(json.dumps(result), flush=True) | |
| if __name__ == "__main__": | |
| main() | |