You can do this by overriding the __getitem__ in a custom implementation of dataset, where you load the frames and perform the above reshaping. You can refer here 41 for the implementation of custom dataset and dataloader.