Skip to content

Commit b03444a

Browse files
author
gas
committed
epsilon in loss has been changed
1 parent e392728 commit b03444a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/test/
2-
/models/
2+
/models/
3+
.vscode
4+

Diff for: utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ def load_checkpoint(checkpoint_path, model, optimizer, cpu):
166166
print('model loaded from %s' % checkpoint_path)
167167

168168
def jaccard(intersection, union, eps=1e-15):
169-
return (intersection + eps) / (union - intersection + eps)
169+
return (intersection) / (union - intersection + eps)
170170

171171
def dice(intersection, union, eps=1e-15):
172-
return (2. * intersection + eps) / (union + eps)
172+
return (2. * intersection) / (union + eps)
173173

174174
class BCESoftJaccardDice:
175175

176-
def __init__(self, bce_weight=0.5, mode="dice", eps=1e-15, weight=None):
176+
def __init__(self, bce_weight=0.5, mode="dice", eps=1e-7, weight=None):
177177
self.nll_loss = torch.nn.BCEWithLogitsLoss(weight=weight)
178178
self.bce_weight = bce_weight
179179
self.eps = eps
@@ -457,7 +457,7 @@ def fit(self, dataset, dataset_val, **kwargs):
457457
y_pred = nn.functional.interpolate(y_pred, scale_factor=2, mode='bilinear', align_corners=True)
458458

459459
loss_fn = BCESoftJaccardDice(bce_weight=bce_loss_weight,
460-
weight=mask_w.cuda(self.device_idx), mode="dice", eps=1.)
460+
weight=mask_w.cuda(self.device_idx), mode="dice")
461461
loss = loss_fn(y_pred, Variable(mask.cuda(self.device_idx)))
462462

463463
self.optimizer.zero_grad()

0 commit comments

Comments
 (0)