Skip to content

A production-ready image classification system for the Fashion MNIST dataset, featuring a CNN model with ~92% accuracy, REST API, and interactive web interface.

License

Notifications You must be signed in to change notification settings

millenniumsingha/StyleNet

Repository files navigation

Fashion MNIST Classifier πŸ‘—

Python TensorFlow FastAPI Docker Streamlit App

A production-ready image classification system for the Fashion MNIST dataset, featuring a CNN model with ~92% accuracy, REST API, and interactive web interface.

πŸ”΄ Live Demo

You can deploy this application directly to Streamlit Cloud to see it in action:

Deploy to Streamlit

Note: After deploying, update the link above to your specific app URL.

Demo

🎯 Quick Start

Option 1: Docker (Recommended)

# Clone repository
git clone https://github.com/millenniumsingha/StyleNet.git
cd StyleNet

# Train model and start services
docker-compose --profile training up train
docker-compose up -d api streamlit

# Access:
# - API Docs: http://localhost:8000/docs
# - Web App:  http://localhost:8501

Option 2: Local Installation

# Install dependencies
pip install -r requirements.txt

# Train model
python -m src.train --model cnn --epochs 15

# Start API
uvicorn api.main:app --reload

# Start Web App (new terminal)
streamlit run app/streamlit_app.py

πŸ“Š Model Performance

Model Test Accuracy Parameters
Simple (Original) ~88% ~101K
CNN (Current) ~92% ~400K

πŸ—οΈ Architecture

Input (28x28x1)
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Conv Block 1    β”‚  32 filters, BatchNorm, MaxPool, Dropout
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Conv Block 2    β”‚  64 filters, BatchNorm, MaxPool, Dropout
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Conv Block 3    β”‚  128 filters, BatchNorm, MaxPool, Dropout
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Dense (256)     β”‚  BatchNorm, Dropout
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Output (10)     β”‚  Softmax
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”Œ API Reference

Endpoints

Method Endpoint Description
GET / API information
GET /health Health check
GET /classes List class names
POST /predict Classify single image
POST /predict/batch Classify multiple images

Example Request

curl -X POST "http://localhost:8000/predict" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@your_image.png"

Example Response

{
  "success": true,
  "predicted_class": "Ankle boot",
  "predicted_index": 9,
  "confidence": 0.97,
  "top_predictions": [
    {"class_name": "Ankle boot", "class_index": 9, "confidence": 0.97},
    {"class_name": "Sneaker", "class_index": 7, "confidence": 0.02},
    {"class_name": "Sandal", "class_index": 5, "confidence": 0.01}
  ]
}

πŸ“ Project Structure

β”œβ”€β”€ src/                 # Core ML code
β”‚   β”œβ”€β”€ model.py         # CNN architecture
β”‚   β”œβ”€β”€ train.py         # Training script
β”‚   └── predict.py       # Inference utilities
β”œβ”€β”€ api/                 # FastAPI backend
β”‚   └── main.py          # REST API endpoints
β”œβ”€β”€ app/                 # Streamlit frontend
β”‚   └── streamlit_app.py # Web interface
β”œβ”€β”€ tests/               # Unit tests
β”œβ”€β”€ models/              # Saved models
β”œβ”€β”€ notebooks/           # Jupyter notebooks
└── legacy/              # Original project files

πŸ§ͺ Testing

# Run all tests
pytest tests/ -v

# With coverage
pytest tests/ --cov=src --cov=api

πŸ“ˆ Training Your Own Model

# CNN model (recommended)
python -m src.train --model cnn --epochs 15

# Simple model (for comparison)
python -m src.train --model simple --epochs 10

🎨 Supported Classes

Index Class
0 T-shirt/top
1 Trouser
2 Pullover
3 Dress
4 Coat
5 Sandal
6 Shirt
7 Sneaker
8 Bag
9 Ankle boot

πŸš€ Future Improvements

  • Model versioning with MLflow
  • CI/CD pipeline with GitHub Actions
  • Kubernetes deployment configs
  • Model monitoring and drift detection
  • A/B testing framework

πŸ”„ CI/CD Pipeline

The project uses GitHub Actions for Continuous Integration and Deployment:

  • Build & Test: runs on every push to verify code quality.
  • Docker Build: pushes new images to GitHub Container Registry (GHCR) on release.

πŸ“¦ Model Versioning (MLflow)

Experiments are tracked using MLflow.

# Start MLflow server
docker-compose up -d mlflow

# View dashboard at http://localhost:5000

πŸ“Š Monitoring (Evidently AI)

Data drift is monitored comparing production traffic against training data.

  • Drift Logic: Implemented in src/monitoring.py.
  • Logs: Predictions are logged to monitoring/current_data.csv.

☸️ Kubernetes Deployment

Deploy to a cluster using the manifests in k8s/:

kubectl apply -f k8s/

Includes:

  • API: 2 Replicas, Health Checks.
  • Streamlit: LoadBalancer Service.

πŸ”€ A/B Testing

Traffic is routed between stable and canary models based on environment variables:

  • Set AB_TEST_RATIO=0.2 to send 20% of traffic to the canary model.

πŸ™ Acknowledgments


Originally created as a learning project, upgraded to production-ready status.

About

A production-ready image classification system for the Fashion MNIST dataset, featuring a CNN model with ~92% accuracy, REST API, and interactive web interface.

Resources

License

Stars

Watchers

Forks

Packages