當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PyTorch Batcher用法及代碼示例

本文簡要介紹python語言中 torchdata.datapipes.iter.Batcher 的用法。

用法:

class torchdata.datapipes.iter.Batcher(datapipe: IterDataPipe, batch_size: int, drop_last: bool = False, wrapper_class=DataChunk)

參數

  • datapipe-可迭代DataPipe正在批量處理

  • batch_size-每批的大小

  • drop_last-如果最後一批未滿,可選擇刪除最後一批

  • wrapper_class-在屈服之前應用於每個批次(類型 List )的包裝器,默認為 DataChunk

創建小批量數據(函數名稱:batch)。如果 drop_last 設置為 True ,則外部尺寸將添加為 batch_size ;如果 drop_last 設置為 False ,則最後一批的外部尺寸將添加為 length % batch_size

示例

>>> from torchdata.datapipes.iter import IterableWrapper
>>> dp = IterableWrapper(range(10))
>>> dp = dp.batch(batch_size=3, drop_last=True)
>>> list(dp)
[[0, 1, 2], [3, 4, 5], [6, 7, 8]]

相關用法


注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torchdata.datapipes.iter.Batcher。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。