You could create a Dataset and write the code to return a single sample.
Wrapping the Dataset into a DataLoader will automatically batch your data.
Have a look at the Data Loading Tutorial 253 for more information.
Basically, you have to define how a single sample is extracted in the __getitem__ method.