官网给的:
https://github.com/ultralytics/yolov5/issues/475
指定显卡
指定单显卡:
$ python train.py --batch 64 --data coco.yaml --weights yolov5s.pt --device 0
使用pytorch 的DataParallel mode 指定多显卡(不推荐),为啥不推荐,因为反传的时候梯度默认都在0卡上算了,所以显存分配不均衡,在显卡0占用非常多,别的显卡的显存又占用没那么多。训练时间也没增加多少。
$ python train.py --batch 64 --data coco.yaml --weights yolov5s.pt --device 0,1
单机多卡(推荐)
使用pytorch的 DistributedDataParallel Mode 进行单机多卡训练。(推荐)
$ python -m torch.distributed.launch --nproc_per_node 2 train.py --batch 64 --data coco.yaml --weights yolov5s.pt --device 0,1
–nproc_per_node specifies how many GPUs you would like to use. In the example above, it is 2.
–batch is the total batch-size. It will be divided evenly to each GPU. In the example above, it is 64/2=32 per GPU.</