Swish instead of ReLU
The same three-block network with Swish activations in the convolutional layers, trained without augmentation. Early stopping ended training at epoch 7.
95.8% test accuracy
No improvement. ReLU stayed.
MIT Applied Data Science and AI · Capstone project
I built and compared five convolutional neural networks that classify microscope images of red blood cells as parasitized or uninfected. The goal was a model accurate enough to help, and careful enough to almost never miss an infection.
01 · The problem
Malaria remains one of the world's most serious health challenges. The World Health Organization estimated 249 million cases and 608,000 deaths in 2022, most of them young children and pregnant women in sub-Saharan Africa.
The standard diagnosis is a technician examining a blood smear under a microscope. It works, but it is slow, depends on scarce expertise, and is prone to human error. Rapid diagnostic tests exist, but they can lack sensitivity and are not always available in remote areas.
An image classifier that reads the same blood cell images could make screening faster and more consistent, and ease the load on health workers where it matters most.
Build a CNN that separates parasitized from uninfected cell images.
Prioritize recall on the parasitized class over raw accuracy.
Use preprocessing and augmentation so the model holds up on unseen cells.
Judge every model with confusion matrices and held-out test images.
02 · The data
Each image is one red blood cell cropped from a stained blood smear. Parasitized cells contain the Plasmodium parasite; uninfected cells do not.
A balanced dataset means accuracy is a fair headline metric, and neither class dominates training.
Uninfected cells tend to be rounder, but shape is not reliable. The real tell is the stain: parasitized cells carry one or more dark purple or pink spots.
Try it
You are the model for a minute. Look at the cell and make the call. Then see how you compare to the network's 98.5%.
No answers yet.
Three quick explorations tested whether simple image processing makes the difference between classes easier to see.
Parasitized
Uninfected
Parasitized
Uninfected
Parasitized
Uninfected03 · The models
Each model builds on a lesson from the one before. All were trained with the Adam optimizer and categorical cross-entropy, for up to 30 epochs with early stopping, then scored on the same 2,600 held-out test images. Pick a model to see how it was built and how it did.
04 · Results
Out of 1,300 infected test cells and 1,300 healthy ones, here is how many each model got wrong. Shorter bars are better, and the top bar in each pair is the one that matters most.
| Model | Accuracy | Recall infected | Precision infected | Missed | False alarms | Test loss | Parameters |
|---|
Recall is the share of infected cells the model caught. Precision is the share of its "infected" calls that were right. Both are computed from each model's confusion matrix on the 2,600 test images. One caveat: the test images also served as the validation data that early stopping monitored, so these figures are likely slightly optimistic. A stricter rerun would hold out part of the training set for that job.
05 · The final model
Model 4 was the most accurate, had the fewest missed infections, and its errors were evenly balanced: 19 missed infections against 20 false alarms. What set it apart was less the network and more the training data.
4.3 million trainable parameters, nearly all of them in the first dense layer.
Every training image was randomly transformed each time the model saw it, so it could not simply memorize cells. The test images were left untouched.
A batch of augmented training images. The streaks at the edges come from filling in pixels after a shift or rotation.
def cnn_model_4():
model = Sequential([
Conv2D(64, (3, 3), activation='relu', padding='same', input_shape=(128, 128, 3)),
MaxPooling2D(2, 2),
Conv2D(64, (3, 3), activation='relu', padding='same'),
MaxPooling2D(2, 2),
Conv2D(128, (3, 3), activation='relu', padding='same'),
MaxPooling2D(2, 2),
Flatten(),
Dense(128, activation='relu'),
Dropout(0.5), # regularization to prevent overfitting
Dense(2, activation='softmax')
])
return model
datagen = ImageDataGenerator(
rescale=1.0/255, # normalize pixel values to [0, 1]
rotation_range=20, # rotate up to 20 degrees
width_shift_range=0.2, # shift horizontally up to 20%
height_shift_range=0.2, # shift vertically up to 20%
shear_range=0.2, # shearing transformations
zoom_range=0.2, # zoom in or out up to 20%
horizontal_flip=True, # random horizontal flips
fill_mode='nearest' # fill new pixels from their nearest neighbors
)
06 · Further experiments
The same three-block network with Swish activations in the convolutional layers, trained without augmentation. Early stopping ended training at epoch 7.
95.8% test accuracy
No improvement. ReLU stayed.
A quick trial of a small CNN on HSV-converted images, using an 80/20 split of the 2,600 test images (2,080 to train, 520 to validate) for 30 epochs.
98.5% validation accuracy
Promising for so little data, and the top candidate for follow-up work.
The final architecture retrained with different augmentation strengths and scored on the test images.
Heavier rotation and shear caught the most infections, at the cost of more false alarms (38). The original settings scored lower on this rerun than in the first run, a reminder that a point or so of difference between top models is within run-to-run variation.
07 · Takeaways
The complete Jupyter notebook is available, with all the code, training logs and plots. A few result cells that displayed the wrong model's output have been corrected and are clearly marked.