我已经通过 virtualenv
安装了 TensorFlow。而且效果很好。
现在我想使用 C++ 加载模型并进行预测。但是由于 protobuf 版本不匹配,我无法编译我的程序。错误如:
tensorflow/core/framework/device_attributes.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
#error This file was generated by an older version of protoc which is
^
tensorflow/core/framework/device_attributes.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
^
tensorflow/core/framework/device_attributes.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
在虚拟环境中:
$ pip show protobuf
Name: protobuf
Version: 3.4.0
Summary: Protocol Buffers
在外壳中:
$ protoc --version
libprotoc 3.4.0
我曾经在我的环境中有 protobuf-2.6.1
但现在升级到 3.4.0
。
Ubuntu 16.04
原文由 Jason Ren 发布,翻译遵循 CC BY-SA 4.0 许可协议
问题在于 TensorFlow 编译过程使用了自己的协议缓冲区分布。从 TensorFlow v1.3.0 开始,此发行版是协议缓冲区 3.3.0。如果您想将自己的 C++ 代码与 TensorFlow 生成的标头混合使用,则需要使用完全相同的版本(或者只需使用脚本来使用 Bazel 下载的发行版)。
另一种选择是使用您自己的
protoc
从原始消息描述文件生成您自己的标头。编辑:
TensorFlow 使用的库版本目前(TF v1.9)定义在
tensorflow/workspace.bzl
中。原则上,只要它与 TensorFlow 和所有其他依赖项兼容(请注意,由于源代码中解释的原因,有是协议缓冲区的三个 HTTP 存档,protobuf_archive
、com_google_protobuf
和com_google_protobuf_cc
,因此您需要修改其中三个)。