How to work with Tensorflow on Odroid

Background and Before I start my instruction

Based on an article, our company needs an Odroid computer, and it MUST work with Tensorflow. Yes, the nightmare begins.

There is only one guideline available on the internet.

Here is the Link:
https://hackernoon.com/running-yolo-on-odroid-yolodroid-5a89481ec141

I have followed this instruction and practiced over 10+ time, but I can not get it to work.
No! Do not think about it. I spent at least ONE month on it.
The concept of the guideline will lead you to compile the Bazle and Tensorflow form source code! Each compile will take at least a half hour!

Therefore, Please flow me, I will save you a lot of time!

Get ready for Odroid

  1. Please go to the official website to download the image file, which will be found here:

https://wiki.odroid.com/odroid-xu4/os_images/linux/ubuntu_4.14/ubuntu_4.14

  1. Prepare the running environment:
    TensorFlow needs python, either python2.7 or python3.5+, and among of libraries to drive it.
    Therefore we need to use the following command lines to install it.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y pkg-config zip g++ zlib1g-dev unzip wget curl -y
sudo apt-get install -y gcc-4.8 g++-4.8 -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 100
apt-get install -y libstdc++6
sudo apt-get install -y libhdf5-serial-dev hdf5-tools

  1. We can choose Python2.7 or Python3.5+
    (Of course, we can install both without any problem)

Python2.7

sudo apt-get install python-pip python-numpy swig python-dev

Python3.5

sudo apt-get install python3-pip python3-numpy swig python3-dev 

Then, upgrade the Python pipeline to the latest version
Python 2.7

Curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

Python 3

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
  1. Once the Python installation is finished, we need to install some python libraries as well.

Python2.7

pip2 install h5py six numpy wheel mock

Python3.5

pip3 install h5py six numpy wheel mock
  1. Download and install pre-compiled TensorFlow
    Thanks for lhelontra who pre-compiled the TensorFlow and release to Github. He saved a lot of time for us.
    Souce: https://github.com/lhelontra/tensorflow-on-arm/releases

Python2.7

wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.11.0/tensorflow-1.11.0-cp27-none-linux_armv7l.whl
pip2 install ./tensorflow-1.11.0-cp27-none-linux_armv7l.whl

Python3.5

wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.11.0/tensorflow-1.11.0-cp35-none-linux_armv7l.whl
pip3 install ./tensorflow-1.11.0-cp35-none-linux_armv7l.whl

Note: tensorflow-1.11.0-cp27-none-linux_armv7l.whl is for Python2.7, and tensorflow-1.11.0-cp35-none-linux_armv7l.whl is for Python3.5+.
We can not use python2.7 to install tensorflow-1.11.0-cp35-none-linux_armv7l.whl. Otherwise, we will get an error message like this:
tensorflow-1.11.0-cp35-none-linux_armv7l.whl is not a supported wheel on this platform.

How to work with Tensorflow on Odroid_第1张图片
Error Message
  1. After the installation completed, we can use the following command lines to verify the installation is successfully or not.

Python 2
python -c 'import tensorflow as tf; print(tf.__version__)'

Python 3
python3 -c 'import tensorflow as tf; print(tf.__version__)'

If it returned the version number properly, it means we have a TensorFlow ready!

Version Number

Share resources

At the same time, I also build a Docker image for this task.
Follow this instruction to install Docker, https://docs.docker.com/install/,then we could pull the docker image to the local machine and start using it.

Enjoy!
Docker File:https://github.com/infinitysky/Odroid_Tensorflow_Docker/tree/Dev

Docker hub :https://hub.docker.com/r/infinitysky/odroidtensorflow/

Common Error

  1. When we are using PIP to install h5py, it might shows this error message:
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0,
  from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:18,
  from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
  from /tmp/pip-install-U0QZSk/h5py/h5py/api_compat.h:26,
  from /tmp/pip-install-U0QZSk/h5py/h5py/defs.c:654:
  /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
  #warning "Using deprecated NumPy API, disable it by " \
  ^
  In file included from /tmp/pip-install-U0QZSk/h5py/h5py/defs.c:654:0:
  /tmp/pip-install-U0QZSk/h5py/h5py/api_compat.h:27:18: fatal error: hdf5.h: No such file or directory
  compilation terminated.
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
  Failed building wheel for h5py
  Running setup.py clean for h5py

This problem is caused by h5py libraries are missing.
It will disappear after we used this command to install the missing libraries.

sudo apt-get install libhdf5-serial-dev hdf5-tools

  1. TensorFlow is already installed, but I can not import it
    The Error message is like this.

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /usr/local/lib/python2.7/dist-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

This is error message means the library, which called libstdc++6, is missing.

Please follow these command lines to install the missing library.

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get -y upgrade
apt-get install -y libstdc++6

你可能感兴趣的:(How to work with Tensorflow on Odroid)