Abhaykoul commited on
Commit
bea65b2
1 Parent(s): c7b23e5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -0
README.md ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ ```python
5
+ from PIL import Image
6
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
7
+ import torch
8
+ from rich import print
9
+
10
+ image_path = "./OIP.jpeg"
11
+
12
+ image = Image.open(image_path)
13
+
14
+ model_name = "Abhaykoul/emo-face-rec"
15
+ processor = AutoImageProcessor.from_pretrained(model_name)
16
+ model = AutoModelForImageClassification.from_pretrained(model_name)
17
+
18
+
19
+ inputs = processor(images=image, return_tensors="pt")
20
+
21
+ # Make a prediction
22
+ with torch.no_grad():
23
+ outputs = model(**inputs)
24
+
25
+
26
+ predicted_class_id = outputs.logits.argmax(-1).item()
27
+ predicted_emotion = model.config.id2label[predicted_class_id]
28
+
29
+
30
+ confidence_scores = torch.nn.functional.softmax(outputs.logits, dim=-1)
31
+ scores = {model.config.id2label[i]: score.item() for i, score in enumerate(confidence_scores[0])}
32
+
33
+ # Print the results
34
+ print(f"Predicted emotion: {predicted_emotion}")
35
+ print("\nConfidence scores for all emotions:")
36
+ for emotion, score in scores.items():
37
+ print(f"{emotion}: {score:.4f}")
38
+
39
+ ```