MesserMMP's picture
Update the research workspace
24da0c6 verified
|
Raw History Blame Contribute Delete
5.86 kB
# Inference contract
`engine` exposes `inspect(path)`, `classify(paths, progress=None)`,
`infer(left_paths, right_paths, progress=None)`, and `status()`.
The progress callback receives `(stage: str, detail: dict)`; detail includes
`fraction`, `current`, and `total` when the amount of work is known.
Importing the API and calling `status()` neither downloads nor loads a model.
## Provenance and loading
The source is `MesserMMP/coronary-syntax-prediction` at the immutable revision
in `manifest.json`. Ten complete R3D-18 + projected-LSTM checkpoints are used:
five left and five right models, paired by fold. The artery classifier is a
separate R3D-18. Safetensors are loaded strictly, after verifying their SHA-256
hash and expected size. Calibration is fetched from the same revision and
its checksum and coefficients are also verified. No legacy pickle checkpoints,
secondary weights repository, randomly initialized fallback, or incomplete
ensemble is used.
Set `SYNTAX_MODEL_CACHE` to a directory whose relative paths match the model
repository. Missing files are fetched on demand. Set `SYNTAX_DEVICE=cpu`
(default) or `cuda` on a compatible machine; `SYNTAX_CPU_THREADS` defaults to 2.
Models run sequentially in float32 and are released after use. Only one
projection's backbone activations are retained at a time, followed by the
original LSTM over the ordered features.
## Input and preprocessing
The supported input is an unsigned 8-bit or 16-bit, single-channel DICOM cine
with 10–1024 frames and at most 512 MiB of decoded pixels. DICOM header
dimensions must match the pixels. StudyInstanceUID and SOPInstanceUID must be
retained. Mixed-study inputs and repeated SOPInstanceUIDs are rejected. Source
files are read without modification. Returned metadata excludes patient names,
patient identifiers, dates, institution names, and free-text DICOM fields.
The score transform matches `full_model/rnn_dataset.py`: uint16 is scaled by
the maximum value of the entire sequence to uint8; shorter-than-32-frame clips
are doubled repeatedly, then the central 32 frames are selected. Grayscale is
replicated into RGB, scaled to [0, 1], bilinearly resized to 256×256 with
antialiasing, and normalized with ImageNet mean and standard deviation.
Windowing, rescale, and MONOCHROME1 inversion are not applied because the
published pipeline reads `pixel_array` directly. Unsupported signed, color,
or single-frame input is rejected instead of being silently reinterpreted.
Within each artery, input order is retained exactly. The LSTM is
order-sensitive, so filename sorting would change predictions. To reproduce
an evaluation study, pass the paths in `videos_left` and `videos_right` order.
## Artery assignment
The classifier uses all original frames, RGB grayscale at 224×224, bilinear
tensor resizing with `antialias=False`, and ImageNet normalization.
`probability_right` is sigmoid of its one output:
left is ≤0.1, right is ≥0.9, and values between these thresholds are unassigned
in the engine output. The service automatically excludes these uncertain
projections from scoring. This is artery probability, not confidence in a
SYNTAX estimate. Only classifier-determined left/right lists reach `infer`;
users cannot override assignments or projection order.
The antialias setting is explicit because torchvision changed its unspecified
default in version 0.17. The archived Philips probabilities are reproduced by
`False`; the recently repaired Siemens examples were classified with `True`.
All artery groups in the two verification studies agree under both settings,
but their probabilities differ. This does not guarantee identical grouping for
every possible input. Published examples cache verified GPU classifier outputs
and ensemble results computed with those assignments. The score model separately uses
`antialias=True`, as explicitly specified by its reference inference code.
See the [official Resize documentation](https://docs.pytorch.org/vision/0.21/generated/torchvision.transforms.Resize.html).
For long sequences, classifier convolution uses temporal tiles with 56-frame
context on either side, aligned to the final temporal stride of 8. R3D-18 has
a 109-frame temporal receptive field. Disjoint final feature positions are
averaged once, so all original frames contribute without subsampling. Minor
floating-point differences relative to one large batch are expected.
## Scores and calibration
Each artery model's second output is log(1 + artery SYNTAX). Its score is
`float(torch.exp(output)) - 1`. The first output is an artery-specific binary
logit and is not exposed as a total disease probability.
For fold i, calculate `raw_i = left_i + right_i` and
`calibrated_i = a_i * raw_i + b_i`. Average each of those five values, then
clip only the final study score at zero. Do not clip artery/fold intermediate
values, apply calibration separately to arteries, or calibrate an ensemble
mean with averaged coefficients. The returned `per_fold` values preserve the
unclipped intermediates for reproducibility.
If a side is absent, its score is `null` and both study totals are `null` with
`complete=false`. The present side can still be inspected. The original batch
evaluation represented missing sides by zero; this interactive service instead
makes incompleteness explicit, because absence of an artery view does not show
that the artery has no disease.
## Validation
Run `python -m unittest engine.test_engine -v` for offline transform, tiling,
architecture, calibration, and checkpoint-integrity checks.
`python -m engine.validate_reference --help` describes the optional real-data
check. It compares explicit JSON grouping/order to archived evaluation results,
and can execute the original source model and dataset on CPU for an independent
batched comparison. It does not download or alter input studies.