sampler argument in DataLoader of Pytorch

Viewed 318

While using Pytorch's DataLoader utility, in sampler what is the purpose of RandomIdentitySampler? And in RandomIdentitySampler there is an argument instances. Does instances depends upon number of workers? If there is are 4 workers then should there be 4 instances as well?

Following is the chunk of code:

c_dataloaders = DataLoader(Preprocessor(cluster_dataset.train_set,
                                        root=cluster_dataset.images_dir,
                                        transform=train_transformer),
                                        batch_size=args.batch_size_stage2,
                                        num_workers=args.workers,
                                        sampler=RandomIdentitySampler(cluster_dataset.train_set,
                                        args.batch_size_stage2,
                                        args.instances)
1 Answers

This sampler is not part of the PyTorch or any other official lib (torchvision, torchtext, etc.). Anyway, there is a RandomIdentitySampler in the torchreid from KaiyangZhou. Assuming this is the case:

  1. While using Pytorch's DataLoader utility, in sampler what is the purpose of RandomIdentitySampler?
  1. And in RandomIdentitySampler there is an argument instances. Does instances depends upon number of workers?
  • Based on the previous answer, you can note that instances does not depend on the number of workers. It simply sets the number of instances of each identity that will be drawn from the dataset for each batch.
  1. If there are 4 workers then should there be 4 instances as well?
  • Not necessarily. The only constraint is that the number of instances should not be smaller than the batch size.
Related