Skip to content

Commit 00c99ad

Browse files
authored
ensure forward() always returns a tensor
1 parent f15f440 commit 00c99ad

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)