Attention
June 2024 Status Update: Removing DataPipes and DataLoader V2
We are re-focusing the torchdata repo to be an iterative enhancement of torch.utils.data.DataLoader. We do not plan on continuing development or maintaining the [DataPipes] and [DataLoaderV2] solutions, and they will be removed from the torchdata repo. We’ll also be revisiting the DataPipes references in pytorch/pytorch. In release torchdata==0.8.0 (July 2024) they will be marked as deprecated, and in 0.9.0 (Oct 2024) they will be deleted. Existing users are advised to pin to torchdata==0.8.0 or an older version until they are able to migrate away. Subsequent releases will not include DataPipes or DataLoaderV2. Please reach out if you suggestions or comments (please use this issue for feedback)
Filter¶
- class torchdata.datapipes.iter.Filter(datapipe: IterDataPipe[_T_co], filter_fn: Callable, input_col=None)¶
Filters out elements from the source datapipe according to input
filter_fn
(functional name:filter
).- Parameters:
datapipe – Iterable DataPipe being filtered
filter_fn – Customized function mapping an element to a boolean.
input_col –
Index or indices of data which
filter_fn
is applied, such as:None
as default to applyfilter_fn
to the data directly.Integer(s) is used for list/tuple.
Key(s) is used for dict.
Example
>>> # xdoctest: +SKIP >>> from torchdata.datapipes.iter import IterableWrapper >>> def is_even(n): ... return n % 2 == 0 >>> dp = IterableWrapper(range(5)) >>> filter_dp = dp.filter(filter_fn=is_even) >>> list(filter_dp) [0, 2, 4]