Downloads · 30 days
87
44% of all-time downloads
lokeshkumar79/facial-emotion-recognition
facial-emotion-recognition is a image classification model from lokeshkumar79. Use it when you need a label for an image. It is set up for keras. The card lists the license as mit.
A convolutional neural network trained on the FER-2013 dataset to classify grayscale 48x48 face crops into 7 emotions.
Downloads · 30 days
87
44% of all-time downloads
All-time downloads
196
Public
Repo size
44.3 MB
Likes
0
Public
Click a slice to open those files.
.keras44.3 MB · 100%
From the Hugging Face model README
A convolutional neural network trained on the FER-2013 dataset to classify grayscale 48x48 face crops into 7 emotions.
(48, 48, 1), pixel values normalized to [0, 1]finalfacialemotionmodel.keras (the recommended, verified-working model from the source repo)0 angry
1 disgust
2 fear
3 happy
4 neutral
5 sad
6 surprise
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.
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).
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.