Edit model card
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}")
Downloads last month
20
Safetensors
Model size
85.8M params
Tensor type
F32
·
Inference API
Unable to determine this model's library. Check the docs .