Code for: Deep Learning for Odontoid Fractures: The Critical Role of Patient-Level Partitioning and Grad-CAM Verification in Model Generalization
Abstract
Description This repository contains the complete, reproducible PyTorch source code for the study "Deep Learning for Odontoid Fractures: The Critical Role of Patient-Level Partitioning and Grad-CAM Verification in Model Generalization". The codebase implements an end-to-end deep learning framework designed to eliminate data leakage and selection bias in cervical spine CT fracture detection, benchmark six transfer learning CNN architectures, visualize anatomical decision-making via Explainable AI (XAI), and perform rigorous patient-level statistical validation. What's New in Version 1.1.0 Version 1.1.0 incorporates critical methodological and statistical updates addressing peer-review requirements for clinical validation rigor: 3-Way Patient-Level Zero-Leakage Split: Data partitioning is strictly enforced at the patient level into three mutually disjoint subsets: Training (60 patients, 326 CT slices), Validation (16 patients, 92 CT slices), and an independent held-out Test set (20 patients, 122 CT slices). Untouched Held-Out Test Evaluation: Early stopping loss is strictly monitored on the independent Validation cohort with a patience of 40 epochs. The held-out Test set remains completely isolated during training and hyperparameter optimization, being queried exactly once per trained model solely for final inference. Multiple Comparison Correction (Holm-Bonferroni): Pairwise patient-level bootstrap hypothesis testing (N = 1000 iterations) relative to DenseNet121 now integrates the step-down Holm-Bonferroni procedure to control the family-wise error rate (FWER) across candidate comparisons. Slice Capping: Standardized patient sampling enforces a maximum of 10 slices per subject to prevent dominant scan bias. Repository Structure & Pipeline Scripts 01_data_preparation.py: Reads raw DICOM volumes and applies Min-Max normalization to generate 8-bit PNG images. Executes patient-level 3-way partitioning (Train/, Val/, Test/) with random slice capping (≤ 10 slices/patient). Generates sample composite grid visualizations (Figure 1). 02_model_training_and_testing.py: Implements standardized label-agnostic upper-neck ROI cropping (top=5%, left=15%, height=65%, width=60%) and ImageNet normalization. Trains and fine-tunes 6 CNN architectures: SqueezeNet 1.1, AlexNet, VGG19, GoogLeNet, ResNet18, and DenseNet121. Applies class-weighted cross-entropy loss based on training distribution to handle class imbalance. Enforces fully deterministic seed control (seed=42) and validation-monitored early stopping checkpoints. Evaluates the saved checkpoints on the held-out test cohort to output confusion matrix metrics (TP, TN, FP, FN, Accuracy, Sensitivity, Specificity). 03_gradcam_visualization.py: Computes Gradient-weighted Class Activation Mapping (Grad-CAM) heatmaps across the final convolutional layer of each trained architecture. Visually verifies whether models localize the C1–C2 articulation and dens axis or rely on confounding soft-tissue artifacts. 04_result_plots.py: Exports publication-ready multi-panel Confusion Matrices and comparative ROC curves. Executes 1,000-iteration patient-level bootstrapping with replacement to calculate 95% Confidence Intervals (CI) for Accuracy and AUC. Performs pre-specified one-sided pairwise hypothesis testing against DenseNet121, outputting both raw p-values and Holm-adjusted padj values. System Requirements & Dependencies Python ≥ 3.10 PyTorch ≥ 2.0.0 / Torchvision ≥ 0.15.0 (CUDA enabled) Core libraries: pydicom, opencv-python, pytorch-grad-cam, scikit-learn, numpy, pandas, matplotlib, seaborn Citation & Academic Attribution If you utilize this codebase, experimental protocol, or pipeline in your research, please cite this repository: BibTeX: @software{kiymaz2026odontoid_code, author = {K{\i}ymaz, Yunus Emre and Ta{\c{s}}demir, {\c{S}}akir and Gezer, Burak and Uyar P{\i}nar, K{\"u}bra}, title = {{Deep Learning for Odontoid Fractures: The Critical Role of Patient-Level Partitioning and Grad-CAM Verification in Model Generalization}}, month = sep, year = 2026, publisher = {Zenodo}, version = {v1.1.0}, doi = {10.5281/zenodo.22677577}, url = {https://doi.org/10.5281/zenodo.22677577} } APA Style: Kıymaz, Y. E., Taşdemir, Ş., Gezer, B., & Uyar Pınar, K. (2026). Deep Learning for Odontoid Fractures: The Critical Role of Patient-Level Partitioning and Grad-CAM Verification in Model Generalization (Version 1.1.0) [Software]. Zenodo. https://doi.org/10.5281/zenodo.21950279