-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (25 loc) · 747 Bytes
/
test.py
File metadata and controls
31 lines (25 loc) · 747 Bytes
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
import matplotlib.pyplot as plt
import torch as T
from data import load
from checkpoints import load_checkpoint, save_checkpoint
def test(model, imgs):
"""
Show model's predictions
"""
for i in range(imgs.size(0)):
pred = model.forward(imgs[i:i+1])
pred_label = int(T.argmax(pred))
plt.imshow(imgs[i][..., 0], cmap='gray')
plt.title('Prediction=' + str(pred_label))
plt.draw()
try:
plt.waitforbuttonpress()
except:
break
if __name__ == "__main__":
"""
Load trained model and show predictions
"""
model, _, _ = load_checkpoint('checkpoints/CapsEncoder_mnist.pth')
imgs, _ = load('test', num_samples=500)
test(model, imgs)