ESEN← Back to projects
Machine Learning · Case study

Convolutional neural network for classifying COVID-19 chest X-rays

By Guille Ferveg· 2026· Deep Learning · TensorFlow / Keras

I designed, trained and optimized a convolutional neural network (CNN) to distinguish normal chest X-rays from COVID-19 cases. The goal was not only high accuracy, but also choosing appropriate metrics, applying regularization and proposing systematic hyperparameter tuning so the model would generalize.

Important note: this is an academic deep-learning exercise using a public dataset. It is not a medical device or clinical diagnostic tool and must not be used for real healthcare decisions.
Type
Academic exercise · Computer vision
Dataset
COVID-19 X-ray (Kaggle) · ~2,100 images
Stack
TensorFlow · Keras · scikit-learn
Result
92.86% accuracy · 94.29% COVID recall

01 The problem

During the pandemic, quickly classifying chest X-rays was a bottleneck. CNNs are particularly effective with images because they learn which features matter on their own, without requiring those features to be hand-coded. But a good model is not only its architecture: it also depends on metric selection, regularization and hyperparameter tuning. That was the core of the project.

02 Data and preprocessing

The dataset contains X-rays in two classes (COVID-19 and normal). Before training, I prepared the images:

from tensorflow.keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(
    rescale=1./255,        # normalize to [0,1]
    rotation_range=15,     # rotate up to ±15°
    zoom_range=0.1,        # 10% zoom
    horizontal_flip=True,   # horizontal flip
    validation_split=0.2
)

03 CNN architecture

I designed a network with three convolutional blocks (32 → 64 → 128 filters), incorporating BatchNormalization and Dropout as regularization from the beginning rather than as a final patch.

model = models.Sequential([
    # Block 1
    layers.Conv2D(32, (3,3), activation='relu', padding='same'),
    layers.BatchNormalization(),
    layers.MaxPooling2D(2,2),
    layers.Dropout(0.25),
    # ... blocks 2 and 3 (64 and 128 filters) ...
    layers.Flatten(),
    layers.Dense(256, activation='relu'),
    layers.Dropout(0.5),
    layers.Dense(1, activation='sigmoid')  # binary output
])
▶ Total parameters: 1,482,177 · trainable: 1,481,217

For training I used the Adam optimizer with EarlyStopping (to prevent overtraining) and ReduceLROnPlateau (which lowers the learning rate when the model stalls). Training stopped automatically at epoch 35.

04 Results

The model achieved solid performance on the test set:

92.86%Overall accuracy
94.29%COVID recall — detects real cases
91.43%Precision — low false-positive rate
0.928F1 score — precision/recall balance
MetricValueIdealInterpretation
Accuracy92.86%→ 100%Strong overall performance
Recall (COVID)94.29%→ 100%Detects 94% of real COVID cases
Precision (COVID)91.43%→ 100%Low false-positive rate
F1-Score0.928→ 1Strong precision/recall balance
The key criterion: in medical diagnosis, accuracy alone can be misleading. I prioritized Recall (94.29%) because the most costly error is a false negative: missing a real COVID case. For that reason, the analysis went beyond accuracy and examined precision, recall and F1 separately.

05 Optimization techniques

I combined three families of techniques with complementary effects on generalization:

The result was stable convergence with a training/validation gap below 3%, indicating that the model is not overfitting.

06 Hyperparameter tuning

I proposed systematic tuning with Keras Tuner over the most influential parameters: lowering the learning rate with a scheduler, reducing the batch size, replacing Adam with AdamW and refining dropout. The comparison below presents the baseline model against a projected tuned scenario; it is not a second independent clinical validation.

Baseline vs. projected tuned scenario
Impact of regularization and hyperparameter tuning
Accuracy · baseline
87.14%
Accuracy · tuned (projected)
92.86%
Recall · baseline
88.57%
Recall · tuned (projected)
94.29%

Academic projection: +5.7 percentage points in accuracy and recall, with an estimated 33% reduction in error (MSE). These values do not replace independent evaluation or clinical validation.

Conclusion and future work

The project shows that a diagnostic support system requires balancing performance, methodological rigor and responsibility. A well-regularized CNN, evaluated with metrics chosen according to the real cost of each error, can deliver robust results. As a next step, I proposed exploring Transfer Learning with pretrained architectures such as ResNet50, EfficientNet and MobileNetV2, which often perform well on limited datasets.

PythonTensorFlowKerasCNNDeep LearningComputer visionscikit-learnKeras Tuner

Working on an image or prediction problem?

Classification, computer vision or predictive models—I can help take your idea to a prototype. Let’s talk.

Let’s talk →