c++ - Tensorflow分类使用c ++多次调用“创建的设备”
问题描述
我正在使用 tensorflow c++ 进行图像分类。我的部分代码如下,
std::vector<Tensor> outputs;
tensorflow::Tensor a(tensorflow::DT_BOOL, tensorflow::TensorShape({ }));
tensorflow::Tensor b(tensorflow::DT_FLOAT, tensorflow::TensorShape({ 1}));
tensorflow::Tensor c(tensorflow::DT_INT64, tensorflow::TensorShape({ 1 }));
b.vec<float>()(0) = 1.0;
a.scalar<bool>()() = false;
tensorflow::TensorShape shape = resized_tensor.shape();
Status run_status = session->Run({ { input_layer, resized_tensor },{ input_layer2, b } ,{ input_layer1, a } }, { output_layer }, {}, &outputs);
if (!run_status.ok()) {
LOG(ERROR) << "Running model failed: " << run_status;
return -1;
}
第一次调用Run()函数,输出如下:
2019-05-01 18:02:36.575459: I D:\projects\c++\tensorflow_GPU\tensorflow\core\common_runtime\gpu\gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3039 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
2019-05-01 18:02:36.620825: I D:\projects\c++\tensorflow_GPU\tensorflow\core\common_runtime\gpu\gpu_device.cc:1423] Adding visible gpu devices: 0
2019-05-01 18:02:36.624719: I D:\projects\c++\tensorflow_GPU\tensorflow\core\common_runtime\gpu\gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-05-01 18:02:36.628097: I D:\projects\c++\tensorflow_GPU\tensorflow\core\common_runtime\gpu\gpu_device.cc:917] 0
2019-05-01 18:02:36.631864: I D:\projects\c++\tensorflow_GPU\tensorflow\core\common_runtime\gpu\gpu_device.cc:930] 0: N
When I call the Run function again, It has the same message,
D:\projects\c++\tensorflow_GPU\tensorflow\core\common_runtime\gpu\gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3039 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
再次调用后如何避免 tensorflow 再次调用“已创建的 Tensorflow 设备” Run()
?会不会导致速度变慢?`
解决方案
推荐阅读
- python - 循环遍历具有列标题的行
- graphql - GraphQL Dataloader - 带有 load() 函数的全局变量
- tensorflow - 无法在我的 Colab 托管运行时中使用 tensorflow.keras.layers.CuDNNLSTM 或 keras.layers.CuDNNLSTM
- mysql - aws mysql 数据库(Amazon RDS)还是 mongodb?
- ruby-on-rails - 使用管理时添加请求参数时出现不允许的参数错误
- python - 我怎样才能使列表中的每个项目延迟发生?
- python - 如何将字符串添加到文件中的奇数行?
- javascript - 防止内表在嵌套 Html 表中过滤
- python - 集群内的集群是嵌套集群的数据表的多类集群
- java - 由于 android studio 和 adb.exe 的更新,我无法运行我的程序