本文首发于个人博客https://kezunlin.me/post/8d877e63/,欢迎阅读!
cpp caffe net run in multiple threads
Guide
set_mode
Caffe fails to use GPU in a new thread ???see here
the `Caffe::mode_` variable that controls this is thread-local,
so ensure you’re calling `caffe.set_mode_gpu()` in each thread
before running any Caffe functions. That should solve your issue.
Caffe set_mode GPU 在多线程下失效
在main thread中设置GPU模式,在worker thread中调用网络进行检测,
GPU模式不起效,默认仍然使用CPU模式,所以速度很慢,和GPU相比慢了
10倍左右。
解决方案:在子线程中set_mode,然后调用网络进行检测。
(1)创建网络在main thread。static 网络存储在全局静态数据区。