Last active
December 6, 2017 10:31
-
-
Save ciela/8e2c8ec628b73c9172de1ecf6fe05d7b to your computer and use it in GitHub Desktop.
pytorch で multi-labal classification に利用されそうなロスとその使い方
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
# MultiLabelSoftMarginLoss only | |
ml_criterion = nn.MultiLabelSoftMarginLoss() | |
## torch.randn | |
data, labels = Variable(torch.randn([1, 5])), Variable(torch.randn([1, 5])) | |
print(data.data, labels.data) | |
print(ml_criterion(data, labels)) | |
## fixed FloatTensor | |
data, labels = Variable(torch.FloatTensor([1, 50, 100, 50, 1])), Variable(torch.FloatTensor([0, 0, 1, 0, 0])) | |
print(data.data, labels.data) | |
print(ml_criterion(data, labels)) | |
# Sigmoid + BCELoss | |
ml_criterion = nn.BCELoss() | |
sigmoid = nn.Sigmoid() | |
data, labels = Variable(torch.FloatTensor([1, 50, 100, 50, 1])), Variable(torch.FloatTensor([0, 0, 1, 0, 0])) | |
print(data.data, labels.data) | |
print(ml_criterion(sigmoid(data), labels)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment