-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccurancy.py
46 lines (34 loc) · 1.1 KB
/
Accurancy.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
from tqdm.notebook import tqdm
import torch
### Test accuracy when using both modalities, rgb and depth
def test_acc_rgbd(net, test, DEVICE):
net.train(False)
running_corrects_label = 0
contatore = 0
for rgb, depth, labels in tqdm(test):
rgb = rgb.to(DEVICE)
depth = depth.to(DEVICE)
labels = labels.to(DEVICE)
lab = net(rgb, depth)
_, preds = torch.max(lab.data, 1)
running_corrects_label += torch.sum(preds == labels.data).data.item()
val = running_corrects_label / float(len(test.dataset))
print(val)
return val
### Test accuracy when using a single modality (RGB or depth)
def test_acc(net, test, DEVICE, tipo = "rgb"):
net.train(False)
running_corrects_label = 0
contatore = 0
for rgb, depth, labels in tqdm(test):
if tipo == "rgb":
img = rgb.to(DEVICE)
else:
img = depth.to(DEVICE)
labels = labels.to(DEVICE)
lab = net(img)
_, preds = torch.max(lab.data, 1)
running_corrects_label += torch.sum(preds == labels.data).data.item()
val = running_corrects_label / float(len(test.dataset))
print(val)
return val