π Dataset β’ ποΈ Methodology β’ π Results β’ π¬ Ablation Studies β’ π Quick Start
The CT Kidney Dataset comprises 12,446 unique CT images collected from PACS (Picture Archiving and Communication System) across multiple hospitals in Dhaka, Bangladesh. The dataset includes four distinct classes of kidney conditions:
| π’ Normal | π‘ Cyst | π΄ Tumor | π΅ Stone |
|---|---|---|---|
| 5,077 | 3,709 | 2,283 | 1,377 |
| 40.8% | 29.8% | 18.4% | 11.0% |
- Total Images: 12,446 unique CT scans
- Image Types: Coronal and Axial cuts
- Contrast: Mix of contrast and non-contrast studies
- Protocols: Whole abdomen and urogram protocols
- Format: Lossless JPG (converted from DICOM)
The dataset underwent rigorous validation by medical experts:
- Initial Selection: DICOM studies selected by diagnosis
- Anonymization: Patient information removed
- Expert Validation: Verified by radiologist and medical technologist
train_transform = T.Compose([
T.Resize((224, 224)),
T.RandomHorizontalFlip(p=0.5),
T.RandomRotation(15),
T.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.1),
T.RandomAffine(degrees=0, translate=(0.1, 0.1), scale=(0.9, 1.1)),
T.ToImage(),
T.ToDtype(torch.float32, scale=True),
T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])We employed an entropy-based active learning approach:
| Parameter | Value |
|---|---|
| Initial labeled set | 200 samples |
| Query size per round | 300 samples |
| Total rounds | 7 |
| Final labeled samples | 2,000 |
ResNet50 with transfer learning:
- Pre-trained on ImageNet
- Modified final layer (2048 β 4 classes)
- Total parameters: 23.52M
- Input size: 224Γ224Γ3
| Metric | Value |
|---|---|
| Test Accuracy | 99.73% |
| Balanced Accuracy | 99.61% |
| Macro F1-Score | 99.67% |
| Weighted F1-Score | 99.73% |
| Cohen's Kappa | 0.9962 |
| Matthews Correlation | 0.9962 |
| Hamming Loss | 0.0027 |
| Jaccard Score (macro) | 0.9935 |
| Log Loss | 0.0098 |
| Macro AUC-ROC | 0.9999 |
| Round | Labeled | Val Acc | Train Loss | Uncertainty |
|---|---|---|---|---|
| 0 | 200 | 45.2% | 1.3842 | 1.3726 |
| 1 | 500 | 62.8% | 0.9567 | 1.2584 |
| 2 | 800 | 74.5% | 0.6123 | 1.1038 |
| 3 | 1,100 | 83.1% | 0.3945 | 0.8952 |
| 4 | 1,400 | 90.4% | 0.2876 | 0.6721 |
| 5 | 1,700 | 95.8% | 0.1563 | 0.4315 |
| 6 | 2,000 | 98.2% | 0.0894 | 0.2547 |
| 7 | 2,000 | 99.73% | 0.0421 | 0.1238 |
| Model | Params (M) | Accuracy | GFLOPs |
|---|---|---|---|
| ResNet50 | 25.6 | 99.73% | 4.1 |
| EfficientNet-B0 | 5.3 | 98.91% | 0.39 |
| Custom CNN | 2.1 | 96.45% | 0.8 |
| Learning Rate | Final Loss | Convergence |
|---|---|---|
| 1e-5 | 1.2345 | β Slow |
| 5e-5 | 0.8976 | |
| 1e-4 | 0.4123 | β Optimal |
| 5e-4 | 0.5678 | |
| 1e-3 | 1.8923 | β Diverging |
| Strategy | Round 7 | Improvement |
|---|---|---|
| Random Sampling | 80% | +35% |
| Entropy Sampling | 86% | +41% |
| Margin Sampling | 84% | +39% |
| Certainty Sampling | 82% | +37% |
| Batch Size | Avg Loss | Memory (MB) | Throughput |
|---|---|---|---|
| 8 | 0.4123 | 48 | 89 img/s |
| 16 | 0.3945 | 96 | 129 img/s |
| 32 | 0.3876 | 192 | 171 img/s |
| 64 | 0.4234 | 384 | 205 img/s |
| 128 | 0.5123 | 768 | 226 img/s |
| Strategy | Final Loss | Loss Reduction |
|---|---|---|
| Basic (No Aug) | 0.6234 | - |
| Flip + Rotation | 0.4567 | 26.7% |
| Full Augmentation | 0.3876 | 37.8% |
Using PCA for dimensionality reduction of the learned features:
- Clear separation between all four classes
- Well-defined decision boundaries
- Minimal class overlap
Interactive 3D visualization available in interactive_3d_features.html
Python 3.8+
PyTorch 2.0+
CUDA-capable GPU (recommended)# Clone repository
git clone https://github.com/yourusername/ct-kidney-classification.git
cd ct-kidney-classification
# Install dependencies
pip install torch torchvision numpy pandas matplotlib seaborn scikit-learn plotly pillow# Using Kaggle API
kaggle datasets download -d nazmul0087/ct-kidney-dataset-normal-cyst-tumor-and-stone
unzip ct-kidney-dataset-normal-cyst-tumor-and-stone.zip# Run the complete pipeline
python train.py
# Or use notebook
jupyter notebook ct_kidney_classification.ipynbimport torch
from torchvision import transforms
from PIL import Image
# Load model
model = torch.load('best_model.pth')
model.eval()
# Preprocess
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
])
# Predict
img = Image.open('kidney_scan.jpg').convert('RGB')
img_tensor = transform(img).unsqueeze(0)
with torch.no_grad():
outputs = model(img_tensor)
_, predicted = torch.max(outputs, 1)
classes = ['Cyst', 'Normal', 'Stone', 'Tumor']
print(f"Prediction: {classes[predicted.item()]}")ct-kidney-classification/
βββ π train.py # Main training script
βββ π inference.py # Inference script
βββ π models/ # Model definitions
βββ π utils/ # Helper functions
βββ π notebooks/ # Jupyter notebooks
βββ π requirements.txt # Dependencies
βββ π README.md # This file
If you find this work helpful, please cite:
@article{islam2022vision,
title={Vision transformer and explainable transfer learning models for auto detection of kidney cyst, stone and tumor from CT-radiography},
author={Islam, MN and Hasan, M and Hossain, M and Alam, M and Rabiul, G and Uddin, MZ and Soylu, A},
journal={Scientific Reports},
volume={12},
number={1},
pages={1--4},
year={2022},
publisher={Nature Publishing Group}
}Dataset Link: https://www.kaggle.com/datasets/nazmul0087/ct-kidney-dataset-normal-cyst-tumor-and-stone
This project is licensed under the MIT License - see the LICENSE file for details.
β Star this repository if you find it useful! β