Fix evaluation

Former-commit-id: 2b649bc9a337818696291280cd87ad93a6fc5032
This commit is contained in:
milesial 2021-08-21 08:41:23 +02:00 committed by GitHub
parent 890719f4b7
commit 8c761f9d06

View file

@ -24,12 +24,12 @@ def evaluate(net, dataloader, device):
# convert to one-hot format
if net.n_classes == 1:
mask_pred = (F.sigmoid(mask_pred) > 0).float()
mask_pred = (F.sigmoid(mask_pred) > 0.5).float()
else:
mask_pred = F.one_hot(mask_pred.argmax(dim=1), net.n_classes).permute(0, 3, 1, 2).float()
# compute the Dice score, ignoring background
dice_score += multiclass_dice_coeff(mask_pred[:, :1, ...], mask_true[:, :1, ...], reduce_batch_first=False)
dice_score += multiclass_dice_coeff(mask_pred[:, 1:, ...], mask_true[:, 1:, ...], reduce_batch_first=False)
net.train()
return dice_score / num_val_batches