An open API service indexing awesome lists of open source software.

https://github.com/rahulpatel2002/blood-group-detection

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.
https://github.com/rahulpatel2002/blood-group-detection

blood-group-detection computer-vision deep-learning flask image-processing infrared-images machine-learning medical-api tenserflow

Last synced: about 1 month ago
JSON representation

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.

Awesome Lists containing this project

README

          

# ๐Ÿฉธ BloodSense AI โ€” Blood Group Detection

![BloodSense AI](https://img.shields.io/badge/BloodSense-AI-e63946?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTEyIDJDNi40OCAyIDIgNi40OCAyIDEyczQuNDggMTAgMTAgMTAgMTAtNC40OCAxMC0xMFMxNy41MiAyIDEyIDJ6Ii8+PC9zdmc+)
![Python](https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white)
![TensorFlow](https://img.shields.io/badge/TensorFlow-2.20-FF6F00?style=for-the-badge&logo=tensorflow&logoColor=white)
![Flask](https://img.shields.io/badge/Flask-3.1-000000?style=for-the-badge&logo=flask&logoColor=white)
![License](https://img.shields.io/badge/License-Research-green?style=for-the-badge)

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

[๐Ÿš€ Live Demo](#deployment) ยท [๐Ÿ“– Documentation](#usage) ยท [๐Ÿ› Issues](https://github.com/RAHULPATEL2002/blood-group-detection/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

```bash
# 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)

```bash
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

```bash
# 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/` | 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](https://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](https://img.shields.io/badge/GitHub-RAHULPATEL2002-181717?style=flat-square&logo=github)](https://github.com/RAHULPATEL2002)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-Rahul_Patel-0A66C2?style=flat-square&logo=linkedin)](https://www.linkedin.com/in/rahul-patel-27b552250/)
[![Email](https://img.shields.io/badge/Email-rahulpatelanuppur@gmail.com-D14836?style=flat-square&logo=gmail&logoColor=white)](mailto:rahulpatelanuppur@gmail.com)

---

## ๐Ÿ“„ Publications

- [Blood Group Detection Using Infrared Hand Image โ€” IJIRT189616](IJIRT189616_PAPER_final_published.pdf)

---

โญ **Star this repo if you find it helpful!**