Skip to content

Instantly share code, notes, and snippets.

@ciela
Created December 7, 2017 03:10
Show Gist options
  • Save ciela/46358d5636d319978b336e84894846b5 to your computer and use it in GitHub Desktop.
Save ciela/46358d5636d319978b336e84894846b5 to your computer and use it in GitHub Desktop.
Multi-label Classification 用のロス比較2(全て同じ結果にはなる)
import torch
from torch import nn as nn
from torch import autograd as ag
data = ag.Variable(torch.Tensor(torch.randn([100, 100])))
labels = ag.Variable(torch.Tensor(torch.randn([100, 100])))
multi_label_soft_margin = nn.MultiLabelSoftMarginLoss()
print(multi_label_soft_margin(data, labels))
bce_with_logits = nn.BCEWithLogitsLoss()
print(bce_with_logits(data, labels))
bce = nn.BCELoss()
sigmoid = nn.Sigmoid()
print(bce(sigmoid(data), labels))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment