Skip to content

Commit

Permalink
fix: Fixed loss weight buffer (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm authored Jul 28, 2021
1 parent afae658 commit e1fed60
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions holocron/nn/modules/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ def __init__(
# Cast class weights if possible
self.weight: Optional[Tensor]
if isinstance(weight, (float, int)):
self.weight = torch.Tensor([weight, 1 - weight]) # type: ignore[assignment]
self.register_buffer('weight', torch.Tensor([weight, 1 - weight]))
elif isinstance(weight, list):
self.weight = torch.Tensor(weight) # type: ignore[assignment]
self.register_buffer('weight', torch.Tensor(weight))
elif isinstance(weight, Tensor):
self.register_buffer('weight', weight)
else:
self.weight = weight
self.weight = None
self.ignore_index = ignore_index
# Set the reduction method
if reduction not in ['none', 'mean', 'sum']:
Expand Down

0 comments on commit e1fed60

Please sign in to comment.