-
Notifications
You must be signed in to change notification settings - Fork 364
Convert YoloV5 models #730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I had been able to fix that issue manually but I am still struggling with this error:
You can find the corresponding code in the YoloV5 repository. |
Hi @mfoglio , Seems that it's caused by a limitation of torchscript, you can handle this piece like I did with a similar change in another repository (I did some experiments to make YOLOv5's |
@zhiqwang following the notebooks in your repository I have been able to successfully create a torchscript model. However, when converting to TensorRT, I get the error:
Full code:
script 2
|
Hi @mfoglio I didn't test from yolort.models import yolov5s
from yolort.relaying import get_trace_module
input_shape = (640, 640)
model_func = yolov5s(pretrained=True)
trace_model = get_trace_module(model_func, input_shape=input_shape) # do the torch.jit.trace here |
Hello @zhiqwang I seem to have the same issue even tracing the model:
|
@zhiqwang , my bad, I had an error in the code. I am making progress with your suggestion. Now, I have a:
despite enabling |
Well, I am not sure what other settings could be used to convert the model. I feel like this could possibly be a bug, and in any case, the error is quite different from the one that I had at the beginning of this post. I opened a new thread here #731 (comment) to spare some times to the new readers. |
@mfoglio I wonder if any of your issues are due to the fact that you're trying to export the AutoShape() wrapper with a YOLOv5 model inside it. The default YOLOv5 export code works with TorchScript without issue. This is a YOLOv5 export by itself, we don't try to export AutoShape() wrapped models. |
@glenn-jocher let me try |
I have tried to convert yolov5 from the original ts export a few days ago, but without any luck :/ |
If we export the model with:
and then run:
The conversion works. Note that I am converting
I get the error:
|
If I try to converted the torch script model in its entirety:
I get the error:
|
@mfoglio This will not solve your exact problem, but if your goal is to have a TRT version of yolo, you can try this repo: https://github.com/alxmamaev/jetson_yolov5_tensorrt . It uses onnx and trtexec to create the trt engine. Works fine |
@mfoglio Did you end up succeeding eventually? I am trying to load a YOLOv5-torchscript module into libtorch-tensorrt right now and also failing. Example error messages:
|
This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days |
If you insist on using TRT Backend to accelerate inference speed, I suggest you to convert this model to Tensorflow format and then convert to tensorrt. I failed to convert from torchscript to tensorrt too. Maybe there is some mismatches in floating point between torchscript and tensorrt which generates this error |
This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days |
This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days |
Uh oh!
There was an error while loading. Please reload this page.
It is my understanding that the new stable release should be able to convert any PyTorch model with fallback to PyTorch when operations cannot be directly converted to TensorRT. I am trying to convert
I am trying to convert YoloV5s6 to TensorRT using the code that you can find below. I believe that it would be great to be able to convert this particular model given its popularity.
During the conversion I am encountering some errors. Is this because the model cannot be converted to TorchScript? I also noticed that the model is composed of classes which extends
nn.Module
.Of course, YoloV5 code can be found here: https://github.com/ultralytics/yolov5
Thank you!
To Reproduce
Output:
Expected behavior
The model gets converted.
Environment
conda
,pip
,libtorch
, source): pipEDIT: I am going to try to update yolov5 code to remove the
warnings
that seem to cause the issue, but it would be nice if this wasn't necessary. Let me know if you have suggestions on how to proceed.The text was updated successfully, but these errors were encountered: