AWS Builder Center

How I built an uncertainty-aware medical AI system on AWS Free Tier

How I built SafeGuard AI, an uncertainty-aware medical X-ray triage system for rural India, deployed on AWS Free Tier. Covers the problem, the tech stack, what fought back during deployment, and what I learned.

Backend developer | Java, Spring Boot, Python, ML, AWS

How I built an uncertainty-aware medical AI system on AWS Free Tier

The Problem

In rural India, there is roughly one radiologist for every 100,000+ people. When a patient gets a chest X-ray, the X-ray is taken within hours, but the report takes 1 to 2 weeks. By then, pneumonia or TB may have become critical.
Existing AI models output things like "Pneumonia: 92%" but they do not know when they are wrong. In a rural clinic with no doctor on-site, a confidently wrong prediction is dangerous.
The real question is not whether AI can detect disease. The real question is whether AI knows when it does not know.

The Solution: SafeGuard AI

SafeGuard AI is a dual-disease chest X-ray triage system that:
  1. Detects Pneumonia and Tuberculosis from X-ray images
  1. Quantifies its own uncertainty using Monte Carlo Dropout
  1. Escalates to a human doctor when uncertain, instead of guessing
  1. Explains its decisions using Grad-CAM heatmaps
The hero feature: when pneumonia probability is 56.5% with uncertainty 0.05, the system outputs "DOCTOR REVIEW NEEDED" instead of "PNEUMONIA". The model knows it does not know.

The Stack

  • ML Framework: PyTorch 2.14 (CPU)
  • Model: MobileNetV3-Small with transfer learning
  • Uncertainty: Monte Carlo Dropout (20 stochastic forward passes)
  • Explainability: Grad-CAM
  • Backend: FastAPI + Uvicorn
  • Containerization: Docker
  • Deployment: AWS EC2 t3.micro (Mumbai region)
  • Training: Kaggle Free GPU (T4 x2)

Architecture

Browser -> HTTP POST /predict -> EC2 t3.micro -> Docker container -> FastAPI + PyTorch -> MobileNetV3 + MC Dropout + Grad-CAM -> JSON response -> Browser

Model Performance

Model
Training Images
Validation Accuracy
Pneumonia
5,216
98.7%
TB
4,200
100.0%

What Fought Back (Challenges)

Three things fought back during this build:

1. PyTorch GPU wheels would not fit in 8 GB disk

My EC2 t3.micro had an 8 GB root volume. When I ran pip install torch, it tried to install GPU-enabled PyTorch (torch + nvidia-cudnn-cu13 + nvidia-cublas + nvidia-nccl + triton) totaling about 4 GB. The install failed with "No space left on device".
Solution: I used --extra-index-url  https://download.pytorch.org/whl/cpu  to force CPU-only PyTorch (~200 MB instead of 4 GB). Since t3.micro has no GPU, this was the right call anyway. Saved 3.8 GB disk space.

2. Security Group rule editing removed my SSH rule

When I edited security group rules to add HTTP (port 80), the existing SSH rule (port 22) got removed because the "Type" dropdown reset it. I had to re-add SSH quickly before I lost access to the instance.
Solution: Always double-check rules after each edit. Add all rules in one go instead of editing one at a time.

3. AWS Builder Center vs AWS Console confusion

These are two separate sites with separate logins. As a student, I was first on Builder Center for student verification, then had to create a separate AWS Console account. The relationship between them is not explained clearly.
Solution: Use the same email for both. Complete student verification first, then set up Console.

What I learned

  1. Uncertainty is a feature, not a bug. A model that knows what it does not know is more useful than one that is confidently wrong.
  1. Deployment is most of the work. The model was the easy part. Docker, EC2, environment paths, kernel updates, and disk space management took longer.
  1. Cost-aware architecture matters. Using CPU-only PyTorch (about 200 MB) instead of GPU-enabled PyTorch (about 4 GB) saved both time and money.
  1. Grad-CAM is underrated. Showing where the model looks makes the AI immediately more trustworthy.

Cost

Total monthly cost: $0 within AWS Free Tier.
  • EC2 t3.micro: 750 hours/month free for 12 months
  • EBS 8 GB gp3: within 30 GB free tier
  • Public IPv4: free for first 12 months
  • Training on Kaggle Free GPU: $0

Links

Built for First Commit Hackathon 2026 (Bharat Builds Tour).
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article