The most flexible way to load your data would be to write your own Dataset.
Basically you just have to worry about three functions:


__init__: here you have to pass your data or paths to your data, if you want to lazily load it. Also you can define transformations here, which should be applied on your data (and target).

__getitem__: here you have to implement your logic to load your data. E.g. in case you’ve passed paths to your Dataset, you can get the current path using index and use whatever library you want to load a single sample.

__len__: returns the length of your Dataset.

Here is a small example:
from PIL import Image
from torch.utils.data import Dataset, DataLoader

class MyDataset(Dataset):
    def __init__(self, gif_paths):
        self.paths = gif_paths

    def __getitem__(self, index):
        x = Image.open(self.paths[index])
        # Convert the gif here to frames, etc.
        ...
        return x

    def __len__(self):
        return len(self.paths)

gif_paths = ['./a.gif', './b.gif']
dataset = MyDataset(gif_paths)
loader = DataLoader(
    dataset,
    batch_size=10,
    num_workers=2,
    shuffle=True
)