I’m running into: Predictions and targets are expected to have the same shape, but got torch.Size([1013, 100]) and torch.Size(). I am using class indices as the predictions of which there are 100 and the batch size is 1013. What am I missing? I’ve gotten this to work on other code and the example in PyTorch is very similar with targets as [5,3] and preds as .
The probable cause of your error is that your
target is a
when it should be a
CrossEntropyLoss supports both integer-class-index and floating-point
targets. The former is required to have shape
nClass dimension) and have values that run from
nClass - 1, while the latter is required to have shape
with values that run from
target is a
CrossEntropyLoss assumes that you
are using a probabilistic
target and requires it to have the same shape
as your predictions (the
Hi K. Frank,
Thanks for the reponse. I thought that same thing too, but after checking it in the debugger my prediction is HalfTensor and my target is LongTensor. I’m super confused. I went back and reran some old code that was fully functional solving a similar problem and the shapes agreed with what I’m doing now.
I ran through the debugger and it looks like it’s actually happening in my TorchMetrics accuracy function. I’ll dig in deep and get back to everyone.