The code that generated the error:
import torch
yolo_ = torch.hub.load('ultralytics/yolov5', 'yolov5x', pretrained=True, force_reload=True)
yolo_(torch.rand((2,3,1280,720)))
The error:
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 46 but got size 45 for tensor number 1 in the list.
%debug shows:
~/.cache/torch/hub/ultralytics_yolov5_master/models/common.py in forward(self, x)
310
311 def forward(self, x):
--> 312 return torch.cat(x, self.d)
This issue was raised while trying to integrate yolo in a larger classifier. I narrow it down to the code above. As far as I can tell, this error is within the model. I tried different input shapes but get the same result. I also tried yolo5s, same deal. Here is the yolo github code where the error originates from. yolov5/common.py at master ยท ultralytics/yolov5 ยท GitHub
The concatenation is done on a list x
of 2 tensors:
x[0].shape=
torch.Size([2, 640, 80, 46])
x[1].shape=
torch.Size([2, 640, 80, 45])
The problem is not there is I pass a numpy array of various different shapes for instance:
yolo_(torch.rand((1280,720,3,2)).numpy())
works.
However, The input has to be a torch tensor still as the torch dataloader presents tensors to the model during training and not numpy arrays. Any help is greatly appreciated.