| --- |
| license: apache-2.0 |
| tags: |
| - image-classification |
| - medical |
| - malaria |
| - africa |
| - tanzania |
| - dinov2 |
| - blood-smear |
| - imbalanced-classification |
| datasets: |
| - harvard-dataverse-malaria-tanzania |
| metrics: |
| - balanced_accuracy |
| - mcc |
| - recall |
| - auc |
| base_model: facebook/dinov2-base |
| --- |
| |
| # Malaria Detector β DINOv2 fine-tuned on Tanzania Blood Smears π¦ |
|
|
| Fine-tuned [facebook/dinov2-base](https://huggingface.co/facebook/dinov2-base) for binary classification of blood smear images: **malaria infected** vs **healthy**. |
|
|
| Trained on **real patient data** from 5 Tanzanian health centres, with **rigorous handling of class imbalance**. |
|
|
| ## π Performance (test set) |
|
|
| | Metric | Value | Note | |
| |--------|-------|------| |
| | Accuracy | 99.44% | Can be misleading with imbalance | |
| | **Balanced Accuracy** | **99.25%** | β Imbalance-robust | |
| | **MCC (Matthews)** | **0.988** | β Best single metric | |
| | F1 Macro | 99.40% | Equitable across classes | |
| | Recall (Sensitivity) | 100.00% | β Critical clinical metric | |
| | Specificity | 98.51% | | |
| | AUC-ROC | 100.00% | | |
| | AUC-PR | 100.00% | Imbalance-robust AUC | |
|
|
| ## βοΈ Class imbalance handling |
|
|
| Dataset has **1.64x imbalance** (Paludisme: 62% vs Sain: 38%). |
|
|
| **Techniques applied** : |
| 1. β
Class weights in loss function |
| 2. β
Stratified split on subtype (not just binary label) |
| 3. β
Aggressive data augmentation |
| 4. β
MCC-based model selection (instead of accuracy) |
| 5. β
Multiple imbalance-robust metrics reported |
|
|
| ## π Quick Start |
|
|
| ```python |
| from transformers import AutoImageProcessor, AutoModelForImageClassification |
| from PIL import Image |
| import torch |
| |
| processor = AutoImageProcessor.from_pretrained('Sadou/malaria-detector-dinov2-tanzania') |
| model = AutoModelForImageClassification.from_pretrained('Sadou/malaria-detector-dinov2-tanzania') |
| |
| img = Image.open('blood_smear.jpg').convert('RGB') |
| inputs = processor(img, return_tensors='pt') |
| |
| with torch.no_grad(): |
| outputs = model(**inputs) |
| |
| probs = torch.softmax(outputs.logits, dim=-1)[0] |
| pred = torch.argmax(probs).item() |
| |
| labels = ['Healthy', 'Malaria'] |
| print(f'{labels[pred]} (confidence: {probs[pred]:.1%})') |
| ``` |
|
|
| ## π Dataset |
|
|
| **Tanzania Malaria Blood Smear Dataset** |
| - Source: Harvard Dataverse |
| - DOI: [10.7910/DVN/O2WVWA](https://doi.org/10.7910/DVN/O2WVWA) |
| - Images: 3,544 real blood smears |
| - Source: 5 health centres in Tanga region, Tanzania |
| - Microscope: 4K SONY IMX334 sensor (40X-2500X) |
| - Staining: Giemsa reagent |
| - Reference: Lufyagila et al. 2024, *Data in Brief* |
|
|
| ### Class distribution |
| | Class | Count | |
| |-------|-------| |
| | Thick Infected | 1,139 | |
| | Thick Uninfected | 1,071 | |
| | Thin Infected | 1,064 | |
| | Thin Uninfected | 270 | |
|
|
| ## β οΈ Disclaimer |
|
|
| **This is a research tool, NOT a certified medical device.** |
| Any real diagnosis must be confirmed by a qualified microscopist or physician. |
| Clinical validation is required before any real-world deployment. |
|
|
| ## π Citation |
|
|
| ```bibtex |
| @misc{malaria-dinov2-2026, |
| author = {Sadou Barry}, |
| title = {Malaria Detector β DINOv2 fine-tuned on Tanzania Blood Smears with Class Imbalance Handling}, |
| year = {2026}, |
| publisher = {HuggingFace}, |
| url = {https://huggingface.co/Sadou/malaria-detector-dinov2-tanzania} |
| } |
| ``` |
|
|