Does torchvision.transforms work on mini batches of data?

I am confused as to whether data pre-processing using torchvision.transforms takes place on the whole dataset at once or individually on the mini-batches of data?
Suppose I have:

transform = transforms.Compose([transforms.RandomResizedCrop(224),
dataset = datasets.ImageFolder(root, transform = transform)
dataset_loader =, batch_size = batch_size)

Can anyone explain whether transform occurs on the whole dataset at once or does it occur in mini-batches of data with batch size being equal to the batch_size specified in DataLoader.

The transformation will be applied on each sample as shown in this line of code.
Each time the __getitem__ method of your Dataset is called, the sample will be transformed if self.transform was properly set.

The DataLoader created a batch of (transformed) samples by calling __getitem__ mutliple times (using multiple workers if specified).


Oh okay. Thanks for the answer. It was really helpful!