allantacuelwvsu commited on
Commit
69535bd
·
1 Parent(s): 483052e

added evaluations

Browse files
classification_report_matrix.png ADDED
confusion_matrix.png ADDED
data/models/expression_predictor_cnn.pth CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dbe74499e1659461a187bd820854520513fb94b2e9c094da7c2adf2915038d32
3
  size 1576685
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f5740fcfd8235c0acf7242a591c0991391a8cea8962d179e7e9680c02cd4c45
3
  size 1576685
evaluation.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torchvision import transforms
3
+ from torchvision.datasets import ImageFolder
4
+ from torch.utils.data import DataLoader
5
+ from sklearn.metrics import classification_report, confusion_matrix
6
+ import matplotlib.pyplot as plt
7
+ import seaborn as sns
8
+ import pandas as pd
9
+ from utils.model_loader import load_model
10
+
11
+ # ----- CONFIG -----
12
+ MODEL_PATH = 'data/models/expression_predictor_cnn.pth'
13
+ TEST_DIR = 'data/validation'
14
+ BATCH_SIZE = 32
15
+ CLASSES = ['Angry', 'Disgust', 'Scared', 'Happy', 'Neutral', 'Sad', 'Surprised']
16
+
17
+ # Load model
18
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
19
+ model = load_model(MODEL_PATH, device)
20
+
21
+ # Transforms
22
+ transform = transforms.Compose([
23
+ transforms.Grayscale(),
24
+ transforms.Resize((48, 48)),
25
+ transforms.ToTensor(),
26
+ transforms.Normalize((0.5,), (0.5,))
27
+ ])
28
+
29
+ # Load test data
30
+ test_data = ImageFolder(TEST_DIR, transform=transform)
31
+ test_loader = DataLoader(test_data, batch_size=BATCH_SIZE, shuffle=False)
32
+
33
+ # Predict
34
+ all_preds = []
35
+ all_labels = []
36
+ with torch.no_grad():
37
+ for images, labels in test_loader:
38
+ images = images.to(device)
39
+ outputs = model(images)
40
+ _, preds = torch.max(outputs, 1)
41
+ all_preds.extend(preds.cpu().numpy())
42
+ all_labels.extend(labels.numpy())
43
+
44
+ # Classification report
45
+ report = classification_report(all_labels, all_preds, target_names=CLASSES, output_dict=True)
46
+ report_df = pd.DataFrame(report).transpose()
47
+ print("\nClassification Report:")
48
+ print(report_df)
49
+
50
+ # Confusion Matrix
51
+ cm = confusion_matrix(all_labels, all_preds)
52
+ plt.figure(figsize=(10, 8))
53
+ sns.heatmap(cm, annot=True, fmt='d', xticklabels=CLASSES, yticklabels=CLASSES, cmap="Blues")
54
+ plt.xlabel("Predicted")
55
+ plt.ylabel("True")
56
+ plt.title("Confusion Matrix")
57
+ plt.tight_layout()
58
+ plt.savefig("confusion_matrix.png")
59
+ print("\n✅ Saved confusion matrix as 'confusion_matrix.png'")
60
+
61
+ # Save classification report heatmap (Precision, Recall, F1, Support)
62
+ plt.figure(figsize=(12, 6))
63
+ sns.heatmap(report_df.iloc[:-1, :-1], annot=True, fmt=".2f", cmap="YlGnBu")
64
+ plt.title("Classification Report (Precision, Recall, F1-score, Support)")
65
+ plt.tight_layout()
66
+ plt.savefig("classification_report_matrix.png")
67
+ print("✅ Saved classification_report_matrix.png")
src/streamlit_app.py CHANGED
@@ -13,6 +13,7 @@ from utils.model_loader import load_model
13
 
14
 
15
  st.title("Facial Expression Recognition")
 
16
 
17
  # Load model
18
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
13
 
14
 
15
  st.title("Facial Expression Recognition")
16
+ st.caption("dataset: https://www.kaggle.com/datasets/jonathanoheix/face-expression-recognition-dataset")
17
 
18
  # Load model
19
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
training_loss_plot.png CHANGED
utils/train.py CHANGED
@@ -8,7 +8,7 @@ from PIL import ImageFile
8
 
9
  # Configuration
10
  BATCH_SIZE = 64
11
- EPOCHS = 10
12
  IMG_SIZE = 48
13
  MODEL_PATH = "data/models/expression_predictor_cnn.pth"
14
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
8
 
9
  # Configuration
10
  BATCH_SIZE = 64
11
+ EPOCHS = 100
12
  IMG_SIZE = 48
13
  MODEL_PATH = "data/models/expression_predictor_cnn.pth"
14
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")