Fix eval.py iterating within batch

Former-commit-id: d4b8040593d4bc82774b1dac647c701b2486c477
This commit is contained in:
milesial 2019-12-02 12:06:29 +01:00 committed by GitHub
parent 48f45274b7
commit 5a7e934560

View file

@ -20,12 +20,12 @@ def eval_net(net, loader, device, n_val):
mask_pred = net(imgs)
for true_mask in true_masks:
mask_pred = (mask_pred > 0.5).float()
for true_mask, pred in zip(true_masks, mask_pred):
pred = (pred > 0.5).float()
if net.n_classes > 1:
tot += F.cross_entropy(mask_pred.unsqueeze(dim=0), true_mask.unsqueeze(dim=0)).item()
tot += F.cross_entropy(pred.unsqueeze(dim=0), true_mask.unsqueeze(dim=0)).item()
else:
tot += dice_coeff(mask_pred, true_mask.squeeze(dim=1)).item()
tot += dice_coeff(pred, true_mask.squeeze(dim=1)).item()
pbar.update(imgs.shape[0])
return tot / n_val