Skip to content

Instantly share code, notes, and snippets.

@uzl
Created January 16, 2020 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uzl/b7b53f274648fd9d7c975f73d2d9f33c to your computer and use it in GitHub Desktop.
Save uzl/b7b53f274648fd9d7c975f73d2d9f33c to your computer and use it in GitHub Desktop.
BCELoss Testing with custom input
import torch
y_pred = torch.tensor([
[1, 1, 0, 1, 1, 1]
], dtype=torch.float)
y_truth_id = torch.tensor([2], dtype=torch.long)
y_truth_id_tmp = y_truth_id.unsqueeze(0)
y_truth_one_hot = torch.zeros(y_truth_id_tmp.size(0), 6).scatter_(1, y_truth_id_tmp, 1.)
criterion_2 = torch.nn.BCELoss()
res_2 = criterion_2(y_pred, y_truth_one_hot)
print('BCELoss: ', res_2)
# output: BCELoss: tensor(27.6310)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment