DataLoader中的persistent_workers參數
torch.utils.data.DataLoader(dataset, batch_size=1, shuffle=False, sampler=None, batch_sampler=None, num_workers=0, collate_fn=None, pin_memory=False, drop_last=False, timeout=0, worker_init_fn=None, multiprocessing_context=None, generator=None, *, prefetch_factor=2, persistent_workers=False)
-
persistent_workers (bool, optional) – If
True, the data loader will not shutdown the worker processes after a dataset has been consumed once. This allows to maintain the workers Dataset instances alive. (default:False)
如果為True,數據加載器將不會在數據集運行完一個Epoch后關閉worker進程。這允許維護worker數據集實例保持激活。(默認值:False)
意思是運行完一個Epoch后並不會關閉worker進程,而是保持現有的worker進程繼續進行下一個Epoch的數據加載。
好處是Epoch之間不必重復關閉啟動worker進程,加快訓練速度。
這樣對訓練精度是否有影響?True和False的結果似乎會略有差異。
