本文簡要介紹python語言中 torchdata.datapipes.iter.LineReader 的用法。
- 用法:- class torchdata.datapipes.iter.LineReader(source_datapipe: IterDataPipe[Tuple[str, IO]], *, skip_lines: int = 0, strip_newline: bool = True, decode: bool = False, encoding='utf-8', errors: str = 'ignore', return_path: bool = True)
- source_datapipe-帶有文件名和字符串數據流元組的DataPipe 
- skip_lines-每個文件開頭要跳過的行數 
- strip_newline-如果 - True,新行字符將被剝離
- decode-如果 - True,這將根據指定的- encoding解碼文件的內容
- encoding-文件的字符編碼( - default=’utf-8’)
- errors-解碼時使用的錯誤處理方案 
- return_path-如果 - True,每一行將返回一個路徑和內容的元組,而不僅僅是內容
 
- 接受由文件名和字符串數據流的元組組成的DataPipe,並且對於流中的每一行,生成文件名和行的元組(函數名稱: - readlines)。- 示例 - >>> from torchdata.datapipes.iter import IterableWrapper >>> import io >>> text1 = "Line1\nLine2" >>> text2 = "Line2,1\r\nLine2,2\r\nLine2,3" >>> source_dp = IterableWrapper([("file1", io.StringIO(text1)), ("file2", io.StringIO(text2))]) >>> line_reader_dp = source_dp.readlines() >>> list(line_reader_dp) [('file1', 'Line1'), ('file1', 'Line2'), ('file2', 'Line2,1'), ('file2', 'Line2,2'), ('file2', 'Line2,3')]
參數:
相關用法
- Python PyTorch LinearLR用法及代碼示例
- Python PyTorch Linear用法及代碼示例
- Python PyTorch LinearReLU用法及代碼示例
- Python PyTorch LazyModuleMixin用法及代碼示例
- Python PyTorch LKJCholesky用法及代碼示例
- Python PyTorch L1Loss用法及代碼示例
- Python PyTorch LPPool2d用法及代碼示例
- Python PyTorch LeakyReLU用法及代碼示例
- Python PyTorch LogSigmoid用法及代碼示例
- Python PyTorch LowRankMixtureCrossNet用法及代碼示例
- Python PyTorch LayerNorm用法及代碼示例
- Python PyTorch LogNormal用法及代碼示例
- Python PyTorch LambdaLR用法及代碼示例
- Python PyTorch LocalResponseNorm用法及代碼示例
- Python PyTorch LSTM用法及代碼示例
- Python PyTorch LowRankMultivariateNormal用法及代碼示例
- Python torchrec.modules.crossnet.LowRankCrossNet用法及代碼示例
- Python PyTorch LogSoftmax用法及代碼示例
- Python PyTorch LSTMCell用法及代碼示例
- Python PyTorch LocalElasticAgent用法及代碼示例
- Python PyTorch LPPool1d用法及代碼示例
- Python PyTorch Laplace用法及代碼示例
- Python PyTorch LazyModuleExtensionMixin.apply用法及代碼示例
- Python PyTorch frexp用法及代碼示例
- Python PyTorch jvp用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torchdata.datapipes.iter.LineReader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
