Improved Model Inference β Usage Guide (download_imp)
What this runner does
run_inference.py runs the latest improved model trained from the notebooks in improvement/:
- EfficientNet-B4 backbone (
tf_efficientnet_b4) - 2.5D input (prev + center + next slices β 9 channels)
- 6 outputs (
any+ 5 hemorrhage subtypes) - 5-fold ensemble (
best_model_fold0..4.pth) - Saved calibration (
isotonic/temperature) fromcalibration_params.json
Outputs:
- Per-slice JSON report (
outputs/reports/*.json) - Slice-level CSV (
outputs/slice_predictions.csv) - Patient-level CSV (
outputs/patient_predictions.csv)
Required files (already in download_imp/)
best_model_fold0.pthbest_model_fold1.pthbest_model_fold2.pthbest_model_fold3.pthbest_model_fold4.pthcalibration_params.jsonisotonic_models.pklnormalization_stats.jsonmanifest.csv(optional at inference time; used only fortrue_anyif IDs match)
Python package requirements
pip install -r requirements.txt
Notes:
timmis required fortf_efficientnet_b4model construction.scikit-learnis needed to deserialize and useisotonic_models.pkl.
Folder setup
Create this folder and place DICOM files there:
download_imp/
βββ run_inference.py
βββ run_interface.py
βββ best_model_fold0.pth
βββ best_model_fold1.pth
βββ best_model_fold2.pth
βββ best_model_fold3.pth
βββ best_model_fold4.pth
βββ calibration_params.json
βββ isotonic_models.pkl
βββ normalization_stats.json
βββ manifest.csv
βββ dicom_inputs/
βββ ID_xxx1.dcm
βββ ID_xxx2.dcm
βββ ...
Run commands
From workspace root:
cd download_imp
python run_inference.py
or (same thing):
python run_interface.py
Important behavior
- No CLI arguments; all settings are at top of
run_inference.py(CONFIGsection). FOLD_SELECTIONcontrols checkpoint selection:"ensemble"= use all available folds and average logits0..4= use one specific fold only
- If
best_methodisisotonic, the runner usesisotonic_models.pkl. - Missing prev/next slice in a series is handled exactly like training cache logic: neighbor falls back to center slice.
- Decision threshold defaults to
threshold_at_spec90fromcalibration_params.jsonunless overridden in config.
Recommended production checklist
- Keep all fold checkpoints and calibration files in the same
download_imp/directory. - Verify DICOMs are non-contrast head CT slices before inference.
- Run once on a small sample and review
slice_predictions.csvand JSON reports. - Have radiologist review all flagged and uncertain cases.