Skip to content

MedMod in-hospital mortality (3/4): image tools, synthetic data, MedSigLIP and examples - #1639

Open
Rainie-Hu wants to merge 6 commits into
sunlabuiuc:masterfrom
Rainie-Hu:medmod-ihm-images-examples
Open

Rainie-Hu wants to merge 6 commits into
sunlabuiuc:masterfrom
Rainie-Hu:medmod-ihm-images-examples

Conversation

@Rainie-Hu

@Rainie-Hu Rainie-Hu commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Contributors: Yuqing Hu (GT username yhu672, yhu672@gatech.edu) and Hanh Trang Do (GT username hdo61, hdo61@gatech.edu), Georgia Tech CSE 6250

Contribution Type: Full Pipeline, part 3 of 4 (#1609): the example scripts that run dataset → task → model → evaluation, and the MedSigLIP extension

**Part 3 of 4 of #1609. Depends on #1637 (#1638 is merged). Until #1637 merges, this diff also shows its files. After it merges, this branch will be rebased so it shows only part 3. The split: 1. dataset, task and processor (#1637); 2. models (#1638); 3. this PR; 4. runner scripts and Colab notebook (#1640, after this one).

Paper: Elsharief, S., et al. (2025). MedMod: Multimodal Benchmark for Medical Prediction Tasks with Electronic Health Records and Chest X-Ray Scans. CHIL 2025, PMLR 287. https://proceedings.mlr.press/v287/elsharief25a.html (code: https://github.com/nyuad-cai/MedMod)

What it adds:

  • Image tools: image_presets (the chest X-ray transforms each model uses, get_preset, load_cxr) and resize_cxr (MedFuse's 512-px resize of MIMIC-CXR-JPG images).
  • Extension: medsiglip computes and looks up stored embeddings from a frozen MedSigLIP image encoder (google/medsiglip-448). In both examples, the option --embeddings uses them instead of the ResNet-34.
  • ConVIRT pretraining samples: pretraining builds them from the output of MedMod's extraction scripts and the MIMIC-CXR-JPG metadata.
  • Without MIMIC access: synthetic creates synthetic samples with the same format. Both examples run end to end on them with --synthetic, including the extension (--embeddings synthetic).
  • Examples: examples/mimic4_medmod_ihm_early_fusion.py and examples/mimic4_medmod_convirt.py, plus examples/mimic4_medmod_ihm_results.md with the results, all settings and the deviations.

Results on MedMod's test split (1,241 stays, 187 deaths), mean ± sample standard deviation over MedMod's five seeds:

Model Image encoder AUROC AUPRC Paper AUROC
Early Fusion ResNet-34 0.8407 ± 0.0004 0.5140 ± 0.0007 0.842 ± 0.004
Early Fusion MedSigLIP (extension) 0.8461 ± 0.0010 0.5367 ± 0.0035 –
ConVIRT linear probe ResNet-34 0.8206 ± 0.0049 0.4588 ± 0.0114 0.847 ± 0.002 (Table 4), 0.813 ± 0.010 (Table 8)
ConVIRT linear probe MedSigLIP (extension) 0.8200 ± 0.0037 0.4686 ± 0.0077 –

Each ConVIRT probe uses the pretraining epoch with the highest validation AUROC, as the paper describes.

Deviations from the paper and our proposal (examples/mimic4_medmod_ihm_results.md has the details, our hypotheses and all settings):

  • EHR: 1-hour bins and MedMod's phenotyping normalizer, as in MedMod's released code. The paper text says 2-hour bins and a normalizer fitted on the dataset.
  • Early Fusion uses MedFuse's released pretrained encoders, frozen, because MedMod does not release its own. Our proposal said the encoders were trained from scratch, but the paper's Early Fusion uses pretrained encoders.
  • Frozen encoders stay in evaluation mode. MedMod's and MedFuse's code leave them in training mode.
  • Early Fusion stops after 15 epochs without improvement (MedFuse's code). The paper text says 10.
  • ConVIRT pretraining runs all 300 epochs, without MedMod's early stopping. The pretraining epoch is chosen among every 10th epoch, with a quick probe without augmentation. MedMod's script uses epoch 65.
  • The linear probe uses MedMod's script settings (AdamW, up to 200 epochs, patience 30). The paper text describes Adam, up to 300 epochs and patience 10.
  • Both models use the learning rates from the released code. We did not repeat the paper's learning-rate search.
  • The test split has 1,241 stays, not 1,242, because one image is missing from PhysioNet.
  • Training uses the examples' own loops instead of PyHealth's Trainer, which has no learning-rate scheduler.
  • MedSigLIP was trained on data that include MIMIC-CXR.

Links to other components: this part uses only our own components from #1637 and #1638 (the task, the EHR processor and both models). It does not import or change existing PyHealth components.

Files to review (part 3 only):

  • pyhealth/datasets/medmod/image_presets.py, resize_cxr.py, medsiglip.py, pretraining.py, synthetic.py
  • tests/core/test_medmod_mimic4_images.py, test_medmod_medsiglip.py, test_medmod_pretraining.py, test_medmod_mimic4_synthetic.py
  • the two example scripts, the results page and their entries in examples/README.md
  • mentions of these modules added back to six part-1 files: the dataset and task docs pages, pyhealth/datasets/medmod/__init__.py, files/NOTICE, the split_by_medmod example in medmod_mimic4.py and the task's image_dir docstring

Testing: on this branch, all 142 tests pass (our 121 plus upstream's 21 MedMod decompensation tests), on synthetic data only, with no network access. python tools/check_pr_rules.py passes.

Data: no MIMIC data, identifiers or trained weights are in this PR. The results page shows only aggregate scores and counts.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 88.87% (62610 / 70451 lines)

Modified file Coverage Lines
pyhealth/datasets/__init__.py 100.00% 95 / 95
pyhealth/datasets/medmod/__init__.py 100.00% 0 / 0
pyhealth/datasets/medmod/discretizer.py 97.01% 162 / 167
pyhealth/datasets/medmod/downloads.py 97.78% 44 / 45
pyhealth/datasets/medmod/extraction.py 92.61% 326 / 352
pyhealth/datasets/medmod/image_presets.py 82.22% 37 / 45
pyhealth/datasets/medmod/medsiglip.py 92.06% 116 / 126
pyhealth/datasets/medmod/pretraining.py 97.94% 95 / 97
pyhealth/datasets/medmod/resize_cxr.py 88.64% 78 / 88
pyhealth/datasets/medmod/synthetic.py 94.85% 129 / 136
pyhealth/datasets/medmod_mimic4.py 100.00% 79 / 79
pyhealth/processors/medmod_ehr_processor.py 97.50% 39 / 40
pyhealth/tasks/__init__.py 98.66% 147 / 149
pyhealth/tasks/medmod_mortality_mimic4.py 98.44% 63 / 64

Workflow run · c04b28b

@Rainie-Hu Rainie-Hu changed the title Part 3 of 4 of sunlabuiuc/PyHealth#1609 MedMod in-hospital mortality (3/4): image tools, synthetic data, MedSigLIP and examples Nov 27, 2026
@dhtrg
dhtrg force-pushed the medmod-ihm-images-examples branch from c798297 to 984974f Compare November 27, 2026 22:35
dhtrg and others added 3 commits November 30, 2026 17:01
Part 1 of 4 of sunlabuiuc#1609.

Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
The task page now says the image transform belongs to the model's image
loader; the task returns image_path only. A custom itemid_map adds a digest
of its file to dataset_name, so each map gets its own PyHealth cache, with a
test that builds two maps on one cache_dir.

Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
The dataset drops events outside its item map before caching, so a
task whose item map has other ids would silently miss their events.
set_task now raises a ValueError naming them, with a test. This is the
second half of the AI review's item-map comment.

Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
@dhtrg
dhtrg force-pushed the medmod-ihm-images-examples branch from 984974f to 6aaf1b9 Compare November 30, 2026 22:01
dhtrg and others added 3 commits November 30, 2026 18:52
Starting and stopping PyHealth's local Dask cluster took about 5 s per event-table build on 28 fake rows. The dataset tests now run the same Dask graph in the test process, and the custom item map test checks its cache key and row filter without a second build. The slowest step is now the module's one shared build (about 1.7 s); every test takes under 0.5 s.

Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
…ples

Part 3 of 4 of sunlabuiuc#1609. Builds on parts 1 and 2.

Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
resize_cxr leaves a .tmp_*.jpg file behind if it is killed while saving. list_images now skips it, as existing_basenames already does.

Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants