forked from goytomdesta/Defect_classification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
27 lines (21 loc) · 715 Bytes
/
test.py
File metadata and controls
27 lines (21 loc) · 715 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
import torch
import torch.nn as nn
import torch.optim as optim
from data import train_loader, test_loader, validset
from model import cl_model
import matplotlib.pyplot as plt
DEVICE = 'cuda'
PATH = "C:/Users/goytom/Desktop/m_vis/defect_detection_ResNet18.pth"
cl_model.load_state_dict(torch.load(PATH))
cl_model.eval()
correct = 0
total = 0
with torch.no_grad():
for images, labels in test_loader:
images, labels = images.to(DEVICE), labels.to(DEVICE)
outputs = cl_model(images)
_, predicted = torch.max(outputs.data, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
accuracy = correct / total
print(f'Test Accuracy: {100 * accuracy:.2f}%')