本文簡要介紹python語言中 torchdata.datapipes.iter.ZipArchiveLoader
的用法。
用法:
class torchdata.datapipes.iter.ZipArchiveLoader(datapipe: Iterable[Tuple[str, io.BufferedIOBase]], length: int = - 1)
datapipe-可迭代的 DataPipe 提供路徑名和 zip 二進製流的元組
length-DataPipe的標稱長度
從 Iterable DataPipe 打開/解壓縮 zip 二進製流,其中包含路徑名和 zip 二進製流的元組,並生成路徑名和提取的二進製流的元組(函數名稱:
load_from_zip
)。注意
如果附加了默認的
DecoderDataPipe
,打開的文件句柄將自動關閉。否則,用戶應負責顯式關閉文件句柄或讓 Python 的 GC 定期關閉它們。由於zipfiles
如何實現其open()
方法,下麵的data_stream 變量不能在此函數範圍內關閉。示例
>>> from torchdata.datapipes.iter import FileLister, FileOpener >>> datapipe1 = FileLister(".", "*.zip") >>> datapipe2 = FileOpener(datapipe1, mode="b") >>> zip_loader_dp = datapipe2.load_from_zip() >>> for _, stream in zip_loader_dp: >>> print(stream.read()) b'0123456789abcdef'
參數:
相關用法
- Python PyTorch Zipper用法及代碼示例
- Python torch.distributed.optim.ZeroRedundancyOptimizer用法及代碼示例
- Python PyTorch ZeroPad2d用法及代碼示例
- Python PyTorch frexp用法及代碼示例
- Python PyTorch jvp用法及代碼示例
- Python PyTorch cholesky用法及代碼示例
- Python PyTorch vdot用法及代碼示例
- Python PyTorch ELU用法及代碼示例
- Python PyTorch ScaledDotProduct.__init__用法及代碼示例
- Python PyTorch gumbel_softmax用法及代碼示例
- Python PyTorch get_tokenizer用法及代碼示例
- Python PyTorch saved_tensors_hooks用法及代碼示例
- Python PyTorch positive用法及代碼示例
- Python PyTorch renorm用法及代碼示例
- Python PyTorch AvgPool2d用法及代碼示例
- Python PyTorch MaxUnpool3d用法及代碼示例
- Python PyTorch Bernoulli用法及代碼示例
- Python PyTorch Tensor.unflatten用法及代碼示例
- Python PyTorch Sigmoid用法及代碼示例
- Python PyTorch Tensor.register_hook用法及代碼示例
- Python PyTorch ShardedEmbeddingBagCollection.named_parameters用法及代碼示例
- Python PyTorch sqrt用法及代碼示例
- Python PyTorch PackageImporter.id用法及代碼示例
- Python PyTorch column_stack用法及代碼示例
- Python PyTorch diag用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torchdata.datapipes.iter.ZipArchiveLoader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。