Facial Emotion Recognition (FER-2013 CNN)

A convolutional neural network trained on the FER-2013 dataset to classify grayscale 48x48 face crops into 7 emotions.

Model details

  • Architecture: CNN (Conv2D + MaxPooling blocks, Dropout, Dense, softmax output)
  • Input: grayscale image, shape (48, 48, 1), pixel values normalized to [0, 1]
  • Output: softmax over 7 classes
  • File: finalfacialemotionmodel.keras (the recommended, verified-working model from the source repo)

Class order (index -> label)

0 angry
1 disgust
2 fear
3 happy
4 neutral
5 sad
6 surprise

Usage

from huggingface_hub import hf_hub_download
from tensorflow.keras.models import load_model
import numpy as np

model_path = hf_hub_download(
    repo_id="lokeshkumar79/facial-emotion-recognition",
    filename="finalfacialemotionmodel.keras",
)
model = load_model(model_path)

EMOTION_LABELS = {0: "angry", 1: "disgust", 2: "fear", 3: "happy",
                  4: "neutral", 5: "sad", 6: "surprise"}

# face: a (48, 48) grayscale numpy array, cropped to just the face
face = face.reshape(1, 48, 48, 1) / 255.0
pred = model.predict(face)
label = EMOTION_LABELS[int(np.argmax(pred))]

Face detection (e.g. OpenCV Haar cascade) and cropping to the face region before resizing to 48x48 is expected as a preprocessing step โ€” this model only classifies emotion given an already-cropped face.

Training data

FER-2013 (Kaggle: https://www.kaggle.com/datasets/msambare/fer2013) โ€” 35,887 grayscale 48x48 images across 7 emotion classes (28,709 train / 3,589 validation / 3,589 test).

Limitations

FER-2013 is a noisy, crowd-labeled dataset with known label-quality issues and class imbalance (disgust is underrepresented). Expect lower accuracy on disgust and fear, and degraded performance on faces/lighting/angles not well represented in the dataset.

Downloads last month
17
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Space using lokeshkumar79/facial-emotion-recognition 1