ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.03k stars 16.17k forks source link

multi-gpu validation #13164

Closed yjseok closed 1 month ago

yjseok commented 3 months ago

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

glenn-jocher commented 3 months ago

@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.

github-actions[bot] commented 2 months ago

πŸ‘‹ 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 ⭐