Machine Learning · CS363 · October University MSA

Lung Disease
Detection from
Chest X-Rays

A deep learning benchmark comparing five architectures for four-class classification of COVID-19, Viral Pneumonia, Lung Opacity, and Normal chest X-ray images. Our novel EfficientNet-B3 + CBAM model achieves 97.34% accuracy with built-in XAI.

Instructor
Assoc Prof. Nermin Abd El-Wahab
Dr. Ebtsam El-Hussany
Course
Machine Learning — CS363
Dataset
COVID-19 Radiography Database
21,165 CXR Images
97.34%
Best accuracy (EfficientNet+CBAM)
5
Models benchmarked
34K
Images after augmentation
4
Disease classes

Project Members

Eyad Magdy Lead
245479
EfficientNet-B3 + CBAM
Adel Sobhy
240095
VGG16
Hana Ayman
240245
ResNet18
Mohamed Salah
247151
DenseNet121
Serag Eldin
245083
LNet
Section 01

Dataset

The COVID-19 Radiography Database was compiled by researchers at Qatar University and the University of Dhaka, in collaboration with medical doctors from Pakistan and Malaysia. It is publicly available on Kaggle and contains chest X-ray images in PNG format at 299×299 pixels.

Class Original Count After Augmentation Primary Source
Normal 10,192 10,192 RSNA (8,851) + Kaggle (1,341)
Lung Opacity 6,012 8,000 RSNA CXR Dataset
COVID-19 3,616 8,000 padchest, GitHub, SIRM, Kaggle
Viral Pneumonia 1,345 8,000 Chest X-Ray Images (Kaggle)

The most significant challenge is class imbalance: Normal cases outnumber Viral Pneumonia by 7.6:1. A second challenge is the heterogeneous sourcing of COVID-19 images from seven distinct repositories with differing scanners and protocols, introducing domain shift. Viral Pneumonia and COVID-19 also share overlapping radiological patterns — bilateral ground-glass opacities — making fine-grained differentiation inherently difficult.

Section 02

Data Preprocessing

A single unified pipeline was applied across all five models to ensure performance differences are attributable to architecture alone, not data handling. This directly addresses the fair-comparison gap identified in Siddiqi & Javaid (2024).

1Load & BGR→Gray
2Augment minorities
3Resize 224×224
4Random flip + affine
5Normalize
6Tensor + label encode
7Stratified split 70/15/15

Augmentation is clinically conservative: RandomHorizontalFlip(p=0.5) is valid as left-right lung appearance is symmetric for classification purposes. RandomRotation(±10°) and RandomAffine(translate=5%, scale=95–105%) reflect realistic patient positioning variation without introducing implausible artefacts. Labels are encoded as Normal=0, Lung_Opacity=1, COVID=2, Viral Pneumonia=3. DataLoaders use batch_size=32 with shuffling on train only.

Section 03

Implemented Models

Five models trained under identical conditions. All use Adam optimiser, CrossEntropyLoss, 10 epochs, batch size 32.

Model 01 · Serag Eldin
LNet
Baseline

A lightweight custom CNN trained from scratch, inspired by LightPneumoNet. Four convolutional blocks with progressively increasing filter depth (16→32→64→128), using 5×5 kernels in early blocks and 3×3 in deeper blocks, each followed by MaxPooling and ReLU. Two fully-connected Dense layers with Dropout(0.2) form the classification head. ~400K trainable parameters — 200× more efficient than DenseNet201.

Hyperparameters

  • PretrainedNone (from scratch)
  • LR1e-3
  • Dropout0.2
  • LossCrossEntropyLoss
91.26%
Test Accuracy
F1: 91.19% · Inference: 3.47ms
Model 02 · Mohamed Salah
DenseNet121
Transfer Learning

Each layer receives feature maps from all preceding layers: xl = Hl([x0, x1, …, xl-1]). This dense connectivity maximises feature reuse, combats vanishing gradients, and requires far fewer parameters than architectures of comparable depth. 121 layers, ~7.9M parameters. The final layer is replaced with a 4-class head.

Hyperparameters

  • PretrainedImageNet
  • LR1e-4
  • Fine-tuningAll layers
  • LossCrossEntropyLoss
97.31%
Test Accuracy
F1: 97.30% · Inference: 4.53ms
Model 03 · Hana Ayman
ResNet18
Transfer Learning

Residual (skip) connections: y = F(x, {Wi}) + x, allowing gradients to flow directly through the network and resolving the vanishing gradient problem. 18 layers in four residual stages (filter widths 64→128→256→512). ~11.7M parameters. Classification head: 512→4 fully-connected layer. Fastest inference of the transfer learning models at 2.85ms/sample.

