Created
January 16, 2020 17:02
-
-
Save uzl/b7b53f274648fd9d7c975f73d2d9f33c to your computer and use it in GitHub Desktop.
BCELoss Testing with custom input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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