1 前言
在使用PyTorch搭建目标检测模型时,我们需要设置最佳的数据读取的进程数量;
我觉得,这个数量最好就设置成CPU的线程数量;
2 获取CPU的线程数量
获取CPU线程数量的代码:
from multiprocessing import cpu_count
print(cpu_count())
备注:
Python官方文档中关于
multiprocessing.
cpu_count
()的功能是这样说的:Return the number of CPUs in the system.
我先以为是文档描述的不准确,后来
Andrew Svetlov在我的Python文档Bug提交中告诉我:
CPU as a shortcut for "logical processor" is very common in software engineering.
所以这里的“the number of CPUs”实际上就是指的系统可以获取到的CPU逻辑核心数;如果是对于单个CPU而言,那就是当前CPU的线程数量;
3 致谢
感谢 Andrew Svetlov的帮助,
原文链接如下: