2018-04-09 03:15:24 +00:00
|
|
|
import torch
|
2017-08-19 08:59:51 +00:00
|
|
|
import torch.nn.functional as F
|
2017-11-30 06:44:34 +00:00
|
|
|
|
2018-06-08 17:27:32 +00:00
|
|
|
from dice_loss import dice_coeff
|
2017-08-19 08:59:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def eval_net(net, dataset, gpu=False):
|
2018-06-08 17:27:32 +00:00
|
|
|
"""Evaluation without the densecrf with the dice coefficient"""
|
2018-09-26 06:57:10 +00:00
|
|
|
net.eval()
|
2017-08-19 08:59:51 +00:00
|
|
|
tot = 0
|
|
|
|
for i, b in enumerate(dataset):
|
2018-06-08 17:27:32 +00:00
|
|
|
img = b[0]
|
|
|
|
true_mask = b[1]
|
2017-08-19 08:59:51 +00:00
|
|
|
|
2018-06-08 17:27:32 +00:00
|
|
|
img = torch.from_numpy(img).unsqueeze(0)
|
|
|
|
true_mask = torch.from_numpy(true_mask).unsqueeze(0)
|
2017-08-19 08:59:51 +00:00
|
|
|
|
|
|
|
if gpu:
|
2018-06-08 17:27:32 +00:00
|
|
|
img = img.cuda()
|
|
|
|
true_mask = true_mask.cuda()
|
2017-08-19 08:59:51 +00:00
|
|
|
|
2018-06-08 17:27:32 +00:00
|
|
|
mask_pred = net(img)[0]
|
2018-11-10 22:42:16 +00:00
|
|
|
mask_pred = (mask_pred > 0.5).float()
|
2017-08-19 08:59:51 +00:00
|
|
|
|
2018-06-08 17:27:32 +00:00
|
|
|
tot += dice_coeff(mask_pred, true_mask).item()
|
2017-08-19 08:59:51 +00:00
|
|
|
return tot / i
|