XPathology-CNN / README.md
rarfileexe's picture
Update README.md
5ab5473 verified
|
Raw
History Blame Contribute Delete
4.37 kB
---
license: mit
language:
- en
---
# **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 served as the core visual engine for the broader **X-Pathology pipeline** (but now upgraded to a better more accurate model), 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**
```bash
pip install tensorflow huggingface\_hub
```
### **2\. Load the Model**
```bash
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.
[image1]: <data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAXCAYAAADpwXTaAAAAt0lEQVR4XmNgGAWjgDpAQUGBQ05OLk1UVJQHXY4cwCgvL98KNNAYXYIsADIIaGAvkMmCLkcOYAR6twBoaByIjSIDlBAA2iRJClZSUgKaJTcfyJ6soqLCBzZIXFycGyhQDcSzSMVAw3YA6a9A3Aw0kB3FhaQAWVlZE6Ahq6WlpWXQ5UgCQAOEgQYtVlRUlEeXIxkADcoChnMEujjJAJRogYZNlZGRkUaXIwcwqqur84JodIlRMMAAAJV7J+RoCL8jAAAAAElFTkSuQmCC>