• Stars
    star
    347
  • Rank 122,141 (Top 3 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample projects for TensorFlow Lite in C++ with delegates such as GPU, EdgeTPU, XNNPACK, NNAPI

Play with tflite

  • Sample projects to use TensorFlow Lite in C++ for multi-platform
  • Typical project structure is like the following diagram
    • 00_doc/design.jpg

Target

  • Platform
    • Linux (x64)
    • Linux (armv7)
    • Linux (aarch64)
    • Android (aarch64)
    • Windows (x64). Visual Studio 2019
  • Delegate
    • Edge TPU
    • XNNPACK
    • GPU
    • NNAPI(CPU, GPU, DSP)

Usage

./main [input]

 - input = blank
    - use the default image file set in source code (main.cpp)
    - e.g. ./main
 - input = *.mp4, *.avi, *.webm
    - use video file
    - e.g. ./main test.mp4
 - input = *.jpg, *.png, *.bmp
    - use image file
    - e.g. ./main test.jpg
 - input = number (e.g. 0, 1, 2, ...)
    - use camera
    - e.g. ./main 0

How to build a project

0. Requirements

  • OpenCV 4.x

1. Download

  • Download source code and pre-built libraries
    git clone https://github.com/iwatake2222/play_with_tflite.git
    cd play_with_tflite
    git submodule update --init
    sh InferenceHelper/third_party/download_prebuilt_libraries.sh
  • Download models
    sh ./download_resource.sh

2-a. Build in Linux

cd pj_tflite_cls_mobilenet_v2   # for example
mkdir -p build && cd build
cmake ..
make
./main

2-b. Build in Windows (Visual Studio)

  • Configure and Generate a new project using cmake-gui for Visual Studio 2019 64-bit
    • Where is the source code : path-to-play_with_tflite/pj_tflite_cls_mobilenet_v2 (for example)
    • Where to build the binaries : path-to-build (any)
  • Open main.sln
  • Set main project as a startup project, then build and run!

2-c. Build in Android Studio

  • Please refer to
  • Copy resource directory to /storage/emulated/0/Android/data/com.iwatake.viewandroidtflite/files/Documents/resource
    • the directory will be created after running the app (so the first run should fail because model files cannot be read)
  • Modify ViewAndroid\app\src\main\cpp\CMakeLists.txt to select a image processor you want to use
    • set(ImageProcessor_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../../pj_tflite_cls_mobilenet_v2/image_processor")
    • replace pj_tflite_cls_mobilenet_v2 to another
  • By default, InferenceHelper::TENSORFLOW_LITE_DELEGATE_XNNPACK is used. You can modify ViewAndroid\app\src\main\cpp\CMakeLists.txt to select which delegate to use. It's better to use InferenceHelper::TENSORFLOW_LITE_GPU to get high performance.
    • You also need to select framework when calling InferenceHelper::create .

Note

Options (Delegate)

# Edge TPU
cmake .. -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_EDGETPU=on  -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_GPU=off -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_XNNPACK=off
cp libedgetpu.so.1.0 libedgetpu.so.1
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`
sudo LD_LIBRARY_PATH=./ ./main
# you may get "Segmentation fault (core dumped)" without sudo

# GPU
cmake .. -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_EDGETPU=off -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_GPU=on  -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_XNNPACK=off
# you may need `sudo apt install ocl-icd-opencl-dev` or `sudo apt install libgles2-mesa-dev`

# XNNPACK
cmake .. -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_EDGETPU=off -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_GPU=off -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_XNNPACK=on

# NNAPI (Note: You use Android for NNAPI. Therefore, you will modify CMakeLists.txt in Android Studio rather than the following command)
cmake .. -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_EDGETPU=off -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_GPU=off -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_XNNPACK=off -DINFERENCE_HELPER_ENABLE_TFLITE_DELEGATE_NNAPI=on

You also need to select framework when calling InferenceHelper::create .

EdgeTPU

NNAPI

By default, NNAPI will select the most appropreate accelerator for the model. You can specify which accelerator to use by yourself. Modify the following code in InferenceHelperTensorflowLite.cpp

// options.accelerator_name = "qti-default";
// options.accelerator_name = "qti-dsp";
// options.accelerator_name = "qti-gpu";

License

Acknowledgements

  • This project utilizes OSS (Open Source Software)
  • This project utilizes models from other projects:
    • Please find model_information.md in resource.zip

More Repositories

1

self-driving-ish_computer_vision_system

This project generates images you've probably seen in autonomous driving demo. Object Detection, Lane Detection, Road Segmentation, Depth Estimation using TensorRT
C++
354
star
2

InferenceHelper

C++ Helper Class for Deep Learning Inference Frameworks: TensorFlow Lite, TensorRT, OpenCV, OpenVINO, ncnn, MNN, SNPE, Arm NN, NNabla, ONNX Runtime, LibTorch, TensorFlow
C++
272
star
3

rotation_master

Provide conversion between the major representations of 3D rotation and visualize the orientation of a rigid body
C++
232
star
4

DigitalCamera_STM32

This is a project to create a digital camera with STM32 and OV7670
C
190
star
5

play_with_tensorrt

Sample projects for TensorRT in C++
C++
182
star
6

dear_ros_node_viewer

Dear RosNodeViewer: Visualize ROS2 Node Graph
Python
111
star
7

DeviceDriverLesson

組み込みLinuxデバイスドライバの実装方法
C
60
star
8

pico-mnist

Number recognition with MNIST on Raspberry Pi Pico + TensorFlow Lite for Microcontrollers
C++
59
star
9

opencv_sample

OpenCV Sample Code in C++
C++
54
star
10

rotop

top command for ROS 2
Python
47
star
11

play_with_mnn

Sample projects to use MNN. PoseNet, SemanticSegmentation, etc.
C++
33
star
12

pico-work

My playground for Raspberry Pi Pico with C/C++ SDK
Jupyter Notebook
31
star
13

pico-badapple

Bad Apple!! on Raspberry Pi Pico + OLED
C
26
star
14

pico-loud_talking_detector

A tinyML system using a Raspberry Pi Pico and TensorFlow Lite for Microcontrollers to detect loud talking. It can be utilized to encourage people to eat quietly to prevent the spread of the coronavirus and help in the fight against COVID
Jupyter Notebook
20
star
15

InferenceHelper_Sample

Sample projects for InferenceHelper, a Helper Class for Deep Learning Inference Frameworks: TensorFlow Lite, TensorRT, OpenCV, ncnn, MNN, SNPE, Arm NN, NNabla, ONNX Runtime, LibTorch, TensorFlow
C++
20
star
16

aiine_transform

Swapping face using Face Mesh with TensorFlow Lite
C++
19
star
17

cpp_project_in_github

Awesome C++ Project in GitHub
C++
18
star
18

OpenCV_CUDA

Sample code for OpenCV with GPU(CUDA) on Jetson Nano
C++
14
star
19

InferenceHelper_Sample_ROS

DNN Node Collection using Inference Helper in ROS2
C++
13
star
20

DigitalCamera_RaspberryPi

A project to create a digital camera with Raspberry Pi in Linux standard way such as ioctl
C++
13
star
21

opencv_sample_in_rust

OpenCV Sample Projects in Rust
Rust
12
star
22

ros2_monitor_grafana

Monitor ROS 2 topic status and provide a nice dashboard in Grafana
Python
12
star
23

bittle_controlled_by_pose

A project to control Petoi Bittle using human pose
C++
12
star
24

AR_Smart_Glasses_EdgeTPU

Home-built AR Smart Glasses using Edge TPU and Raspberry Pi
Python
12
star
25

ZYBO_IoT_Vivado

This is a Vivado project to create an IoT device with ZYBO (Zynq).
VHDL
12
star
26

generic-tflmicro

CMake project for TensorFlow Lite Micro
C++
11
star
27

VideoCompare

Tool to compare two video files, as well as two sets of still images
JavaScript
11
star
28

play_with_depthai

Sample projects to use DepthAI + OpenCV with OAK-D cameras in C++
C++
10
star
29

InferenceHelper_Binary

Provides pre-built libraries for InferenceHelper
Shell
9
star
30

RaspberryPiControllerQtPython

This is a project to control devices attached to Raspberry Pi
Python
9
star
31

FastGameOfLife

Fast Conway's Game of Life with OpenGL, OpenMP and CUDA
C
7
star
32

play_with_ncnn

Sample projects to use ncnn
C++
7
star
33

TDD_EmbeddedC

テスト駆動開発による組み込みプログラミング
C
7
star
34

ZYBO_HDMI_OUT

This is a Vivado project to output image data stored in DDR memory to TMDS output port.
VHDL
7
star
35

CNN_NumberDetector

Number Detect applications by CNN (Keras)
C++
6
star
36

visualize_imu

WIP
C++
5
star
37

imgui_test

Sample project to use ImGui + GLFW + OpenGL3
C++
5
star
38

android_bluetooth_rfcomm

Android sample project for Bluetooth RFCOMM
Java
5
star
39

VR_Hiking

VR application for hiking
C#
4
star
40

networkx2dearpygui

Python
4
star
41

Camera_STM32_StdLib

Digital Still Camera on STM32 with Standard Peripheral Libraries
C
4
star
42

LifeGame

the Game of Life (JavaScript)
JavaScript
4
star
43

ZYBO_IoT_PetaLinux

This is a PetaLinux project to create an IoT device with ZYBO (Zynq).
HTML
3
star
44

MoviePlayer_BlackWhite

ATmega328P
C
3
star
45

cmake_samples

CMake
3
star
46

Become_Dhalsim

Python
3
star
47

ZYBO_Portable_Mandelbrot

Portable Mandelbrot Set with ZYBO (Zynq)
Verilog
2
star
48

wasm_emscripten_test

CMake
2
star
49

ZYBO_IoT_SDK

This is a XSDK project to create an IoT device with ZYBO (Zynq).
C++
2
star
50

play_with_opengl

OpenGL + GLFW test projects
C++
2
star
51

aws_cloudformation_template

AWS CloudFormation template
Python
2
star
52

study_ros

Python
2
star
53

cmms

CMMS
Java
1
star
54

libjpeg_porting_microcontroller

Porting libjpeg to microcontrollers (without OS)
C
1
star
55

InputDeviceServer

Web application to display input device status on Raspberry Pi
C++
1
star
56

googletest_test

C++
1
star
57

3D_SpaceMouse

print HID value from 3D connexion space mouse (space navigator) on ubuntu
Python
1
star
58

TongueTwisterTeacher

TongueTwisterTeacher (Android App)
Java
1
star
59

Kalman_Filter

Test code for Kalman Filter
C++
1
star
60

CudaSampleApp

Sample project to use CUDA code with normal C/C++ console application as DLL library
C++
1
star
61

SDSOC_VARIOUS_IMPLEMENTATIONS

HTML
1
star
62

LedBlinkTDD

C++
1
star
63

rust_embedded_wio_bottom_up

Rust
1
star
64

RaspberryPiCrossCompileSetup

Raspberry Pi Setup Guide
C++
1
star
65

JetsonNanoTest

C++
1
star