<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Cracking the Code of Rare Cases]]></title><description><![CDATA[Cracking the Code of Rare Cases]]></description><link>https://meta-learning.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 06:26:23 GMT</lastBuildDate><atom:link href="https://meta-learning.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Cracking the Code of Rare Cases: Meta-Learning in Medical Imaging]]></title><description><![CDATA[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...]]></description><link>https://meta-learning.hashnode.dev/cracking-the-code-of-rare-cases-meta-learning-in-medical-imaging</link><guid isPermaLink="true">https://meta-learning.hashnode.dev/cracking-the-code-of-rare-cases-meta-learning-in-medical-imaging</guid><category><![CDATA[meta-learning]]></category><category><![CDATA[few shot learning]]></category><dc:creator><![CDATA[Shivashiga A M AIML]]></dc:creator><pubDate>Wed, 25 Jun 2025 06:27:24 GMT</pubDate><content:encoded><![CDATA[<p>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 <em>with very little data</em>. In this blog, I’ll walk you through my recent project where I built a <strong>chest X-ray classifier</strong> that can detect diseases like <strong>COVID-19, pneumonia, and tuberculosis</strong> using just a <em>few labeled examples</em> per class.</p>
<p>Sounds like magic? That’s the power of <strong>meta-learning</strong> — specifically, <strong>prototypical networks</strong> — which I’ll explain in a beginner-friendly way (with real results!).</p>
<h2 id="heading-the-problem">🚨 The Problem</h2>
<p>Diagnosing lung diseases quickly and accurately is incredibly important — especially in the middle of global health crises like COVID-19. While <strong>chest X-rays</strong> are affordable and widely available, interpreting them is tough, time-consuming, and requires expert radiologists.</p>
<p>To make things more difficult:</p>
<ul>
<li><p>There's <strong>not enough labeled data</strong> for many diseases.</p>
</li>
<li><p>Traditional deep learning models need <em>tons</em> of examples.</p>
</li>
<li><p>Medical data is sensitive, making sharing and labeling difficult.</p>
</li>
</ul>
<p>That’s where meta-learning comes in.</p>
<p>💡 What’s Meta-Learning, Anyway?</p>
<p>Meta-learning is like teaching a model <em>how to learn</em> — not just what to learn.</p>
<p>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.</p>
<p>In this project, I used <strong>Prototypical Networks</strong>, a meta-learning method that:</p>
<ul>
<li><p>Learns a <strong>prototype (average feature)</strong> for each class</p>
</li>
<li><p>Classifies new images based on <strong>distance from those prototypes</strong></p>
</li>
</ul>
<p>Super lightweight. Super effective.</p>
<p>🔧 The Project Setup</p>
<h3 id="heading-dataset">🗂 Dataset</h3>
<p>I used a dataset of chest X-ray images (from kaggle) across <strong>5 classes</strong>:</p>
<ul>
<li><p>Normal</p>
</li>
<li><p>Bacterial Pneumonia</p>
</li>
<li><p>Viral Pneumonia</p>
</li>
<li><p>COVID-19</p>
</li>
<li><p>Tuberculosis</p>
</li>
</ul>
<p>A total of <strong>8,070 images</strong> were split into:</p>
<ul>
<li><p>6,054 for training</p>
</li>
<li><p>2,016 for testing</p>
</li>
</ul>
<p>All images were resized to <strong>128×128 pixels</strong> and normalized.</p>
<h3 id="heading-training-strategy-few-shot-amp-episodic">🧠 Training Strategy: Few-Shot &amp; Episodic</h3>
<p>Instead of the usual full-dataset training, I used an <strong>episodic training setup</strong>:</p>
<ul>
<li><p><strong>Each episode:</strong> 5 classes (randomly picked)</p>
</li>
<li><p>For each class:</p>
<ul>
<li><p><strong>10 support images</strong> (known labels)</p>
</li>
<li><p><strong>15 query images</strong> (to be predicted)</p>
</li>
</ul>
</li>
<li><p>Total: <strong>500 episodes × 20 epochs</strong></p>
</li>
</ul>
<p>This approach simulates a real-world scenario where you only have a handful of labeled images — and it works surprisingly well.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750832106889/123ea054-d847-45fc-8e8e-83437b8b3a1a.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-the-model-architecture">🧱 The Model Architecture</h3>
<p>I kept it simple — a small <strong>CNN encoder</strong> with:</p>
<ul>
<li><p>3 convolutional layers</p>
</li>
<li><p>ReLU activations + MaxPooling</p>
</li>
<li><p>AdaptiveAvgPooling + Linear layer</p>
</li>
</ul>
<p>The idea was to extract <strong>embedding vectors</strong> that summarize each image's features.</p>
<h3 id="heading-how-classification-works">🔍 How Classification Works</h3>
<p>Here's where prototypical networks shine:</p>
<ol>
<li><p><strong>Calculate prototype</strong> for each class (just the average of embeddings from support images)</p>
</li>
<li><p>For each query image:</p>
<ul>
<li><p>Get its embedding</p>
</li>
<li><p><strong>Compare distance</strong> to each prototype (using Euclidean distance)</p>
</li>
<li><p>Assign the class of the <strong>nearest prototype</strong></p>
</li>
</ul>
</li>
</ol>
<p>No heavy classifier needed. Just smart geometry in feature space.</p>
<p>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.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750831604228/439619a6-137b-4406-8b27-457f588e0244.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-the-results-spoiler-it-works">📊 The Results (Spoiler: It Works!)</h2>
<p>After training the model, I got an overall <strong>accuracy of 81.6%</strong> — which is quite solid considering I trained it on just a few examples per class!</p>
<h3 id="heading-class-wise-scores">🧾 Class-wise Scores</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750831682126/26c1117c-61d3-4256-8f1c-7a5eb51094e0.png" alt class="image--center mx-auto" /></p>
<p>✅ Best performance: <strong>COVID-19, Tuberculosis, Normal</strong><br />⚠️ Some confusion: <strong>Bacterial vs. Viral Pneumonia</strong> — probably due to similar X-ray patterns</p>
<h2 id="heading-comparing-with-other-methods">🧪 Comparing with Other Methods</h2>
<h3 id="heading-meta-learning-models">Meta-Learning Models</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Method</td><td>Classes</td><td>Accuracy</td></tr>
</thead>
<tbody>
<tr>
<td>MetaCOVID (2021)</td><td>3</td><td>88–91%</td></tr>
<tr>
<td>UMLF-COVID (2023)</td><td>3</td><td>83–89%</td></tr>
<tr>
<td>Proposed Model (this work)</td><td>5</td><td><strong>81.6%</strong></td></tr>
</tbody>
</table>
</div><p>🧠 Note: Most other models used only 2–3 classes. Multi-class tasks are much harder, but more realistic.</p>
<h3 id="heading-deep-learning-models">Deep Learning Models</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Model</td><td>Accuracy</td><td>Remarks</td></tr>
</thead>
<tbody>
<tr>
<td>ResNet50</td><td>91.6%</td><td>Needs huge data</td></tr>
<tr>
<td>MobileNetV2</td><td>99.6%</td><td>Heavy model</td></tr>
<tr>
<td><strong>My Model</strong></td><td><strong>81.6%</strong></td><td>Works with few samples!</td></tr>
</tbody>
</table>
</div><h2 id="heading-why-this-matters">Why This Matters</h2>
<ul>
<li><p>No need for huge datasets</p>
</li>
<li><p>Works with simple CNN</p>
</li>
<li><p>Easily adapts to new diseases</p>
</li>
<li><p>Perfect for <strong>low-resource clinical settings</strong></p>
</li>
</ul>
<p>In short: <strong><em><mark>it’s practical, scalable, and smart.</mark></em></strong></p>
<h2 id="heading-whats-next">🚀 What’s Next?</h2>
<p>This was a great learning experience, but I’m already thinking of how to improve it:</p>
<ul>
<li><p>Try <strong>transformer-based encoders</strong> for richer features</p>
</li>
<li><p>Add <strong>explainable AI (XAI)</strong> to make model predictions more transparent</p>
</li>
<li><p>Use other modalities like CT or MRI scans</p>
</li>
</ul>
<h2 id="heading-want-to-explore-more">🔗 Want to Explore More?</h2>
<ul>
<li><p>📁 Dataset: <a target="_blank" href="https://www.kaggle.com/datasets/omkarmanohardalvi/lungs-disease-dataset-4-types">Kaggle Lung Disease Dataset</a></p>
</li>
<li><p>🧠 Code repo: <a target="_blank" href="https://github.com/shiga2006/Multi-class-lung-disease-classification">Github repo link</a></p>
</li>
</ul>
<h2 id="heading-final-thoughts">✍️ Final Thoughts</h2>
<p>This project showed me how powerful <strong>meta-learning</strong> 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.</p>
<p>Thanks for reading! 💙<br />Feel free to drop your thoughts, feedback, or questions in the comments.</p>
]]></content:encoded></item></channel></rss>