mirror of
https://github.com/Laurent2916/REVA-QCAV.git
synced 2024-11-09 15:02:03 +00:00
b1ac7151b4
Former-commit-id: 3ab827241455818c7b81172a426d805f9ace0f8f
27 lines
658 B
Python
27 lines
658 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 = (F.sigmoid(mask_pred) > 0.5).float()
|
|
|
|
tot += dice_coeff(mask_pred, true_mask).item()
|
|
return tot / i
|