简体   繁体   English

Pytorch 的 DataLoader 中的采样器参数

[英]sampler argument in DataLoader of Pytorch

While using Pytorch's DataLoader utility, in sampler what is the purpose of RandomIdentitySampler ?在使用 Pytorch 的 DataLoader 实用程序时,在采样器RandomIdentitySampler的目的是什么? And in RandomIdentitySampler there is an argument instances .RandomIdentitySampler中有一个参数instances Does instances depends upon number of workers ? instances是否取决于工人的数量? If there is are 4 workers then should there be 4 instances as well?如果有 4 个工人,那么也应该有 4 个实例吗?

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)

This sampler is not part of the PyTorch or any other official lib (torchvision, torchtext, etc.).此采样器不是 PyTorch 或任何其他官方库(torchvision、torchtext 等)的一部分。 Anyway, there is a RandomIdentitySampler in the torchreid from KaiyangZhou .不管怎样,开阳torchreid里有一个RandomIdentitySampler Assuming this is the case:假设是这种情况:

  1. While using Pytorch's DataLoader utility, in sampler what is the purpose of RandomIdentitySampler ?在使用 Pytorch 的 DataLoader 实用程序时,在采样器RandomIdentitySampler的目的是什么?
  1. And in RandomIdentitySampler there is an argument instances .RandomIdentitySampler中有一个参数instances Does instances depends upon number of workers? instances是否取决于工人的数量?
  • Based on the previous answer, you can note that instances does not depend on the number of workers.根据前面的答案,您可以注意到instances不依赖于工作人员的数量。 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?如果有 4 个工人,那么也应该有 4 个实例吗?
  • Not necessarily.不必要。 The only constraint is that the number of instances should not be smaller than the batch size.唯一的限制是实例的数量不应小于批量大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM