3rd Party Libraries#
A few tutorials listed will require the user to install a certain third party libraries on the host systems which will be required to run the application. These libraries are typically used for image loading, image processing, display and a few other libraries for deep learning runtime to run the pre/post processing in the auto crop model.
Python#
The only additional dependency needed for Python tutorials is:
pip install opencv-python
Note
Be sure to have your Python env active!
C++#
When on apt
-based Linux systems, installation is very simple.
Pre/Post Processing
Simply installing the memx-accl-plugins
library will pull in required the dependencies for pre/post processing (ONNX, TF, TFLite).
sudo apt install memx-accl-plugins
MemryX GUI Toolkit
Some C++ tutorials will use the MemryX GUI library, which can be installed via:
sudo apt install memx-utils-gui
On other Linuxes or Windows, manual installation is currently required. Future SDK revisions will help automate this process.
OpenCV
On Debian/Ubuntu systems, OpenCV can be installed using the commands:
sudo apt-get install build-essential
sudo apt-get install libopencv*-dev
On other Linux systems, OpenCV can be installed using the following commands:
# Install minimal prerequisites
sudo apt update && sudo apt install -y cmake g++ wget unzip
# Download and unpack sources (select the latest available version)
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip
unzip opencv.zip
unzip opencv_contrib.zip
# Create build directory and switch into it
mkdir -p build && cd build
# Configure
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x
# Build
cmake --build .
Note
You will have to use the absolute path to this build folder’s include and lib when building OpenCV applications!
On Windows, OpenCV can be installed using vcpkg :
git clone https://github.com/microsoft/vcpkg
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg install opencv:x64-windows
OnnxRuntime
wget -cO onnxruntime.tgz https://github.com/microsoft/onnxruntime/releases/download/v1.18.0/onnxruntime-linux-x64-1.18.0.tgz
tar -xvf onnxruntime.tgz
cd onnxruntime-linux-x64-1.18.0
sudo cp lib/* /lib/x86_64-linux-gnu/.
sudo cp -r include/ /usr/include/onnxruntime
#Download the latest windows zip from
https://github.com/microsoft/onnxruntime/releases/
#Extract the zip file to a desired location such as
C:\Downloads\onnxruntime
#Copy the files onnxruntime.dll and onnxruntime.lib to the application's excectable directory
#Change the procject settings of application to include the following directory
C:\Downloads\onnxruntime\include
#Change the procject settings of application to link the following files
onnxruntime.dll
onnxruntime.lib
Tensorflow
Tensorflow doesn’t provide an official C++ release. But it can be seen that the python install of tensorflow also gives us the reqired files for C++. The first step is to install tensorflow with pip
python3 -m pip install tensorflow
Now we need to find the site_packages where the python packages are stored and set that directory to an env variable. Genearally it can be found in,
export TENSORFLOW_PATH=$HOME/.local/lib/python3.10/site-packages
We need to copy the required shared object files and include files to system default locations,
sudo cp $TENSORFLOW_PATH/tensorflow/libtensorflow* /lib/x86_64-linux-gnu
sudo cp $TENSORFLOW_PATH/tensorflow/libtensorflow* /usr/lib
sudo cp -r $TENSORFLOW_PATH/tensorflow/include/* /usr/include/tensorflow/
TFLite
First, we will need to install some dependencies, libabsl-dev and libeigen3-dev:
sudo apt install libabsl-dev libeigen3-dev
Download the tensorflow source files:
wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.17.0.zip
unzip tensorflow.zip
rm tensorflow.zip
cd tensorflow-2.17.0
You will have to apply a patch to one of the tensorflow CMake file, otherwise, the cmake configuration might fail. In the following file:
tensorflow/lite/tools/cmake/modules/ml_dtypes/CMakeLists.txt
Apply the following patch:
-target_include_directories(ml_dtypes INTERFACE
- "${ML_DTYPES_SOURCE_DIR}"
- "${ML_DTYPES_SOURCE_DIR}/ml_dtypes")
+target_include_directories(ml_dtypes INTERFACE
+ "$<BUILD_INTERFACE:${ML_DTYPES_SOURCE_DIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
+ "$<BUILD_INTERFACE:${ML_DTYPES_SOURCE_DIR}/ml_dtypes>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ml_dtypes>")
Then, create a build/ folder in the tensorflow root directory:
mkdir build && cd build
Once in the build/ folder, you can perform the CMake configuration:
cmake ../tensorflow/lite/ \
-D TFLITE_ENABLE_INSTALL=ON \
-D FETCHCONTENT_FULLY_DISCONNECTED=OFF \
-D BUILD_SHARED_LIBS=ON \
-D CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
-D CMAKE_INSTALL_LIBDIR=/usr/lib/ \
-D CMAKE_INSTALL_INCLUDEDIR=/usr/include/
Note
If any error regarding flatbuffers are encountered, try the following steps from build folder and rerun the above cmake configuration steps
mkdir flatc-native-build && cd flatc-native-build
cmake ../../tensorflow/lite/tools/cmake/native_tools/flatbuffers/
cmake --build .
cd ..
CMake might display some error messages, ignore them:
CMake Error: install(EXPORT "tensorflow-liteTargets" ...) includes target "tensorflow-lite" which requires target "ruy" that is not in any export set.
CMake Error: install(EXPORT "tensorflow-liteTargets" ...) includes target "tensorflow-lite" which requires target " " that is not in any export set.
CMake Error: install(EXPORT "tensorflow-liteTargets" ...) includes target "tensorflow-lite" which requires target "XNNPACK" that is not in any export set.
You can then perform the build itself (this will take a while):
make -j $(nproc)
You can finally install Tensorflow Lite:
sudo make install