Deep Learning · Chest X-Ray · MCC

Chest X-ray Classification

A complete presentation of the current notebook: data preparation, ResNet50 architecture, training behavior, class balancing, competition scoring, validation results and final test submission.

ResNet50ImageNet1K_V2 pretrained
20Pathology classes
20 epochsTraining run
17,015Test predictions

Project overview

The notebook uses a 5-fold stratified split, with fold 0 held out for validation. The training set is rebalanced by undersampling No Finding to 3,000 examples and oversampling rare disease classes to at least 200 examples. Training uses weighted cross-entropy and a weighted random sampler.

ResNet50CrossEntropyLossAdamWOneCycleLRAMP / CUDAWeightedRandomSampler5-fold StratifiedKFold20 classes

Training history

These are the actual values printed by the 20-epoch notebook run.

Training curves

Notebook training curves

MetricBest / FinalEpoch
Best validation competition score-6.246919
Best validation accuracy15.56%19
Final train accuracy81.02%20
Final validation accuracy15.22%20
Minimum validation loss3.40616

Class balancing

The notebook compares the original class counts with the resampled training distribution. No Finding is deliberately reduced from 34,079 to 3,000; rare classes are raised to at least 200.

Validation performance by class

Competition score per class from the best saved model. The scoring function is TP − FP − 5×FN, normalized by the number of actual examples in each class.

Atelectasis
-5.0936
Cardiomegaly
-5.9917
Consolidation
-8.5573
Edema
-6.2462
Effusion
-3.7610
Emphysema
-6.8000
Fibrosis
-6.7179
Hernia
-5.0000
Infiltration
-4.9452
Mass
-7.1040
Nodule
-10.4150
Pleural_Thickening
-8.9835
Pneumonia
-7.6562
Pneumothorax
-5.7713
Pneumoperitoneum
-4.7778
Pneumomediastinum
-5.0000
Subcutaneous Emphysema
-5.0000
Tortuous Aorta
-7.0200
Calcification of the Aorta
-5.7222
No Finding
-4.3744

Model architecture

  • ResNet50 with IMAGENET1K_V2 pretrained weights.
  • Original ResNet FC replaced by Identity.
  • Backbone feature size: 2048.
  • LayerNorm(2048).
  • Dropout 0.4.
  • Linear 2048 → 512.
  • ReLU.
  • Dropout 0.2.
  • Linear 512 → 20.

Optimization

  • Batch size: 64.
  • 20 epochs.
  • AdamW optimizer.
  • Backbone LR: 1e-4.
  • Head LR: 1e-3.
  • Weight decay: 1e-4.
  • OneCycleLR with cosine annealing.
  • Mixed precision with CUDA AMP.
  • Gradient clipping at 1.0.

Image preprocessing & augmentation

Training

Resize to 224×224 → Random Horizontal Flip (p=0.5) → Random Rotation (15°) → ColorJitter (brightness=0.3, contrast=0.3) → Tensor → ImageNet normalization.

Validation / test

Resize to 224×224 → Tensor → ImageNet normalization. The notebook also defines three TTA transforms: baseline, horizontal flip and 1.1× resize + center crop.

Threshold tuning

The notebook tested No Finding confidence thresholds from 0.50 to 0.98 in increments of 0.02. In this run the best reported threshold was 0.50, with score -6.3904, which was worse than the default argmax score of -6.2469. Therefore the default argmax remained preferable.

This is a source-derived result from the notebook output; the individual threshold scores were not stored in the notebook output, so they are not fabricated here.

Competition submission

The final submission contains 17,015 rows and 21 columns: one id column plus the 20 class columns. Each row is validated to contain exactly one positive class.

FieldValue
Test images17,015
Submission columns21
Class columns20
Row validationExactly one class = 1
Best validation score-6.2469

20 classes

AtelectasisCardiomegalyConsolidationEdemaEffusionEmphysemaFibrosisHerniaInfiltrationMassNodulePleural_ThickeningPneumoniaPneumothoraxPneumoperitoneumPneumomediastinumSubcutaneous EmphysemaTortuous AortaCalcification of the AortaNo Finding
Academic / research use: This project is a machine-learning classification experiment and is not a clinical diagnostic system. Predictions should not be used as a substitute for qualified medical assessment.