An AI-powered diagnostic and generative research platform that uses Conditional Generative Adversarial Networks (cGANs) to synthesize realistic microscopy patches of red blood cells, balancing imbalanced datasets to boost classifier recall.
2024–2025
Overview
In medical diagnostics, rare diseases suffer from severe data scarcity, which biases classifier models. This research project presents a Conditional GAN pipeline designed to generate highly realistic synthetic cell patches of sickle and normal red blood cells, creating a perfectly balanced clinical training environment.
Sickle Cell CGAN active research dashboard, designed to preserve crescent-like sickle characteristics and micro-textures.
Objectives
Our key objectives: solve data scarcity, fix majority class classifier bias, and provide explainable visual diagnostics via Grad-CAM.
Sickle cell images are extremely rare in public databases. We train a Conditional GAN to "create" high-quality, morphology-accurate synthetic cell patches.
Standard neural networks often miss sickle cells because they are outnumbered 3:1 in clinical datasets. SGAN balances the training set to a perfect 1:1 ratio.
Instead of a simple "Normal/Sickle" black-box label, the platform generates a Grad-CAM saliency heatmap highlighting precisely which crescent curvatures drove the decision.
Successfully boosted ResNet18 diagnosis accuracy to 85.47% and achieved a test set F1-Score of 90.44% with 100.00% precision.
The Problem
Over 300,000 infants are born annually with Sickle Cell Disease (SCD), yet globally there are fewer than 5 public microscopic image datasets available for deep learning. This severe lack of representation means standard networks are highly biased toward normal blood cells, leading to a high rate of missed diagnoses (false negatives).
Impact of Generative Augmentation
By generating 80 synthetic sickle cell patches to balance the clinical data, classifier recall on the minority class was boosted from 0.45 to 0.80 (+35% improvement), drastically reducing false negatives.
Microscopic Cell Morphology
Comparing standard blood smears (left) to normal blood disc diagrams (center) and the high-res "crescent" signatures (right) that SGAN must learn to replicate.
Package Structure
Below is a detailed engineering map of the Python files and functions within the core package namespace:
| File Name | Key Class / Function | Functional Role |
|---|---|---|
config.py |
Hyperparameters |
Centralized dictionary containing learning rates, directories, batch sizes, and model parameters. |
data_utils.py |
prepare_low_data_split() |
Partitions raw dataset into 80% train / 20% test and subsamples training set to a skewed 3:1 ratio. |
get_transforms() |
Pre-processing pipeline: resizes images to 128x128, converts to Tensors, and normalizes pixels to [-1, 1]. | |
SickleCellDataset |
Custom PyTorch handler performing real-time data augmentations (flips, stains, and rotations). | |
models.py |
Generator |
StyleGAN-inspired Conditional Generator mapping noise (z) and class labels (y) to 128x128 synthetic patches. |
MultiScaleDiscriminator |
Dual-scale patch evaluator analyzing boundaries at 128x128 and textures/colors at 64x64. | |
Reconstructor |
Auxiliary classifier mapping fake patches back to class labels to preserve crescent curvatures. | |
train_gan_v2.py |
train_dsgan() |
Co-trains G, D, and Reconstructor with multi-scale adversarial losses and cycle penalties. |
save_sample() |
Saves intermediate synthetic grids under outputs/samples/ for qualitative evaluations. |
|
train_classifier.py |
build_classifier() |
Swaps the classification head of a pre-trained ResNet18 to output 2 classes. |
train_classifier() |
Trains ResNet18 using PyTorch Mixed Precision (AMP) and Cosine Annealing learning rate schedules. | |
realistic_synthesis.py |
generate_augmented_samples() |
Morphology-preserving fallback synthesizer generating synthetic samples directly from real cell crops. |
_remove_annotation_lines() |
Uses OpenCV fast marching inpainting to erase red/black bounding box annotation markers in source data. | |
_normalize_stain() |
Adjusts color distributions to simulate pink/purple blood cytoplasm staining variations. | |
gradcam.py |
GradCAM (Class) |
Registers forward/backward hooks on ResNet18 layer4 convolutional activations to compute gradients. |
generate() |
Overlays ReLU-filtered feature gradients as jet-color heatmaps over microscope images. |
Workflow
The platform runs an end-to-end data pipeline to train models and serve diagnostic outputs:
Subsamples the raw clinical Kaggle data to 120 Normal vs. 40 Sickle patches, simulating low-data rare medical regimes.
Trains the generator against a Multi-Scale Discriminator. An auxiliary Reconstructor penalizes the generator if synthesized sickle shapes lose crescent properties.
Generates 80 high-res synthetic cells to balance the dataset. A ResNet18 diagnostic model is trained on this balanced 120 vs. 120 dataset.
Serves diagnostics via Streamlit. Uploaded images are classified and mapped with Grad-CAM heatmaps for explainable verification.
cGAN Training Losses & Progressions
Adversarial losses of Generator (green), Discriminator (red), and L1 Reconstructor (blue) co-training alongside generative textures progressing across 40 epochs (bottom).
Classifier Training Logs
Accuracy, F1-Score, Precision, and Recall validation curves across training epochs (top), demonstrating stable classification convergence.
Classifier Training Loss Curve
Best classifier loss convergence curve decreasing smoothly from 0.35 to 0.01 at epoch 40.
Stack
| Library / Framework | Functional Role |
|---|---|
| PyTorch (v2.0+) | Defines models (Generator, PatchDiscriminator, Reconstructor) and runs tensor operations. |
| Torchvision | Loads pre-trained ResNet18 weights and handles image transformations. |
| OpenCV (cv2) | Handles stain normalization, Fast Marching inpainting, and vignette filters. |
| Scikit-Learn | Computes validation metrics (accuracy, F1-score, confusion matrices). |
| Technology | Functional Role |
|---|---|
| Streamlit | Interactive dashboard layout hosting diagnostic uploading and synthetic image generation panels. |
| Matplotlib & Seaborn | Generates validation graphs and plots confusion matrix heatmaps. |
| Pandas & NumPy | Data management and fast array operations for custom dataset balancing. |
Dashboard
The research app was built in Streamlit to give doctors and researchers direct interactive control over diagnostic classification, Grad-CAM overlays, and high-resolution synthetic cell generation.
Automated Sickle Cell Diagnosis & Saliency Mapping
Diagnosing a sickle cell smear: predicts SICKLE_CELL with 81.9% confidence and displays the Grad-CAM heatmap highlighting the crescent curvatures driving the decision.
Automated Normal Cell Smear Diagnosis
Diagnosing a normal smear: predicts NORMAL with 99.3% confidence, showing general surface distribution activations.
Synthetic Generation Control Panel
Input options sidebar in Streamlit allowing the user to select target class, samples, seed, and resolution (256 / 512) for high-res generation.
Synthetic Sickle Cell In-App Output Grid
Visual grid output of 6 generated synthetic sickle cells (512x512) within circular vignettes, ready for training-like augmentation.
Synthetic Normal Cell In-App Output Grid
Visual grid output of 4 generated synthetic normal cells (512x512) for comparison verification.
Morphology Verification - Normal Class
Side-by-side comparison screen in Streamlit: Real normal samples vs. augmented synthetic normal samples for visual quality assurance.
Morphology Verification - Sickle Cell Class
Side-by-side comparison screen in Streamlit: Real sickle cells vs. augmented synthetic sickle cells containing crescent shapes.
More Projects