Skip to content

Tengine Lite Quick Start Guide

BUG1989 edited this page May 6, 2021 · 1 revision

Documentation

Online Documentation

Tengine Lite Quick Start Guide

Tengine Lite is an excellent lightweight end-to-side/embedded environment deep neural network inference engine. Compatible with multiple operating systems and deep learning algorithms, AIoT development kit based on AI reasoning framework. This document will take the classification model (TensorFlow MobileNetv1 model) as an example on the x86 Linux platform to take you quickly to get started with Tengine Lite.

Linux local compilation (support arm32, arm64, x86)

Download code

$ git clone https://github.com/OAID/Tengine/ Tengine-Lite

Install the required tools and dependent libraries

Before starting to compile Tengine-Lite, you need to confirm that you have installed cmake, g++, if not, you can install it through the following instructions:

$ sudo apt install cmake g++

Model Zoo

  • We provide tmfile files of common open source models, you can find them here Tengine Model zoo(Password: hhgc )

  • You can also use convert_model_to_tm to convert the mobilenet.pb model into a Tengine model. Refer to Model Conversion Tool

When you get the Tengine model file such as mobilenet.tmfile, you can use Tengine Lite to happily develop applications on various platforms.

Common API introduction

The core API of Tengine Lite is as follows:

  • init_tengine

Initialize Tengine Lite, this function only needs to be called once in the program.

  • create_graph

Create Tengine Lite calculation graph.

  • prerun_graph

Pre-run, prepare the resources required for computational graph inference.

  • run_graph

Start Tengine Lite calculation graph inference.

  • postrun_graph

Stop the graph and release the resources occupied by the graph.

  • destroy_graph

Destroy the graph.

The postrun_graph and destroy_graph are called after the model inference is executed, and they are generally called continuously.

Use Tengine Lite C/C++ API to develop mobilenet image classification code

Tengine provides C and C++ API for users to use. Here we use Tengine C++ API to show how to run the MobileNetv1 network model to realize the image classification function, so that you can quickly get started with Tengine C++ API. We will use detailed code comments in the code to facilitate you to familiarize yourself with the functions of Tengine's core API and develop your own code faster. Here, we use the tiger cat picture that is loved by industry practitioners in this cat era as the test picture.

Test code

Example of test code: ./example/tm_classificaton.c

Compile

Refer to build.sh in the root directory, take local compilation (x86) as an example, enter the command as follows:

mkdir -p build
pushd build
cmake ..
make -j4 && make install
popd

After the compilation is complete, if there is a libtengine-lite.so file in the build/install/lib directory, the compilation is successful.

ls /build/install/lib
libtengine-lite.so

The classification demo (tm_classification) now exists in the ./build/install/bin directory.

operation result

Find mobilenet.tmfile and synset_words.txt in the folder Tengine_models/classification/mobilenet/ you just downloaded.

Download the test picture (cat.jpg) and the model file (mobilenet.tmfile) in the root directory of Tengine-Lite,

Just run the following command:

export LD_LIBRARY_PATH=./build/install/lib
./build/install/example/tm_classification -m mobilenet.tmfile -i cat.jpg -g 224,224 -s 0.017,0.017,0.017 -w 104.007,116.669,122.679

The results are as follows:

tengine-lite library version: 1.4-dev

model file: mobilenet.tmfile
image file: cat.jpg
img_h, img_w, scale[3], mean[3]: 224 224, 0.017 0.017 0.017, 104.0 116.7 122.7
Repeat 1 times, thread 1, avg time 30.53 ms, max_time 30.53 ms, min_time 30.53 ms
--------------------------------------
8.574144, 282
7.880117, 277
7.812573, 278
7.286458, 263
6.357486, 281
--------------------------------------

Combined with the synset_words.txt file, we have successfully classified the test picture as a tiger cat. At this point, the most basic started guide has been completed. Friends can explore on their own examples. We will also update various tutorial examples from time to time to everyone~

...\(^0^)/...