sroyyors
(Sushmita Roy)
1
Hi,
I was wondering how in C++ I can specify the weight parameter in the binary_cross_entropy function.
I am using something like
auto loss_classification = torch::nn::functional::binary_cross_entropy(output_class, target_class);
I tried using
auto loss_classification = torch::nn::functional::binary_cross_entropy(output_class, target_class, torch::nn::BCELossOptions().weight("0.7"));
as a third argument but it did not work.
sroyyors
(Sushmita Roy)
2
OK I was able to get this work using
torch::Tensor weight=torch::zeros(1);
weight.index_put_({0},0.7);
auto loss_classification = torch::nn::functional::binary_cross_entropy(output_class, target_class,torch::nn::functional::BinaryCrossEntropyFuncOptions().weight(weight));
felt like an overkill to make a tensor of 1 dimension, but this compiled and executed.