CoolFace
Apppublic

ramyamail2/Classroom-Stress-Detection

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿง  Face Emotion Recognition ยท Deep Learning Mini Project

A complete, from-scratch implementation of a Convolutional Neural Network for 7-class facial emotion recognition โ€” no TensorFlow/PyTorch required.


๐Ÿ“ Project Structure

emotion_recognition/
โ”‚
โ”œโ”€โ”€ model.py          # CNN layers, EmotionCNN class, FER dataset generator
โ”œโ”€โ”€ train.py          # Full training pipeline + visualisation
โ”œโ”€โ”€ inference.py      # Real-time webcam / image / demo inference
โ”œโ”€โ”€ dataset_utils.py  # Data loading, augmentation, class weights
โ”œโ”€โ”€ demo.html         # Self-contained interactive browser demo
โ”œโ”€โ”€ requirements.txt  # Python dependencies
โ”‚
โ””โ”€โ”€ outputs/          # Generated after training
    โ”œโ”€โ”€ best_weights.npy
    โ”œโ”€โ”€ metrics.json
    โ”œโ”€โ”€ sample_images.png
    โ”œโ”€โ”€ class_distribution.png
    โ”œโ”€โ”€ architecture.png
    โ”œโ”€โ”€ training_curves.png
    โ”œโ”€โ”€ confusion_matrix.png
    โ””โ”€โ”€ per_class_metrics.png

๐Ÿš€ Quick Start

1. Install dependencies

bash
pip install -r requirements.txt

2. Quick smoke-test (3 epochs, synthetic data)

bash
python train.py --quick

3. Full training on synthetic dataset (FER-2013 style)

bash
python train.py

4. Use real FER-2013 dataset

bash
# Download via Kaggle CLI
kaggle datasets download -d msambare/fer2013 -p data --unzip
python train.py --fer2013 data/fer2013.csv

5. Run inference

bash
# Demo grid (no camera needed)
python inference.py --demo

# On a single image file
python inference.py --image path/to/face.jpg

# Live webcam (requires camera)
python inference.py --webcam

6. Interactive browser demo

Simply open demo.html in any modern browser โ€” no server needed.


๐Ÿ—๏ธ Model Architecture

Input (1ร—48ร—48)
  โ†“
Conv2D(32, 3ร—3) โ†’ BatchNorm โ†’ ReLU โ†’ MaxPool(2ร—2)   โ†’  32ร—24ร—24
Conv2D(64, 3ร—3) โ†’ BatchNorm โ†’ ReLU โ†’ MaxPool(2ร—2)   โ†’  64ร—12ร—12
Conv2D(128,3ร—3) โ†’ BatchNorm โ†’ ReLU โ†’ MaxPool(2ร—2)   โ†’ 128ร—6ร—6
  โ†“
Flatten โ†’ 4608
Dense(256) โ†’ Dropout(0.5)
Dense(128) โ†’ Dropout(0.3)
Dense(7)   โ†’ Softmax

Parameters: ~1.2 million Framework: Pure NumPy (no TF/PyTorch)


๐Ÿ“Š Dataset: FER-2013

EmotionTrainTest
Angry3,995958
Disgust436111
Fear4,0971,024
Happy7,2151,774
Neutral4,9651,233
Sad4,8301,247
Surprise3,171831
Total28,7097,178

Images: 48ร—48 grayscale Source: Kaggle โ€“ msambare/fer2013


๐Ÿ“ˆ Expected Performance (Real FER-2013)

MetricValue
Val Accuracy~63โ€“68%
Happy F1~0.85โ€“0.89
Surprise F1~0.78โ€“0.82
Disgust F1~0.45โ€“0.55
Note: The synthetic dataset used for quick testing produces low accuracy by design โ€” it only simulates the data structure. Use real FER-2013 for production-quality results.

๐Ÿ”ง Implementation Notes

No External DL Framework

All layers are implemented from scratch in NumPy:

  • โ€”ConvLayer โ€” 2-D convolution with He initialisation
  • โ€”BatchNorm โ€” channel-wise batch normalisation
  • โ€”MaxPool2x2 โ€” 2ร—2 max pooling with correct backprop
  • โ€”Dropout โ€” inverted dropout
  • โ€”Dense โ€” fully-connected layer
  • โ€”Softmax โ€” numerically stable softmax + CE loss

Augmentation (dataset_utils.py)

  • โ€”Horizontal flip
  • โ€”Random rotation (ยฑ12ยฐ)
  • โ€”Translation (ยฑ4 px)
  • โ€”Zoom (0.9โ€“1.1ร—)
  • โ€”Brightness jitter
  • โ€”Gaussian noise

Class Imbalance

compute_class_weights() returns per-class weights for weighted cross-entropy, especially important for the underrepresented Disgust class (436 samples).


๐Ÿ“„ License

MIT โ€” free for academic and personal use.

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference