Downloads · 30 days
7
3% of all-time downloads
Abhaykoul/emo-face-rec
emo-face-rec is a machine learning model from Abhaykoul. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Downloads · 30 days
7
3% of all-time downloads
All-time downloads
265
Public
Parameters
85.8M
343 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors343 MB · 100%
From the Hugging Face model README
from PIL import Image
from transformers import AutoImageProcessor, AutoModelForImageClassification
import torch
from rich import print
image_path = "./OIP.jpeg"
image = Image.open(image_path)
model_name = "Abhaykoul/emo-face-rec"
processor = AutoImageProcessor.from_pretrained(model_name)
model = AutoModelForImageClassification.from_pretrained(model_name)
inputs = processor(images=image, return_tensors="pt")
# Make a prediction
with torch.no_grad():
outputs = model(**inputs)
predicted_class_id = outputs.logits.argmax(-1).item()
predicted_emotion = model.config.id2label[predicted_class_id]
confidence_scores = torch.nn.functional.softmax(outputs.logits, dim=-1)
scores = {model.config.id2label[i]: score.item() for i, score in enumerate(confidence_scores[0])}
# Print the results
print(f"Predicted emotion: {predicted_emotion}")
print("\nConfidence scores for all emotions:")
for emotion, score in scores.items():
print(f"{emotion}: {score:.4f}")