A production-ready, end-to-end MLOps pipeline for plant image classification (Dandelion vs Grass) with automated retraining, comprehensive monitoring, and enterprise-grade deployment capabilities.
- Overview
- Project Objectives
- Architecture
- Technologies Used
- Quick Start
- Project Structure
- Step-by-Step Guide
- Documentation
- License
This project implements a complete MLOps solution covering the entire machine learning lifecycle:
- Data Engineering: Automated data extraction, preprocessing, and feature storage
- Model Development: Deep learning with FastAI, experiment tracking with MLflow
- Model Storage: S3-compatible object storage (MinIO) for model artifacts
- API Development: FastAPI with Prometheus metrics and health monitoring
- User Interface: Streamlit web application for interactive predictions
- Containerization: Multi-stage Docker builds optimized for production
- Orchestration: Kubernetes deployment with ConfigMaps and Services
- Automation: Apache Airflow for automated retraining pipelines
- Monitoring: Prometheus + Grafana for comprehensive observability
- CI/CD: GitHub Actions with self-hosted runners
This project successfully implements all 10 core MLOps objectives:
- β Data Pipeline: Extract images from URLs, clean, and preprocess for training
- β Model Training: FastAI ResNet34 for binary classification (Dandelion vs Grass)
- β S3 Storage: MinIO (S3-compatible) for model artifact storage
- β MLflow Tracking: Complete experiment tracking with metrics, parameters, and artifacts
- β REST API: FastAPI with prediction endpoints and health checks
- β Web Application: Streamlit UI for image upload and prediction visualization
- β Kubernetes Deployment: Docker containerization + K8s orchestration with CI/CD
- β GitHub Version Control: Clean structure, comprehensive documentation, and git workflows
- β Apache Airflow: Automated retraining pipeline with 13 task DAG
- β Prometheus + Grafana: Full-stack monitoring for API, model, Airflow, and infrastructure
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MLOps Platform β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ ββββββββββββββββ βββββββββββββββ β
β β Data βββββΆβ Training βββββΆβ MLflow β β
β β Pipeline β β Pipeline β β Tracking β β
β βββββββββββββββ ββββββββββββββββ βββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β βββββββββββββββ ββββββββββββββββ βββββββββββββββ β
β β Feature β β Model βββββΆβ MinIO β β
β β Store β β Artifacts β β (S3 Store) β β
β βββββββββββββββ ββββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββ β
β β FastAPI Service β β
β β (Prometheus Metrics Enabled) β β
β βββββββββββββββββββββββββββββββββββββββββ β
β β β β
β βββββββββββ΄βββββββββ ββββββββββ΄ββββββββββ β
β β Streamlit UI β β K8s Cluster β β
β β (Web App) β β (Production) β β
β ββββββββββββββββββββ ββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Automation Layer β β
β β ββββββββββββββββ ββββββββββββββββ β β
β β β Airflow ββββββββββΆβ Retraining β β β
β β β Scheduler β β Pipeline β β β
β β ββββββββββββββββ ββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Monitoring Layer β β
β β ββββββββββββββββ ββββββββββββββββ β β
β β β Prometheus ββββββββββΆβ Grafana β β β
β β β (Metrics) β β (Dashboards) β β β
β β ββββββββββββββββ ββββββββββββββββ β β
β β β² β β
β β β β β
β β [All Services] β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- FastAI 2.7.13: Deep learning framework built on PyTorch
- PyTorch 2.1.0: Neural network training and inference
- MLflow 2.8.1: Experiment tracking and model registry
- FastAPI 0.104.1: High-performance REST API framework
- Streamlit 1.28.1: Interactive web application framework
- Uvicorn 0.24.0: ASGI server for FastAPI
- MinIO: S3-compatible object storage
- PostgreSQL 13: Database for MLflow and Airflow
- Redis: Cache and message broker
- Kubernetes 1.28+: Container orchestration
- Docker 20.10+: Containerization platform
- Apache Airflow 2.7.0: Workflow automation and scheduling
- Prometheus 2.x: Metrics collection and alerting
- Grafana: Metrics visualization and dashboards
- Node Exporter: System-level metrics
- cAdvisor: Container metrics
- Prometheus Client: Python instrumentation library
- GitHub Actions: CI/CD automation
- Git: Version control system
- Python 3.9 or higher
- Docker Desktop with Kubernetes enabled
- Git for version control
- 8GB+ RAM recommended
- 10GB+ disk space for Docker images and data
- Clone the repository
git clone <repository-url>
cd ML\ Project- Create virtual environment
python -m venv venv
# Windows
.\venv\Scripts\activate
# Linux/Mac
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Start infrastructure services
# Start MLflow and MinIO
docker-compose -f docker-compose.mlflow.yml up -d- Run the complete pipeline
# 1. Data pipeline
python run_data_pipeline.py
# 2. Train model with MLflow
python run_training_with_mlflow.py
# 3. Start API
python run_api.py
# 4. Start Web App (in another terminal)
streamlit run streamlit_app.py- Streamlit UI: http://localhost:8501
- FastAPI Docs: http://localhost:8000/docs
- MLflow UI: http://localhost:5000
- MinIO Console: http://localhost:9001 (admin/minioadmin)
ML Project/
βββ π README.md # This file
βββ π STEP_BY_STEP_GUIDE.md # Detailed step-by-step instructions
βββ π requirements.txt # Python dependencies
βββ π setup.py # Package setup
β
βββ π³ Docker & Kubernetes
β βββ Dockerfile # Main API container
β βββ Dockerfile.api # Optimized API image
β βββ docker-compose.yml # Main services
β βββ docker-compose.mlflow.yml # MLflow stack
β βββ docker-compose.airflow.yml # Airflow stack
β βββ docker-compose.monitoring.yml # Monitoring stack
β βββ k8s/ # Kubernetes manifests
β βββ namespace.yaml
β βββ configmap.yaml
β βββ deployment.yaml
β βββ service.yaml
β
βββ π§ Configuration
β βββ configs/config.yaml # Main configuration
β βββ .env # Environment variables
β βββ .dockerignore # Docker ignore patterns
β
βββ π Data
β βββ data/raw/ # Downloaded images
β βββ data/processed/ # Preprocessed data
β βββ data/splits/ # Train/val/test splits
β βββ data/feature_store/ # Feature storage
β
βββ π€ Source Code
β βββ src/
β β βββ data/ # Data pipeline modules
β β β βββ extract.py # URL image extraction
β β β βββ preprocess.py # Image preprocessing
β β β βββ database.py # Data management
β β βββ models/ # Model training
β β β βββ train.py # FastAI training logic
β β βββ storage/ # Storage layer
β β β βββ s3_storage.py # MinIO/S3 operations
β β βββ tracking/ # Experiment tracking
β β β βββ mlflow_tracker.py # MLflow integration
β β βββ api/ # API layer
β β βββ app.py # FastAPI application
β β βββ model_handler.py # Model inference
β β
β βββ run_data_pipeline.py # Execute data pipeline
β βββ run_training.py # Basic training script
β βββ run_training_with_mlflow.py # MLflow training script
β βββ run_api.py # Start API server
β βββ streamlit_app.py # Web application
β
βββ π Airflow (Objective 9)
β βββ airflow/
β β βββ dags/
β β β βββ plant_retraining_dag.py # Automated retraining
β β βββ airflow.env # Airflow configuration
β βββ AIRFLOW_GUIDE.md # Airflow documentation
β
βββ π Monitoring (Objective 10)
β βββ docker/
β β βββ prometheus/
β β β βββ prometheus.yml # Prometheus config
β β β βββ rules/alerts.yml # Alert rules
β β βββ grafana/
β β βββ provisioning/ # Auto-provisioning
β β βββ dashboards/ # Dashboard definitions
β βββ MONITORING_GUIDE.md # Monitoring documentation
β βββ MONITORING_IMPLEMENTATION.md # Implementation details
β
βββ π¨ Scripts
β βββ scripts/
β β βββ start-airflow.ps1 # Start Airflow services
β β βββ start-monitoring.ps1 # Start monitoring stack
β β βββ build-docker.ps1 # Build Docker images
β β βββ deploy-k8s.ps1 # Deploy to Kubernetes
β β βββ cleanup-k8s.ps1 # Clean Kubernetes resources
β β
β βββ start_api.bat # Quick start API (Windows)
β βββ start_webapp.bat # Quick start WebApp (Windows)
β
βββ π§ͺ Models
β βββ models/ # Trained model artifacts
β βββ mlruns/ # MLflow experiment data
β
βββ π Documentation
β βββ CONTRIBUTING.md # Contribution guidelines
β βββ CHANGELOG.md # Version history
β βββ LICENSE # MIT License
β βββ AIRFLOW_GUIDE.md # Airflow setup guide
β
βββ βοΈ CI/CD
βββ .github/
βββ workflows/ci-cd.yml # GitHub Actions pipeline
βββ ISSUE_TEMPLATE/ # Issue templates
For detailed instructions on how to run each of the 10 objectives, see:
This guide includes:
- Objective 1: Data extraction and preprocessing
- Objective 2: Model training with FastAI
- Objective 3: S3 storage with MinIO
- Objective 4: MLflow experiment tracking
- Objective 5: FastAPI REST API
- Objective 6: Streamlit web application
- Objective 7: Kubernetes deployment
- Objective 8: GitHub version control (this repo!)
- Objective 9: Apache Airflow retraining pipeline
- Objective 10: Prometheus + Grafana monitoring
Each section includes:
- β What was implemented
- π How to run it
- π How to verify it works
- π Expected results
- STEP_BY_STEP_GUIDE.md: Complete guide for all 10 objectives
- AIRFLOW_GUIDE.md: Apache Airflow setup and usage
- MONITORING_GUIDE.md: Prometheus + Grafana monitoring
- CONTRIBUTING.md: How to contribute to this project
- CHANGELOG.md: Project version history
- Interactive API Docs: http://localhost:8000/docs (when API is running)
- ReDoc: http://localhost:8000/redoc (alternative API documentation)
| Service | URL | Credentials |
|---|---|---|
| Streamlit UI | http://localhost:8501 | - |
| FastAPI | http://localhost:8000 | - |
| API Docs | http://localhost:8000/docs | - |
| MLflow | http://localhost:5000 | - |
| MinIO Console | http://localhost:9001 | admin/minioadmin |
| Airflow | http://localhost:8080 | admin/admin |
| Grafana | http://localhost:3000 | admin/admin |
| Prometheus | http://localhost:9090 | - |
- Downloads images from CSV URLs
- Validates image integrity
- Applies preprocessing (resize, normalize)
- Creates train/validation/test splits
- Stores metadata for reproducibility
- FastAI ResNet34 with transfer learning
- Fine-tuning on plant classification task
- Data augmentation for robustness
- Automated train/validation evaluation
- Model export for inference
- MinIO as S3-compatible storage
- Automatic model versioning
- Metadata storage with models
- Efficient artifact management
- Easy model retrieval for inference
- Experiment organization
- Parameter and metric logging
- Model registry with versioning
- Artifact storage integration
- Comparison across runs
- RESTful endpoints for predictions
- Health check endpoints
- Prometheus metrics exposition
- Async request handling
- Batch prediction support
- Image validation and preprocessing
- User-friendly image upload
- Real-time predictions
- Confidence score visualization
- Example images
- Model information display
- Docker containerization
- K8s namespace isolation
- ConfigMap for configuration
- Service for networking
- Resource limits and requests
- GitHub Actions CI/CD
- Clean repository structure
- Comprehensive documentation
- Issue templates
- Pull request templates
- Automated CI/CD workflows
- Dependency management
- 13-task automated pipeline
- Data validation
- Model training
- Performance evaluation
- Model registration
- S3 upload
- Deployment
- Slack notifications
- Schedule: Daily at 2 AM
- Failure handling and retries
- Prometheus: Metrics collection from 10 targets
- API metrics (requests, latency, errors)
- Model metrics (inference time, predictions)
- Airflow metrics (DAG runs, task status)
- Infrastructure metrics (CPU, memory, disk, network)
- Container metrics (cAdvisor)
- Grafana: Visualization dashboards
- MLOps Overview dashboard
- System metrics dashboard
- API performance dashboard
- Alerts: 15+ alert rules for critical conditions
- Exporters: Node Exporter, cAdvisor, Pushgateway
# Test data pipeline
python run_data_pipeline.py
# Test model training
python run_training.py
# Test API
python -m pytest tests/
# Test Docker build
docker build -t plant-api -f Dockerfile.api .
# Test Kubernetes deployment
kubectl apply -f k8s/
kubectl get pods -n plant-classification# Health check
curl http://localhost:8000/health
# Predict endpoint
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: multipart/form-data" \
-F "file=@test_image.jpg"
# Metrics endpoint
curl http://localhost:8000/metricsCreate a .env file in the project root:
# MLflow
MLFLOW_TRACKING_URI=http://localhost:5000
MLFLOW_S3_ENDPOINT_URL=http://localhost:9000
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
# MinIO
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=minioadmin
MINIO_BUCKET=mlflow
# API
API_HOST=0.0.0.0
API_PORT=8000
MODEL_PATH=models/plant_classifier_final.pkl
# Airflow
AIRFLOW_UID=50000
AIRFLOW_IMAGE_NAME=apache/airflow:2.7.0-python3.9
# Monitoring
PROMETHEUS_RETENTION=30d
GRAFANA_ADMIN_PASSWORD=adminEdit configs/config.yaml for pipeline settings:
data:
raw_dir: "data/raw"
processed_dir: "data/processed"
splits_dir: "data/splits"
train_ratio: 0.7
val_ratio: 0.15
test_ratio: 0.15
training:
model_name: "resnet34"
batch_size: 32
epochs: 10
learning_rate: 0.001
image_size: 224
storage:
s3_bucket: "mlflow"
model_prefix: "models"
mlflow:
experiment_name: "plant_classification"
run_name: "resnet34_training"# Build images
docker build -t plant-api:latest -f Dockerfile.api .
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down# Create namespace
kubectl apply -f k8s/namespace.yaml
# Apply configurations
kubectl apply -f k8s/configmap.yaml
# Deploy application
kubectl apply -f k8s/deployment.yaml
# Create service
kubectl apply -f k8s/service.yaml
# Check status
kubectl get all -n plant-classification
# Access service
kubectl port-forward -n plant-classification svc/plant-api-service 8000:8000# Build Docker image
.\scripts\build-docker.ps1
# Deploy to Kubernetes
.\scripts\deploy-k8s.ps1
# Start Airflow
.\scripts\start-airflow.ps1
# Start Monitoring
.\scripts\start-monitoring.ps1
# Cleanup Kubernetes
.\scripts\cleanup-k8s.ps1# Start Prometheus + Grafana
docker-compose -f docker-compose.monitoring.yml up -d
# Or use the script
.\scripts\start-monitoring.ps1-
Grafana: http://localhost:3000 (admin/admin)
- MLOps Overview Dashboard
- Node Exporter Full Dashboard
- Custom dashboards in
docker/grafana/dashboards/
-
Prometheus: http://localhost:9090
- Query metrics directly
- View targets and alerts
- Explore time series data
- API Metrics: Request rate, latency, error rate
- Model Metrics: Inference time, prediction count, accuracy
- System Metrics: CPU, memory, disk, network
- Container Metrics: Docker container resource usage
- Airflow Metrics: DAG run success/failure, task duration
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Your Name - Initial work and MLOps implementation
- FastAI for the excellent deep learning framework
- MLflow community for experiment tracking tools
- FastAPI for the modern API framework
- Streamlit for rapid UI development
- Apache Airflow for workflow orchestration
- Prometheus and Grafana for monitoring solutions
- Kubernetes community for orchestration best practices
For questions or issues:
- Open an issue in this repository
- Check the documentation in
docs/ - Review the STEP_BY_STEP_GUIDE.md
Status: β COMPLETE - All 10 objectives successfully implemented
- β Core objectives (1-8): Fully functional
- β Bonus objective 9 (Airflow): Implemented and tested
- β Bonus objective 10 (Monitoring): Implemented and verified