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 [124] of labels
optimizer.zero_grad()
outputs = convnet(images) #convnet is a cnn
Is there a quick and easy function that allows batchSelection from the train_X and train_Y tensors images?
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: