-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
47 lines (30 loc) · 891 Bytes
/
test.py
File metadata and controls
47 lines (30 loc) · 891 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import torch
import torchvision
import torchvision.transforms as transforms
from models.model import NeuralNet
#Transforming the images to Tensors
transform = transforms.ToTensor()
#Loading the Dataset
test_dataset = torchvision.datasets.MNIST(
root = './data',
train = False,
transform = transform ,
)
test_loader = torch.utils.data.DataLoader(
dataset = test_dataset,
batch_size = 64,
shuffle = False,
)
#loading the model
model = NeuralNet()
model.load_state_dict(torch.load('model.pth'))
model.eval()
correct = 0
total = 0
with torch.no_grad():
for images , labels in test_loader:
outputs = model(images)
_, predicted = torch.max(outputs.data , 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
print(f"Accuracy of the model on the 10000 test images : {100 * correct / total} %")