Hi William!



 WilliamWithering:

I’m trying to train the network using a RandomSampler as suggested. However, if I understood correctly, it only yields a single index at a time, so I have to wrap it with a BatchSampler (?)


I’m not sure, but this seems plausible.


    trainSampler = BatchSampler(RandomSampler(trainset, replacement = True, num_samples = epochs * len(trainset)), batch_size = bs, drop_last = True)
    trainloader = torch.utils.data.DataLoader(trainset, sampler = trainSampler)

When I test it, I get a TypeError
…
I had never used samplers before, so I’m not really sure of what I’m doing here.


I haven’t used samplers either, so I’m not certain of what is
going on.
However, looking at the DataLoader 2 documentation, it appears
that the DataLoader() constructor has two mutually-exclusive
arguments,  sampler and batch_sampler.  Your code is using
sampler.
Is it possible that in order to use trainSampler, the
BatchSampler you’ve constructed, you have to pass it
in as batch_sampler = trainSampler?
Just a thought …
Best.
K. Frank