- 2.5D Deep Learning Models for Osteosarcoma Early Recurrence Prediction (CE-MRI)
2.5D Deep Learning Models for Osteosarcoma Early Recurrence Prediction (CE-MRI)
This repository provides 12 pre-trained 2.5D deep learning models for predicting postoperative early recurrence (< 2 years) after limb-salvage surgery in patients with primary extremity osteosarcoma, based on preoperative contrast-enhanced MRI (T1W_TSE_FS+C).
π¬ Model Overview
- Clinical Task: Preoperative prediction of early recurrence (< 2 years) following limb-salvage surgery in extremity osteosarcoma.
- Imaging Modality: Preoperative axial T1-weighted fat-suppressed contrast-enhanced MRI (
T1W_TSE_FS+C). - Cohort Structure:
- Total multi-center study cohort: $N = 355$ patients (Development cohort: $n = 168$ with an 8:2 stratified split into $n = 134$ training and $n = 34$ validation cases; Internal test cohort: $n = 112$, from which $N = 70$ cases with manual segmentation benchmarking served as the held-out deep learning evaluation cohort; Temporal validation cohort: $n = 40$; External validation cohort: $n = 35$).
- Backbone Architectures:
DenseNet121(Best performing deep learning backbone)ResNet18ResNet34ConvNeXt-Tiny
π οΈ Complete Preprocessing Pipeline
To ensure reproducible predictions during inference, raw NIfTI MRI scans and segmentation masks must undergo the exact 6-step preprocessing pipeline used during model training (fully implemented in inference.py via preprocess_nifti / predict_from_nifti):
- N4ITK Bias Field Correction (
n4_correction = True): Non-parametric N4 bias field correction is applied to eliminate low-frequency magnetic field inhomogeneities. - Spatial Resampling (
target_spacing = (1.0, 1.0, 3.0)mm): MRI volumes and segmentation masks are spatially resampled to a standardized voxel spacing of $1.0 \times 1.0 \times 3.0\text{ mm}^3$ using B-spline interpolation (for MRI volumes) and nearest-neighbor interpolation (for binary masks). - Global Z-Score Intensity Normalization (
intensity_normalization = 'z-score'): Voxel intensities are standardized across all finite, non-zero tissue voxels within the whole scan volume: $$I_{\text{norm}} = \frac{I - \mu}{\sigma}$$ - 2.5D Axial Slice Selection (
slice_stride = 1): For each region of interest (ROI), the axial slice with the largest foreground mask area ($z_{\max}$) is selected together with its immediately adjacent superior and inferior slices ($[z_{\max}-1,; z_{\max},; z_{\max}+1]$). - Bounding-Box Cropping & Resizing (
crop_margin = 20.0,input_size = 224): Slices are cropped to the 3D mask bounding box expanded by a 20-pixel margin and resized to $224 \times 224$ pixels via bilinear interpolation. - Channel Assembly:
- Intratumoral Models (
3 channels): 3 adjacent slices extracted using the intratumoral core mask $\rightarrow$ tensor shape(1, 3, 224, 224). - Peritumoral Models (
3 channels): 3 adjacent slices extracted using the 5-mm peritumoral ring mask $\rightarrow$ tensor shape(1, 3, 224, 224). - Fusion Models (
6 channels): 3 intratumoral slices and 3 peritumoral (5-mm) slices extracted independently and concatenated along the channel dimension ($3 + 3 = 6$) $\rightarrow$ tensor shape(1, 6, 224, 224).
- Intratumoral Models (
π Held-Out Test Cohort Performance
Evaluated on the held-out test cohort ($N = 70$ patients):
| Architecture | Region / Mode | Input Channels | Test AUC (95% CI) | Accuracy | Sensitivity | Specificity |
|---|---|---|---|---|---|---|
| DenseNet121 | Intratumoral | 3 | 0.767 (0.655β0.879) | 0.743 | 0.760 | 0.733 |
| DenseNet121 | Peritumoral | 3 | 0.764 (0.651β0.877) | 0.729 | 0.720 | 0.733 |
| DenseNet121 | Fusion | 6 | 0.753 (0.638β0.868) | 0.714 | 0.720 | 0.711 |
| ResNet18 | Intratumoral | 3 | 0.748 (0.633β0.863) | 0.714 | 0.680 | 0.733 |
| ResNet18 | Peritumoral | 3 | 0.738 (0.620β0.856) | 0.700 | 0.680 | 0.711 |
| ResNet18 | Fusion | 6 | 0.747 (0.631β0.863) | 0.714 | 0.720 | 0.711 |
| ConvNeXt-Tiny | Intratumoral | 3 | 0.751 (0.636β0.866) | 0.714 | 0.720 | 0.711 |
| ConvNeXt-Tiny | Peritumoral | 3 | 0.732 (0.613β0.851) | 0.686 | 0.640 | 0.711 |
| ConvNeXt-Tiny | Fusion | 6 | 0.736 (0.618β0.854) | 0.700 | 0.680 | 0.711 |
| ResNet34 | Intratumoral | 3 | 0.682 (0.556β0.808) | 0.657 | 0.640 | 0.667 |
| ResNet34 | Peritumoral | 3 | 0.669 (0.542β0.796) | 0.643 | 0.600 | 0.667 |
| ResNet34 | Fusion | 6 | 0.675 (0.548β0.802) | 0.657 | 0.640 | 0.667 |
π¦ Repository Structure & Checkpoint Format
βββ README.md
βββ inference.py
βββ models/
βββ densenet121/
β βββ intratumoral_best_model_25d.pth (3 channels)
β βββ peritumoral_best_model_25d.pth (3 channels)
β βββ fusion_best_model_25d.pth (6 channels)
βββ resnet18/
β βββ intratumoral_best_model_25d.pth (3 channels)
β βββ peritumoral_best_model_25d.pth (3 channels)
β βββ fusion_best_model_25d.pth (6 channels)
βββ resnet34/
β βββ intratumoral_best_model_25d.pth (3 channels)
β βββ peritumoral_best_model_25d.pth (3 channels)
β βββ fusion_best_model_25d.pth (6 channels)
βββ convnext_tiny/
βββ intratumoral_best_model_25d.pth (3 channels)
βββ peritumoral_best_model_25d.pth (3 channels)
βββ fusion_best_model_25d.pth (6 channels)
Each .pth checkpoint dictionary contains four keys:
model_state_dict: Trained PyTorch model weights.epoch: Training epoch (int) at which early stopping locked the optimal checkpoint.validation_metrics: Dictionary of validation set metrics at the optimal epoch (auc,accuracy,precision,recall_sensitivity,specificity,f1,loss,tn,fp,fn,tp,n).config: Dictionary of model architecture, preprocessing parameters (target_spacing,n4_correction,intensity_normalization,crop_margin,input_size), and training hyperparameters (lr,weight_decay,dropout,batch_size,epochs,patience,threshold,seed).
π Quick Start / Inference
1. Requirements
pip install torch torchvision numpy SimpleITK
2. End-to-End Inference from Raw NIfTI MRI & Masks (Recommended)
inference.py executes the full preprocessing pipeline (N4 bias correction $\rightarrow$ $(1,1,3)\text{ mm}$ resampling $\rightarrow$ global Z-score normalization $\rightarrow$ max-area slice $\pm 1$ $\rightarrow$ 20-px margin crop $\rightarrow$ $224 \times 224$ resize) automatically:
import torch
from inference import load_model, predict_from_nifti
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# 1. Single-Region Inference (e.g., DenseNet121 Intratumoral, 3 channels)
intra_model = load_model(
architecture='densenet121',
mode='intratumoral',
weight_path='models/densenet121/intratumoral_best_model_25d.pth',
device=device
)
res_intra = predict_from_nifti(
model=intra_model,
image_path='patient_ce_mri.nii.gz',
mask_path='intratumoral_mask.nii.gz',
device=device,
apply_n4=True
)
print("Intratumoral Recurrence Risk Probability:", res_intra['probability'])
# 2. Multi-Region Fusion Inference (e.g., DenseNet121 Fusion, 6 channels)
fusion_model = load_model(
architecture='densenet121',
mode='fusion',
weight_path='models/densenet121/fusion_best_model_25d.pth',
device=device
)
res_fusion = predict_from_nifti(
model=fusion_model,
image_path='patient_ce_mri.nii.gz',
mask_path='intratumoral_mask.nii.gz',
peritumoral_mask_path='peritumoral_5mm_mask.nii.gz',
device=device,
apply_n4=True
)
print("Fusion Recurrence Risk Probability:", res_fusion['probability'])
3. Direct Inference on Pre-processed Normalized Tensors
If your input tensor is already preprocessed and Z-score normalized:
import torch
from inference import load_model, predict_tensor
model = load_model(
architecture='densenet121',
mode='fusion',
weight_path='models/densenet121/fusion_best_model_25d.pth'
)
# Pre-processed Z-score normalized tensor of shape (B, 6, 224, 224)
normalized_tensor = torch.randn(1, 6, 224, 224)
result = predict_tensor(model, normalized_tensor)
print("Recurrence Probability:", result['probability'])
βοΈ Intended Use & Limitations
- Intended Use: Research use only. These models are intended for retrospective prognostic modeling research in primary extremity osteosarcoma. They are not validated for clinical decision-making and must not be used as a substitute for professional medical judgment.
- Expected Input: Preoperative axial
T1W_TSE_FS+CMRI with a corresponding intratumoral segmentation mask (and, for peritumoral/fusion models, the 5-mm peritumoral mask). Performance may degrade on other pulse sequences, scanners, or acquisition protocols not represented in the development cohort ($N = 355$, two centers), and the reported test-cohort confidence intervals are wide ($N = 70$). - No Patient Data: This repository distributes model weights and code only β no imaging or clinical data are included. The underlying data were not distributed with this repository due to patient privacy considerations.
π Citation
If you use these models or weights in your research, please cite:
@article{jin2026osteosarcoma,
title={Prognostic Value of Peritumoral and Intratumoral Features on Contrast-Enhanced MRI for Early Recurrence After Limb-Salvage Surgery in Osteosarcoma},
author={Jin, Xuan-chen and Jiang, Meng-dan and Zhang, Rui-peng and Li, Yue-Hua},
year={2026}
}
π License
This model repository is released under the Apache 2.0 License.