yolov5 icon indicating copy to clipboard operation
yolov5 copied to clipboard

ImportError: cannot import name 'draw_bounding_boxes' from 'torchvision.utils'

Open abcsunshine opened this issue 3 years ago β€’ 8 comments
trafficstars

Search before asking

  • [X] I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Training

Bug

image

Environment

No response

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • [ ] Yes I'd like to help by submitting a PR!

abcsunshine avatar Aug 08 '22 06:08 abcsunshine

πŸ‘‹ Hello @abcsunshine, 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 [email protected].

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.

github-actions[bot] avatar Aug 08 '22 06:08 github-actions[bot]

@thepycoder can you take a look please? @abcsunshine is this error related to clearml logger? Does it work fine without clearml?

AyushExel avatar Aug 08 '22 07:08 AyushExel

Can you do a pip freeze and make sure you have torchvision installed? Is it the same version as in the requirements.txt?

thepycoder avatar Aug 08 '22 08:08 thepycoder

I think this is the right version. However, when I just ignore the import code,it can work well.

image

image

abcsunshine avatar Aug 09 '22 02:08 abcsunshine

It seems like the draw_bounding_boxes functionality was only added to torchvision starting from v0.9.0. In contrast, the requirements of YOLOv5 specify torchvision>=0.8.1, which means if you have 0.8.1 or 0.8.2 installed, it will error because of this import statement.

So the solution for you @abcsunshine is to upgrade torchvision, or (if you don't use ClearML), commenting out the import statement is indeed also fine.

@AyushExel How do you want to solve this? I assume you won't like it to change the whole repo requirements file from torchvision>=0.8.1 to torchvision>=0.9.0. So in that case, we should re-implement the draw_bounding_boxes function without using torchvision. Any other ideas?

thepycoder avatar Aug 09 '22 12:08 thepycoder

@thepycoder ah got it. Simplest quick fix is to scope the import to place it within the try: import clearml statement. This will reduce the affected userbase.

A more permanent fix might be to use the YOLOv5 Annotator class below. We can't bump the torchvision requirements right now because there are some Jetson Nano tutorials that require torch 1.7.0 torchvision 0.8.1

Annotator class: https://github.com/ultralytics/yolov5/blob/b551098d59cce7aa9755b711b9cbe49758d3beae/utils/plots.py#L68-L126

detect.py usage example for box annotation: https://github.com/ultralytics/yolov5/blob/b551098d59cce7aa9755b711b9cbe49758d3beae/detect.py#L170

glenn-jocher avatar Aug 09 '22 18:08 glenn-jocher

@abcsunshine @thepycoder good news πŸ˜ƒ! Your original issue may now be fixed βœ… in PR #8915. This is not a permanent solution but rather a scoped import quickfix.

To receive this update:

  • Git – git pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Docker – sudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 πŸš€!

glenn-jocher avatar Aug 09 '22 18:08 glenn-jocher

@abcsunshine @thepycoder I think this shows the need for another CI check at the torch minimum requirement. I'll add this to the YOLOv5 CI to catch these problems earlier in the future. Trying to add in https://github.com/ultralytics/yolov5/pull/8916

glenn-jocher avatar Aug 09 '22 18:08 glenn-jocher