How do you randomly select a batchSize of fixed size during training?
Say I have my training input as a tensor of size
[124, 3, 32, 32], during training, I want to randomly select a batch of
31 from the tensor e.g.
for epoch in range(maxIter):
images = Variable(train_X) #e.g. train_X is a 124 tensor of images of size [3, 32, 32]
labels = Variable(train_Y) #e.g. train_Y is of size  of labels
outputs = convnet(images) #convnet is a cnn
Is there a quick and easy function that allows batchSelection from the
train_Y tensors images?
I think I found it out. One can index the tensor the way a python list could be index. For example,
The first tensor would be
tensor_1 = train_X[0, :, :, :]
and so on ...
Yes, you can index a tensor like a Python list or NumPy array. If you want to sample without replacement you can use the TensorDataset and DataLoader classes:
inputs = torch.randn(124, 3, 32, 32)
targets = torch.LongTensor(124).random_(1, 10)
dataset = torch.utils.data.TensorDataset(inputs, targets)
loader = torch.utils.data.DataLoader(dataset, batch_size=31, shuffle=True)
for images, labels in loader:
Thanks a lot for the info. I did not realize you could use the class
torch.utils.data to load data that is not native to pytorch.