Tensorflow and Protobuf....

Ok - so i compiled Tensorflow on my jetson as per instructions kindly delivered by

https://syed-ahmed.gitbooks.io/nvidia-jetson-tx2-recipes/content/first-question.html

now it seems that Tensorflow is working when i test the set up worked ok via the validation method from the install instructions which brings me to my query…

Ive got something working on my local machine im porting over to the jetson

When i run the script im getting an error re: protobuf

Using TensorFlow backend.
[libprotobuf FATAL google/protobuf/stubs/common.cc:61] This program requires version 3.1.0 of the Protocol Buffer runtime library, but the installed version is 2.6.1. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in “external/protobuf/src/google/protobuf/any.pb.cc”.)
terminate called after throwing an instance of ‘google::protobuf::FatalException’
what(): This program requires version 3.1.0 of the Protocol Buffer runtime library, but the installed version is 2.6.1. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in “external/protobuf/src/google/protobuf/any.pb.cc”.)
Aborted (core dumped)

Now in the github account there a note saying

5 # We use the release distribution so that we don’t have to build protobuf
6 #
7 INSTALL_DIR=$PWD
8 cd $HOME
9 wget --no-check-certificate https://github.com/bazelbuild/bazel/releases/download/0.4.5/bazel-0.4.5-dist.zip

https://github.com/jetsonhacks/installTensorFlowTX2/search?utf8=✓&q=protobuf&type=

and tensorflow does seem to be installed on the jetson so im slightly baffled why it’s not working?

I have installed 3.1.0 protobuf.whl however i dont think tensorflow has linked against it. I’m slightly concerned that installing tensorflow without the above install script is going to be a bit of a pain. Is there a simple way to upgrade and link to protobuf 3.1.0 or am i missing something here?

whl files install python modules, typically what you’ll find in /usr/lib/python2.7 and such.

Tensorflow is complaining about the shared library version of protobuf, typically what you’ll find in /usr/lib/

Typically, the protobuf library version is dependent on what version of the host OS you’re using, so for example, if it’s built on Ubuntu 16.04, it proabably won’t run on 14.04.
If it’s failing on the same system where it was compiled, then you have to figure out where the libprotobuf binary lives, and why it’s different from what it was compiled with. There are many reasons this could happen, including library search paths, separate versions used by the Python installer being picked up by the TensorFlow code, and so forth.

I understand the headers could be pointing to the wrong place but what im struggling to grasp is why does tensorflow seem to run ok when importing tensforflow in python yet when i run it in a script its throwing this error?

Ive tried important tensorflow as TF first in order to avoid possible library loading conflicts as some talk of this onine but still no luck.

Im happy to rebuild tensorflow again if thats what it takes but i’m concerned its not going to solve the problem as i would be more or less following the build i did originally.

One option could be to remove tensorflow etc and protobuf, install protobuf 3.1.0 and then go back through the steps above?

for installation u may use as a reference: http://www.jetsonhacks.com/2017/04/02/tensorflow-on-nvidia-jetson-tx2-development-kit/

Presumably, because it’s picking up a different instance of the shared library?

Try this:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install locate
sudo updatedb
locate libtensor
locate libproto

This should show various installations of Tensorflow and Protobuf that exist on your system. If there’s more than one, that would explain the discrepancy.

Ok all done - some intersting stuff…

$ locate libtensor
/home/ubuntu/tensorflow/tensorflow/tools/ci_build/builds/libtensorflow.sh
/home/ubuntu/tensorflow/tensorflow/tools/ci_build/linux/libtensorflow.sh
/home/ubuntu/tensorflow/tensorflow/tools/ci_build/linux/libtensorflow_cpu.sh
/home/ubuntu/tensorflow/tensorflow/tools/ci_build/linux/libtensorflow_docker.sh
/home/ubuntu/tensorflow/tensorflow/tools/ci_build/osx/libtensorflow_cpu.sh
/home/ubuntu/tensorflow/tensorflow/tools/ci_build/osx/libtensorflow_gpu.sh
/home/ubuntu/tensorflow/tensorflow/tools/lib_package/libtensorflow_test.c
/home/ubuntu/tensorflow/tensorflow/tools/lib_package/libtensorflow_test.sh

$ locate libproto
/home/ubuntu/rawto/protobuf/cmake/libprotobuf-lite.cmake
/home/ubuntu/rawto/protobuf/cmake/libprotobuf.cmake
/home/ubuntu/rawto/protobuf/cmake/libprotoc.cmake
/home/ubuntu/rawto/protobuf/src/libprotobuf-lite.map
/home/ubuntu/rawto/protobuf/src/libprotobuf.map
/home/ubuntu/rawto/protobuf/src/libprotoc.map
/usr/lib/aarch64-linux-gnu/libprotobuf-lite.so.9
/usr/lib/aarch64-linux-gnu/libprotobuf-lite.so.9.0.1
/usr/lib/aarch64-linux-gnu/libprotobuf.so.9
/usr/lib/aarch64-linux-gnu/libprotobuf.so.9.0.1
/usr/lib/aarch64-linux-gnu/libprotoc.so.9
/usr/lib/aarch64-linux-gnu/libprotoc.so.9.0.1
/usr/lib/chromium-browser/libprotobuf_lite.so
/usr/lib/libreoffice/program/libprotocolhandlerlo.so
/usr/lib/pulse-8.0/modules/libprotocol-cli.so
/usr/lib/pulse-8.0/modules/libprotocol-http.so
/usr/lib/pulse-8.0/modules/libprotocol-native.so
/usr/lib/pulse-8.0/modules/libprotocol-simple.so
/usr/share/doc/libprotobuf-lite9v5
/usr/share/doc/libprotobuf-lite9v5/changelog.Debian.gz
/usr/share/doc/libprotobuf-lite9v5/copyright
/usr/share/doc/libprotobuf9v5
/usr/share/doc/libprotobuf9v5/changelog.Debian.gz
/usr/share/doc/libprotobuf9v5/copyright
/usr/share/doc/libprotoc9v5
/usr/share/doc/libprotoc9v5/changelog.Debian.gz
/usr/share/doc/libprotoc9v5/copyright
/var/cache/apt/archives/libprotobuf-dev_2.6.1-1.3_arm64.deb
/var/cache/apt/archives/libprotoc9v5_2.6.1-1.3_arm64.deb
/var/lib/dpkg/info/libprotobuf-lite9v5:arm64.list
/var/lib/dpkg/info/libprotobuf-lite9v5:arm64.md5sums
/var/lib/dpkg/info/libprotobuf-lite9v5:arm64.shlibs
/var/lib/dpkg/info/libprotobuf-lite9v5:arm64.triggers
/var/lib/dpkg/info/libprotobuf9v5:arm64.list
/var/lib/dpkg/info/libprotobuf9v5:arm64.md5sums
/var/lib/dpkg/info/libprotobuf9v5:arm64.shlibs
/var/lib/dpkg/info/libprotobuf9v5:arm64.triggers
/var/lib/dpkg/info/libprotoc9v5:arm64.list
/var/lib/dpkg/info/libprotoc9v5:arm64.md5sums
/var/lib/dpkg/info/libprotoc9v5:arm64.shlibs
/var/lib/dpkg/info/libprotoc9v5:arm64.triggers

$ protoc --version
libprotoc 2.6.1

ok so looks like i have version 2.6.1 - fine BUT i did download a .whl for 3.1.0 and when i run pip install i’m being told its already installed

pip install protobuf-3.1.0-py2.py3-none-any.whl
Requirement already satisfied: protobuf==3.1.0 from file:///home/ubuntu/protobuf-3.1.0-py2.py3-none-any.whl in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.1.0)
Requirement already satisfied: six>=1.9 in /usr/local/lib/python2.7/dist-packages (from protobuf==3.1.0)
Requirement already satisfied: packaging>=16.8 in /usr/local/lib/python2.7/dist-packages (from setuptools->protobuf==3.1.0)
Requirement already satisfied: appdirs>=1.4.0 in /usr/local/lib/python2.7/dist-packages (from setuptools->protobuf==3.1.0)
Requirement already satisfied: pyparsing in /usr/local/lib/python2.7/dist-packages (from packaging>=16.8->setuptools->protobuf==3.1.0)

/usr/lib/aarch64-linux-gnu/libprotobuf.so.9.0.1

This means that C/C++ code will find version 2.6.

pip install protobuf-3.1.0-py2.py3-none-any.whl

This means that Python code will find version 3.1.

You need to upgrade the C++ (system) library to match version 3.1.

I don’t think there’s a default package on Ubuntu that does this, so you will have to either hack it by building your own and installing it on top of the system package, or you will have to find a deb package that has a newer version that will still install on your current system.

Hmmmm - i would have thought using a virtual environment should have insulated me against this?

Ive tried a whole bunch of things here and nothing is really working out.

It would be great if you could pin point me to a deb package that has a newer version @snarky ?

It would be great if you could pin point me to a deb package that has a newer version

I’m not sure such a version exists for Ubuntu. You may have to build it yourself.

This, unfortunately, often happens when trying to build some parts of a Linux system yourself and use some parts from upstream :-(

This is why I try to stay with stock distributions as much as possible. Once I start pulling on the “I do this custom” thread, what ends up happening is that everything unravels, and I have to build larger parts of the system custom than I’d initially hoped for.

ok - i have actually managed to build 3.1.0 in C++ from here

https://github.com/google/protobuf/releases

(just to check this is what you meant when you said “build” ) ?

However despite the fact now when i run these commands (which all look good!) im still hitting this error when i run my script

ubuntu@tegra-ubuntu:~/rawto$ /usr/bin/protoc --version
libprotoc 3.1.0
ubuntu@tegra-ubuntu:~/rawto$ which protoc
/usr/local/bin/protoc
ubuntu@tegra-ubuntu:~/rawto$ protoc --version
libprotoc 3.1.0

It sounds stupid but i would have thought someone else would be getting in to this trouble as i cant be the only person running / attempting to run TF on the jetson…i’m guessing reflashing and starting over from scratch wont help

use as the reference: http://www.jetsonhacks.com/2017/04/02/tensorflow-on-nvidia-jetson-tx2-development-kit/

Where does libprotoc.so live?
Did you replace the one that came with the system?
(It’s a hack to just overwrite it, but you gotta do what you gotta do …)

Ok so…

ls $ /usr/lib/aarch64-linux-gnu/libprotobuf.so*

Gave me…

$ /usr/lib/aarch64-linux-gnu/libprotobuf.so.9 /usr/lib/aarch64-linux-gnu/libprotobuf.so.9.0.1

I did try

cp /usr/lib/aarch64-linux-gnu/libprotobuf.so.9 /usr/lib/aarch64-linux-gnu/libprotobuf.so

and it doesnt really seemed to have helped, could try rebuilding and instead if you think its worth while?

ln -s /usr/lib/aarch64-linux-gnu/libprotobuf.so.9 /usr/lib/aarch64-linux-gnu/libprotobuf.so

Also re: hacks etc - i’m not precious what so ever on how this gets solved / the sustainability of the tech stack moving forward. Its to get a proof of concept out of the door and i can make it stable / look at alternative approaches later!

cp /usr/lib/aarch64-linux-gnu/libprotobuf.so.9 /usr/lib/aarch64-linux-gnu/libprotobuf.so

That’s unlikely to work right, although I guess it checks whether the problem is a missing .so itself.

Did you run “sudo ldconfig” after you did “make install” for the protobufs?

You can also start programs with LD_LIBRARY_PATH=… to tell the dynamic loader where to look for dynamic libraries.

So, paths forward you can try:

  1. try with LD_LIBRARY_PATH=…

  2. start with “strace” and look through the output to see what library it’s looking for / finding when it’s loading it, and try to work backwards from there

  3. build everything from source, configured to look at the things you build rather than system libraries. (Or configure to install in the system library directories, rather than /usr/local, and “sudo make install” after building.)

It’s quite possible there’s something dumb that I’ve overlooked, but as this isn’t my system and I can’t poke at it, that’s all I can think of to try.

I found a work around…

basically i went through the scripts line by line and found that it was something to do with the import of TF and keras… moving these two to the start of my import statements seems to have fixed that particular issue.

import tensorflow as tf
from keras.models import Sequential (previously in another script which was causing the protobuf when it was called)

Thanks for the guidance @snarky - it really helped a lot and i understand whats fundamentally going on to a point but fixing it via that route seems like a real pain!

fixing it via that route seems like a real pain!

You and me both :-)
Glad it’s running for you.

Hi @yes_yes_yall,

Can you please share how did you manage to install protobuf 3.1.0 eventually on tthe TX2?
I have the same problem and wasn’t able to resolve it by importing tf to the start of the code (I don’t even use keras)…

Many thanks,
Matan

Hi Matan,

Can you share any info on what language you are using or if you are using another API etc? Might help trouble shooting for us both ! I’d forget about installing protobuf if you need to ugrade it becuase i just couldnt find a distro in the end that was compatible with the jetson and no one here could really do much for me (not for lack of trying and @Snarky helped a lot for me to drill down on certain things).

Do you import tf or any tools from tf more than once in your code?

Hi Matan,

Can you share any info on what language you are using or if you are using another API etc? Might help trouble shooting for us both ! I’d forget about installing protobuf if you need to ugrade it becuase i just couldnt find a distro in the end that was compatible with the jetson and no one here could really do much for me (not for lack of trying and @Snarky helped a lot for me to drill down on certain things).

Do you import tf or any tools from tf more than once in your code?