REVA-QCAV/eval.py
rht 81234be7da Move the sigmoid activation to the model itself
Former-commit-id: e3f8ca7b1ac7c5e9694637a81be260e9b48973b9
2018-11-10 23:11:52 +00:00

27 lines
647 B
Python

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 = (mask_pred > 0.5).float()
tot += dice_coeff(mask_pred, true_mask).item()
return tot / i