I have a problem about calculating binary cross entropy. The way I know that works out in pytorch is:
import torch
import torch.nn as nn
import torch.nn.functional as F
def lossfunc():
return F.binary_cross_entropy
criterion = lossFunc()
input = torch.randn((3, 2), requires_grad=True)
target = torch.rand((3, 2), requires_grad=False)
loss = criterion(torch.sigmoid(input),target)
But how to complete the lossfunc() in such way, because I don't know how to pass the arguments to the function:
#the function that add sigmoid to input and calculate the binary cross entropy loss
def lossfunc():
return
criterion = lossFunc()
input = torch.randn((3, 2), requires_grad=True)
target = torch.rand((3, 2), requires_grad=False)
loss = criterion(input,target)