Skip to content

Instantly share code, notes, and snippets.

@InnovArul
Created December 28, 2020 08:01
Show Gist options
  • Save InnovArul/58bccf265adfaf8e0adfa71b6e554e43 to your computer and use it in GitHub Desktop.
Save InnovArul/58bccf265adfaf8e0adfa71b6e554e43 to your computer and use it in GitHub Desktop.
import torch
import torch.nn.functional as F
is_cuda = True
input = torch.randn(1, 19, 32, 64, requires_grad=True)
target = torch.randint(22, size=(1,32,64,))
print(input.dim())
print("number of out-of-bound targets", (target > 18).sum())
if is_cuda:
input = input.cuda()
target = target.cuda()
out = F.cross_entropy(input, target, weight=None, ignore_index=255, reduction='none')
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment