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

multi-gpu validation #13164

Open
1 task done
yjseok opened this issue Jul 4, 2024 · 2 comments
Open
1 task done

multi-gpu validation #13164

yjseok opened this issue Jul 4, 2024 · 2 comments
Labels
question Further information is requested Stale

Comments

@yjseok
Copy link

yjseok commented Jul 4, 2024

Search before asking

Question

Hello,

Is there any way to use multi-gpu during running val.py of Yolov5?
I set --device parameter as 0,1,2,3, but it doesn't work

Additional

No response

@yjseok yjseok added the question Further information is requested label Jul 4, 2024
@glenn-jocher
Copy link
Member

@yjseok hello,

Thank you for reaching out and for your thorough search before posting your question! Currently, val.py in YOLOv5 does not support multi-GPU validation directly through the --device parameter. The multi-GPU functionality is primarily designed for training purposes using train.py.

However, you can achieve multi-GPU validation by modifying the code to use torch.nn.DataParallel or torch.nn.parallel.DistributedDataParallel. Here’s a brief guide on how you might approach this:

  1. Clone the YOLOv5 repository and install dependencies:

    git clone https://github.com/ultralytics/yolov5
    cd yolov5
    pip install -r requirements.txt
  2. Modify val.py to use torch.nn.DataParallel:

    import torch
    from models.yolo import Model
    
    # Load model
    model = Model(cfg='yolov5s.yaml', ch=3, nc=80).to(device)
    
    # Wrap model with DataParallel
    if torch.cuda.device_count() > 1:
        model = torch.nn.DataParallel(model, device_ids=[0, 1, 2, 3])
    
    # Validate
    results, maps, times = validate(model=model, ...)
  3. Run the modified val.py:

    python val.py --data coco.yaml --weights yolov5s.pt --device 0,1,2,3

For more detailed instructions and advanced configurations, you can refer to our Multi-GPU Training Guide.

If you encounter any issues or have further questions, please provide a minimum reproducible example of your code and the specific error messages you are seeing. This will help us to better understand and address your issue. You can find more information on creating a minimum reproducible example here.

Lastly, please ensure you are using the latest versions of torch and the YOLOv5 repository to avoid any compatibility issues.

Copy link
Contributor

github-actions bot commented Aug 4, 2024

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

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 YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants