c++ - TensorFlow protobuf 版本不匹配

标签 c++ tensorflow protocol-buffers

我已经通过 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

在 shell 中:

$ protoc --version
libprotoc 3.4.0

我以前在我的环境中有 protobuf-2.6.1 但现在升级到 3.4.0

Ubuntu 16.04

最佳答案

问题是 TensorFlow 编译过程使用拉取它自己的 Protocol Buffer 分布。从 TensorFlow v1.3.0 开始,这个发行版是 protocol buffers 3.3.0。如果您想将自己的 C++ 代码与 TensorFlow 生成的 header 混合,则需要使用完全相同的版本(或者只需使用脚本来使用 Bazel 下载的分发版)。

另一种方法是使用您自己的 protoc 从原始消息描述文件生成您自己的 header 。

编辑:

TensorFlow 使用的库版本当前 (TF v1.9) 在 tensorflow/workspace.bzl 中定义.原则上,只要它与 TensorFlow 和所有其他依赖项兼容(请注意,出于源代码中解释的原因,有是 Protocol Buffer 的三个 HTTP 存档,protobuf_archivecom_google_protobufcom_google_protobuf_cc,因此您需要修改其中三个)。

关于c++ - TensorFlow protobuf 版本不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46235376/

相关文章:

machine-learning - 如何在 TensorFlow 中正确实现卷积的 dropout

.net - C# : How Are Boxed Value Types Handled 中的 Protocol Buffer

c++ - 当使用预构建步骤时,protoc.exe 会导致整个解决方案的重新编译

c++ - 当应用于命名空间范围内的类时,静态意味着什么?

c++ - 从文本文件中读取整数

c++ - 如何从另一个打开的表单读取和更改主表单内的变量?

tensorflow - TFLearn 无法正确加载具有形状的训练数据

tensorflow - 分布式 TensorFlow 中一台机器上的多个工作人员

c++ - Protocol Buffer 的 ASCII 安全序列化

c++ - 如何评估代码的复杂性 (Big-O)?