首先,使用PyTorch构建目标检测模型时,需要设置最佳的数据读取进程数。
我觉得把这个数量设定为CPU的线程数比较好;
获取2个CPU的线程数要获取CPU线程数的代码:
frommultiprocessingimportcpu _ count print (CPU _ count ) )注释:
Python官方文档multiprocessing.cpu_count ()的功能描述如下:
returnthenumberofcpusinthesystem
我原以为文档的描述不准确,后来
Andrew Svetlov在我的Python文档的错误提交中对我说:
cpuasashortcutfor ' logical processor ' isverycommoninsoftwareengineering。
因此,这里的“the number of CPUs”是指系统实际可以获取的CPU逻辑内核数。 对于单个CPU,为当前CPU的线程数
感谢Andrew Svetlov的帮助。
原文的链接如下。
https://bugs.python.org/issue 39097 & gt;