forked from milesial/Pytorch-UNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.py
More file actions
26 lines (19 loc) · 658 Bytes
/
eval.py
File metadata and controls
26 lines (19 loc) · 658 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
import torch
import torch.nn.functional as F
from dice_loss import dice_coeff
def eval_net(net, dataset, gpu=False):
"""Evaluation without the densecrf with the dice coefficient"""
net.eval()
tot = 0
for i, b in enumerate(dataset):
img = b[0]
true_mask = b[1]
img = torch.from_numpy(img).unsqueeze(0)
true_mask = torch.from_numpy(true_mask).unsqueeze(0)
if gpu:
img = img.cuda()
true_mask = true_mask.cuda()
mask_pred = net(img)[0]
mask_pred = (F.sigmoid(mask_pred) > 0.5).float()
tot += dice_coeff(mask_pred, true_mask).item()
return tot / i