win10 tensorflow1.8 c++ set_visible_device_list / SetDefaultDevice 问题解决

1.问题描述

使用CMake编译tensorflow1.8的c++版本,得到了tensorflow.lib和tensorflow.dll,但是在使用下面所示的方法

tensorflow::graph::SetDefaultDevice("/device:GPU:0", &graph_def);

或者

tensorflow::ConfigProto* config = &session_options.config;
    config->mutable_gpu_options()->set_allow_growth(true);
    config->set_allow_soft_placement(true);
    config->mutable_gpu_options()->set_visible_device_list("0");

指定某一个session到指定的显卡时,出现了如下图所示的bug:
这里写图片描述

在google、stackoverflow、github上都没有找到解决方案,最终经过摸索得到解决方案为:
这里写图片描述
即在工程的属性中依赖编译出的和tensorflow相关的所有的lib文件,不要单纯只使用tensorflow.lib。

另外,本人测试:
不需要tensorflow的版本 < 1.6;
也不需要在tensorflow/tf_version_script.lds中添加protobuf;

欢迎批评指正!

参考链接:https://github.com/tensorflow/tensorflow/issues/5379
https://github.com/tensorflow/tensorflow/issues/16291
https://github.com/tensorflow/tensorflow/issues/5379
https://github.com/tensorflow/tensorflow/issues/18861
https://github.com/tensorflow/tensorflow/issues/19083

猜你喜欢

转载自blog.csdn.net/cdknight_happy/article/details/81100554