惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
B
Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
博客园_首页
C
Check Point Blog
博客园 - 【当耐特】
美团技术团队
Last Week in AI
Last Week in AI
A
About on SuperTechFans
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence
Martin Fowler
Martin Fowler
J
Java Code Geeks
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
F
Fortinet All Blogs

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built an AI That Detects Pneumonia From Chest X-Rays He...
Sheikh Sadi · 2026-05-01 · via DEV Community

A few weeks ago, I shipped PneumoScan AI a deep learning model that analyzes chest X-ray images and detects pneumonia in seconds, with 90%+ accuracy. It's live, it's free, and anyone can use it right now.

🔗 pneumonia-scan-ai.netlify.app

This is the story of how I built it — and everything I learned along the way.


Why Pneumonia?

Pneumonia kills over 2 million people annually. A huge portion of those deaths happen in low-resource areas where radiologists are scarce and diagnosis is slow.

I'm not claiming to solve that problem. But I wanted to build something that mattered not just another MNIST classifier or iris flower predictor. Medical imaging felt real.


The Dataset

I used the Chest X-Ray Images (Pneumonia) dataset from Kaggle.

  • 5,800+ clinical chest X-ray images
  • Two classes: NORMAL and PNEUMONIA (Viral & Bacterial)
  • Real hospital data from Guangzhou Women and Children's Medical Center

One thing I learned immediately: the dataset is imbalanced. There are significantly more pneumonia images than normal ones. This is something you have to think about carefully in medical AI because a model that just predicts "pneumonia" on everything could still hit decent accuracy numbers while being completely useless.


The Architecture — MobileNetV2 + Custom Head

I chose MobileNetV2 as my base model for two reasons:

  1. It's lightweight (14MB) perfect for deployment on free-tier infrastructure
  2. It was pre-trained on ImageNet, so it already knows how to extract visual features

The key idea is transfer learning instead of training a CNN from scratch on 5,800 images (which isn't enough), I used MobileNetV2 as a frozen feature extractor and added my own classification head on top.

Here's the full pipeline:

Input (any size RGB image)
    ↓
Resizing Layer      → 224 × 224 (built into model)
Rescaling Layer     → pixel values ÷ 255
    ↓
MobileNetV2         → FROZEN (trainable = False)
16 inverted residual blocks
Final feature map: 7 × 7 × 1280
    ↓
GlobalAveragePooling2D  → collapses to 1280 values
    ↓
Dense(128, ReLU)        → learns pneumonia-specific patterns
    ↓
Dropout(0.3)            → prevents overfitting
    ↓
Dense(1, Sigmoid)       → outputs probability (0 = Normal, 1 = Pneumonia)

Enter fullscreen mode Exit fullscreen mode

Why freeze MobileNetV2?

Because it already knows how to see. The ImageNet weights encode knowledge about edges, textures, and shapes that transfer surprisingly well to X-rays. Fine-tuning all those layers on a small dataset would just cause overfitting.

Why add Dense(128) before the output?

The raw GlobalAveragePooling output is 1280 features most of which are irrelevant to pneumonia. The Dense(128) layer acts as a bottleneck, forcing the model to compress what it learned into the most useful 128 features for this specific task.

Training config:

  • Optimizer: Adam (lr=0.001)
  • Loss: Binary Crossentropy
  • Final accuracy: 90%+

The Problem I Didn't Expect The Dog Test

After I deployed the first version, I decided to test it.

I uploaded a photo of a dog sitting in a bathroom smoking a cigarette.

The result?

{
  "Result": "PNEUMONIA DETECTED",
  "Confidence Score": "100.00%"
}

Enter fullscreen mode Exit fullscreen mode

100% confident. That dog had pneumonia.

This is a classic failure mode of CNNs the model has no concept of "this isn't even an X-ray." It was trained only on X-rays, so it forced every single image into one of two buckets regardless of what it actually was.

I needed an input validation layer.


The Fix Saturation Gate

The solution I came up with is what I call a Saturation Gate.

The logic is simple: chest X-rays are grayscale. Any real X-ray will have near-zero color saturation. A photo of a dog, a selfie, a meme these all have high saturation.

So before the image ever reaches the model, I convert it to HSV color space and measure the mean saturation value. If it exceeds a threshold.

The dog photo gets rejected now. The model only sees what it was trained to see.


The Deployment Stack

I wanted this to be completely free to host — no cloud bills, no server management.

Here's what I ended up with:

Layer Technology
Model Inference Hugging Face Spaces (Gradio + TensorFlow-CPU)
Frontend Netlify (custom Tailwind CSS portal)
Bridge iframe

The Gradio app on Hugging Face handles all the heavy lifting loading the .h5 model, running inference, returning JSON results. The Netlify frontend is just a clean portal that embeds the Gradio Space via iframe.

Total hosting cost: $0.


What I Learned

1. Accuracy alone is a lie in medical AI.
A model can hit 90% accuracy while still missing dangerous cases. Always look at your confusion matrix. False negatives missed pneumonia cases — are the ones that matter most.

2. Input validation is not optional.
Any model you deploy in the real world needs to handle unexpected inputs gracefully. The Saturation Gate wasn't in any tutorial I followed. I had to think of it myself after seeing the model fail in a funny but revealing way.

3. Transfer learning is magic for small datasets.
If you're working with fewer than 50,000 images, you almost certainly shouldn't be training a CNN from scratch. Use pretrained weights. Freeze the base. Train only the head.

4. Ship first, improve later.
The first version was broken in obvious ways. But shipping it is what revealed those problems. The dog test only happened because I deployed it.


What's Next

  • Grad-CAM heatmap overlays showing which part of the X-ray triggered the detection. This is the standard in medical AI and would make the tool genuinely useful for educational purposes. Precision/Recall analysis properly evaluating false negative rate on the test set
  • More pathologies tuberculosis, pleural effusion, cardiomegaly

The Repo

The trained model is open source. You can download it, use it, build on it.

github.com/GradienNinja/PneumoScan-AI


Final Thought

I fix cars for a living. I don't have a degree. I didn't take a course that handed me this project.

I just built it.

If you're self-taught and reading this wondering whether you're "ready" to build something real you're not going to get ready by waiting. You get ready by shipping.


Built by Sheikh Sadi Asif — @GradienNinja | AstroLabSoft AI Lab

  • Disclaimer: This is a research and educational project. Not a certified medical device. Always consult a qualified healthcare professional for medical decisions.*