XPathology-CNN π¬
XPathology-CNN is an Explainable AI (XAI) computer vision model designed for the binary classification of H&E-stained histopathology slides (Benign vs. Adenocarcinoma).
This model serves as the core visual engine for the broader X-Pathology pipeline, which pairs CNN-based feature extraction with Large Language Models (LLMs) to generate plain-English and clinical dual-persona diagnostic reports.
To see full indepth training and visualization with complete overview, visit my GitHub Profile: https://github.com/Muhammad-Hassan12/Colon-Cancer-Prediction-CNN-Model
π§ Model Architecture
The model utilizes a transfer learning approach, leveraging a pre-trained VGG16 backbone fine-tuned for histopathological feature recognition.
- Base Model: VGG16 (Pre-trained Convolutional Base)
- Top Layers: Flatten β Dense (256, ReLU) β Dense (1, Sigmoid)
- Input Shape: (256, 256, 3)
- Output: Binary probability score (0 = Benign, 1 = Malignant)
π Performance & Training
The model exhibits highly stable convergence with minimal validation loss across 30 epochs, making its internal gradient structure highly optimal for feature extraction.
| Metric | Value |
|---|---|
| Training Set | 4,200 images |
| Validation Set | 900 images |
| Validation Accuracy | 1.00 (100%) |
| F1-Score | 1.00 (Across both classes) |
β οΈ Disclaimer!
The model is very accurate, but as it is trained on the architecture of VGG16 (which has 138 million trainable parameters) the data is pretty limited for its true capability, so the model has become a little overconfident!
Although it is very accurate on unseen data, but can be a little over-confident with the images that are not actually histo-reports π (for example: If tested on the image of dog, it will accuse it as it is either Benign or Adenocarcinoma with 95%+ confidence)
π― Explainable AI (XAI) Integration
This model was explicitly fine-tuned to maintain stable gradients for Grad-CAM (Gradient-weighted Class Activation Mapping).
By targeting the final convolutional layer (block5_conv3), the model generates highly accurate heatmaps that highlight specific cellular structuresβsuch as nuclear atypia or irregular glandular formationsβthat drive its diagnostic predictions. This transparency allows clinicians to verify the morphological basis of the AI's classification.
π» How to Use
You can download and load this model directly into a TensorFlow/Keras environment using the huggingface_hub library.
1. Install Requirements
pip install tensorflow huggingface\_hub
2. Load the Model
import tensorflow as tf
from tensorflow.keras import models, layers
from tensorflow.keras.applications import VGG16
from huggingface\_hub import hf\_hub\_download
\# 1\. Download the weights from Hugging Face
\# IMPORTANT: Replace 'YOUR\_USERNAME' with your actual Hugging Face handle
model\_path \= hf\_hub\_download(repo\_id="YOUR\_USERNAME/XPathology-CNN", filename="C\_DA\_1.h5")
\# 2\. Reconstruct the architecture
conv\_base \= VGG16(weights=None, include\_top=False, input\_shape=(256, 256, 3))
conv\_base.\_name \= 'vgg16\_base'
cnn\_model \= models.Sequential(\[
conv\_base,
layers.Flatten(name='flatten\_layer'),
layers.Dense(256, activation='relu', name='dense\_hidden'),
layers.Dense(1, activation='sigmoid', name='dense\_output')
\])
\# 3\. Load the weights
cnn\_model.load\_weights(model\_path)
print("XPathology Model Loaded Successfully\!")
β οΈ Disclaimer
This model is developed for educational, portfolio, and research purposes only. It is not intended for use in actual clinical diagnostics or patient care. All AI-assisted medical screenings must be reviewed by a certified human pathologist.