Skip to content
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

Still unable to detect with TorchScript model #5161

Closed
iumyx2612 opened this issue Oct 13, 2021 · 4 comments
Closed

Still unable to detect with TorchScript model #5161

iumyx2612 opened this issue Oct 13, 2021 · 4 comments
Labels
bug Something isn't working Stale

Comments

@iumyx2612
Copy link
Contributor

Before submitting a bug report, please be aware that your issue must be reproducible with all of the following,
otherwise it is non-actionable, and we can not help you:

  • Current repo: run git fetch && git status -uno to check and git pull to update repo
    On branch master
    Your branch is up to date with 'origin/master'.
  • Common dataset: coco128.yaml
  • Common environment:My PC

If this is a custom dataset/training question you must include your train*.jpg, val*.jpg and results.png
figures, or we can not help you. You can generate these with utils.plot_results().

🐛 Bug

Cannot run inference with TorchScript model

To Reproduce (REQUIRED)

I export your pretrained yolov5s.pt to yolov5s.torchscript.pt using export.py
python3 export.py --weights="yolov5/weights/yolov5s.pt" --device=0 --optimize --include=torchscript
Then I run inference with yolov5s.torchscript.pt using detect.py
python3 detect.py --weights="yolov5/weights/yolov5s.torchscript.pt" --source="Test/ok1.mp4" --conf-thres=0.82 --device=0 --view-img --nosave --classes=0

Output:

YOLOv5  2021-10-13 torch 1.9.0 CUDA:0 (GeForce GTX 1050, 4096.0MB)

Traceback (most recent call last):
  File "E:/Work work/Python/Work/atin/Camera_Elevator/detect_v5.py", line 308, in <module>
    main(opt)
  File "E:/Work work/Python/Work/atin/Camera_Elevator/detect_v5.py", line 303, in main
    run(**vars(opt))
  File "E:\Anaconda\envs\pytorch\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "E:/Work work/Python/Work/atin/Camera_Elevator/detect_v5.py", line 84, in run
    stride = int(model.stride.max())  # model stride
  File "E:\Anaconda\envs\pytorch\lib\site-packages\torch\jit\_script.py", line 667, in __getattr__
    return super(RecursiveScriptModule, self).__getattr__(attr)
  File "E:\Anaconda\envs\pytorch\lib\site-packages\torch\jit\_script.py", line 384, in __getattr__
    return super(ScriptModule, self).__getattr__(attr)
  File "E:\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1130, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'RecursiveScriptModule' object has no attribute 'stride'

Process finished with exit code 1

Expected behavior

Normal detection like yolov5s.pt

Environment

If applicable, add screenshots to help explain your problem.

  • OS: Windows10
  • GPU: GTX 1050

Additional context

Add any other context about the problem here.

@iumyx2612 iumyx2612 added the bug Something isn't working label Oct 13, 2021
@glenn-jocher
Copy link
Member

@iumyx2612 thanks for the bug report! You probably want to connect with @andreiionutdamian who knows more about torchscript inference than I do.

@andreiionutdamian
Copy link
Contributor

andreiionutdamian commented Oct 15, 2021

@iumyx2612 there are quite a few issues. This particular issue and other similar ones (such as constants that are not saved in torchscript file) will be solved in a PR that I will submit however there are bigger show-stoppers I am trying to figure out such as #5070 . I will post updates asap.
Nevertheless we have to thank @glenn-jocher that we have a strong base to work and test on.

andreiionutdamian added a commit to andreiionutdamian/yolov5 that referenced this issue Oct 16, 2021
@andreiionutdamian
Copy link
Contributor

The proposed modifications should enable a minimal export of torchscript graph including "locked" (traced) input size and required stride for image resize (although due to the fact that HW are fixed the stride is not actually used). Be aware that inference batch-size should be the same as during tracing (exporting) if running on GPU (running on CPU allows variable batch size it seems)

glenn-jocher pushed a commit to andreiionutdamian/yolov5 that referenced this issue Oct 19, 2021
andreiionutdamian added a commit to andreiionutdamian/yolov5 that referenced this issue Oct 23, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 16, 2021

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

3 participants