🩺 Breast Cancer Detection CNN Model
This is a deep-learning model for
binary classification of breast cancer tumors as
Malignant (Cancerous) or
Benign (Non-Cancerous) using the
Breast Cancer Wisconsin (Diagnostic) Dataset.
📊 Dataset
- Name: Breast Cancer Wisconsin (Diagnostic)
- Samples: 569
- Features: 30 numerical features derived from fine needle aspirate (FNA) images
- Examples: mean radius, texture, perimeter, area, smoothness, compactness, concavity, symmetry, fractal dimension.
- Target: Binary classification
- Preprocessing:
- Removed duplicates or missing rows if present
- Standard scaling (mean=0, variance=1) applied to all features
- Train/Test Split: 80% training / 20% testing
🧠 Model Details
Framework: TensorFlow / Keras
Architecture:
• Input layer for 50×50 RGB image patches
• Three convolutional blocks:
- Each block has 2–3 Conv2D layers (3×3 kernels, ReLU activation)
- MaxPooling2D layers for spatial downsampling
- Dropout (rate 0.3) for regularization
• Flatten layer to convert feature maps to 1D
• Fully connected Dense layer (256 units, ReLU activation)
• Output layer with 2 neurons (Softmax activation) for IDC vs No IDC classification
Loss Function: Categorical Crossentropy
Optimizer: Adam (learning rate ≈ 0.001)
Batch Size: 32
Epochs: 50 (EarlyStopping used to prevent overfitting)
🧠 Model Architecture
| Layer (Type) | Output Shape | Param # | Description |
|---|
| Input Layer | (50, 50, 3) | – | RGB image input |
| Conv2D (32 filters, 3×3, ReLU) | (48, 48, 32) | 896 | First convolution layer |
| Conv2D (32 filters, 3×3, ReLU) | (46, 46, 32) | 9,248 | Second convolution layer |
| Conv2D (32 filters, 3×3, ReLU) | (44, 44, 32) | 9,248 | Third convolution layer |
| MaxPooling2D (2×2) | (22, 22, 32) | 0 | Spatial downsampling |
| Dropout (0.3) | (22, 22, 32) | 0 | Regularization to prevent overfitting |
| Conv2D (64 filters, 3×3, ReLU) | (20, 20, 64) | 18,496 | Start of second conv block |
| Conv2D (64 filters, 3×3, ReLU) | (18, 18, 64) | 36,928 | |
| Conv2D (64 filters, 3×3, ReLU) | (16, 16, 64) | 36,928 | |
| MaxPooling2D (2×2) | (8, 8, 64) | 0 | Spatial downsampling |
| Dropout (0.3) | (8, 8, 64) | 0 | Regularization |
| Conv2D (128 filters, 3×3, ReLU) | (6, 6, 128) | 73,856 | Start of third conv block |
| Conv2D (128 filters, 3×3, ReLU) | (4, 4, 128) | 147,584 | |
| Conv2D (128 filters, 3×3, ReLU) | (2, 2, 128) | 147,584 | |
| MaxPooling2D (2×2) | (1, 1, 128) | 0 | Final downsampling |
| Dropout (0.3) | (1, 1, 128) | 0 | Regularization |
| Flatten | (128) | 0 | Flatten feature maps to 1D |
| Dense (256, ReLU) | (256) | 33,024 | Fully connected layer |
| Dropout (0.3) | (256) | 0 | Regularization |
| Dense (2, Softmax) | (2) | 514 | Output layer (IDC vs No IDC classification) |
Total Parameters: ~514,000 (all trainable)
📈 Performance Metrics
| Class / Metric | Precision | Recall | F1-Score | Support |
|---|
| a_no_idc (No IDC) | 0.91 | 0.82 | 0.86 | 7,879 |
| b_has_idc (Has IDC) | 0.83 | 0.92 | 0.88 | 7,879 |
| Accuracy | | | 0.87 | 15,758 |
| Macro Avg | 0.87 | 0.87 | 0.87 | 15,758 |
| Weighted Avg | 0.87 | 0.87 | 0.87 | 15,758 |
(Exact results may vary depending on random seed and train/test split.)
🚀 Usage
To use this model for inference:
1from tensorflow.keras.models import load_model
2import numpy as np
3
4# Load the model
5model = load_model("breast_model.h5")
6
7# Example input: a single patient record (30 scaled features)
8features = np.array([[...your_30_features...]])
9prediction = model.predict(features)
10
11print("Malignant" if prediction[0][0] > 0.5 else "Benign")
12
🛠 Training Details
Hardware Used: CPU/GPU (e.g., Google Colab or local GPU)
Environment: Python 3.8+, TensorFlow 2.x
Dependencies: See requirements.txt in this repository.
📂 Files in This Repository
- breast_model.h5
- breast-cancer-notebook.ipynb
- requirements.txt
📜 License
This model is released under the Apache 2.0 License
You are free to use, modify, and distribute it with proper attribution.
🤝 Contributions
You can:
- Improve preprocessing or feature engineering
- Experiment with different deep learning architectures
- Add CI/CD pipelines for automated training and deployment
- Create a Docker container for production use
❤️ Citation
@misc{breast_cancer_detection_2025,
title = {Breast Cancer Detection CNN Model},
author = {Waseem Khan},
year = {2025},
note = {LinkedIn: \url{
https://www.linkedin.com/in/waseem-khan-2839a7227}},
url = {
https://huggingface.co/Waseem-Khan-Dawar/breast-cancer-detection-cnn}
}
Disclaimer: This model is for educational and research purposes only and is not a substitute for medical diagnosis. Always consult a medical professional for real-world use.