importing error default_collate is not defined

Question:

I tried to import default_collate from torch.utils.data.dataloader but it says that default_collate does not exist, but another function does exist (_collate_fn_t).

from torch.utils.data.dataloader import default_collate
from torch.utils.data.dataloader import _collate_fn_t

Are these commands are similar?

Asked By: Mohamed Nabih

||

Answers:

The _collate_fn_t is the type definition of a collate function in general, it is defined here as:

_collate_fn_t = Callable[[List[T]], Any]

default_collate is the default collate function used by the DataLoader class.

Importing these is not equivalent, you should check your spelling and try again with:

from torch.utils.data.dataloader import default_collate
Answered By: uniquefine
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.