RuntimeError Traceback (most recent call last)
Cell In[36], line 42
41 # Compute the loss
—> 42 loss = loss_function(outputs[0], labels)
44 train_loss += loss.item()
RuntimeError: The size of tensor a (85) must match the size of tensor b (5) at non-singleton dimension 4
I guess the number of classes in the model is different from the number of classes in the label tensor.
What could have led to this and how do I approach fixing this. Thank you
Here again (as in your previous question on this) it is a pretty clear error message, but interpreting it in a way that is “actionable” requires understanding how your data is structured. We have no visibility into that, but I hope you do. What are the shapes of those two tensors? What is the meaning of dimension 4 of those tensors? Obviously the function being called expects the tensors to have the same number of elements on that axis, but they don’t. So the first question is what I said in the previous sentence: what is the meaning of that axis? Then once you know that, it should be a pretty good clue as to why the two tensors do not agree on that axis and what you need to do to fix that.
Actually if your data is structured in the same way as in the YOLO assignment in DLS C4 W3, then maybe there is more we can read into that error. If I remember correctly in that assignment 85 is the number of classes and I think 5 was the number of anchor boxes. So maybe there is some problem in how you are creating those tensors, meaning you are comparing apples and oranges.
Appears to me this question has nothing to do with the course assignment. V5 is from Ultralytics. Not everyone loves their use of the YOLO name or their version numbering.
It might help the community help you if make it explicit that you’re using PyTorch and a totally different model architecture to solve a totally different problem and this isn’t actually a question about a deeplearning.ai assignment.