Skip to content

Commit 6359c1e

Browse files
authored
Merge pull request #7 from AdeelH/AdeelH-patch-1
Ensure forward() always returns a tensor
2 parents f15f440 + 00c99ad commit 6359c1e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

focal_loss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def forward(self, x: Tensor, y: Tensor) -> Tensor:
6666
unignored_mask = y != self.ignore_index
6767
y = y[unignored_mask]
6868
if len(y) == 0:
69-
return 0.
69+
return torch.tensor(0.)
7070
x = x[unignored_mask]
7171

7272
# compute weighted cross entropy term: -alpha * log(pt)

0 commit comments

Comments
 (0)