ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
49.63k stars 16.11k forks source link

where is the shuffle in dataloader? #1919

Closed Laughing-q closed 3 years ago

Laughing-q commented 3 years ago

❔Question

it seems like there is no shuffle when create a dataloader, is this better ? or I just didn't find where shuffle is ?

Additional context

maybe shuffle is not that important when we using mosaic which set default, but shuffle is important when we training without any augment or mosaic.

glenn-jocher commented 3 years ago

@Laughing-q yes shuffle=False by default when training and testing. There are a few threads on this topic, but I believe everything this fine, because 3/4 of the images in each mosaic are shuffled, so in reality 75% of the content is effectively shuffled with the 4-mosaic, or 8/9 if the 9-mosaic is used.

Laughing-q commented 3 years ago

@Laughing-q yes shuffle=False by default when training and testing. There are a few threads on this topic, but I believe everything this fine, because 3/4 of the images in each mosaic are shuffled, so in reality 75% of the content is effectively shuffled with the 4-mosaic, or 8/9 if the 9-mosaic is used.

  • 1016

  • 932

I see, thanks

glenn-jocher commented 2 years ago

@Laughing-q good news 😃! Your original issue may now be fixed ✅ in PR #5623 by @werner-duvaud. This PR turns on shuffling in the YOLOv5 training DataLoader by default, which was missing until now. This works for all training formats: CPU, Single-GPU, Multi-GPU DDP.

train_loader, dataset = create_dataloader(train_path, imgsz, batch_size // WORLD_SIZE, gs, single_cls,
                                          hyp=hyp, augment=True, cache=opt.cache, rect=opt.rect, rank=LOCAL_RANK,
                                          workers=workers, image_weights=opt.image_weights, quad=opt.quad,
                                          prefix=colorstr('train: '), shuffle=True)  # <--- NEW

I evaluated this PR against master on VOC finetuning for 50 epochs, and the results show a slight improvement in most metrics and losses, particularly in objectness loss and mAP@0.5, perhaps indicating that the shuffle addition may help delay overtraining.

Screenshot 2021-11-13 at 13 03 26

https://wandb.ai/glenn-jocher/VOC

To receive this update:

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 🚀!