ramyamail2/Classroom-Stress-Detection
0
๐ง 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
pip install -r requirements.txt2. Quick smoke-test (3 epochs, synthetic data)
python train.py --quick3. Full training on synthetic dataset (FER-2013 style)
python train.py4. Use real FER-2013 dataset
# Download via Kaggle CLI
kaggle datasets download -d msambare/fer2013 -p data --unzip
python train.py --fer2013 data/fer2013.csv5. Run inference
# 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 --webcam6. 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) โ SoftmaxParameters: ~1.2 million Framework: Pure NumPy (no TF/PyTorch)
๐ Dataset: FER-2013
Images: 48ร48 grayscale Source: Kaggle โ msambare/fer2013
๐ Expected Performance (Real FER-2013)
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 initialisationBatchNormโ channel-wise batch normalisationMaxPool2x2โ 2ร2 max pooling with correct backpropDropoutโ inverted dropoutDenseโ fully-connected layerSoftmaxโ 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
