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.
- Host: GitHub
- URL: https://github.com/rahulpatel2002/blood-group-detection
- Owner: RAHULPATEL2002
- Created: 2025-03-05T09:09:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-05T10:46:13.000Z (over 1 year ago)
- Last Synced: 2025-03-05T11:34:52.720Z (over 1 year ago)
- Topics: blood-group-detection, computer-vision, deep-learning, flask, image-processing, infrared-images, machine-learning, medical-api, tenserflow
- Language: Python
- Homepage:
- Size: 13.7 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ฉธ BloodSense AI โ Blood Group Detection





**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**
[](https://github.com/RAHULPATEL2002)
[](https://www.linkedin.com/in/rahul-patel-27b552250/)
[](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!**