Skip to content

markusprap/ml-service-skinmate

Repository files navigation

SkinMate ML Service

Machine Learning service untuk SkinMate - Your Trusted Skincare Companion

Tech Stack

  • Language: Python 3.9+
  • Framework: Flask / FastAPI
  • ML Libraries: TensorFlow, OpenCV, scikit-learn
  • Image Processing: PIL, OpenCV
  • Data Processing: pandas, numpy
  • Model Serving: TensorFlow Serving
  • Containerization: Docker

Features

  • 🤖 AI-Powered Skin Type Classification
  • 📸 Real-time Image Processing
  • 🔍 Facial Feature Detection
  • 📊 Skin Analysis Reports
  • 🧪 Product Ingredient Analysis
  • 📈 Model Training Pipeline
  • 🚀 Model Serving API
  • 📋 Dataset Management

Getting Started

Prerequisites

  • Python 3.9+
  • pip or conda
  • CUDA (optional, for GPU acceleration)

Installation

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Download pre-trained models
python download_models.py

# Start development server
python main.py

Environment Variables

Create a .env file:

# Flask Configuration
FLASK_ENV=development
FLASK_DEBUG=True
PORT=5000

# Model Configuration
MODEL_PATH=./models
SKIN_MODEL_VERSION=v1.0
CONFIDENCE_THRESHOLD=0.8

# Image Processing
MAX_IMAGE_SIZE=2048
ALLOWED_EXTENSIONS=jpg,jpeg,png,webp

# External Services
BACKEND_API_URL=http://localhost:8080
FRONTEND_URL=http://localhost:3000

# Dataset Configuration
DATASET_PATH=./datasets
KAGGLE_USERNAME=your-username
KAGGLE_KEY=your-key

Project Structure

ml-service/
├── main.py                      # Main Flask application
├── requirements.txt             # Python dependencies
├── Dockerfile                   # Docker configuration
├── download_models.py           # Download pre-trained models
├── app/
│   ├── __init__.py
│   ├── models/
│   │   ├── skin_classifier.py   # Skin type classification model
│   │   ├── face_detector.py     # Face detection model
│   │   └── ingredient_analyzer.py # Ingredient analysis
│   ├── services/
│   │   ├── image_service.py     # Image processing service
│   │   ├── analysis_service.py  # Skin analysis service
│   │   └── recommendation_service.py # Product recommendation
│   ├── utils/
│   │   ├── image_utils.py       # Image processing utilities
│   │   ├── model_utils.py       # Model loading utilities
│   │   └── validation.py        # Input validation
│   └── routes/
│       ├── analysis.py          # Analysis endpoints
│       ├── models.py            # Model management endpoints
│       └── health.py            # Health check endpoints
├── models/                      # Trained models directory
│   ├── skin_classifier_v1.h5
│   ├── face_detector.xml
│   └── ingredient_classifier.pkl
├── datasets/                    # Training datasets
│   ├── raw/                     # Raw scraped data
│   ├── processed/               # Preprocessed data
│   └── augmented/               # Data augmentation results
├── notebooks/
│   ├── SkinMate_Model_Training.ipynb # Main training notebook
│   ├── data_exploration.ipynb   # Data analysis
│   └── model_evaluation.ipynb   # Model evaluation
├── scripts/
│   ├── train_model.py           # Model training script
│   ├── prepare_dataset.py       # Dataset preparation
│   ├── skin_dataset_scraper.py  # Data scraping
│   └── preprocess_datasets.py   # Data preprocessing
└── tests/
    ├── test_models.py           # Model tests
    ├── test_services.py         # Service tests
    └── test_utils.py            # Utility tests

API Endpoints

Skin Analysis

  • POST /api/analyze/skin - Analyze skin type from image
  • POST /api/analyze/batch - Batch analysis for multiple images
  • GET /api/analyze/history/:user_id - Get analysis history

Image Processing

  • POST /api/image/preprocess - Preprocess image for analysis
  • POST /api/image/detect-face - Detect face in image
  • POST /api/image/validate - Validate image quality

Product Analysis

  • POST /api/products/analyze-ingredients - Analyze product ingredients
  • POST /api/products/recommend - Get product recommendations
  • POST /api/products/compare - Compare multiple products

Model Management

  • GET /api/models/status - Get model status and versions
  • POST /api/models/reload - Reload models
  • GET /api/models/metrics - Get model performance metrics

Skin Types Classification

  • Normal: Balanced moisture and oil production
  • Dry: Low moisture, may appear flaky or tight
  • Oily: Excess sebum production, prone to shine
  • Combination: Mix of oily T-zone and dry cheeks
  • Sensitive: Reactive to products, prone to irritation
  • Acne-Prone: Tendency to develop acne and blemishes

Model Architecture

  • Base Model: EfficientNet-B0
  • Input Size: 224x224 pixels
  • Preprocessing: Face detection → Crop → Normalize
  • Output: Skin type probabilities + confidence scores
  • Performance:
    • Accuracy: 87.3%
    • F1-Score: 0.85
    • Inference Time: ~200ms

Dataset Information

  • Total Images: 15,000+ curated images
  • Sources: Multiple dermatology datasets + web scraping
  • Augmentation: Rotation, brightness, contrast adjustments
  • Validation Split: 80% train, 10% validation, 10% test
  • Quality Control: Manual review + automated filtering

Training Pipeline

# Download and prepare datasets
python scripts/skin_dataset_scraper.py
python scripts/prepare_dataset.py

# Preprocess data
python scripts/preprocess_datasets.py

# Train model
python scripts/train_model.py

# Evaluate model
python -m pytest tests/test_models.py

Docker Support

# Build Docker image
docker build -t skinmate-ml .

# Run container
docker run -p 5000:5000 skinmate-ml

# Run with GPU support
docker run --gpus all -p 5000:5000 skinmate-ml

Performance Optimization

  • Model Quantization: Reduced model size by 70%
  • Batch Processing: Support for multiple images
  • Caching: Result caching for repeated requests
  • GPU Acceleration: CUDA support for faster inference
  • Model Versioning: A/B testing for model improvements

Monitoring & Logging

  • Model Drift Detection: Monitor prediction distributions
  • Performance Metrics: Track inference time and accuracy
  • Error Logging: Comprehensive error tracking
  • Usage Analytics: Track API usage patterns

Data Privacy & Security

  • Image Storage: Temporary processing only
  • Data Encryption: All data encrypted in transit
  • GDPR Compliance: User data handling policies
  • Model Security: Protected model endpoints

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

Private - SkinMate Project

Model Credits

  • Face detection: OpenCV Haar Cascades
  • Base architecture: EfficientNet (Google Research)
  • Training framework: TensorFlow/Keras
  • Preprocessing: OpenCV, PIL

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors