Cracking the Code of Rare Cases: Meta-Learning in Medical Imaging

If you're reading this, you're probably curious about how machine learning can help in healthcare — or how we can teach models to work with very little data. In this blog, I’ll walk you through my recent project where I built a chest X-ray classifier that can detect diseases like COVID-19, pneumonia, and tuberculosis using just a few labeled examples per class.

Sounds like magic? That’s the power of meta-learning — specifically, prototypical networks — which I’ll explain in a beginner-friendly way (with real results!).

🚨 The Problem

Diagnosing lung diseases quickly and accurately is incredibly important — especially in the middle of global health crises like COVID-19. While chest X-rays are affordable and widely available, interpreting them is tough, time-consuming, and requires expert radiologists.

To make things more difficult:

  • There's not enough labeled data for many diseases.

  • Traditional deep learning models need tons of examples.

  • Medical data is sensitive, making sharing and labeling difficult.

That’s where meta-learning comes in.

💡 What’s Meta-Learning, Anyway?

Meta-learning is like teaching a model how to learn — not just what to learn.

Imagine showing a child just 2-3 animal pictures and they can already guess new ones — that’s what meta-learning tries to do. Instead of feeding it thousands of X-rays, we teach it to generalize from just a few.

In this project, I used Prototypical Networks, a meta-learning method that:

  • Learns a prototype (average feature) for each class

  • Classifies new images based on distance from those prototypes

Super lightweight. Super effective.

🔧 The Project Setup

🗂 Dataset

I used a dataset of chest X-ray images (from kaggle) across 5 classes:

  • Normal

  • Bacterial Pneumonia

  • Viral Pneumonia

  • COVID-19

  • Tuberculosis

A total of 8,070 images were split into:

  • 6,054 for training

  • 2,016 for testing

All images were resized to 128×128 pixels and normalized.

🧠 Training Strategy: Few-Shot & Episodic

Instead of the usual full-dataset training, I used an episodic training setup:

  • Each episode: 5 classes (randomly picked)

  • For each class:

    • 10 support images (known labels)

    • 15 query images (to be predicted)

  • Total: 500 episodes × 20 epochs

This approach simulates a real-world scenario where you only have a handful of labeled images — and it works surprisingly well.

🧱 The Model Architecture

I kept it simple — a small CNN encoder with:

  • 3 convolutional layers

  • ReLU activations + MaxPooling

  • AdaptiveAvgPooling + Linear layer

The idea was to extract embedding vectors that summarize each image's features.

🔍 How Classification Works

Here's where prototypical networks shine:

  1. Calculate prototype for each class (just the average of embeddings from support images)

  2. For each query image:

    • Get its embedding

    • Compare distance to each prototype (using Euclidean distance)

    • Assign the class of the nearest prototype

No heavy classifier needed. Just smart geometry in feature space.

For example, let us consider the following figure, the model calculates the distances between the query embedding and each class prototype in the latent space. The query image is assigned to the class whose prototype is closest in this embedding space. For example, if the prototype for Class V (COVID-19) is nearest to the query embedding, the image will be classified as COVID-19. This process highlights the distance-based matching principle that is central to prototypical networks, allowing for accurate classification with minimal labeled data. The figure also illustrates how embeddings from the support set are grouped and averaged to create prototypes, which serve as reference points for assigning class labels to unseen queries.

📊 The Results (Spoiler: It Works!)

After training the model, I got an overall accuracy of 81.6% — which is quite solid considering I trained it on just a few examples per class!

🧾 Class-wise Scores

✅ Best performance: COVID-19, Tuberculosis, Normal
⚠️ Some confusion: Bacterial vs. Viral Pneumonia — probably due to similar X-ray patterns

🧪 Comparing with Other Methods

Meta-Learning Models

MethodClassesAccuracy
MetaCOVID (2021)388–91%
UMLF-COVID (2023)383–89%
Proposed Model (this work)581.6%

🧠 Note: Most other models used only 2–3 classes. Multi-class tasks are much harder, but more realistic.

Deep Learning Models

ModelAccuracyRemarks
ResNet5091.6%Needs huge data
MobileNetV299.6%Heavy model
My Model81.6%Works with few samples!

Why This Matters

  • No need for huge datasets

  • Works with simple CNN

  • Easily adapts to new diseases

  • Perfect for low-resource clinical settings

In short: it’s practical, scalable, and smart.

🚀 What’s Next?

This was a great learning experience, but I’m already thinking of how to improve it:

  • Try transformer-based encoders for richer features

  • Add explainable AI (XAI) to make model predictions more transparent

  • Use other modalities like CT or MRI scans

🔗 Want to Explore More?

✍️ Final Thoughts

This project showed me how powerful meta-learning can be — especially in situations where data is scarce and speed matters. It’s a practical tool that can actually help in real-world healthcare, not just academic papers.

Thanks for reading! 💙
Feel free to drop your thoughts, feedback, or questions in the comments.

1
Subscribe to my newsletter

Read articles from Shivashiga A M AIML directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shivashiga A M AIML
Shivashiga A M AIML