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.
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.
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).
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.
Five models trained under identical conditions. All use Adam optimiser, CrossEntropyLoss, 10 epochs, batch size 32.
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.
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.
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.
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.
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.
| 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.
Classes: 0 = Normal · 1 = Lung Opacity · 2 = COVID-19 · 3 = Viral Pneumonia
Monitoring for overfitting — validation loss should track training loss without diverging.
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.
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.
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.
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.
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.
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 selectionMeta-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 integrationDecouples 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 inspirationCustom 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