Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add __len__ to get dp length #1289

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion torchdata/datapipes/iter/util/webdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# LICENSE file in the root directory of this source tree.

import re
from typing import Any, Dict, Iterator, List, Union
from typing import Any, Dict, Iterator, List, Union, Sized

from torchdata.datapipes import functional_datapipe
from torchdata.datapipes.iter import IterDataPipe
Expand Down Expand Up @@ -99,3 +99,8 @@ def __iter__(self) -> Iterator[Dict]:
sample[suffix] = data
if sample != {}:
yield sample

def __len__(self):
if isinstance(self.source_datapipe, Sized):
return len(self.source_datapipe)
raise TypeError(f"{type(self).__name__} instance doesn't have valid length")