Cancer Pathos
Binary classification of metastatic cancer in 96×96 histopathologic tissue patches (PatchCamelyon / Kaggle Histopathologic Cancer Detection). Backbone ConvNeXt-Tiny a custom residual classification head (1 logit,...
Model source
- Kind
- Other
- File size
- 108–324 MB
- Version
- vRevision 6747da1
- Updated
- Sep 17, 2026
- Downloads
- 0
- Source
- Hugging Face
Source description
Cancer_pathos — Histopathologic Cancer Detection (ConvNeXt-Tiny)
Binary classification of metastatic cancer in 96×96 histopathologic tissue patches (PatchCamelyon / Kaggle Histopathologic Cancer Detection). Backbone ConvNeXt-Tiny
- a custom residual classification head (1 logit, sigmoid).
⚠️ Research Use Only (RUO) — this is not a certified medical device and must not be used for clinical diagnosis.
🔗 Code & full report: https://github.com/Hakim78/histopathologic-cancer-detection 🤗 Interactive demo: https://huggingface.co/spaces/hakim78/Cancer_pathos_demo
📦 Checkpoints
| File | Training data | Role | Headline metric |
|---|---|---|---|
models/best_model_epoch50_auc0.9980.pth | ~95 % of labels, 50 epochs | v1 — deployed in the demo | Validation AUC 0.9983 (TTA ×5) |
models/final_model_v2_locked.pth | 70 % train, early-stopped on val | v2 — rigorous evaluation | Locked-test AUC 0.9979 (TTA ×5) |
- v1 maximizes performance (more data, longer training) and powers the live demo.
- v2 was trained under a stricter protocol — a 3-way split with a strictly locked test set + 5-fold cross-validation — to report a defensible, independent test metric.
📊 Results (v2 — rigorous protocol)
70 / 15 / 15 stratified split (seed 42). The 15 % test set (33,004 patches) is locked: never used for training, model selection or hyperparameters — opened once for the final metrics. Robustness first estimated by 5-fold cross-validation on train+val.
| Metric | 5-fold CV (mean ± σ) | Locked test (TTA ×5) |
|---|---|---|
| AUC-ROC | 0.9975 ± 0.0001 | 0.9979 |
| Accuracy | 0.9821 ± 0.0008 | 0.9847 |
| F1-score | 0.9778 ± 0.0010 | 0.9810 |
| Brier Score | 0.0212 ± 0.0005 | 0.0172 |
| Sensitivity | 0.9753 ± 0.0015 | 0.9794 |
| Specificity | 0.9867 ± 0.0006 | 0.9882 |
Calibration on the locked test: Brier 0.0172, ECE 0.0449.
Confusion matrix (33,004 patches): TN 19,405 · FP 231 · FN 275 · TP 13,093.
TTA ×5 yields a small but statistically significant gain (DeLong on AUC: z = 6.62, p < 10−4).
Full metrics in results_v2/.
🏗 Architecture & training
- Backbone:
timmconvnext_tiny(ImageNet-pretrained,num_classes=0,drop_rate=0.3) → 768-d features. - Head: Residual MLP —
Linear(768→256) → BN → GELU → Dropout → Linear(256→256) → BN → (+ shortcut) → GELU → Dropout → Linear(256→1). - Loss: Focal Loss (α = 0.25, γ = 2.0). Optimizer: AdamW (lr 1e-4, wd 1e-5). Scheduler: CosineAnnealingLR. AMP enabled. Seed: 42.
- Input: RGB 96×96, ImageNet normalization (mean
[0.485, 0.456, 0.406], std[0.229, 0.224, 0.225]).
🚀 Usage
import torch, timm
import torch.nn as nn
from huggingface_hub import hf_hub_download
class ResidualHead(nn.Module):
def __init__(self, in_features, hidden=256, dropout=0.3):
super().__init__()
self.fc1, self.bn1 = nn.Linear(in_features, hidden), nn.BatchNorm1d(hidden)
self.fc2, self.bn2 = nn.Linear(hidden, hidden), nn.BatchNorm1d(hidden)
self.fc_out, self.shortcut = nn.Linear(hidden, 1), nn.Linear(in_features, hidden)
self.gelu, self.dropout = nn.GELU(), nn.Dropout(dropout)
def forward(self, x):
identity = self.shortcut(x)
out = self.dropout(self.gelu(self.bn1(self.fc1(x))))
out = self.gelu(self.bn2(self.fc2(out)) + identity)
return self.fc_out(self.dropout(out))
class CancerClassifier(nn.Module):
def __init__(self):
super().__init__()
self.backbone = timm.create_model("convnext_tiny", pretrained=False, num_classes=0)
self.head = ResidualHead(self.backbone.num_features)
def forward(self, x):
return self.head(self.backbone(x))
model = CancerClassifier()
# v2 (rigorous) — raw state_dict:
path = hf_hub_download("hakim78/Cancer_pathos", "models/final_model_v2_locked.pth")
model.load_state_dict(torch.load(path, map_location="cpu"))
# v1 (deployed) — checkpoint dict:
# path = hf_hub_download("hakim78/Cancer_pathos", "models/best_model_epoch50_auc0.9980.pth")
# model.load_state_dict(torch.load(path, map_location="cpu")["model_state_dict"])
model.eval()
Prediction = torch.sigmoid(model(x)) (probability of cancer; threshold 0.5). For best results, average over 5 TTA views (original + H/V flip + 90° rotation + transpose).
⚠️ Limitations
- Patch-level only (96×96), not whole-slide. A 1.18 % per-patch false-positive rate aggregates over the tens of thousands of patches in a slide → a MIL aggregation step is required for slide-level use.
- PatchCamelyon originates from a limited set of centers/scanners → external multicentric validation and stain normalization are required before any clinical perspective.
- Calibration is good but shows a slight sigmoid profile (ECE 0.045) → temperature scaling recommended before any autonomous use.
👤 Author
Hakim Djaalal — Master's in Big Data & AI. License: MIT (Research Use Only).
Sources
1 source
Sources
1 sourceVerified Sep 17
Model artifacts
32 artifacts
Model artifacts
32 artifactsmodels/best_model_epoch01_auc0.9844.pth
pth · 324 MB · SHA-256 668fdcb65a21…82cb · Hugging Face
Downloadmodels/best_model_epoch02_auc0.9886.pth
pth · 324 MB · SHA-256 a1c7329ee30f…ffd2 · Hugging Face
Downloadmodels/best_model_epoch04_auc0.9910.pth
pth · 324 MB · SHA-256 7879592088c4…8c60 · Hugging Face
Downloadmodels/best_model_epoch05_auc0.9923.pth
pth · 324 MB · SHA-256 c56f97fcacce…39af · Hugging Face
Downloadmodels/best_model_epoch06_auc0.9933.pth
pth · 324 MB · SHA-256 f373a00eda55…33c2 · Hugging Face
Downloadmodels/best_model_epoch09_auc0.9938.pth
pth · 324 MB · SHA-256 41a519587cab…a0a6 · Hugging Face
Downloadmodels/best_model_epoch10_auc0.9943.pth
pth · 324 MB · SHA-256 b816cf180a23…85ec · Hugging Face
Downloadmodels/best_model_epoch11_auc0.9944.pth
pth · 324 MB · SHA-256 1058bae090d2…58f2 · Hugging Face
Downloadmodels/best_model_epoch12_auc0.9951.pth
pth · 324 MB · SHA-256 230b69d8fdf0…96c6 · Hugging Face
Downloadmodels/best_model_epoch13_auc0.9956.pth
pth · 324 MB · SHA-256 c5c8c4ad4a4e…4f89 · Hugging Face
Downloadmodels/best_model_epoch15_auc0.9960.pth
pth · 324 MB · SHA-256 3f04788d0c74…b453 · Hugging Face
Downloadmodels/best_model_epoch16_auc0.9961.pth
pth · 324 MB · SHA-256 d104c81192e0…71a3 · Hugging Face
Downloadmodels/best_model_epoch18_auc0.9964.pth
pth · 324 MB · SHA-256 75e8e7674827…d5d8 · Hugging Face
Downloadmodels/best_model_epoch19_auc0.9967.pth
pth · 324 MB · SHA-256 230347c3147a…b986 · Hugging Face
Downloadmodels/best_model_epoch21_auc0.9969.pth
pth · 324 MB · SHA-256 5e39171586f3…4cbe · Hugging Face
Downloadmodels/best_model_epoch22_auc0.9969.pth
pth · 324 MB · SHA-256 76bad756c687…6ec3 · Hugging Face
Downloadmodels/best_model_epoch23_auc0.9971.pth
pth · 324 MB · SHA-256 dfdf1d8c1687…b272 · Hugging Face
Downloadmodels/best_model_epoch25_auc0.9974.pth
pth · 324 MB · SHA-256 5b398d0643f0…d9cd · Hugging Face
Downloadmodels/best_model_epoch26_auc0.9974.pth
pth · 324 MB · SHA-256 8e0e8fef898b…10e5 · Hugging Face
Downloadmodels/best_model_epoch28_auc0.9974.pth
pth · 324 MB · SHA-256 d867906017db…dcdd · Hugging Face
Downloadmodels/best_model_epoch29_auc0.9975.pth
pth · 324 MB · SHA-256 e0d7acc023e3…0654 · Hugging Face
Downloadmodels/best_model_epoch31_auc0.9976.pth
pth · 324 MB · SHA-256 aa4f8c504b75…9637 · Hugging Face
Downloadmodels/best_model_epoch32_auc0.9978.pth
pth · 324 MB · SHA-256 c1b42c677c1e…7ca0 · Hugging Face
Downloadmodels/best_model_epoch34_auc0.9976.pth
pth · 324 MB · SHA-256 76e34dcb5b41…a71d · Hugging Face
Downloadmodels/best_model_epoch35_auc0.9978.pth
pth · 324 MB · SHA-256 134ede4a8877…f1ad · Hugging Face
Downloadmodels/best_model_epoch36_auc0.9979.pth
pth · 324 MB · SHA-256 5ce6303623d6…9efb · Hugging Face
Downloadmodels/best_model_epoch45_auc0.9979.pth
pth · 324 MB · SHA-256 5b94ecbc0b36…d109 · Hugging Face
Downloadmodels/best_model_epoch46_auc0.9980.pth
pth · 324 MB · SHA-256 17bf17268228…1627 · Hugging Face
Downloadmodels/best_model_epoch48_auc0.9980.pth
pth · 324 MB · SHA-256 1080df36aef5…e8e0 · Hugging Face
Downloadmodels/best_model_epoch49_auc0.9980.pth
pth · 324 MB · SHA-256 233e6fa63dae…de14 · Hugging Face
Downloadmodels/best_model_epoch50_auc0.9980.pth
pth · 324 MB · SHA-256 0f8c1189ab1f…6682 · Hugging Face
DownloadSource excerpts
2 excerpts
Source excerpts
2 excerpts--- license: mit language: - en tags: - image-classification - medical-imaging - histopathology - breast-cancer - pytorch - convnext - patchcamelyon pipeline_tag: image-classification --- # Cancer_pathos — Histopathologic Cancer Detection (ConvNeXt-Tiny) Binary classification of **metastatic cancer in 96×96 histopathologic tissue patches** (PatchCamelyon / Kaggle *Histopathologic Cancer Detection*). Backbone **ConvNeXt-Tiny** + a custom **residual classification head** (1 logit, sigmoid). > ⚠️ **Research Use Only (RUO)** — this is **not** a certified medical device and must **not** be used for clinical diagnosis. 🔗 **Code & full report:** https://github.com/Hakim78/histopathologic-cancer-detection 🤗 **Interactive demo:** https://huggingface.co/spaces/hakim78/Cancer_pathos_demo --- ## 📦 Checkpoints | File | Training data | Role | Headline metric | |------|---------------|------|-----------------| | `models/best_model_epoch50_auc0.9980.pth` | ~95 % of labels, 50 epochs | **v1 — deployed in the demo** | Validation AUC **0.9983** (TTA ×5) | | `models/final_model_v2_locked.pth` | 70 % train, early-stopped on val | **v2 — rigorous evaluation** | Locked-test AUC **0.9979** (TTA ×5) | - **v1** maximizes performance (more data, longer training) and powers the live demo. - **v2** was trained under a stricter protocol — a 3-way split with a **strictly locked test set** + 5-fold cross-validation — to report a **defensible, independent** test metric. --- ## 📊 Results (v2 — rigorous protocol) 70 / 15 / 15 stratified split (seed 42). The 15 % **test set (33,004 patches) is locked**: never used for training, model selection or hyperparameters — opened once for the final metrics. Robustness first estimated by 5-fold cross-validation on train+val. | Metric | 5-fold CV (mean ± σ) | Locked test (TTA ×5) | |--------|:--------------------:|:--------------------:| | AUC-ROC | 0.9975 ± 0.0001 | **0.9979** | | Accuracy | 0.9821 ± 0.0008 | **0.9847** | | F1-score | 0.9778 ± 0.0010 | **0.9810** | | Brier Score | 0.0212 ± 0.0005 | **0.0172** | | Sensitivity | 0.9753 ± 0.0015 | **0.9794** | | Specificity | 0.9867 ± 0.0006 | **0.9882** | Calibration on the locked test: **Brier 0.0172, ECE 0.0449**. Confusion matrix (33,004 patches): **TN 19,405 · FP 231 · FN 275 · TP 13,093**. TTA ×5 yields a small but statistically significant gain (DeLong on AUC: z = 6.62, p...
Source context: 0 downloads · 1 likes · Pipeline image-classification · Repo hakim78/Cancer_pathos
