TNN - Q-engineering
Q-engineering
Q-engineering
Go to content
images/empty-GT_imagea-1-.png
Install TNN framework on Raspberry Pi 4

Install TNN deep learning framework on a Raspberry Pi 4.

Last updated: April 21, 2022

Introduction.

This page will guide you through the installation of Tencent's TNN framework on a Raspberry Pi 4. The given C ++ code examples are written in the Code::Blocks IDE for the Raspberry Pi 4. We only guide you through the basics, so in the end, you can build your application. For more information about the TNN library, see: https://github.com/Tencent/TNN. Perhaps unnecessarily, but the installation is the C ++ version. It is not suitable for Python.

Dependencies.

The TNN framework has no dependencies that need to be pre-installed. OpenCV would be useful, but not necessary.

Version check.
Please check your operating system before installing ncnn on your Raspberry Pi 4. Run the command getconf LONG_BIT and verify your version.

Version check

In case of a 64-bit operating system, please check also your C++ compiler with the command gcc -v. It must also be an aarch64-linux-gnu version. In case of a different gcc version, reinstall the whole operating system with the latest version. The guide is found here: Install 64 bit OS on Raspberry Pi 4. You must have a 64-bit C ++ compiler as we are going to build the ncnn libraries.
Also note the zram swap size of more than 3 Gbyte after installation according to our instructions.

VersionCheck_64

Installation.

Install OpenCV first if it is not already installed. The installation guide is here and takes about an hour.
The entire installation of TNN on a Raspberry is as follows.
# check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# install dependencies
$ sudo apt-get install cmake wget
$ sudo apt-get install build-essential gcc g++
# download TNN
$ git clone --depth=1 https://github.com/Tencent/TNN.git
# install TNN
$ cd TNN
$ mkdir build
$ cd build
# build 64-bit TNN
$ cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_SYSTEM_NAME=Linux \
-D CMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-D CMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
-D TNN_ARM_ENABLE=ON \
-D TNN_TEST_ENABLE=ON \
-D TNN_CPU_ENABLE=ON \
-D TNN_RK_NPU_ENABLE=OFF \
-D TNN_OPENMP_ENABLE=ON \
-D TNN_OPENCL_ENABLE=OFF \
-D CMAKE_SYSTEM_PROCESSOR=aarch64 \
-D TNN_BUILD_SHARED=ON ..
$ make -j4
$ sudo make install
# copy output to dirs
$ sudo mkdir /usr/local/lib/tnn
$ sudo cp -r ../include/tnn /usr/local/include/tnn
$ sudo cp -r libTNN.* /usr/local/lib/tnn
# check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# install dependencies
$ sudo apt-get install cmake wget
$ sudo apt-get install build-essential gcc g++
# download TNN
$ git clone --depth=1 https://github.com/Tencent/TNN.git
# install TNN
$ cd TNN
$ mkdir build
$ cd build
# build 32-bit TNN
$ cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_SYSTEM_NAME=Linux \
-D CMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \
-D CMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \
-D TNN_ARM_ENABLE=ON \
-D TNN_TEST_ENABLE=ON \
-D TNN_CPU_ENABLE=ON \
-D TNN_RK_NPU_ENABLE=OFF \
-D TNN_OPENMP_ENABLE=ON \
-D TNN_OPENCL_ENABLE=OFF \
-D CMAKE_SYSTEM_PROCESSOR=arm \
-D TNN_BUILD_SHARED=ON ..
$ make -j4
$ sudo make install
# copy output to dirs
$ sudo mkdir /usr/local/lib/tnn
$ sudo cp -r ../include/tnn /usr/local/include/tnn
$ sudo cp -r libTNN.* /usr/local/lib/tnn
If everything went well, you will get two folders. One with all header files and one with the library as shown in the screen dumps.

IncludeDirTNN

LibDirTNN

Please note also the folder with the examples. Many different types of deep learning are covered here.

ExampleDirTNN

Deep learning software for Raspberry Pi
Deep learning examples for Raspberry Pi
images/GithubSmall.png
images/YouTubeSmall.png
images/SDcardSmall.png
Back to content