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

Running yolo with GPU #12690

Closed
1 task done
usagi123 opened this issue May 14, 2024 · 4 comments
Closed
1 task done

Running yolo with GPU #12690

usagi123 opened this issue May 14, 2024 · 4 comments
Labels
question Further information is requested

Comments

@usagi123
Copy link

usagi123 commented May 14, 2024

Search before asking

Question

I am just started learning how to use yolo and just trying out by follow quickstart guide. As I wanted to export model yolov8n.pt to engine by using yolo export model=yolov8n.pt format=engine which required pytorch with cuda as yolo returns

torch.cuda.is_available(): False
torch.cuda.device_count(): 0
os.environ['CUDA_VISIBLE_DEVICES']: None

image

So I double check that and it returns true

Python 3.11.3 (tags/v3.11.3:f3909b8, Apr  4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.__version__
'2.3.0+cu121'

So I am confused. How my machine can both have and cannot have gpu. Not sure if this is related but I noticed yolo shown Ultralytics YOLOv8.2.15 🚀 Python-3.10.9 torch-2.1.0 while I am using python 3.11.3 and torch 2.3.0. Maybe that's the reason?

Further searching, I found this issue #4144 which the solution is to use "CUDA-enabled PyTorch build" is what I was using by installing pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 which generated from pytorch getting started locally

Additional

No response

@usagi123 usagi123 added the question Further information is requested label May 14, 2024
Copy link

👋 Hello @usagi123, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

Hello! It looks like you're encountering an issue where your environment is not consistently recognizing the GPU. This could indeed be related to the different Python and PyTorch versions you're using compared to those reported by YOLOv8.

Here are a couple of steps to help resolve this:

  1. Environment Consistency: Ensure that the Python environment from which you're running the YOLO command is the same one where torch.cuda.is_available() returns True. Sometimes, different terminals or IDEs might use different environments.

  2. Version Compatibility: YOLOv8 might have specific requirements or better compatibility with certain versions of Python and PyTorch. You might want to try aligning your environment more closely with the versions YOLO reports (Python-3.10.9 and torch-2.1.0). You can create a virtual environment to test this without affecting your current setup:

    python -m venv yolovenv
    yolovenv\Scripts\activate  # Windows
    pip install torch==2.1.0+cu121 torchvision torchaudio
  3. Check CUDA Visibility: Before running the YOLO command, ensure that CUDA devices are visible in your session:

    import torch
    print(torch.cuda.is_available())
    print(torch.cuda.device_count())
    print(os.environ['CUDA_VISIBLE_DEVICES'])

If these steps don't resolve the issue, it might be helpful to reinstall the CUDA-enabled PyTorch build ensuring it matches the CUDA version installed on your machine. Sometimes, a fresh installation can clear up any discrepancies.

Hope this helps! Let me know if you have any more questions. 😊

@usagi123
Copy link
Author

Thank you so much, I just uninstall both of them and reinstall and everything fixed.

@glenn-jocher
Copy link
Member

Great to hear that a reinstall fixed the issue! If you encounter any more questions or need further assistance as you continue exploring YOLOv8, feel free to reach out. Happy detecting! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants