Reputation: 125
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
Upvotes: 5
Views: 17271
Reputation: 9900
Had a similar issue which I struggled to resolve: compile script was always able to find an outdated version of protoc somewhere.
Checking protoc location:
which protoc # /usr/bin/protoc
sudo apt-get uninstall protobuf-compiler
conda uninstall protobuf
conda uninstall libprotobuf
exit # resign in
which means that there is a protoc binary /usr/bin/protoc
and header files here /usr/include/google/protoc
. Removing protoc installation would not necessarily remove header files inside include folder which would cause error to reappers. If you keep seeing the error after installing protobuf try cleaning include files for each protobuf locaiton.
After that feel free to download a compiled binary for your platform (in my case it was protoc-3.10.1-linux-x86_64.zip) and place it to a convenient location:
mkdir ~/tmp/
cd ~/tmp
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/protoc-3.10.1-linux-x86_64.zip
sudo rm -rf ./protoc
unzip protoc-3.10.1-linux-x86_64.zip -d protoc
chmod 755 -R protoc
BASE=/usr/local
sudo rm -rf $BASE/include/google/protobuf/
sudo cp protoc/bin/protoc $BASE/bin
sudo cp -R protoc/include/* $BASE/include
Despite seeing both"your protobuf version is older" and "your protobuf version is newer" during resolving the issue, simply latest version of protoc worked.
Upvotes: 0
Reputation: 59701
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).
Upvotes: 9
Reputation: 339
Please use the same version with tensorflow
to recompile your proto files. You will find it in tensorflow/tensorflow/contrib/makefile/gen/protobuf/bin/protoc
if you build tensorflow
from source using build_all_linux.sh
.
Upvotes: 0