TensorFlow Protobuf版本不匹配

Jas*_*Ren 3 c++ protocol-buffers tensorflow

我已经通过安装TensorFlow virtualenv。而且效果很好。

现在,我想使用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.
Run Code Online (Sandbox Code Playgroud)

在virtualenv中:

$ pip show protobuf
Name: protobuf
Version: 3.4.0
Summary: Protocol Buffers
Run Code Online (Sandbox Code Playgroud)

并在外壳中:

$ protoc --version
libprotoc 3.4.0
Run Code Online (Sandbox Code Playgroud)

我曾经protobuf-2.6.1在自己的环境中使用过,但现在升级到3.4.0

Ubuntu 16.04

jde*_*esa 8

问题是TensorFlow编译过程使用拉自身的协议缓冲区分配。从TensorFlow v1.3.0开始,此分发是协议缓冲区3.3.0。如果要将自己的C ++代码与TensorFlow生成的标头混合使用,则需要使用完全相同的版本(或仅使用脚本来使用Bazel下载的发行版)。

另一种选择是使用protoc原始消息描述文件中的标题生成自己的标题。

编辑:

TensorFlow使用的库的版本当前(TF v1.9)在中定义tensorflow/workspace.bzl。原则上,应该可以生成定制版本的TensorFlow,并在其中更改库的特定所需版本,只要它与TensorFlow和所有其他依赖项兼容(请注意,出于源中解释的原因,有三个HTTP档案为协议缓冲区,protobuf_archivecom_google_protobufcom_google_protobuf_cc,所以你需要给他们三个修改)。

  • @JasonRen是的,`libprotobuf9v5`是Ubuntu中的C ++协议缓冲区运行时库。看来Gnome本身正在使用协议缓冲区,因此删除它不是一个好主意。您需要编译较新的版本,并配置编译器和链接器以选择正确的头和库(并且,正如我所说,更喜欢静态链接,否则您的程序将尝试加载系统中安装的旧版本并失败)。 (2认同)