I am training yolov5 with custom data, i’m at beginner level with machine learning, however, I have a persistent error with which I am stuck. Some help would be greatly appareciated:
RuntimeError Traceback (most recent call last)
Cell In, line 46
44 # Stack the padded tensors only if they have the same size
45 if len(padded_boxes) > 0:
—> 46 pred_boxes = torch.stack(padded_boxes, dim=0) # Stack the padded tensors
49 # Flatten and pad the predicted and target bounding boxes
RuntimeError: stack expects each tensor to be equal size, but got [3, 32, 32, 32] at entry 0 and [3, 16, 32, 32] at entry 1
It looks like you are using PyTorch and trying to “stack” two tensors along the “samples” axis. But the problem is that will only work if the other dimensions of the two tensors match. But they don’t: they aren’t both the same shape in the height, width and channel dimensions. So you need to understand if that is just a mistake in terms of the format of the two tensors or whether the problem is that you needed more logic to pad one of them to match the shape of the larger one.
Or perhaps I have the dimensions wrong and you’re using “Channels First” mode so maybe what you really wanted was to do the “stack” operation on axis = 1 in order to stack on the channels dimension.
But the high level point is that it’s always important to understand the structure and meaning of your input data even before you start writing the actual algorithms to handle that data.
The other general comment here is that the first rule of debugging is “Believe the error message”. Sometimes the messages can be a bit cryptic and that means you need to invest the effort to see what it is really trying to say. But I think the message is about as clear as one could hope for in this case.
Thank you very much. Moving forward with this in mind.
Thank you very much, I applied the approach to better understand the problem and fixed this issue.