Hi there, love this project! I'm having some trouble using the exported models - but can't tell how to solve this.
I have trained a model with the resultant model in the root of the repo called "v3seaDrone.pt" (with an image size of 1920). this works fine with my test image "3.jpg" when called either with the python detect.py script or through the torch.hub.load method. I have exported this model to onnx and torchscript with the command:
model = torch.hub.load(".", "custom", path="v3seaDrone.onnx", source='local')
results = model("3.jpg", size=1920)
results.print()
I get the following error (I have installed onnx):
Loading v3seaDrone.onnx for ONNX Runtime inference...
Adding AutoShape...
Traceback (most recent call last):
File "F:\ml\yolov5\detect_and_notify.py", line 21, in <module>
results = model(img, size=1920)
File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "F:\ml\yolov5\.\models\common.py", line 704, in forward
y = self.model(x, augment=augment) # forward
File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "F:\ml\yolov5\.\models\common.py", line 523, in forward
y = self.session.run(self.output_names, {self.session.get_inputs()[0].name: im})
File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 200, in run
return self._sess.run(output_names, input_feed, run_options)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: images for the following indices
index: 2 Got: 1472 Expected: 1920
Please fix either the inputs or the model.
and with the torchscript version I get:
RuntimeError: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript, serialized code (most recent call last):
File "code/__torch__/models/yolo.py", line 101, in forward
_51 = (_31).forward((_30).forward(act, _50, ), _40, )
_52 = (_33).forward(_46, _48, _50, (_32).forward(_51, ), )
~~~~~~~~~~~~ <--- HERE
return (_52,)
class Detect(Module):
File "code/__torch__/models/yolo.py", line 134, in forward
_25 = torch.split_with_sizes(torch.sigmoid(_24), [2, 2, 7], 4)
xy, wh, conf, = _25
_26 = torch.add(torch.mul(xy, CONSTANTS.c0), CONSTANTS.c1)
~~~~~~~~~ <--- HERE
xy0 = torch.mul(_26, torch.select(CONSTANTS.c2, 0, 0))
_27 = torch.pow(torch.mul(wh, CONSTANTS.c0), 2)
RuntimeError: The size of tensor a (184) must match the size of tensor b (240) at non-singleton dimension 2
Any ideas about what I might be doing wrong or how to fix this?
Additional
No response
👋 Hello @tlong123, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.
If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.
If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.
Requirements
Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:
git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
Environments
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
Notebooks with free GPU:
Google Cloud Deep Learning VM. See GCP Quickstart Guide
Amazon Deep Learning AMI. See AWS Quickstart Guide
Docker Image. See Docker Quickstart Guide
Status
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
Introducing YOLOv8 🚀
We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!
Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.
Check out our YOLOv8 Docs for details and get started with: