0

So as I was programming and skimming through the pytorch docs, I stumbled across DataLoader. I learnt a fair bit and continued researching, and then saw a comment on a youtube video covering it, stating that DataLoader actually outputs a list instead of a tensor.

I then used the type() on the iterable data and learnt that this was true, could anyone please help me understand why the DataLoader outputs a list instead of a tensor.

5
  • Does this answer your question? What is PyTorch Dataset supposed to return? Commented Jan 22, 2024 at 9:09
  • Sorry, @Bhargav it didn't, but appreciate the gesture Commented Jan 22, 2024 at 9:12
  • check the first answer Commented Jan 22, 2024 at 9:13
  • pls post the piece of code you trying. That would be helpful to asses the question Commented Jan 22, 2024 at 9:14
  • Please provide enough code so others can better understand or reproduce the problem. Commented Jan 22, 2024 at 9:43

1 Answer 1

0

The pytorch DataLoader class has a collate_fn that processes dataset items into a batch. Using the example from the pytorch documentation, it works like this:

for indices in batch_sampler:
    yield collate_fn([dataset[i] for i in indices])

If you don't pass a collate_fn, pytorch automatically uses default_collate. The behavior of default_collate depends on the types from you dataset, defined here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.