-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Closed
Description
nn.NLLLoss example does not work in current stable and master doc.
Reported in this thread.
The second example of nn.NLLLoss from the docs throws an error on creating the target tensor:
# 2D loss example (used, for example, with image inputs)
N, C = 5, 4
loss = nn.NLLLoss()
# input is of size N x C x height x width
data = torch.randn(N, 16, 10, 10)
m = nn.Conv2d(16, C, (3, 3))
# each element in target has to have 0 <= value < C
target = torch.tensor(N, 8, 8).random_(0, C)
> TypeError: tensor() takes 1 positional argument but 3 were given
output = loss(m(data), target)
output.backward()Tested under 0.4.0 and 0.5.0a0+e62c3a4.
The fix could be:
target = torch.empty(N, 8, 8, dtype=torch.long).random_(0, C)I'm creating a pull request to fix this issue.
Jeffalltogether
Metadata
Metadata
Assignees
Labels
No labels