Here's an animation of a @PyTorch DataLoader.

It turns your dataset into a shuffled, batched tensors iterator.

(This is my first animation using @manim_community, the community fork of @3blue1brown's manim)

Here's a little summary of the different parts for those curious:
The Dataset has to be passed to the DataLoader. It's where you transform your data and where the inputs and labels are stored.

It is basically one big list of (input, label) tuples. So when you index in like dataset[i], it returns (input[ i ], label[ i ]).
The sampler and batch sampler are used to choose which inputs & labels to yield to the next batch.

Artistic license warning 👨‍🎨⚠️: They don't actually grab the inputs and labels, and the dataset doesn't actually deplete. They tell the DataLoader which indices to grab.
The collate function is what collates/combines the batch of examples into single x_batch, y_batch tensors.

@PyTorch handles a bunch of different types and shapes of data that could need to be collated.
If you need custom behaviour, you can pass in a sampler / batch_sampler and/or a collate function to your DataLoader.

Here's a blog post I wrote that goes into more detail about each part and shows how to customise them.

• • •

Missing some Tweet in this thread? You can try to force a refresh

Keep Current with Scott Condron

Scott Condron Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!