I am trying to rewrite following python sample to C++ (use of nll loss)
>>> # 2D loss example (used, for example, with image inputs)
>>> N, C = 5, 4
>>> loss = nn.NLLLoss()
>>> # input is of size N x C x height x width
>>> data = torch.randn(N, 16, 10, 10)
>>> conv = nn.Conv2d(16, C, (3, 3))
>>> m = nn.LogSoftmax(dim=1)
>>> # each element in target has to have 0 <= value < C
>>> target = torch.empty(N, 8, 8, dtype=torch.long).random_(0, C)
>>> output = loss(m(conv(data)), target)
>>> output.backward()
I have the following code
long long N = 5;
long long C = 4;
auto data = torch::randn({ N, 16, 10, 10 });
auto conv = torch::nn::Conv2d(torch::nn::Conv2dOptions(16, C, 3));
auto target = torch::empty({ N, 8, 8 }, torch::kLong).random_(0, C);
data = conv->forward(data);
data = torch::log_softmax(data, 1);
auto output = torch::nll_loss(data, target);
It crashes with error: multi-target not supported at …\aten\src\THNN/generic/ClassNLLCriterion.c:20
Any ideas ? Thanks