MapToIterConverter¶
- class torchdata.datapipes.iter.MapToIterConverter(datapipe: MapDataPipe, indices: Optional[List] = None)¶
将
MapDataPipe
转换为IterDataPipe
(函数名称:to_iter_datapipe
)。它使用indices
遍历MapDataPipe
,如果未给出,则默认为range(len(mapdatapipe))
。对于相反的转换器,请使用
IterToMapConverter
。- 参数:
datapipe – 带有数据的源 MapDataPipe
indices – 可选的索引列表,将决定如何遍历 datapipe
示例
>>> from torchdata.datapipes.map import SequenceWrapper >>> source_dp = SequenceWrapper(range(10)) >>> iter_dp = source_dp.to_iter_datapipe() >>> list(iter_dp) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> source_dp2 = SequenceWrapper({'a': 1, 'b': 2, 'c': 3}) >>> iter_dp2 = source_dp2.to_iter_datapipe(indices=['a', 'b', 'c']) >>> list(iter_dp2) [1, 2, 3]