-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate_test_data.py
66 lines (55 loc) · 2.98 KB
/
evaluate_test_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import torch
from torch.utils.data import DataLoader
import matplotlib.pyplot as plt
from model import landmarks_angles_detector
from load_data import Dataset_lip
a, b = 50, 35
class Evaluate():
def __init__(self, data):
self.data = data
def show_test_results(self):
model = landmarks_angles_detector(16, 16, previous_model=False)
model.load_state_dict(torch.load("model.pt"))
for index, (images, labels) in enumerate(self.data, start=1): # Start enumerate from index 1
image = images[0] # Assuming you have only one image in each batch
labels = labels[0, :-1] *112 # Assuming you have only one image in each batch
image = image.permute(1, 2, 0)
pred = model(torch.unsqueeze(images[0] / 255, 0))
pred = pred.squeeze()*112
# plt.subplot(4, 4, index) # Update the subplot index
plt.figure(figsize=(20, 20))
# plt.axis('off')
# if index in [3, 6, 9, 12]:
# plt.subplots_adjust(hspace=0.5) # Increase vertical spacing between subplots
if index < 5 * a :
plt.imshow(image)
# Plot labels (nose and cheek) in green
plt.plot(labels[1], labels[0], marker="o", color='green', markersize=b) # Nose point
plt.plot(labels[3], labels[2], marker="o", color='green', markersize=b) # Cheek point
# Plot predictions in red
plt.plot(pred[1].item(), pred[0].item(), marker="o", color='red', markersize=b) # Predicted nose point
plt.plot(pred[3].item(), pred[2].item(), marker="o", color='red', markersize=b) # Predicted cheek point
plt.grid(True, color='k',linewidth=0.9)
plt.savefig(f"save/grid/b_{index}.png")
elif index <10 * a:
plt.imshow(image)
# Plot labels (nose and cheek) in green
plt.plot(labels[1], labels[0], marker="o", color='green', markersize=b) # Nose point
plt.plot(labels[3], labels[2], marker="o", color='green', markersize=b) # Cheek point
# Plot predictions in red
plt.plot(pred[1].item(), pred[0].item(), marker="o", color='red', markersize=b) # Predicted nose point
plt.plot(pred[3].item(), pred[2].item(), marker="o", color='red', markersize=b) # Predicted cheek point
plt.savefig(f"save/gtvspred/b_{index-50}.png")
elif index >10 * a:
plt.imshow(image[int(pred[0].item()):int(pred[2].item()), :, :])
plt.axis('off')
plt.savefig(f"save/lip/b_{index-100}.png")
if index == 15*a:
break
plt.close()
if __name__ == "__main__":
test_dataset = Dataset_lip("Train_Images_f_8.csv",
"train_data-Copy-Copy")
test_loader = DataLoader(test_dataset, 1, True, drop_last=True)
eval = Evaluate(test_loader)
eval.show_test_results()