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)
    • ResNet18
    • ResNet34
    • ConvNeXt-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):

  1. N4ITK Bias Field Correction (n4_correction = True): Non-parametric N4 bias field correction is applied to eliminate low-frequency magnetic field inhomogeneities.
  2. 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).
  3. 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}$$
  4. 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]$).
  5. 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.
  6. 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).

πŸ“Š 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+C MRI 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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support