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

results.show() does not work #9819

Closed
1 of 2 tasks
kiristern opened this issue Oct 17, 2022 · 13 comments · Fixed by #9825
Closed
1 of 2 tasks

results.show() does not work #9819

kiristern opened this issue Oct 17, 2022 · 13 comments · Fixed by #9825
Labels
bug Something isn't working

Comments

@kiristern
Copy link

Search before asking

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

YOLOv5 Component

No response

Bug

I created a new conda env and downloaded the requirements as per the instructions; then tried running the tutorial as is but cannot display the results with results.show()

I get the following message:

Using cache found in /home/azureuser/.cache/torch/hub/ultralytics_yolov5_master
YOLOv5 🚀 2022-10-16 Python-3.10.6 torch-1.12.1+cu102 CUDA:0 (Tesla V100-PCIE-16GB, 16160MiB)

Fusing layers... 
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients
Adding AutoShape... 
image 1/2: 720x1280 2 persons, 2 ties
image 2/2: 1080x810 4 persons, 1 bus
Speed: 11.5ms pre-process, 4.0ms inference, 1.3ms NMS per image at shape (2, 3, 640, 640)

Error: no "view" rule for type "image/png" passed its test case
       (for more information, add "--debug=1" on the command line)
Error: no "view" rule for type "image/png" passed its test case
       (for more information, add "--debug=1" on the command line)

Environment

YOLOv5 🚀 2022-10-16 Python-3.10.6 torch-1.12.1+cu102 CUDA:0 (Tesla V100-PCIE-16GB, 16160MiB)

Minimal Reproducible Example

following #36 (comment) exactly.

Additional

interestingly, the images save in the runs/detect/exp folder, but i'd like to be able to display the results. I am working in a jupyter notebook.... been trying to find a work around for hours:(

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@kiristern kiristern added the bug Something isn't working label Oct 17, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 17, 2022

👋 Hello @kiristern, 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

YOLOv5 CI

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.

@MartinPedersenpp
Copy link

It looks like an issue with PIL(LOW) because the results.show() uses a PIL image.show function.

You can add these lines to your script:

from matplotlib import pyplot as plt
plt.imshow(np.squeeze(results.render()))
plt.title("Yolo results")
plt.show()

Be aware that the render function will draw on your image, so if you want to do something with the image afterwards, you need to store a copy somewhere.

@glenn-jocher
Copy link
Member

@kiristern works for me in PyCharm. I don't think remote notebooks will be able to show popup windows though.

Screenshot 2022-10-17 at 12 09 46

@glenn-jocher
Copy link
Member

@kiristern @MartinPedersenpp I've opened PR #9825 to add notebook support for results.show()

Screenshot 2022-10-17 at 13 02 01

@glenn-jocher
Copy link
Member

Unfortunately check_imshow() in PR seems to crash CI. Not sure what the most reliable way to determine if imshow is available in that case.

@MartinPedersenpp
Copy link

@glenn-jocher Not sure if this helps, but it looks like the cv.imshow method in general does not work on jupyter notebooks, so if you can add a detector to the check_imshow(), you could switch to pyplot instead which should work.
I found this post regarding detecting if a script is running on a notebook: https://discourse.jupyter.org/t/find-out-if-my-code-runs-inside-a-notebook-or-jupyter-lab/6935/13

@glenn-jocher
Copy link
Member

@MartinPedersenpp right, building a solution based off of a new is_notebook() function.

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 17, 2022

@MartinPedersenpp PR works now with is_notebook() and IPython.display.display, but it seems very slow. About 10 seconds to show both images:

import torch

# PyTorch Hub Model
model = torch.hub.load('ultralytics/yolov5:results/display', 'yolov5s')  # or yolov5n - yolov5x6, custom

# Images
img = ['https://ultralytics.com/images/zidane.jpg', 'https://ultralytics.com/images/bus.jpg']  # or file, Path, PIL, OpenCV, numpy, list

# Inference
results = model(img)

# Results
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.
results.show()

@glenn-jocher glenn-jocher linked a pull request Oct 17, 2022 that will close this issue
@glenn-jocher
Copy link
Member

@kiristern good news 😃! Your original issue may now be fixed ✅ in PR #9825.

To receive this update:

  • Gitgit 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 Run on Gradient Open In Colab Open In Kaggle
  • Dockersudo 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 🚀!

@MartinPedersenpp
Copy link

@glenn-jocher Glad to be of help 🙂
I must say, that I am learning so much from browsing the issues section of this repo and trying to help where I can.
I admire the work that you put into this repo and that you help people out every day.

@glenn-jocher
Copy link
Member

@MartinPedersenpp awesome! I basically just try to make daily small incremental changes that improve the most aggregate UI/UX painpoints among the most users/use cases. It adds up over time :)

@kiristern
Copy link
Author

Thank you so much for your prompt resolution, it works now!

@glenn-jocher
Copy link
Member

You're welcome, @kiristern! I'm glad to hear that the issue is resolved for you. If you have any further questions or run into any more issues, feel free to reach out. Happy coding with YOLOv5!

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

Successfully merging a pull request may close this issue.

3 participants