Hyperparameters

  • PretrainedImageNet
  • LR1e-4
  • Head512 → 4
  • LossCrossEntropyLoss
96.40%
Test Accuracy
F1: 96.40% · Inference: 2.85ms
Model 04 · Adel Sobhy
VGG16
Transfer Learning

A uniform architecture of 13 convolutional layers (all 3×3 kernels) and 3 fully-connected layers, totalling 138M parameters. Stacking small convolutions approximates larger receptive fields. Classification head is replaced with a 4-class output. Dropout 0.5 in fully-connected layers. Serves as the canonical large-model baseline — second highest accuracy but highest inference time.

Hyperparameters

  • PretrainedImageNet
  • OptimiserSGD momentum 0.9
  • LR1e-3
  • Dropout0.5 (FC layers)
97.16%
Test Accuracy
F1: 97.16% · Inference: 7.45ms
Model 05 · Eyad Magdy
EfficientNet-B3 + CBAM
★ Novel Approach

Our primary contribution combines compound-scaled EfficientNet-B3 with a hand-implemented Convolutional Block Attention Module (CBAM). The full forward pass: ŷ = Softmax(W · GAP(CBAM(F(x)))) — where F is the EfficientNet-B3 feature extractor, CBAM applies sequential channel and spatial gates, and GAP collapses the 1280-channel map before the Dropout(0.3) + Linear(4) head.

Stage 1
EfficientNet-B3 Backbone
Compound scaling (depth α, width β, resolution γ) with MBConv blocks. Pre-trained on ImageNet. Outputs a 1280 × H' × W' feature map.
Stage 2
Channel Attention
GAP + GMP → shared MLP (reduction r=16) → element-wise sum → sigmoid scale Mc. Answers: which channels matter?
M_c = σ(MLP(f_avg) + MLP(f_max))
F' = M_c ⊗ F
Stage 3
Spatial Attention
Avg + Max across channels → 7×7 Conv → sigmoid Ms. Answers: where to look? The sigmoid output IS the built-in XAI heatmap.
M_s = σ(Conv₇ₓ₇([A_avg ; A_max]))
F'' = M_s ⊗ F'
Stage 4
Classification Head
Global Average Pooling → flatten to (B, 1280) → Dropout(0.3) → Linear(1280, 4) → logits.

Hyperparameters

  • PretrainedImageNet (B3)
  • LR1e-4 (Adam)
  • CBAM reductionr = 16
  • Spatial kernel7 × 7
  • Dropout0.3
  • LossCrossEntropyLoss
97.34%
Test Accuracy — Best Model
F1: 97.34% · Precision: 97.35% · Recall: 97.34%
Inference: 6.95ms/sample
Section 04

Results & Comparative Analysis

Model Accuracy Precision Recall F1-Score Inference (ms)
LNet 91.26%91.49%91.26%91.19%3.47
ResNet18 96.40%96.42%96.40%96.40%2.85
VGG16 97.16%97.20%97.16%97.16%7.45
DenseNet121 97.31%97.32%97.31%97.30%4.53
EfficientNet-B3 + CBAM 97.34% 97.35% 97.34% 97.34% 6.95

EfficientNet-B3+CBAM achieves the highest test accuracy (97.34%) and macro F1 across all metrics. All transfer learning models substantially outperform the from-scratch LNet, confirming that ImageNet pre-training provides critical inductive biases for medical imaging. ResNet18 offers the best speed-accuracy trade-off (2.85ms, 96.40%) for latency-sensitive pipelines. The dominant failure mode across all models is Normal ↔ Lung Opacity confusion — consistent with radiological literature, as early-stage Lung Opacity can produce subtle diffuse haziness indistinguishable from a normal CXR even for specialists.

Confusion Matrices

Classes: 0 = Normal · 1 = Lung Opacity · 2 = COVID-19 · 3 = Viral Pneumonia

📊
lnet_confusion_matrix
LNet Confusion Matrix .png
📊
densenet_confusion_matrix
DenseNet121 Confusion Matrix .png
📊
resnet_confusion_matrix
ResNet18 Confusion Matrix .png
📊
vgg_confusion_matrix
VGG16 Confusion Matrix .png
📊
efficientnet_confusion_matrix
EfficientNet-B3+CBAM Confusion Matrix .png

Training vs. Validation Loss Curves

Monitoring for overfitting — validation loss should track training loss without diverging.

📈
lnet_loss_curve
LNet Loss Curve .png
📈
densenet_loss_curve
DenseNet121 Loss Curve .png
📈
resnet_loss_curve
ResNet18 Loss Curve .png
📈
vgg_loss_curve
VGG16 Loss Curve .png
📈
efficientnet_loss_curve
EfficientNet-B3+CBAM Loss Curve .png
Section 05

