- Overview
- β¨ Key Features
- π οΈ Tech Stack
- ποΈ Project Architecture
- π Project Structure
- π Quick Start
- π¦ Installation
- π» Usage
- π API Documentation
- π³ Docker Deployment
- π§ Configuration
- π Model Details
- π§ͺ Testing
- π Results
- π€ Contributing
- π License
- π Acknowledgments
- π§ Contact
KidneyScan AI is an end-to-end deep learning pipeline for classifying kidney CT scan images as either "Tumor" or "Normal". The project leverages transfer learning with the VGG16 pre-trained model to achieve accurate medical image classification.
This production-ready application includes:
- π Automated ML pipeline orchestration with DVC
- π Experiment tracking with MLflow
- π RESTful API with Flask
- π¨ Modern, responsive web interface
- π³ Docker containerization support
β οΈ Disclaimer: This model is for educational and research purposes only. It should NOT be used as a substitute for professional medical diagnosis.
| Feature | Description |
|---|---|
| π¬ Medical Image Classification | Classify kidney CT scans as Tumor or Normal using deep learning |
| π§ Transfer Learning | Utilizes VGG16 pre-trained on ImageNet for feature extraction |
| π Experiment Tracking | Full MLflow integration for metrics, parameters, and model versioning |
| π Pipeline Automation | DVC-powered reproducible ML pipeline from data ingestion to evaluation |
| π REST API | Flask-based API for seamless integration with other applications |
| π« Modern UI | Beautiful, responsive web interface with drag-and-drop functionality |
| π³ Containerization | Docker support for easy deployment and scaling |
| β‘ Lazy Model Loading | Efficient memory usage with on-demand model loading |
python-box- Configuration managementpyYAML- YAML file handlinggdown- Google Drive file downloadstqdm- Progress barsjoblib- Model serialization
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β KIDNEY CT SCAN CLASSIFIER β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β DATA SOURCE β β DATA SOURCE β β DATA SOURCE β β
β β (Google Drive) ββββββΆβ (DVC Cache) ββββββΆβ (Training) β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β β β
β βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β DVC PIPELINE β β
β β βββββββββββββββ ββββββββββββββββ ββββββββββββββ βββββββββ β β
β β β Stage 01 βββΆβ Stage 02 βββΆβ Stage 03 βββΆβ Stage β β β
β β βData Ingestionβ βPrepare Base β β Training β β 04 β β β
β β β β β Model β β β β Eval β β β
β β βββββββββββββββ ββββββββββββββββ ββββββββββββββ βββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MLflow Tracking β β
β β π Metrics β π Parameters β π¦ Model Registry β π Runs β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β FLASK WEB APPLICATION β β
β β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββββββ β β
β β β /train β β /predict β β / (Home) β β β
β β β (API) β β (API) β β (Web Interface) β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β FRONTEND (HTML/CSS/JS) β β
β β π¨ Drag & Drop β π· Image Preview β π Results Display β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
-
Data Ingestion (
stage_01_data_ingestion.py)- Downloads dataset from Google Drive
- Extracts and organizes CT scan images
- Version control with DVC
-
Prepare Base Model (
stage_02_prepare_base_model.py)- Loads VGG16 pre-trained on ImageNet
- Removes top classification layers
- Configures for transfer learning
-
Model Training (
stage_03_model_training.py)- Trains custom classification head
- Applies data augmentation
- Logs parameters and metrics to MLflow
- Saves trained model
-
Model Evaluation (
stage_04_model_evaluation.py)- Evaluates model on test set
- Calculates loss and accuracy
- Logs metrics to MLflow
- Saves evaluation scores
kidney-prediction-deep-learning/
β
βββ π app.py # Flask web application entry point
βββ π main.py # Direct pipeline execution script
βββ π dvc.yaml # DVC pipeline definition
βββ π params.yaml # Hyperparameters and configuration
βββ π config/
β βββ config.yaml # Application configuration
β
βββ π requirements.txt # Python dependencies
βββ π setup.py # Package setup configuration
βββ π Dockerfile # Docker container configuration
β
βββ π src/
β βββ cnnClassifer/
β βββ π components/ # ML pipeline components
β β βββ data_ingestion.py # Data download & extraction
β β βββ prepare_base_model.py # VGG16 base model setup
β β βββ model_training.py # Model training logic
β β βββ model_evaluation_mlflow.py # Evaluation with MLflow
β β
β βββ π pipeline/ # Pipeline stage executors
β β βββ stage_01_data_ingestion.py
β β βββ stage_02_prepare_base_model.py
β β βββ stage_03_model_training.py
β β βββ stage_04_model_evaluation.py
β β βββ prediction.py # Prediction pipeline
β β
β βββ π config/ # Configuration management
β β βββ configuration.py # Config manager class
β β
β βββ π entity/ # Data entities
β β βββ config_entity.py # Configuration entities
β β
β βββ π utils/ # Utility functions
β β βββ Common.py # Common utilities
β β
β βββ π constants/ # Constants
β β βββ __init__.py
β β
β βββ π __init__.py # Package initializer
β
βββ π model/
β βββ model.h5 # Trained Keras model
β
βββ π templates/
β βββ index.html # Frontend web interface
β
βββ π research/
β βββ 01_data_ingestion.ipynb # Data exploration notebook
β βββ 02_prepare_base_model.ipynb # Base model notebook
β βββ 03_model_training.ipynb # Training notebook
β βββ 04_model_evaluation_with_mlflow.ipynb # Evaluation notebook
β βββ trials.ipynb # Experiment trials
β
βββ π artifacts/ # ML pipeline outputs
β βββ data_ingestion/ # Downloaded dataset
β βββ prepare_base_model/ # Base model files
β βββ training/ # Trained model files
β
βββ π logs/ # Application logs
β βββ (log files)
β
βββ π mlruns/ # MLflow tracking data
β βββ 0/
β βββ meta.yaml
β
βββ π scores.json # Evaluation metrics
βββ π dvc.lock # DVC lock file
βββ π LICENSE # MIT License
βββ π .gitignore # Git ignore file
| Requirement | Version | Description |
|---|---|---|
| π Python | 3.8+ | Programming language |
| π³ Docker | 20.10+ | Containerization (optional) |
| πΎ GPU | CUDA 11.8+ | For faster training (optional) |
# Clone the repository
git clone https://github.com/vams2krish/Kidney-Disease-Classification-MLflow-DVC.git
cd Kidney-Disease-Classification-MLflow-DVC
# Install dependencies
pip install -r requirements.txt
# Start the web application
python app.pyThen open your browser and navigate to: http://localhost:8080
git clone https://github.com/vams2krish/Kidney-Disease-Classification-MLflow-DVC.git
cd Kidney-Disease-Classification-MLflow-DVC# Create virtual environment
python -m venv venv
# Activate on Windows
venv\Scripts\activate
# Activate on Linux/Mac
source venv/bin/activatepip install -r requirements.txtpython -c "import tensorflow; import flask; import mlflow; print('All packages installed successfully!')"# Run the complete ML pipeline
dvc repro# Run pipeline directly
python main.py# Stage 1: Data Ingestion
python src/cnnClassifer/pipeline/stage_01_data_ingestion.py
# Stage 2: Prepare Base Model
python src/cnnClassifer/pipeline/stage_02_prepare_base_model.py
# Stage 3: Model Training
python src/cnnClassifer/pipeline/stage_03_model_training.py
# Stage 4: Model Evaluation
python src/cnnClassifer/pipeline/stage_04_model_evaluation.py# Start Flask app (default port: 8080)
python app.py
# Or specify custom port
python app.py --port 5000The web interface will be available at: http://localhost:8080
curl -X POST http://localhost:8080/predict \
-H "Content-Type: application/json" \
-d '{"image": "<base64_encoded_image>"}'import base64
import requests
# Read and encode image
with open("test_image.jpg", "rb") as f:
image_data = base64.b64encode(f.read()).decode('utf-8')
# Make prediction
response = requests.post(
"http://localhost:8080/predict",
json={"image": image_data}
)
print(response.json())- Open http://localhost:8080 in your browser
- Drag and drop a CT scan image or click to browse
- Click "Analyze CT Scan"
- View the prediction results
# Trigger training pipeline via API
curl -X GET http://localhost:8080/train
# Or using Python
import requests
response = requests.get("http://localhost:8080/train")
print(response.text) # "Training done successfully!"http://localhost:8080
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
GET |
/ |
Home page | - | HTML page |
GET |
/train |
Trigger training | - | String |
POST |
/predict |
Make prediction | {"image": "<base64>"} |
JSON |
[
{
"image": "Normal"
}
]Or with error:
{
"error": "Error message here"
}| Code | Description |
|---|---|
200 |
Success |
400 |
Bad Request - No image provided |
500 |
Internal Server Error |
# Build the image
docker build -t kidney-scan-classifier:latest .# Run the container
docker run -d -p 8080:8080 --name kidney-classifier kidney-scan-classifier:latest
# View logs
docker logs -f kidney-classifier
# Stop the container
docker stop kidney-classifier# docker-compose.yml
version: '3.8'
services:
kidney-classifier:
build: .
ports:
- "8080:8080"
environment:
- PYTHONUNBUFFERED=1
volumes:
- ./model:/app/model
- ./artifacts:/app/artifacts# Start with docker-compose
docker-compose up -d# Build and push to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.us-east-1.amazonaws.com
docker build -t kidney-classifier .
docker tag kidney-classifier:latest <account>.dkr.ecr.us-east-1.amazonaws.com/kidney-classifier:latest
docker push <account>.dkr.ecr.us-east-1.amazonaws.com/kidney-classifier:latest# Using Heroku Container Registry
heroku login
heroku create kidney-classifier
heroku container:push web -a kidney-classifier
heroku container:release web -a kidney-classifier# Model Configuration
IMAGE_SIZE: [224, 224, 3] # VGG16 standard input size
BATCH_SIZE: 16 # Training batch size
EPOCHS: 10 # Number of training epochs
CLASSES: 2 # Number of output classes
WEIGHTS: imagenet # Pre-trained weights
LEARNING_RATE: 0.01 # Initial learning rate
INCLUDE_TOP: False # Exclude top layers
AUGMENTATION: True # Enable data augmentationartifacts_root: artifacts
data_ingestion:
root_dir: artifacts/data_ingestion
source_URL: https://drive.google.com/uc?id=<FILE_ID>
local_data_file: artifacts/data_ingestion/data.zip
unzip_dir: artifacts/data_ingestion
prepare_base_model:
root_dir: artifacts/prepare_base_model
base_model_path: artifacts/prepare_base_model/base_model.h5
updated_base_model_path: artifacts/prepare_base_model/base_model_updated.h5
training:
root_dir: artifacts/training
trained_model_path: artifacts/training/model.h5| Variable | Default | Description |
|---|---|---|
PYTHONUNBUFFERED |
1 | Unbuffered Python output |
LANG |
en_US.UTF-8 | Language setting |
LC_ALL |
en_US.UTF-8 | Locale setting |
MLFLOW_TRACKING_URI |
- | MLflow tracking server URI |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β VGG16 Backbone β
β (Pre-trained on ImageNet, weights frozen) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Input: 224 x 224 x 3 (RGB Image) β
β β
β Block 1: Conv2D(64) Γ 2 β MaxPool β
β Block 2: Conv2D(128) Γ 2 β MaxPool β
β Block 3: Conv2D(256) Γ 3 β MaxPool β
β Block 4: Conv2D(512) Γ 3 β MaxPool β
β Block 5: Conv2D(512) Γ 3 β MaxPool β
β β
β Output: 7 Γ 7 Γ 512 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Custom Classification Head β
β βββββββββββββββββββββββββββββββββββββββββββββββ β
β β GlobalAveragePooling2D β β
β β Dense(512, activation='relu') β β
β β Dropout(0.5) β β
β β Dense(2, activation='softmax') β β
β βββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Output: [Probability_Tumor, Probability_Normal] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Parameter | Value |
|---|---|
| Optimizer | Adam |
| Initial Learning Rate | 0.01 |
| Loss Function | Categorical Crossentropy |
| Batch Size | 16 |
| Epochs | 10 |
| Image Size | 224 Γ 224 Γ 3 |
| Data Augmentation | Yes (rotation, flip, zoom) |
- Source: Kidney CT Scan Image Dataset
- Classes: 2 (Tumor, Normal)
- Split: Training, Validation, Test
- Augmentation: Random horizontal flip, rotation, zoom
# Run all tests
pytest tests/
# Run specific test file
pytest tests/test_prediction.py -v
# Run with coverage
pytest --cov=src tests/# Test data ingestion
python -c "from cnnClassifer.components.data_ingestion import DataIngestion; print('DataIngestion imported successfully')"
# Test configuration
python -c "from cnnClassifer.config.configuration import ConfigurationManager; print('Config imported successfully')"
# Test prediction pipeline
python -c "from cnnClassifer.pipeline.prediction import PredictionPipeline; print('PredictionPipeline imported successfully')"| Metric | Value |
|---|---|
| Loss | 22.63 |
| Accuracy | 48.2% |
β οΈ Note: The current model performance can be improved with:
- More training data
- Extended training epochs
- Hyperparameter tuning
- Advanced architectures (ResNet, EfficientNet)
- Learning rate scheduling
To view experiment tracking:
# Start MLflow UI
mlflow ui
# Open browser at http://localhost:5000Contributions are welcome! Please feel free to submit a Pull Request.
# Fork the repository
# Create your feature branch
git checkout -b feature/AmazingFeature
# Make your changes
git commit -m 'Add some AmazingFeature'
git push origin feature/AmazingFeature
# Open a Pull Request- Follow PEP 8 style guide
- Write docstrings for all functions
- Add type hints where applicable
- Include unit tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 KidneyScan AI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- TensorFlow - Deep learning framework
- Keras - High-level neural networks API
- MLflow - ML lifecycle management
- DVC - Data version control
- Flask - Web framework
- VGG16 - Pre-trained model
- Google Drive - Data hosting
- Community Contributors
| Contact | Details |
|---|---|
| π€ Author | Adam, Vamshi Krishna |
| π§ Email | adam.vamshikrishna@gmail.com |
| π GitHub | vams2krish |
| πΌ LinkedIn | Adam, Vamshi Krishna |
If you found this project helpful, please give it a β on GitHub!
Made with β€οΈ by Adam Vamshi Krishna
Last updated: January 2024