pytorch type_error ai_generated true

TypeError: __getitem__ returned wrong type from Dataset

ID: pytorch/custom-dataset-error

Also available as: JSON · Markdown
82%Fix Rate
86%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

Custom Dataset __getitem__ returns wrong type or shape.

generic

Workarounds

  1. 90% success Return tuple of tensors from __getitem__
  2. 88% success Implement __len__ and __getitem__ correctly matching expected interface

Dead Ends

Common approaches that don't work:

  1. Return Python list instead of tensor 72% fail

    Slow collation

  2. Skip type checking in DataLoader 78% fail

    Error during training instead