How do I reshape a dataloader object?

I need to reshape a dataloader object with the shape (batchsize, n_crops, n_channels, height, width) to (n_crops*batchsize, n_channels, height, width)

I get this error when I try to reshape it:

train_loader.reshape((self.ncrops*batch_size, self.in_channel, self.img_cols, self.img_rows))
AttributeError: ‘DataLoader’ object has no attribute ‘reshape’

You can apply the reshape to the tesnors that comes out as batches from the train_loader. For example:

batch_x, batch_y = next(iter(train_loader))

batch_x = batch_x.reshape((self.ncrops*batch_size, self.in_channel, self.img_cols, self.img_rows))
1 Like