Closed Sanaxen closed 5 years ago
if (!o.requires_grad()) o.set_requires_grad(true);
OK?
ex) inline torch::Tensor safe_log(torch::Tensor x) { torch::Tensor y = log(abs(x) + 1.0e-12); return y; }
torch::Tensor BCEWithLogitsLoss(torch::Tensor o, torch::Tensor t)
{
//Specify the target of automatic differentiation with True
if (!o.requires_grad()) o.set_requires_grad(true);
//o.options().requires_grad(true);
torch::Tensor y = -(t*safe_log(torch::sigmoid(o)) + (1 - t)*safe_log(1 - torch::sigmoid(o))).mean();
return y;
}
BCEWithLogitsLoss ?
How can I define the loss function? Please tell me if you know.