| --- |
| language: en |
| license: cc-by-nc-4.0 |
| pipeline_tag: image-segmentation |
| library_name: pytorch |
| tags: |
| - medical |
| - x-ray |
| - Resnet |
| - cardiac implantable electronic devices |
| - computer-vision |
| metrics: |
| - dice |
| - sensitivity |
| - specificity |
| - F1 |
| --- |
| # Automated Detection of Abandoned Leads and CIED Generator Localization from Chest Radiographs |
|
|
| Code and trained model weights for a multiclass semantic segmentation pipeline that localizes cardiac implantable electronic device (CIED) generators and detects abandoned leads on chest radiographs (CXR). |
|
|
| This repository accompanies the manuscript: |
|
|
| > A Multi-Stage Deep Learning Pipeline for Automated Detection of Abandoned Leads and Identification of Cardiac Implantable Electronic Devices (CIEDs) from Chest Radiographs. |
|
|
| If you use this code, please cite the manuscript above. |
|
|
| --- |
|
|
| ## Overview |
|
|
| The pipeline performs 4-class semantic segmentation (background, generator, active lead, abandoned lead) on chest radiographs using a U-Net with a ResNet-50 encoder. |
| The encoder is initialized via encoder-only transfer learning from a segmentation model pretrained on CIED chest radiographs (Busch et al. Radiol Artif Intell. 2024 Sep;6(5):e230502.), with the decoder randomly initialized and trained from scratch. |
| Training uses a combined Focal-Dice loss with class weighting to address severe class imbalance, and 5-fold stratified cross-validation. An operating threshold for abandoned-lead detection was selected via grid search over out-of-fold (OOF) predictions and locked prior to held-out test set evaluation. |
|
|
| ### Pre-trained Model Weight |
| The encoder backbone was initialized using weights from: |
| * **Zenodo DOI:** [10.5281/zenodo.10955502](https://doi.org/10.5281/zenodo.10955502) |
| * **Reference:** Busch F, Bressem KK, Suwalski P, et al. *Open Access Data and Deep Learning for Cardiac Device Identification on Standard DICOM and Smartphone-based Chest Radiographs*. Radiol Artif Intell. 2024;6(5):e230502. doi:10.1148/ryai.230502 |
|
|
| ### BibTeX |
| ```bibtex |
| @article{busch2024open, |
| title={Open Access Data and Deep Learning for Cardiac Device Identification on Standard DICOM and Smartphone-based Chest Radiographs}, |
| author={Busch, Felix and Bressem, Keno K and Suwalski, Paulina and Hoffmann, L ΰΉΰΈ₯ΰΈ°ΰΈΰΈΰΈ°}, |
| journal={Radiology: Artificial Intelligence}, |
| volume={6}, |
| number={5}, |
| pages={e230502}, |
| year={2024}, |
| publisher={Radiological Society of North America}, |
| doi={10.1148/ryai.230502} |
| } |
| |
| Ethics approval: REC-MURA_06 (Ramathibodi Hospital, Mahidol University). |
| |
| --- |
| |
| ## Repository structure |
| |
| ``` |
| . |
| models/ |
| βββ best_abdn.pth # pretrained weight (best checkpoint weight for abandoned lead) |
| python/ |
| βββ preprocess/ |
| βββ anonymizer.py # remove any burn-in texts |
| βββ CLAHE.py # applies CLAHE (Contrast Limited Adaptive Histogram Equalization) to improve contrast and enhanced edge definitions |
| βββ train/ |
| βββ derive_spatial_prior.py # pre-analysis: find generator area threshold and spatial prior |
| βββ Train_5Fold_CV.py # model training using 5-fold cross validaiton |
| βββ evaluation/ |
| βββ eval_ensemble.py # evaluate 5-fold ensemble segmentation model |
| βββ eval_single_model.py # evaluate a single model |
| βββ eval_generator_crop.py # evaluate generator localization and crop quality |
| βββ inference/ |
| βββ visualized_heatmap_overlay.py # heatmap of all classes (generator, active lead, and abandoned lead) |
| βββ visualized_abandon.py # probability map of abandoned lead |
| βββ crop_generator.py # crop ROI of generator |
| βββ requirements.txt # Pinned dependency versions |
| βββ README.md |
| ``` |
| |
| --- |
|
|
| Tested on Windows 11 with an NVIDIA GPU (CUDA 13.0). |
| --- |
|
|
| ## Data |
|
|
| Due to institutional data governance policies and patient privacy protections, raw chest radiographs and clinical data are **not** included in this repository. Access to de-identified data may be considered for reasonable research requests directed to the corresponding author, subject to institutional approval. |
|
|
| --- |
|
|
| ## Model weights |
|
|
| Trained weights for each of the 5 folds are provided as PyTorch state dicts, not full pickled learner objects, to avoid pickle compatibility issues across environments. Load with `infer_abdnL.py`, which reconstructs the model architecture before loading the state dict. |
|
|
| Weights are released under [license, e.g. CC BY-NC 4.0] for non-commercial research use. |
|
|
| --- |
|
|
| ## Notes on reproducibility |
|
|
| - The 5-fold split uses `StratifiedKFold` with `random_state=42`, stratified on abandoned-lead presence. |
| - Normalization statistics were computed once from the full training/CV dataset prior to fold splitting (Option 1: fixed stats shared across all folds and used unchanged at inference). |
| - The held-out pipeline test set was evaluated once, after the operating threshold was locked from OOF predictions only, to avoid data leakage. |
|
|
| --- |
|
|
| ## Disclosures |
|
|
| Large language model (Claude, Anthropic) was used for auxiliary code development assistance during this project. No patient-identifiable data was shared with external AI tools at any stage. All final code was reviewed by the investigator team. |
|
|
| --- |
|
|
| ## Contact |
|
|
| Assoc. Prof. Sirin Apiyasawat, MD |
| Division of Cardiology, Department of Medicine, Ramathibodi Hospital, Mahidol University |
| Sirin.api@mahidol.ac.th |
|
|
| ## License |
| - **Source Code**: Released under the [MIT License](LICENSE). |
| - **Model Weights & Checkpoints**: Released under the [CC BY 4.0 License](https://creativecommons.org/licenses/by/4.0/). |
|
|