All Projects → TannerGilbert → Tensorflow-Lite-Object-Detection-with-the-Tensorflow-Object-Detection-API

TannerGilbert / Tensorflow-Lite-Object-Detection-with-the-Tensorflow-Object-Detection-API

Licence: other
Run object detection on edge devices using Tensorflow Lite

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Tensorflow-Lite-Object-Detection-with-the-Tensorflow-Object-Detection-API

Tensorflow-Object-Detection-API-train-custom-Mask-R-CNN-model
Train a Mask R-CNN model with the Tensorflow Object Detection API
Stars: ✭ 59 (+156.52%)
Mutual labels:  tensorflow-object-detection-api, tensorflow-object-detection
Selfie2Anime-with-TFLite
How to create Selfie2Anime from tflite model to Android.
Stars: ✭ 70 (+204.35%)
Mutual labels:  tensorflow-lite
MobileNetV2-PoseEstimation
Tensorflow based Fast Pose estimation. OpenVINO, Tensorflow Lite, NCS, NCS2 + Python.
Stars: ✭ 99 (+330.43%)
Mutual labels:  tensorflow-lite
react-native-tflite
Tensorflow Lite for React Native (now just support ios)
Stars: ✭ 20 (-13.04%)
Mutual labels:  tensorflow-lite
mruby-tflite
MRuby binding for TensorFlow Lite
Stars: ✭ 14 (-39.13%)
Mutual labels:  tensorflow-lite
Delta
DELTA is a deep learning based natural language and speech processing platform.
Stars: ✭ 1,479 (+6330.43%)
Mutual labels:  tensorflow-lite
google-coral
Community gathering point for Google Coral dev board and dongle knowledge.
Stars: ✭ 81 (+252.17%)
Mutual labels:  tensorflow-lite
tflite flutter helper
TensorFlow Lite Flutter Helper Library
Stars: ✭ 85 (+269.57%)
Mutual labels:  tensorflow-lite
Tensorflow-lite-kotlin-samples
📌This repo contains the kotlin implementation of TensorflowLite Example Android Apps🚀
Stars: ✭ 17 (-26.09%)
Mutual labels:  tensorflow-lite
Counting-people-video
Counting the number of people in a video.
Stars: ✭ 60 (+160.87%)
Mutual labels:  tensorflow-object-detection-api
pico-mnist
Number recognition with MNIST on Raspberry Pi Pico + TensorFlow Lite for Microcontrollers
Stars: ✭ 44 (+91.3%)
Mutual labels:  tensorflow-lite
BodyPoseEstimationAndroid
🙋‍♂️Use Body Pose Estimation to perform pose matching on Android
Stars: ✭ 15 (-34.78%)
Mutual labels:  tensorflow-lite
Open nsfw android
🔥🔥🔥色情图片离线识别,基于TensorFlow实现。识别只需20ms,可断网测试,成功率99%,调用只要一行代码,从雅虎的开源项目open_nsfw移植,该模型文件可用于iOS、java、C++等平台
Stars: ✭ 1,586 (+6795.65%)
Mutual labels:  tensorflow-lite
TFLite-Mobile-Generic-Object-Localizer
Python TFLite scripts for detecting objects of any class in an image without knowing their label.
Stars: ✭ 42 (+82.61%)
Mutual labels:  tensorflow-lite
Vott
Visual Object Tagging Tool: An electron app for building end to end Object Detection Models from Images and Videos.
Stars: ✭ 3,684 (+15917.39%)
Mutual labels:  tensorflow-object-detection-api
NARUTO-HandSignDetection
物体検出を用いてNARUTOの印(子~亥、壬、合掌)を検出するモデルとサンプルプログラムです。このリポジトリでは、YOLOXを使用しています(This is a model and sample program that detects NARUTO's hand sign using object detection. This repository use YOLOX.)
Stars: ✭ 186 (+708.7%)
Mutual labels:  tensorflow-lite
TFLite-ModelMaker-EfficientDet-Colab-Hands-On
TensorFlow Lite Model Makerで物体検出を行うハンズオン用資料です(Hands-on for object detection with TensorFlow Lite Model Maker)
Stars: ✭ 15 (-34.78%)
Mutual labels:  tensorflow-lite
Tensorflow Lite Demo
An example Android application using TensorFLow Lite is available on Tensorflow github, Creating a project directory in tensorflow/tensorflow/contrib/lite/ , which is builted on Android studio 3.0.I have download the model of tflite format and complie the libtensorflowlite_jni.so and libtensorflowlite.jar
Stars: ✭ 15 (-34.78%)
Mutual labels:  tensorflow-lite
awesome-ml-demos-with-ios
The challenge projects for Inferencing machine learning models on iOS
Stars: ✭ 1,040 (+4421.74%)
Mutual labels:  tensorflow-lite
Netron
Visualizer for neural network, deep learning, and machine learning models
Stars: ✭ 17,193 (+74652.17%)
Mutual labels:  tensorflow-lite

Tensorflow Lite Object Detection with the Tensorflow Object Detection API

TensorFlow 2.5

Object Detection Example

Introduction

TensorFlow Lite(TFLite) is TensorFlow’s lightweight solution for mobile and embedded devices. It enables on-device machine learning inference with low latency and a small binary size. TensorFlow Lite uses many techniques for this such as quantized kernels that allow smaller and faster (fixed-point math) models.

This document walks you through converting a Tensorflow Object Detection API model to Tensorflow Lite.

NOTE: TFLite currently only fully supports SSD Architectures (excluding EfficientDet) for boxes-based detection. CenterNet support is only experimental. For more information see this notebook

1.Train a object detection model using the Tensorflow OD API

For this guide you can either use a pre-trained model from the Tensorflow Model zoo or you can train your own custom model as described in one of my other Github repositories.

2.Convert the model to Tensorflow Lite

After you have a Tensorflow OD model you can start to convert it to Tensorflow Lite.

This is a two-step process:

  1. Export frozen inference graph for TFLite
  2. Convert to TFLite

2.1 Export frozen inference graph for TFLite

After training the model you need to export the model so that the graph architecture and network operations are compatible with Tensorflow Lite. This can be done with the export_tflite_graph_tf2.py file.

# From the tensorflow/models/research/ directory
python object_detection/export_tflite_graph_tf2.py \
    --pipeline_config_path path/to/ssd_model/pipeline.config \
    --trained_checkpoint_dir path/to/ssd_model/checkpoint \
    --output_directory path/to/exported_model_directory

In the output_directory you should now see a saved_model folder.

2.2. Convert to TFLite

Use the TensorFlow Lite Converter to convert the SavedModel to TFLite. Note that you need to use from_saved_model for TFLite conversion with the Python API.

Python API (recommended):

# Convert the model to TF lite
converter = tf.lite.TFLiteConverter.from_saved_model('/content/saved_model/')
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_model = converter.convert()

# Serialize the model
open('model.tflite', 'wb').write(tflite_model)

Command line:

tflite_convert \
  --saved_model_dir=<output_directory>/saved_model \
  --output_file=model.tflite

You can also leverage Post-training Quantization to optimize the performance and decrease the size of your model. Note that this is only possible from the Python API.

converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8,
                                       tf.lite.OpsSet.TFLITE_BUILTINS]
converter.representative_dataset = <...>

Be sure to use a representative dataset

2.3 Add Metadata

To enable easy integration with mobile integrations using the TFLite Task library the model can be packed with TFLite Metadata.

from tflite_support.metadata_writers import object_detector
from tflite_support.metadata_writers import writer_utils

writer = object_detector.MetadataWriter.create_for_inference(
    writer_utils.load_file(_TFLITE_MODEL_PATH), input_norm_mean=[0],
    input_norm_std=[255], label_file_paths=[_TFLITE_LABEL_PATH])
writer_utils.save_file(writer.populate(), _TFLITE_MODEL_WITH_METADATA_PATH)

2.4 Create new labelmap for Tensorflow Lite

Next you need to create a label map for Tensorflow Lite, since it doesn't have the same format as a classical Tensorflow labelmap.

Tensorflow labelmap:

item {
    name: "a"
    id: 1
    display_name: "a"
}
item {
    name: "b"
    id: 2
    display_name: "b"
}
item {
    name: "c"
    id: 3
    display_name: "c"
}

The Tensorflow Lite labelmap format only has the display_names (if there is no display_name the name is used).

a
b
c

So basically the only thing you need to do is to create a new labelmap file and copy the display_names (names) from the other labelmap file into it.

2.5 Optional: Convert Tensorflow Lite model to use with the Google Coral EdgeTPU

If you want to use the model with a Google Coral EdgeTPU you need to run it through the EdgeTPU Compiler.

The compiler can be installed on Linux systems (Debian 6.0 or higher) with the following commands:

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list

sudo apt-get update

sudo apt-get install edgetpu

After installing the compiler you can convert the model with the following command:

edgetpu_compiler [options] model...

Before using the compiler, be sure you have a model that's compatible with the Edge TPU. For compatibility details, read TensorFlow models on the Edge TPU.

3. Using the model for inference

This repository contains two scripts to run the model. On for running the object detection model on a video and one for running it on a webcam. Both can be run with or without the EdgeTPU.

Author

Gilbert Tanner

Support me

Buy Me A Coffee

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].