Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 6caa79f

Browse files
authored
Add files via upload
1 parent 3d3c96b commit 6caa79f

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""## Confusion Matrix"""
2+
3+
model_name = args.model_name
4+
PATH = '/content/drive/My Drive/resnet101_2_75.pth'
5+
checkpoint = torch.load(PATH)
6+
# classes = ('0','1')
7+
model = make_model(
8+
model_name,
9+
pretrained=True,
10+
num_classes=2,
11+
input_size= None,
12+
)
13+
14+
model.load_state_dict(checkpoint['state_dict'])
15+
16+
optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum= args.momentum)
17+
optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
18+
19+
class_correct = list(0. for i in range(2))
20+
class_total = list(0. for i in range(2))
21+
with torch.no_grad():
22+
for data in test_loader:
23+
images = data['image']
24+
labels = data['label']
25+
outputs = model(images)
26+
_, predicted = torch.max(outputs, 1)
27+
c = (predicted == labels).squeeze()
28+
for i in range(16):
29+
label = labels[i]
30+
class_correct[label] += c[i].item()
31+
class_total[label] += 1
32+
33+
34+
for i in range(2):
35+
print('Accuracy of %5s : %2d %%' % (
36+
i, 100 * class_correct[i] / class_total[i]))
37+
38+
39+
for i in range(2):
40+
print('Correct of %5s : %2d, Incorrect of %5s : %2d' % (
41+
i, class_correct[i], i, 200-class_correct[i]))

0 commit comments

Comments
 (0)