Views
No views yet
(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 surprise1from huggingface_hub import hf_hub_download
2from tensorflow.keras.models import load_model
3import numpy as np
4
5model_path = hf_hub_download(
6 repo_id="lokeshkumar79/facial-emotion-recognition",
7 filename="finalfacialemotionmodel.keras",
8)
9model = load_model(model_path)
10
11EMOTION_LABELS = {0: "angry", 1: "disgust", 2: "fear", 3: "happy",
12 4: "neutral", 5: "sad", 6: "surprise"}
13
14# face: a (48, 48) grayscale numpy array, cropped to just the face
15face = face.reshape(1, 48, 48, 1) / 255.0
16pred = model.predict(face)
17label = EMOTION_LABELS[int(np.argmax(pred))]disgust is underrepresented). Expect lower accuracy
on disgust and fear, and degraded performance on faces/lighting/angles
not well represented in the dataset.