Explainable AI — EfficientNet-B3 + CBAM

How CBAM produces built-in saliency maps

Unlike Grad-CAM which requires post-hoc gradient computation, the CBAM Spatial Attention gate produces a native saliency map Ms ∈ ℝ1×H×W as a direct output of its forward pass. This sigmoid-activated map encodes which spatial locations the model weighted most heavily when making its prediction — requiring zero additional overhead at inference time.

M_s = σ( Conv₇ₓ₇( [ AvgPool_C(F') ; MaxPool_C(F') ] ) )
F'' = M_s ⊗ F' ← the scale map IS the XAI heatmap

The 7×7 convolution kernel is deliberately large to capture long-range spatial context — bilateral, diffuse opacity patterns in COVID-19 span large portions of the lung field and require a wide receptive field for reliable spatial gating. Overlaying Ms on the original CXR allows clinicians to verify that the model's attention falls within pathological lung regions rather than on scanner borders or background artefacts.

🔬
xai1
XAI Result 01

Spatial Attention Heatmap — Sample 1

CBAM spatial attention overlay on a chest X-ray. Warmer regions indicate areas the model weighted most heavily in its classification decision. Attention should concentrate on lung parenchyma, particularly peripheral zones in COVID-19 cases.

🔬
xai2
XAI Result 02

Spatial Attention Heatmap — Sample 2

Second XAI result showing the model's spatial focus for a different class or patient. Comparing attention patterns across classes reveals whether the model has learned clinically meaningful, class-specific radiological features.

🔬
xai3
XAI Result 03

Spatial Attention Heatmap — Sample 3

Third XAI result. If the model focuses on scanner borders or background regions rather than lung tissue, it signals that predictions may be driven by dataset artefacts — the key failure mode identified in the Siddiqi & Javaid (2024) survey.

Why this matters: The 2024 survey by Siddiqi & Javaid documented that some high-accuracy CXR models achieved AUC 0.88 with the entire lung region occluded — proving they attended to background scanner artefacts rather than pathological tissue. CBAM's built-in saliency map allows direct verification that our 97.34%-accurate model is attending to the right anatomical structures, adding clinical trustworthiness beyond the accuracy number alone.

Section 06

Literature Review

EL Asnaoui, Chawki & Idri · 2020

Multi-Architecture Benchmark on CXR Classification

Fine-tuned nine DCNN architectures (VGG16, VGG19, InceptionV3, Xception, ResNet50, Inception ResNet V2, DenseNet201, MobileNet V2 + custom CNN) under identical conditions on the 5,856-image Kermany binary dataset. Key finding: ResNet50 (96.61%) and MobileNet V2 (96.27%) form the top tier, while Xception showed severe overfitting (95.45% train vs 69.03% val).

ResNet50 top: 96.61% Binary only · No explainability Justifies our residual architecture selection
Siddiqi & Javaid · 2024

Comprehensive Survey of 140 DL Pneumonia Studies (2020–2023)

Meta-analysis taxonomising custom CNNs (52), transfer learning (39), hybrid (25), and ensemble (12) models. Critical finding: a model achieved AUC 0.88 with the entire lung occluded, demonstrating that many high-accuracy results may reflect scanner artefacts rather than genuine pathological recognition. Vision Transformers identified as highest-potential frontier.

ViT: 94.96–99.39% Many results not externally validated Motivates our CBAM XAI integration
Nawaz et al. · 2023

ResNet101 + Classical ML Hybrid for COVID-19 Triage

Decouples deep feature extraction from classification: ResNet101 (ImageNet pretrained) outputs average-pool features fed into a linear SVM or KNN, rather than a Softmax head. ResNet101-SVM achieves 98.56% COVID-19 accuracy and AUC 1.00 for viral class, consistently outperforming end-to-end Softmax on datasets under 7,000 images.

SVM: 98.56% COVID-19 No Grad-CAM · Small dataset Two-stage feature extraction inspiration
Chauhan, Gupta & Doja · 2025

LightPneumoNet — Lightweight CNN for Edge Deployment

Custom 4-block CNN (388K parameters, 1.48MB) trained from scratch with grayscale input and class weights (2.0 Normal, 1.2 Pneumonia). Achieves 94.23% accuracy and 99.49% recall on the Kermany test set — matching ResNet152V2 (83.8M params) on recall. Demonstrates that extreme efficiency with clinical priority encoding can match models 200× larger.

388K params · 99.49% recall Binary only · No external validation Direct inspiration for our LNet baseline