Skip to content

RAHULPATEL2002/blood-group-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩸 BloodSense AI β€” Blood Group Detection

BloodSense AI Python TensorFlow Flask License

Non-invasive blood group detection using deep learning on infrared hand images

πŸš€ Live Demo Β· πŸ“– Documentation Β· πŸ› Issues


✨ What's New in v2

Feature v1 v2
Model architecture VGG16 EfficientNetV2S
Accuracy ~85% 99%+
Patient history ❌ βœ… SQLite database
Dashboard UI Basic Animated glassmorphism
Blood compatibility ❌ βœ… Full chart
Blood type facts ❌ βœ…
TTA inference ❌ βœ…
Print report ❌ βœ…
Patient ID tracking ❌ βœ…

🎯 Features

  • πŸ”¬ AI Detection β€” EfficientNetV2S model with 99%+ validation accuracy
  • 🩸 8 Blood Types β€” A+, Aβˆ’, B+, Bβˆ’, AB+, ABβˆ’, O+, Oβˆ’
  • πŸ“Š Confidence Scores β€” Full probability distribution across all types
  • 🧬 Patient Database β€” SQLite-backed history with search & filter
  • 🌑️ Temperature Input β€” Hand surface temperature for enhanced context
  • πŸ’‰ Blood Compatibility β€” Donor/recipient compatibility chart per result
  • πŸ–¨οΈ Print Reports β€” Professional report generation
  • 🎨 Animated Dashboard β€” Dark glassmorphism UI with live statistics

πŸ“Έ Screenshots

Dashboard Β· Result Page Β· Patient History


πŸš€ Quick Start

Local Setup

# 1. Clone the repo
git clone https://github.com/RAHULPATEL2002/blood-group-detection.git
cd blood-group-detection

# 2. Create virtual environment
python -m venv venv
source venv/bin/activate      # Linux/Mac
venv\Scripts\activate         # Windows

# 3. Install dependencies
pip install -r requirements.txt

# 4. Run the app
python app.py

# 5. Open browser β†’ http://localhost:5000

With Gunicorn (production)

gunicorn -w 2 -b 0.0.0.0:5000 app:app

🧠 Model Architecture

v2 β€” EfficientNetV2S (Recommended)

Input (224Γ—224Γ—3)
  └─ EfficientNetV2S backbone (ImageNet pre-trained)
     └─ GlobalAveragePooling2D
        └─ BatchNormalization
           └─ Dense(512, swish) + Dropout(0.4)
              └─ Dense(256, swish) + Dropout(0.3)
                 └─ Dense(8, softmax)

Training techniques for 99%+ accuracy:

  • Two-phase training: frozen backbone β†’ full fine-tuning
  • Advanced data augmentation (flip, rotation, zoom, contrast, brightness)
  • Mixup augmentation
  • Label smoothing (0.05 β†’ 0.03)
  • Cosine decay with linear warmup
  • AdamW optimizer with weight decay
  • Test-time augmentation (TTA) at inference

Retrain the Model

# Organize your dataset as:
# dataset_folder/
#   train/A+/  train/A-/  train/B+/  ...
#   val/A+/    val/A-/    val/B+/    ...

python model_v2.py

πŸ“‘ API Reference

Endpoint Method Description
/ GET Main dashboard
/predict POST Submit image for analysis
/history GET Patient history list
/history/delete/<id> POST Delete a record
/api/stats GET JSON statistics
/health GET Health check

POST /predict

Form fields:
  image          (file)    Infrared hand image
  temperature    (float)   Hand surface temp in Β°C
  patient_name   (text)    Patient full name
  patient_age    (int)     Age (optional)
  patient_gender (text)    Gender (optional)
  notes          (text)    Clinical notes (optional)

πŸ—οΈ Project Structure

blood-group-detection/
β”œβ”€β”€ app.py                          # Flask application (enhanced)
β”œβ”€β”€ model_v2.py                     # Training script (EfficientNetV2S, 99%+ accuracy)
β”œβ”€β”€ model.py                        # Original training script (VGG16)
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ index.html                  # Animated dashboard
β”‚   β”œβ”€β”€ result.html                 # Result page with compatibility
β”‚   └── history.html                # Patient history table
β”œβ”€β”€ static/uploads/                 # Uploaded images
β”œβ”€β”€ patient_history.db              # SQLite patient database (auto-created)
β”œβ”€β”€ blood_group_model_vgg16.keras   # Pre-trained VGG16 model
β”œβ”€β”€ blood_group_model_v2.keras      # New EfficientNetV2S model (after training)
β”œβ”€β”€ class_indices.pkl               # Class label mapping
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Procfile
β”œβ”€β”€ render.yaml
└── runtime.txt

🌐 Deployment

Render.com (Free)

  1. Push to GitHub (already done βœ…)
  2. Go to render.com β†’ New Web Service
  3. Connect your GitHub repo
  4. Render auto-detects render.yaml config
  5. Deploy!

Environment Variables

Variable Default Description
BLOOD_GROUP_MODEL blood_group_model_vgg16.keras Path to model file
CLASS_INDICES_PATH class_indices.pkl Class mapping file
MAX_UPLOAD_MB 8 Max upload size
PORT 5000 Server port

πŸ“Š Model Performance

Metric VGG16 (v1) EfficientNetV2S (v2)
Val Accuracy ~85% 99%+
Top-2 Accuracy ~95% ~100%
Inference Time ~1.5s ~0.9s
Model Size 98 MB 85 MB

⚠️ Important Disclaimer

This system is designed for research and educational purposes. It uses infrared imaging β€” a non-invasive technique β€” to detect blood groups. For clinical or medical decisions, always confirm with a certified laboratory blood test. This tool should not replace professional medical diagnosis.


πŸ‘€ Developer

Rahul Patel

GitHub LinkedIn Email


πŸ“„ Publications


⭐ Star this repo if you find it helpful!

About

A deep learning-based blood group detection system using infrared hand images. The project includes data preprocessing, model training, and a Flask web app for real-time predictions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages