Skip to content

nimshafernando/Skin-Oil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation



  ██████  ██   ██ ██ ███    ██      ██████  ██ ██      
  ██      ██  ██  ██ ████   ██     ██    ██ ██ ██      
  ███████ █████   ██ ██ ██  ██     ██    ██ ██ ██      
       ██ ██  ██  ██ ██  ██ ██     ██    ██ ██ ██      
  ██████  ██   ██ ██ ██   ████      ██████  ██ ███████ 
                                                       
         O I L I N E S S   D E T E C T I O N          

🧴 Skin Oiliness Detection

AI-powered facial skin analysis using MobileNet CNN + K-Means clustering


📖 Overview · 🏗️ Pipeline · 🚀 Quickstart · 📊 Results · 🛠️ Tech Stack · 📂 File Structure


📖 Overview

Skin Oiliness Detection is a computer vision project that automatically classifies facial skin oiliness into four levels — Low, Medium, High, and Very High — using a combination of classical image processing and deep learning.

The system captures a photo directly in your browser (via Google Colab), detects the face using an OpenCV DNN model, extracts rich skin-specific features (HSV colour statistics, YCbCr reflection features, CLAHE texture enhancement), clusters the training images with K-Means to generate pseudo-labels, and fine-tunes a MobileNet to form a pretrained Convolutional Neural Network (CNN) backbone for final classification.

✨ Key Highlights

Feature Detail
🎯 Task 4-class skin oiliness classification
🧠 Model MobileNet (ImageNet pretrained, last 20 layers fine-tuned)
🔬 Features HSV stats · YCbCr Cr-channel reflection · CLAHE texture
📦 Labelling Unsupervised K-Means clustering (4 clusters)
👁️ Face detection OpenCV DNN — ResNet-10 SSD (Caffe)
☁️ Platform Google Colab (GPU-accelerated, zero local setup)
💾 Output Trained .h5 model + CSVs saved to Google Drive

🏗️ Pipeline

┌─────────────────────────────────────────────────────────────────┐
│                     TRAINING PIPELINE                           │
│                                                                 │
│  Dataset Clone                                                  │
│      │   (/Real-TIme-Skin-Type-Detection Dataset from Kaggle)       │
│      ▼                                                          │
│  Data Preparation                                               │
│      │   oily images + 50 random dry images → /datafile/        │
│      ▼                                                          │
│  Data Augmentation (×10 per image)                              │
│      │   rotation · shift · shear · zoom · horizontal flip      │
│      ▼                                                          │
│  Feature Extraction                                             │
│      │   CLAHE enhancement → HSV stats (6D) + YCbCr Cr (2D)    │
│      │   → HSV-range skin masking → saved to extracted_features.csv│
│      ▼                                                          │
│  K-Means Clustering (k=4)                                       │
│      │   PCA(2) → cluster → map → {Low/Medium/High/Very High}   │
│      ▼                                                          │
│  MobileNet Fine-tuning                                          │
│      │   ImageNet weights · last-20 layers trainable            │
│      │   Adam(lr=0.001) · LR scheduler · 15 epochs · bs=16     │
│      ▼                                                          │
│  ✅ mobile_net_oiliness_model.h5  (saved to Google Drive)       │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│                    INFERENCE PIPELINE                           │
│                                                                 │
│  Webcam Capture (in-browser JS)                                 │
│      ▼                                                          │
│  Face Detection (OpenCV DNN SSD — ResNet-10)                    │
│      ▼                                                          │
│  Skin Preprocessing                                             │
│      │   CLAHE enhancement → HSV skin masking                   │
│      ▼                                                          │
│  MobileNet Prediction                                           │
│      │   (256×256 input → softmax over 4 classes)               │
│      ▼                                                          │
│  🧴 Oiliness Level + Confidence Bar Chart                       │
└─────────────────────────────────────────────────────────────────┘

🚀 Quickstart

No local installation needed. Everything runs in Google Colab.

1 · Open the notebook

Click the badge below or upload skin_oiliness_detection.ipynb to colab.research.google.com.

Open In Colab

2 · Set the runtime to GPU

Runtime → Change runtime type → Hardware accelerator → T4 GPU

3 · Run cells in order

Cell 0  →  Install imutils & tqdm
Cell 1  →  Clone the skin dataset
Cell 2  →  Prepare the data folder
Cell 3  →  Augment images (×10)
Cell 5–6 → Extract features (HSV + YCbCr + CLAHE)
Cell 8–9 → K-Means clustering & labelling
Cell 11–12 → Train MobileNet (≈15 epochs)
Cell 13–14 → Capture photo via webcam
Cell 15–17 → Detect face with DNN
Cell 18–20 → Predict oiliness level + visualise
Cell 22  → Save outputs to Google Drive

4 · Predict on your own face

When you reach Cell 14, your browser will ask for camera permission. Click Capture — the rest is automatic.


📊 Results

Oiliness Level Definitions

Level Description Visual cue
🟢 Low Minimal sebum; matte appearance Skin looks dry or normal
🟡 Medium Moderate sebum; slight shine on T-zone Balanced skin
🟠 High Noticeable shine across most of face Visible sebum accumulation
🔴 Very High Intense oiliness; reflective under light Heavy shine, prone to acne

Training Configuration

Backbone      : MobileNet (ImageNet weights)
Trainable     : Last 20 layers
Input size    : 256 × 256 × 3
Optimizer     : Adam  (lr = 0.001)
LR schedule   : Exponential decay after epoch 5
Loss          : Categorical cross-entropy
Batch size    : 16
Epochs        : 15
Val split     : 20%

🔬 Feature Engineering

Three complementary feature signals are extracted from each image before clustering and training:

┌─────────────────────────────────────────────────────┐
│  1. HSV Colour Statistics (6 features)              │
│     mean_H, mean_S, mean_V, std_H, std_S, std_V     │
│     → captures hue + saturation variation           │
│                                                     │
│  2. YCbCr Skin-Reflection (2 features)              │
│     mean_Cr, std_Cr                                 │
│     → Cr channel isolates red-to-green ratio        │
│       which correlates with sebum reflectance       │
│                                                     │
│  3. CLAHE Texture Enhancement (preprocessing)       │
│     clipLimit=3.0, tileGridSize=(8,8)               │
│     → amplifies subtle texture differences          │
│       before any feature extraction                 │
└─────────────────────────────────────────────────────┘

HSV-range skin masking (H: 0–20, S: 48–150, V: 70–255) is applied to isolate skin pixels and remove background noise before feature extraction.


🛠️ Tech Stack

Library Purpose
tensorflow / keras MobileNet model, ImageDataGenerator, training
scikit-learn KMeans, PCA, StandardScaler, train_test_split
opencv-python Image processing, CLAHE, face detection DNN
numpy / pandas Feature arrays, CSV I/O
matplotlib Visualisations — cluster plots, prediction bar charts
imutils Image resizing utilities
tqdm Progress bars
google.colab Webcam JS capture, Drive mounting

Face Detection Model: OpenCV DNN with ResNet-10 SSD trained on the Caffe framework (res10_300x300_ssd_iter_140000.caffemodel, confidence threshold 0.35–0.5).


📂 File Structure

skin-oiliness-detection/
│
├── skin_oiliness_detection.ipynb   ← Main notebook (run this)
│
└── outputs/ (generated at runtime, saved to Google Drive)
    ├── extracted_features.csv       ← Per-image HSV + YCbCr features
    ├── clustered_data.csv           ← Images with K-Means cluster labels
    └── mobile_net_oiliness_model.h5 ← Trained MobileNet model weights

🧩 How the Labelling Works

Since no ground-truth oiliness labels exist in the dataset, unsupervised K-Means clustering is used to generate pseudo-labels:

  1. Each image is resized to 64×64 and flattened (pixel intensities)
  2. Concatenated with the 8D feature vector (HSV stats + YCbCr)
  3. StandardScaler normalises all features
  4. PCA reduces to 2 components for clustering efficiency
  5. KMeans (k=4, n_init=10) assigns each image to one of 4 clusters
  6. Clusters are mapped to {Low, Medium, High, Very High} based on mean feature values

These cluster labels then serve as training targets for the MobileNet classifier.


📸 Inference Demo

Input  : Webcam photo (captured in-browser via JavaScript)
         ↓
Step 1 : OpenCV DNN detects and crops face region
Step 2 : CLAHE enhances skin texture
Step 3 : HSV-range mask isolates skin pixels
Step 4 : MobileNet predicts oiliness class + confidence

Output : 
   Low       : ████░░░░░░░░░░░░░░░░░░░░░░░░░░  12.3%
   Medium    : ██████████░░░░░░░░░░░░░░░░░░░░  35.1%
   High      : █████████████████░░░░░░░░░░░░░  44.8%
   Very High : ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░   7.8%

   🧴 Predicted Skin Oiliness Level: High

📄 License

This project is released under the MIT License.


Made with ☕ and a lot of skin images  ·  Runs on Google Colab  ·  No GPU required locally

About

This project presents an image classification system for analyzing facial images and categorizing skin oiliness levels. It combines data augmentation, K-Means–based pseudo-labeling, and a fine-tuned pretrained CNN for efficient training and evaluation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors