Install OpenCV and TensorFlow on ODROID C2
Install OpenCV and TensorFlow on ODROID C2
Here are the instructions we used for recently installing OpenCv and Tensorflow on ODROID C2
Hardware Setup
1. ODROID C2
2. 16GB eMMC module (minimum) + eMMC module reader board
3. 5V/2A Adapter
4. HDMI Screen and HDMI Cable
5. 16GB USB drive for swap (optional, preferred only if your eMMC is 16GB or smaller).
6. Ethernet cable to connect C2 directly to WiFi router.
These are the final set of instructions that worked for OpenCV Installation on latest image of Ubuntu Mate for Odroid C2 (aka Ubuntu 16.04.3 LTS (v2.4)) and also worked on Debian Stretch (Debian-Stretch64–1.0–20180202-C2.img.xz found here).
With Ubuntu Mate, login: odroid, pass: odroid, and all instructions below can be copy pasted as is
With Debian, login: root, pass: odroid, and none of the instructions below need sudo
Instructions after first boot of OS
sudo apt update sudo apt upgrade sudo apt dist-upgrade
Only in case of Ubuntu Mate downloaded from Odroid Wiki
sudo apt install linux-image-c2 sudo reboot
After it reboots (optional)
sudo apt autoremove
OpenCV Dependencies
sudo apt-get install build-essential cmake sudo apt-get install qt5-default libvtk6-dev sudo apt-get install zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev
This is all one line
sudo apt-get install libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev
sudo apt-get install libtbb-dev libeigen3-dev
We're working with python v3.5.2, but both Python2 and Python3 are probably already installed so check their installed versions using:
python2 --version #OR python3 --version
Replace python3 with python if you're interested in working with python v2.x.x
sudo apt-get install python3-dev python3-tk python3-numpy python3-mock sudo apt-get install ant default-jdk sudo apt-get install doxygen sudo apt-get install -y unzip wget
Note: Tensorflow 1.x may not working with Python versions above 3.5.x (3.6.x or 3.7.x). Tensorflow 2.x will need Python versions above 3.7.x.
Get OpenCV version 3.2.0 from the link in the instruction below. You can simply download the zip file by copy pasting the link into your browser as well. You can get the link to whatever version you need by going to opencv.org/releases.html and right-clicking on the Sources under that version.
wget https://github.com/opencv/opencv/archive/3.2.0.zip
Change 3.2.0 to whatever version you just downloaded
unzip 3.2.0.zip mv opencv-3.2.0 OpenCV cd OpenCV mkdir build cd build
cmake -DWITH_QT=ON -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF ..
This step will take about an hour or 2 on the Odroid C2. Takes a lot longer on the RPi3. If at any time the make command fails, type it again and it will pick up right where it left off.
make -j4 sudo make install sudo ldconfig
To check the OpenCV version installed
pkg-config --modversion opencv
During Installation of TensorFlow we had to do A LOT of google searches but have come up with these final instructions tested on Ubuntu Mate for Odroid C2 (so far).
To create a swap memory on the USB Drive (optional) in case you need some extra memory space besides the eMMC. Change sda1 to whatever the SDAx of the USB Drive is.
#Check sda of USB drive ls /dev/sda*
sudo blkid umount /dev/sda1 sudo mkswap /dev/sda1 sudo swapon /dev/sda1 sudo swapon
Install dependencies for Tensorflow
sudo apt-get install openjdk-8-jdk automake autoconf
unzip and wget can be removed if you already installed it above during OpenCV after the doxygen instruction or leave it in just for good measure
sudo apt-get install curl zip unzip libtool swig libpng12-dev pkg-config git zip g++ unzip wget xz-utils sudo apt-get install python3-pip sudo -H pip3 install --upgrade pip
Check the latest version of TensorFlow you want to download from https://github.com/lhelontra/tensorflow-on-arm/releases and download the .whl file directly from the browser or use the wget command to do so (right click on the file you want to download and copy-paste its link in the command below). To work with Python3 on C2, make sure you install the file ending in -cp35-none-linux_aarch64.whl
Here's how to pick the correct version for you based on the name of the file:
For Python2 choose the file with cp27 in the name.
For Python3 choose the file with cp35 or cp37 in the name depending on the python version.
For Raspberry pi one/zero with openblas choose the file with linux_armv6l in the name.
For Raspberry pi 2/3 choose the file with linux_armv7l in the name (might also work on Odroid-XU4, but has not been tested by us yet), though Raspberry Pi now officially supports Tensorflow.
For Odroid-C2 choose the file with linux_aarch64 in the name.
wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.7.0/tensorflow-1.7.0-cp35-none-linux_aarch64.whl
Use the name of the downloaded file instead of tensorflow-1.7.0-cp35-none-linux_aarch64.whl
sudo pip3 install tensorflow-1.7.0-cp35-none-linux_aarch64.whl
To check installed version of TensorFlow
pip3 show tensorflow #OR pip3 list | grep tensorflow
If the pip3 install command did not work you’ll have to follow the remaining steps here: https://github.com/lhelontra/tensorflow-on-arm
But in our case it did work perfectly. Takes a while, so be patient.
Update:
If you are installing Tensorflow 1.11 or above you will also need to run the following commands before the install of the .whl file
sudo apt-get install python3-setuptools sudo apt-get install curl zip unzip libtool swig libpng-dev zlib1g-dev pkg-config git g++ wget xz-utils sudo apt-get install python3-numpy python3-dev python3-pip python3-mock sudo apt-get install libhdf5-dev
Before running the .py file of your tensorflow code, you might need to run the export command as shown below to avoid getting errors in the tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) line which is in most tensorflow codes IF AND ONLY IF on running the .py file normally gives any errors.
export CUDA_VISIBLE_DEVICES=0 python3 tfcodefilename.py
If you are installing Tensorflow Hub, the best way to do that would be to go to https://pypi.org/project/tensorflow-hub/#history, click on the release you need (v0.4.0 and above should work fine), click on Download files and download the .whl file. You can install that using the command:
sudo pip3 install tensorflow_hub-0.6.0-py2.py3-none-any.whl
ERRORS
Now to check if tensorflow or tensorflow_hub is working with python3, type:
python3 >>> import tensorflow >>> import tensorflow_hub
If the tensorflow import returns an error ImportError: /usr/lib/aarch64-linux-gnu/libstdc++.so.6:version 'GLIBCXX_x.x.xx' not found..., where x.x.xx is some version number, then exit() from python, and type the following command:
sudo apt install libstdc++6
This should solve the issue, try importing tensorflow in python again. If you still get the same error as before, check if the version of GLIBCXX exists:
strings /usr/lib/aarch64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
If the x.x.xx version you are looking for is not in the list returned then use these commands:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt upgrade
You should now be able to import tensorflow in python3
For any errors and problems you face, post them in the comments below.