I still faced problem with the F.cross_entropy function. My target/label can be 0 or 1. The shapes should be correct, but I don’t know why the target cannot be 1 when I run the F.cross_entropy function. Any hints to me?
input =  torch.tensor([[-127050.7500],
[ 214151.2344],
[ 282199.3125],
[ 291863.4375],
[ 256611.0469],
[ 275604.2188],
[ 429206.9688],
[ -35253.5273],
[ 167581.2969],
[ -27991.6875],
[ -49363.4688],
[ -39173.5508],
[ -42769.9766],
[ -71630.0938],
[ 288389.4375],
[ -99099.6641]])
target = torch.tensor([0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=torch.int64)
loss = F.cross_entropy(input, target)
loss
IndexError                                Traceback (most recent call last)
<ipython-input-79-a109ce392e4a> in <module>
     19 #input = torch.randn(3, 5, requires_grad=True)
     20 target = torch.tensor([0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=torch.int64)
---> 21 loss = F.cross_entropy(input, target)
     22 loss

/opt/conda/lib/python3.7/site-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
   2315     if size_average is not None or reduce is not None:
   2316         reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 2317     return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
   2318 
   2319 

/opt/conda/lib/python3.7/site-packages/torch/nn/functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
   2113                          .format(input.size(0), target.size(0)))
   2114     if dim == 2:
-> 2115         ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
   2116     elif dim == 4:
   2117         ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignore_index)

IndexError: Target 1 is out of bounds.