torch.utils.data.DataLoader

关于workers,上一篇可能有误。

经查,表示进程之义。0表示只有主进程,大于0的表示多个进程,加快数据读取。

下面是官方解释,估计也没人看官方源码吧

num_workers (int, optional): how many subprocesses to use for data
            loading. ``0`` means that the data will be loaded in the main process.
            (default: ``0``)

上一篇cuda占满的原因还是另一个参数,这个设置为True

pin_memory (bool, optional): If ``True``, the data loader will copy Tensors
            into CUDA pinned memory before returning them.  If your data elements
            are a custom type, or your :attr:`collate_fn` returns a batch that is a custom type,

关于这个锁页内存请参考这个大佬的博文

我试试设置False是否正确,先不设置workers,即为0

但我发现设置False,GPU利用很低,

-j 24

结果如下

    raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str))
RuntimeError: DataLoader worker (pid(s) 115610) exited unexpectedly

真是够了,算了,这个锁页内存也是个坑,都不能搞个傻瓜式的啊。

发布了189 篇原创文章 · 获赞 170 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/SPESEG/article/details/103711315