Skip to content

After converting from .pt to .torchscript, bounding box is off #6947

Closed

Description

@willsonyee

Search before asking

Question

I am playing around with YOLOv5 and exporting to different formats (.pt & .torchscript). But I found that after I exported the pre-trained models using this command:
!python "/content/drive/MyDrive/yolov5/export.py" --weights "/content/drive/MyDrive/yolov5/yolov5s.pt" --include torchscript

The .torchscript model's bounding is off, please advise me on why this is happening and how to resolve it. Thank you.

.pt model:
zidane1

.torchscript model:
zidane2

Additional

No response

Activity

  1. github-actions commented on Mar 11, 2022

    @github-actions
    Contributor

    👋 Hello @willsonyee, 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 screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

    If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

    For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

    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):

    Status

    CI CPU testing

    If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

  2. glenn-jocher commented on Mar 11, 2022

    @glenn-jocher
    Member

    @willsonyee 👋 hi, thanks for letting us know about this possible problem with YOLOv5 🚀. Torchscript export and inference works well for me, I'm unable to reproduce any box issues.

    Screenshot 2022-03-11 at 14 56 32

    We've created a few short guidelines below to help users provide what we need in order to get started investigating a possible problem.

    How to create a Minimal, Reproducible Example

    When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:

    • ✅ Minimal – Use as little code as possible to produce the problem
    • ✅ Complete – Provide all parts someone else needs to reproduce the problem
    • ✅ Reproducible – Test the code you're about to provide to make sure it reproduces the problem

    For Ultralytics to provide assistance your code should also be:

    • ✅ Current – Verify that your code is up-to-date with GitHub master, and if necessary git pull or git clone a new copy to ensure your problem has not already been solved in master.
    • ✅ Unmodified – Your problem must be reproducible using official YOLOv5 code without changes. Ultralytics does not provide support for custom code ⚠️.

    If you believe your problem meets all the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem.

    Thank you! 😃

  3. willsonyee commented on Mar 11, 2022

    @willsonyee
    Author

    @glenn-jocher thanks for your prompt response.

    I am running the code like this:

    import torch
    model = torch.hub.load('/content/drive/MyDrive/yolov5', 'custom', path='/content/drive/MyDrive/yolov5/yolov5s.torchscript', source='local')
    result = model("/content/drive/MyDrive/yolov5/data/images/zidane.jpg")
    result.save() 
    

    The reason I am doing it like this because I am trying to load the model from local and inference without using the detect.py. So I can later on integrate the .torchscript model into my swift IOS app.

    Could you advise me why by running the code I attached will cause the bounding box off ?

  4. glenn-jocher commented on Mar 11, 2022

    @glenn-jocher
    Member

    @willsonyee ah yes you are right there is a bug. I'm able to reproduce with this code:

    !python export.py --weights yolov5s.pt --include torchscript
    model = torch.hub.load('ultralytics/yolov5', 'custom', path='yolov5s.torchscript')
    result = model("data/images/zidane.jpg")
    result.save()

    Screenshot 2022-03-11 at 15 21 14

    I'll take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions