Downloads · 30 days
8
1% of all-time downloads
sreenathsree1578/facial_emotion
facial_emotion is a machine learning model from sreenathsree1578. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A lightweight convolutional neural network (CNN) for facial emotion recognition. The model is trained to classify grayscale facial images into 7 emotion categories.
Downloads · 30 days
8
1% of all-time downloads
All-time downloads
579
Public
Parameters
1.3M
5.1 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors5.1 MB · 100%
From the Hugging Face model README
A lightweight convolutional neural network (CNN) for facial emotion recognition.
The model is trained to classify grayscale facial images into 7 emotion categories.
from huggingface_hub import hf_hub_download
import torch
import json
from facial_emotion import SimpleCNN # your model class
# Load config
config = json.load(open("config.json"))
# Build model
model = SimpleCNN(num_classes=config["num_classes"], in_channels=config["in_channels"])
# Load weights
checkpoint = hf_hub_download(repo_id="sreenathsree1578/facial_emotion", filename="pytorch_model.bin")
model.load_state_dict(torch.load(checkpoint, map_location="cpu"))
model.eval()
# Example inference
dummy = torch.randn(1, 1, 48, 48) # dummy grayscale image
with torch.no_grad():
out = model(dummy)
pred = torch.argmax(out, dim=1).item()
print("Predicted emotion:", config["labels"][str(pred)])