Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow protobuf version mismatch

I've install TensorFlow via virtualenv. And it works well.

Now I want to load model using C++ and do prediction. But I fail to compile my program because of protobuf version mismatch. Error like:

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.

In virtualenv:

$ pip show protobuf
Name: protobuf
Version: 3.4.0
Summary: Protocol Buffers

And in shell:

$ protoc --version
libprotoc 3.4.0

I used to have protobuf-2.6.1 in my environment but now upgrade to 3.4.0.

ubuntu 16.04

like image 921
Jason Ren Avatar asked Sep 15 '17 08:09

Jason Ren


1 Answers

The problem is that the TensorFlow compilation process uses pulls its own distribution of protocol buffers. As of TensorFlow v1.3.0, this distribution is protocol buffers 3.3.0. If you want to mix your own C++ code with TensorFlow generated headers, you need to use that exact same version (or simply use a script to use the distribution downloaded by Bazel).

Another alternative is to generate your own headers with your own protoc from the original message description files.

EDIT:

The version of the library used by TensorFlow is currently (TF v1.9) defined in tensorflow/workspace.bzl. In principle, it should be possible to produce a custom build of TensorFlow with a particular desired version of the library changing it there, as long as it is compatible with TensorFlow and every other dependency (note that, for reasons explained in the source, there are three HTTP archives for Protocol Buffers, protobuf_archive, com_google_protobuf and com_google_protobuf_cc, so you would need to modify the three of them).

like image 127
jdehesa Avatar answered Oct 20 '22 09:10

jdehesa