DataBlock to DataLoader

Hello FastAI

Can someone guide if it is possible to convert a DataBlock into PyTorch DataLoader. I really like FasAI plug & play datablocks but I need to use them with my own customized pytorch models and complex training loops, hence why I want to use DataBlock but the rest use pure PyTorch. Yes I know I can convert the pytorch into fastai, but I rather not.

Thanks in advance.

You can call your dls = datablock.dataloaders(path_for_images)

Then inside dls, you have both dls.train and dls.valid. I think both are PyTorch dataloaders. They might have some addition fields, but I hope they’d work with PyTorch.

fastai’s DataLoader class is entirely custom, but they work similar to PyTorchs in terms of iterating etc.

1 Like

And they use the PyTorch internals for multiprocessing.

2 Likes