Downloads · 30 days
17
11% of all-time downloads
rarfileexe/Xpathology-Colon-Specialist
Xpathology-Colon-Specialist is a image classification model from rarfileexe. Use it when you need a label for an image. It is set up for keras. The card lists the license as apache-2.0.
<p align="center" <img src="https://img.shields.io/badge/Accuracy-99.1%25val|92.7%25holdout-2ea44f?style=for-the-badge" / <img src="https://img.shields.io/badge/Architecture-EfficientNetB1-0066cc?style=for-the-badge"…
Downloads · 30 days
17
11% of all-time downloads
All-time downloads
157
Public
Repo size
74.3 MB
Likes
1
Public
Click a slice to open those files.
.keras74.3 MB · 100%
From the Hugging Face model README
XPathology Colon Specialist is a fine-tuned EfficientNetB1 CNN trained to classify colorectal histopathology patches into 9 distinct tissue types from H&E-stained whole-slide images. It is the core classification backbone of the X-Pathology platform, which combines this model with Grad-CAM explainability and Gemini-powered dual clinical/patient reporting.
This model was trained on the NCT-CRC-HE-100K dataset and independently validated on the official CRC-VAL-HE-7K holdout set — a completely separate dataset scanned on different equipment, confirming genuine generalisation across scanner and staining variation.
Disclaimer: This model is intended for research and educational use only. It is not FDA-approved or CE-marked diagnostic software. All outputs must be verified by a licensed pathologist before any clinical decision-making.
| Property | Value |
|---|---|
| Model name | xpathology_colon_specialist_b1 |
| Architecture | EfficientNetB1 (ImageNet pretrained) |
| Framework | TensorFlow / Keras |
| Input size | 240 × 240 × 3 (RGB, pixel values 0–255) |
| Output | 9-class softmax |
| Training dataset | NCT-CRC-HE-100K (100,000 patches) |
| Validation dataset | CRC-VAL-HE-7K (7,180 patches, external holdout) |
| Temperature (T) | 0.5576 (post-hoc calibration applied) |
| Mixed precision | Yes (float16 compute, float32 weights) |
| Training hardware | Kaggle T4 × 2 (MirroredStrategy) |
| Index | Class | Description |
|---|---|---|
| 0 | ADI | Adipose tissue |
| 1 | BACK | Background / empty slide |
| 2 | DEB | Debris / necrosis |
| 3 | LYM | Lymphocytes |
| 4 | MUC | Mucus |
| 5 | MUS | Smooth muscle |
| 6 | NORM | Normal colon mucosa |
| 7 | STR | Cancer-associated stroma |
| 8 | TUM | Colorectal adenocarcinoma epithelium |
| Metric | Value |
|---|---|
| Accuracy | 99.12% |
| AUC | 0.9998 |
| Top-2 Accuracy | 99.90% |
| Val Loss | 0.5086 |
Tested on a completely separate dataset from a different scanning source, never seen during training or validation.
| Metric | Value |
|---|---|
| Accuracy | 92.73% |
| AUC | 0.9922 |
| Macro F1 | 0.909 |
| Weighted F1 | 0.929 |
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| ADI | 0.9983 | 0.8961 | 0.9445 | 1,338 |
| BACK | 0.9988 | 1.0000 | 0.9994 | 847 |
| DEB | 0.7967 | 0.9941 | 0.8845 | 339 |
| LYM | 0.9983 | 0.9543 | 0.9758 | 634 |
| MUC | 0.9752 | 0.9517 | 0.9633 | 1,035 |
| MUS | 0.6940 | 0.8429 | 0.7613 | 592 |
| NORM | 0.9228 | 0.9838 | 0.9523 | 741 |
| STR | 0.7452 | 0.7363 | 0.7407 | 421 |
| TUM | 0.9829 | 0.9303 | 0.9558 | 1,233 |
Note on MUS/STR: Smooth muscle and cancer-associated stroma are histologically similar under H&E at patch level — this is a known hard pair in colorectal CPath literature. Crucially, both are non-neoplastic tissue types, so MUS↔STR confusion carries no clinical consequence for the primary cancer/non-cancer determination. The critical TUM class achieves F1 = 0.9558 on the external holdout.
Input (240×240×3)
└── EfficientNetB1 backbone (ImageNet weights)
└── GlobalAveragePooling2D
└── BatchNormalization
└── Dropout(0.4)
└── Dense(256, relu)
└── BatchNormalization
└── Dropout(0.3)
└── Dense(9, softmax, dtype=float32)
Phase 1 — Warm-up (15 epochs)
Phase 2 — Fine-tuning (40 epochs, early stopping)
RandomFlip (horizontal + vertical)
RandomRotation (90° increments)
RandomBrightness (±0.2)
RandomContrast (0.8–1.2)
RandomSaturation (0.8–1.2)
RandomHue (±0.05)
RandomCrop (90–100% of image, resized back)
Augmentations were applied on CPU within the tf.data pipeline (not as Keras layers), keeping VRAM usage efficient for large-scale training.
Post-training temperature scaling was applied using the bounded scalar optimisation of NLL on the validation set:
Optimal temperature T = 0.5576
NLL improved after calibration
T < 1 indicates the model's raw softmax outputs were more diffuse than the ground truth distribution — consistent with label smoothing during training, which deliberately softens target distributions.
pip install tensorflow>=2.12 numpy
import numpy as np
import tensorflow as tf
import json
# Load model and calibration assets
model = tf.keras.models.load_model('xpathology_colon_specialist_b1.keras')
T = np.load('temperature_value.npy')[0] # 0.5576
classes = json.load(open('class_names.json'))
# Build logit extractor (pre-softmax)
logit_model = tf.keras.Model(
inputs = model.input,
outputs = model.get_layer('intermediate_dropout').output
)
final_dense = model.get_layer('colon_specialist_output')
weights, bias = final_dense.get_weights()
def predict(image_array):
"""
Args:
image_array: np.ndarray of shape (240, 240, 3), dtype float32, range [0, 255]
Returns:
predicted_class (str), confidence (float), all_probs (dict)
"""
img = tf.expand_dims(image_array, axis=0)
features = logit_model(img, training=False).numpy()
logits = features @ weights + bias # (1, 9) — pre-softmax
scaled = logits / T # temperature scaling
exp_l = np.exp(scaled - scaled.max())
probs = (exp_l / exp_l.sum()).flatten()
pred_idx = int(np.argmax(probs))
pred_class = classes[pred_idx]
confidence = float(probs[pred_idx])
all_probs = dict(zip(classes, probs.tolist()))
return pred_class, confidence, all_probs
# Example
import cv2
img = cv2.imread('patch.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (240, 240)).astype(np.float32)
label, conf, probs = predict(img)
print(f"Prediction : {label}")
print(f"Confidence : {conf:.4f}")
print(f"All probs : {probs}")
| Property | Requirement |
|---|---|
| Format | H&E stained histopathology patch |
| Resolution | 224×224 or larger (will be resized to 240×240) |
| Color space | RGB |
| Pixel range | 0–255 (do NOT normalize to [0,1]) |
| File formats | PNG, JPEG, TIFF (convert TIFF to PNG first) |
Important: EfficientNetB1 performs its own internal normalization. Do not apply
rescale=1./255or any manual normalization before passing the image to the model.
xpathology-colon-specialist/
├── xpathology_colon_specialist_b1.keras # Trained model weights
├── temperature_value.npy # Calibration temperature T
├── class_names.json # Ordered list of 9 class labels
├── training_summary.json # Full training metadata
├── training_log.csv # Epoch-by-epoch metrics (55 epochs)
└── README.md
| Dataset | Purpose | Images | Classes |
|---|---|---|---|
| NCT-CRC-HE-100K | Training + validation split | 100,000 | 9 |
| CRC-VAL-HE-7K | External holdout evaluation | 7,180 | 9 |
Both datasets were originally published by Kather et al. and are widely used benchmarks in computational pathology. Images are 224×224 pixel patches at 0.5 µm/pixel (20× magnification), normalised with Macenko stain normalisation in the original release.
Reference:
Kather JN, Halama N, Marx A. 100,000 histological images of human colorectal cancer and healthy tissue. Zenodo. 2018. https://doi.org/10.5281/zenodo.1214456
This model is deployed as part of X-Pathology, an AI-assisted oncology screening tool built as an educational and research portfolio project.
Pipeline:
Live demo: x-pathology.vercel.app
GitHub: github.com/Muhammad-Hassan12
Full training code is available in the X-Pathology GitHub repository. Key environment details:
Python 3.12
TensorFlow 2.x
Keras 3.x
CUDA 12.x
Hardware Kaggle T4 × 2 (MirroredStrategy)
Mixed precision float16 (mixed_float16 policy)
Global batch 64 (32 per replica × 2 GPUs)
This model is released under the Apache 2.0 License.
The training datasets (NCT-CRC-HE-100K and CRC-VAL-HE-7K) are released under CC BY 4.0 by Kather et al. Please cite the original dataset authors if you use this model in published work.
If you use this model in your research or build upon it, please cite:
@misc{hassan2026xpathology,
author = {Syed Muhammad Hassan},
title = {XPathology Colon Specialist: EfficientNetB1 for 9-Class Colorectal Histopathology},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/rarfileexe/Xpathology-Colon-Specialist}
}