Upload multimodal cervical cancer classifier
Browse files- README.md +179 -0
- config.json +45 -0
- confusion_matrix.png +0 -0
- final_multimodal_model_v1.0.0_20251218.pt +3 -0
- requirements.txt +14 -0
README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: mit
|
| 5 |
+
datasets:
|
| 6 |
+
- smear2005
|
| 7 |
+
tags:
|
| 8 |
+
- medical-imaging
|
| 9 |
+
- multimodal
|
| 10 |
+
- vision-transformer
|
| 11 |
+
- cervical-cancer
|
| 12 |
+
- histopathology
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Cervical Cancer Multimodal Classifier
|
| 16 |
+
|
| 17 |
+
## Model Description
|
| 18 |
+
|
| 19 |
+
This is an advanced **multimodal** model that classifies cervical cancer using both:
|
| 20 |
+
- **Visual features** from histopathological images (Vision Transformer)
|
| 21 |
+
- **Morphological features** from tabular data (20 hand-crafted features)
|
| 22 |
+
|
| 23 |
+
### Model Architecture
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
┌─────────────────┐ ┌──────────────────┐
|
| 27 |
+
│ Histopath. │ │ Tabular Features │
|
| 28 |
+
│ Image (BMP) │ │ (20 features) │
|
| 29 |
+
└────────┬────────┘ └────────┬─────────┘
|
| 30 |
+
│ │
|
| 31 |
+
│ │
|
| 32 |
+
▼ ▼
|
| 33 |
+
┌──────────────┐ ┌────────────┐
|
| 34 |
+
│ ViT-base │ │ MLP │
|
| 35 |
+
│ (768 dims) │ │ (64 dims) │
|
| 36 |
+
└──────┬───────┘ └────┬───────┘
|
| 37 |
+
│ │
|
| 38 |
+
└────────┬──────────────┘
|
| 39 |
+
│
|
| 40 |
+
▼
|
| 41 |
+
┌─────────────────┐
|
| 42 |
+
│ Fusion Layer │
|
| 43 |
+
│ (512 -> 256) │
|
| 44 |
+
└────────┬────────┘
|
| 45 |
+
│
|
| 46 |
+
▼
|
| 47 |
+
┌─────────────────┐
|
| 48 |
+
│ Output (7) │
|
| 49 |
+
│ Classes │
|
| 50 |
+
└─────────────────┘
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## Supported Classes
|
| 54 |
+
|
| 55 |
+
1. **carcinoma_in_situ** - Carcinoma in situ
|
| 56 |
+
2. **light_dysplastic** - Light dysplastic
|
| 57 |
+
3. **moderate_dysplastic** - Moderate dysplastic
|
| 58 |
+
4. **normal_columnar** - Normal columnar
|
| 59 |
+
5. **normal_intermediate** - Normal intermediate
|
| 60 |
+
6. **normal_superficiel** - Normal superficial
|
| 61 |
+
7. **severe_dysplastic** - Severe dysplastic
|
| 62 |
+
|
| 63 |
+
## Performance
|
| 64 |
+
|
| 65 |
+
| Metric | Value |
|
| 66 |
+
|------------------------|--------------------------|
|
| 67 |
+
| **Test Accuracy** | 0.6594 |
|
| 68 |
+
| **Test F1-Score** | 0.6571 |
|
| 69 |
+
| **Weighted Precision** | 0.6558 |
|
| 70 |
+
|
| 71 |
+
## Training Details
|
| 72 |
+
|
| 73 |
+
- **Dataset**: Smear2005 (Herlev Colposcopy)
|
| 74 |
+
- **Vision Backbone**: google/vit-base-patch16-224
|
| 75 |
+
- **Training Epochs**: 50 (with early stopping at 10)
|
| 76 |
+
- **Batch Size**: 16
|
| 77 |
+
- **Learning Rate**: 2e-5 (AdamW)
|
| 78 |
+
- **Scheduler**: CosineAnnealingLR
|
| 79 |
+
- **Hardware**: NVIDIA T4 GPU on Google Colab
|
| 80 |
+
|
| 81 |
+
num_epochs = 50
|
| 82 |
+
best_val_accuracy = 0.6376811594202898
|
| 83 |
+
patience = 10
|
| 84 |
+
patience_counter = 10
|
| 85 |
+
|
| 86 |
+
## Tabular Features
|
| 87 |
+
|
| 88 |
+
The model uses 20 morphological features extracted from nuclei analysis:
|
| 89 |
+
|
| 90 |
+
- **Nucleus Area**: Kerne_A
|
| 91 |
+
- **Cytoplasm Area**: Cyto_A
|
| 92 |
+
- **Nucleus-Cytoplasm Ratio**: K/C
|
| 93 |
+
- **Y-coordinates**: Kerne_Ycol, Cyto_Ycol
|
| 94 |
+
- **Morphological indices**: KerneShort, KerneLong, KerneElong, KerneRund
|
| 95 |
+
- **Perimeter**: KernePeri, CytoPeri
|
| 96 |
+
- **Size ratios**: KerneMax, KerneMin, CytoMax, CytoMin
|
| 97 |
+
- **Position**: KernePos
|
| 98 |
+
|
| 99 |
+
Features are **StandardScaler normalized** using training set statistics.
|
| 100 |
+
|
| 101 |
+
## Usage
|
| 102 |
+
|
| 103 |
+
### Installation
|
| 104 |
+
|
| 105 |
+
```bash
|
| 106 |
+
pip install torch transformers pillow scikit-learn
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### Quick Start
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
import torch
|
| 113 |
+
from PIL import Image
|
| 114 |
+
import numpy as np
|
| 115 |
+
from sklearn.preprocessing import StandardScaler
|
| 116 |
+
|
| 117 |
+
# Load model
|
| 118 |
+
model = torch.load('multimodal_cervical_model.pt')
|
| 119 |
+
|
| 120 |
+
# Your image and tabular data
|
| 121 |
+
image = Image.open('sample.BMP')
|
| 122 |
+
tabular_features = {
|
| 123 |
+
'Kerne_A': 803.5,
|
| 124 |
+
'Cyto_A': 27804.125,
|
| 125 |
+
# ... 18 more features
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
# Predict
|
| 129 |
+
predictions = predict_multimodal(image, tabular_features, ...)
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## Advantages
|
| 133 |
+
|
| 134 |
+
✅ **Multimodal Fusion**: Combines spatial-visual features with quantitative morphological data
|
| 135 |
+
✅ **Robustness**: Less prone to overfitting than single-modality models
|
| 136 |
+
✅ **Interpretability**: Features are human-interpretable (sizes, ratios, etc.)
|
| 137 |
+
✅ **Scalability**: Can add more modalities (ultrasound, genetic data, etc.)
|
| 138 |
+
|
| 139 |
+
## Limitations
|
| 140 |
+
|
| 141 |
+
⚠️ Limited to 7 classes (specific dataset)
|
| 142 |
+
⚠️ Requires both image and tabular data for inference
|
| 143 |
+
⚠️ Image input must be histopathological cervical samples
|
| 144 |
+
|
| 145 |
+
## Citation
|
| 146 |
+
|
| 147 |
+
If you use this model, please cite:
|
| 148 |
+
|
| 149 |
+
```bibtex
|
| 150 |
+
@misc{cervical_multimodal_2025,
|
| 151 |
+
title = {Cervical Cancer Multimodal Classifier},
|
| 152 |
+
author = {Sastelvio MANUEL},
|
| 153 |
+
year = 2025,
|
| 154 |
+
howpublished = {\url{https://huggingface.co/sastelvio/cervical-cancer-multimodal-vit}}
|
| 155 |
+
}
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
## Disclaimer
|
| 159 |
+
|
| 160 |
+
⚠️ **Medical Use Only Under Professional Supervision**
|
| 161 |
+
|
| 162 |
+
This model is for research and educational purposes. It should **NOT** be used for clinical diagnosis without:
|
| 163 |
+
- Validation by medical professionals
|
| 164 |
+
- Proper regulatory approval
|
| 165 |
+
- Thorough clinical testing
|
| 166 |
+
- Integration with clinical workflows
|
| 167 |
+
|
| 168 |
+
## Author
|
| 169 |
+
|
| 170 |
+
[Sastelvio MANUEL]
|
| 171 |
+
Portfolio: [https://github.com/sastelvio]
|
| 172 |
+
|
| 173 |
+
## License
|
| 174 |
+
|
| 175 |
+
MIT License - See LICENSE file for details
|
| 176 |
+
|
| 177 |
+
---
|
| 178 |
+
|
| 179 |
+
*Last updated: 18 December 2025*
|
config.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "multimodal",
|
| 3 |
+
"vision_backbone": "google/vit-base-patch16-224",
|
| 4 |
+
"num_classes": 7,
|
| 5 |
+
"num_tabular_features": 20,
|
| 6 |
+
"class_labels": {
|
| 7 |
+
"0": "carcinoma_in_situ",
|
| 8 |
+
"1": "light_dysplastic",
|
| 9 |
+
"2": "moderate_dysplastic",
|
| 10 |
+
"3": "normal_columnar",
|
| 11 |
+
"4": "normal_intermediate",
|
| 12 |
+
"5": "normal_superficiel",
|
| 13 |
+
"6": "severe_dysplastic"
|
| 14 |
+
},
|
| 15 |
+
"feature_columns": [
|
| 16 |
+
"Kerne_A",
|
| 17 |
+
"Cyto_A",
|
| 18 |
+
"K/C",
|
| 19 |
+
"Kerne_Ycol",
|
| 20 |
+
"Cyto_Ycol",
|
| 21 |
+
"KerneShort",
|
| 22 |
+
"KerneLong",
|
| 23 |
+
"KerneElong",
|
| 24 |
+
"KerneRund",
|
| 25 |
+
"CytoShort",
|
| 26 |
+
"CytoLong",
|
| 27 |
+
"CytoElong",
|
| 28 |
+
"CytoRund",
|
| 29 |
+
"KernePeri",
|
| 30 |
+
"CytoPeri",
|
| 31 |
+
"KernePos",
|
| 32 |
+
"KerneMax",
|
| 33 |
+
"KerneMin",
|
| 34 |
+
"CytoMax",
|
| 35 |
+
"CytoMin"
|
| 36 |
+
],
|
| 37 |
+
"training_config": {
|
| 38 |
+
"batch_size": 16,
|
| 39 |
+
"learning_rate": 2e-05,
|
| 40 |
+
"num_epochs": 50,
|
| 41 |
+
"optimizer": "AdamW",
|
| 42 |
+
"scheduler": "CosineAnnealingLR",
|
| 43 |
+
"early_stopping_patience": 10
|
| 44 |
+
}
|
| 45 |
+
}
|
confusion_matrix.png
ADDED
|
final_multimodal_model_v1.0.0_20251218.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:be9e04cdb262ca93ef786b630658f0b6782c37028356dc80e4bccfff9f705a73
|
| 3 |
+
size 346793317
|
requirements.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.9.1
|
| 2 |
+
transformers==4.57.3
|
| 3 |
+
huggingface_hub==0.36.0
|
| 4 |
+
datasets==4.4.1
|
| 5 |
+
accelerate==1.12.0
|
| 6 |
+
evaluate==0.4.6
|
| 7 |
+
pillow==12.0.0
|
| 8 |
+
numpy==2.0.2
|
| 9 |
+
pandas==2.2.2
|
| 10 |
+
scikit-learn==1.6.1
|
| 11 |
+
openpyxl==3.1.5
|
| 12 |
+
matplotlib==3.10.0
|
| 13 |
+
seaborn==0.13.2
|
| 14 |
+
wandb==0.23.1
|