Error with trained YOLOv5 model from latest version
I am getting this error:
RuntimeError: The size of tensor a (80) must match the size of tensor b (84) at non-singleton dimension 3
I am not sure, whether this is due to the latest version or not, but that's what I think. Because similar issues are there in Roboflow Zero-Shot-tracking. So kindly help me with this. Thanks
Can you show me the detail error? like line number? where did the error occur?
Yes sure. Thanks for getting back to me.
Traceback (most recent call last):
File "track.py", line 144, in <module>
output = tracking.predict(frame.numpy())
File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "track.py", line 89, in predict
pred = self.model(img)[0]
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "yolov5/models/yolo.py", line 123, in forward
return self.forward_once(x, profile, visualize) # single-scale inference, train
File "yolov5/models/yolo.py", line 155, in forward_once
x = m(x) # run
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "yolov5/models/yolo.py", line 64, in forward
y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
RuntimeError: The size of tensor a (80) must match the size of tensor b (84) at non-singleton dimension 3
Also I used following command:
!python track.py --source $VIDEO_PATH --yolo-model /content/drive/MyDrive/ClientsWork/YepiWork/Fall\ Zone\ Detection\ Work/ModelsDir/15April_yolov5_large_640_24_500_coco_0.807.pt --reid-model CLIP-RN50
And it is taking too much RAM, around 20 GB, I think. Is this normal?
The above error is not related with tracking part. Are you sure you can run the model fine with detection code alone in latest yolov5 code? If you can run fine, you need to clone the new version and change the yolov5 model loading part in track.py. They might update it. So, I am not sure if it is the same.
If you inference on video and the video is taking too long, the RAM usage will be high. Because the processed frame will be accumulated until the video's end to be able to write the output video with torchvision.io. You can also change the video reading and writing function. I chose the torchvision as it is easier to read and no need to install other tool just for read/write function.
But I have done the detections with YOLOv5, they is no problem with that.
I found that the latest version of YOLO is not compatible with this project and you should download the YOLO weights from here "https://github.com/ultralytics/yolov5/releases/tag/v5.0" for example you can use this link "https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5l.pt"
I forgot to include the version of the yolo model. At the time of my testing, there is only v4.0. So, you can use v4 weights or just edit the code in track.py to be compatible with v5.
@BarRozenman works fine with weights from https://github.com/ultralytics/yolov5/releases/tag/v4.0