问题描述
我正在Linux上的C ++中使用TensorFlow C API加载人脸检测模型以进行推理。 TensorFlow生成多个线程,我想限制或限制该过程使用一个且仅一个线程。如何限制TensorFlow C API仅生成一个线程。
Linux命令lscpu
显示cpu = 8,而top -H -b -n1 | grep validate11 | wc -l
使用以下代码后返回8
Graph = TF_NewGraph();
Status = TF_NewStatus();
Sessionopts = TF_NewSessionoptions();
// limit number of threads
uint8_t intra_op_parallelism_threads = 1;
uint8_t inter_op_parallelism_threads = 1;
uint8_t device_count = 1;//device_count limits the number of cpus.**strong text**
uint8_t config[15] = {0xa,0x7,0xa,0x3,0x43,0x50,0x55,0x10,device_count,intra_op_parallelism_threads,0x28,0x40,0x1};
TF_SetConfig(Sessionopts,(void*)config,13,Status);
if (TF_GetCode(Status)!= TF_OK)
std::cout << "\nERROR: " << TF_Message(Status);
Runopts = NULL;
// load model
Session = TF_LoadSessionFromSavedModel(Sessionopts,Runopts,saved_model_dir,&tags,ntags,Graph,NULL,Status);
if( TF_GetCode(Status) != TF_OK ) {
std::cout << "\nERROR: Failed to load SavedModel." << TF_Message(Status);
return -1; }
assert( TF_GetCode(Status) == TF_OK);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)