Run object detection model on the Raspberry Pi

Overview

Intro

Using TensorFlow Lite with Python is great for embedded devices based on Linux, such as Raspberry Pi.

This is the guide for installing TensorFlow Lite on the Raspberry Pi and running pre-trained object detection models on it.

Step 1. Setting up Rasperry Pi

Upgrade Raspbian Stretch to Buster

(If you on Buster, skip this step and simply run sudo apt-get update and sudo apt-get dist-upgrade)

$ sudo apt-get update && sudo apt-get upgrade -y

Verify nothing is wrong. Verify no errors are reported after each command. Fix as required (you’re on your own here!).

$ dpkg -C
$ apt-mark showhold

Prepare apt-get Sources

Update the sources to apt-get. This replaces “stretch” with “buster” in the repository locations giving apt-get access to the new version’s binaries.

$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list    
$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list.d/raspi.list

Verify this caught them all by running the following, expecting no output. If the command returns anything having previously run the sed commands above, it means more files may need tweaking. Run the sed command for each. The aim is to replace all instances of “stretch”.

$ grep -lnr stretch /etc/apt

Speed up subsequent steps by removing the list change package.

$ sudo apt-get remove apt-listchanges

Do the Upgrade

To update existing packages without updating kernel modules or removing packages, run the following.

$ sudo apt-get update && sudo apt-get upgrade -y

Alternatively, to include kernel modules and removing packages if required, run the following

$ sudo apt-get update && sudo apt-get full-upgrade -y

Cleanup old outdated packages.

$ sudo apt-get autoremove -y && sudo apt-get autoclean

Verify with

 cat /etc/os-release.

Update Firmware

$ sudo rpi-update

and

sudo apt-get install -y python3-pip

and

pip3 install --upgrade setuptools

2. Making sure camera interface is enabled in the Raspberry Pi Configuration menu

Click the Pi icon in the top left corner of the screen, select Preferences -> Raspberry Pi Configuration, and go to the Interfaces tab and verify Camera is set to Enabled. If it isn't, enable it now, and reboot the Raspberry Pi.

Converting Tensorflow to Tensorflow Lite

Using TensorFlow Lite converter. It takes TensorFlow model and generates a TensorFlow Lite model (an optimized FlatBuffer format identified by the .tflite file extension).

Step 2. Install TF Lite dependecies and set up virtual environment

clone this repo

git clone https://github.com/yanovsk/Raspberry-Pi-TF-Lite-Object-Detection

rename the folder to "tfliteod"

mv Raspberry-Pi-TF-Lite-Object-Detection tfliteod
cd tfliteod

run shell script to install get_pi_requirements

bash get_pi_req.sh

Note: shell script will auto install the lastest version of Tensorflow. To install specific version of TF, run pip3 install tensorflow==x.xx (where x.xx stands for the version you want to install)

Set up virtual environment

Install vitrtualenv

pip3 install virtualenv 

Then, create the "tfliteod-env" virtual environment by issuing:

python3 -m venv tfliteod-env

This will create a folder called tfliteod-env inside the tflite1 directory. The tfliteod-env folder will hold all the package libraries for this environment. Next, activate the environment by issuing:

source tfliteod-env/bin/activate

Step 3. Set up TensorFlow Lite detection model

Once, tensorflow is install we can proceed to seting up the object detection model.

We can use either pre-trained model or train it on our end. For the simplicity sake let's use pre-trained sample model by google

Download the sample model (also could be done thru direct link here)

wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip

upzip it

unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip -d Sample_model

Step 4. Run the model

Note: the model should work on either Picamera module or any other webcam plugged in to the Raspberry Pi as a usb device.

From home/pi/tfliteod run the following command:

python3 TFL_object_detection.py --modeldir=Sample_model

After initializing webcam window should pop-up on your Raspebbery Pi and object detection should work.

Note: this model can recongnize only 80 common objects (check labels.txt for more info on metadata)

However, you can custom train the model using this guide.

Happy hacking!

Owner
Dimitri Yanovsky
Dimitri Yanovsky
GarmentNets: Category-Level Pose Estimation for Garments via Canonical Space Shape Completion

GarmentNets This repository contains the source code for the paper GarmentNets: Category-Level Pose Estimation for Garments via Canonical Space Shape

Columbia Artificial Intelligence and Robotics Lab 43 Nov 21, 2022
Decoding the Protein-ligand Interactions Using Parallel Graph Neural Networks

Decoding the Protein-ligand Interactions Using Parallel Graph Neural Networks Requirements python 0.10+ rdkit 2020.03.3.0 biopython 1.78 openbabel 2.4

Neeraj Kumar 3 Nov 23, 2022
Mesh Graphormer is a new transformer-based method for human pose and mesh reconsruction from an input image

MeshGraphormer ✨ ✨ This is our research code of Mesh Graphormer. Mesh Graphormer is a new transformer-based method for human pose and mesh reconsructi

Microsoft 251 Jan 08, 2023
SberSwap Video Swap base on deep learning

SberSwap Video Swap base on deep learning

Sber AI 431 Jan 03, 2023
HomeAssitant custom integration for dyson

HomeAssistant Custom Integration for Dyson This custom integration is still under development. This is a HA custom integration for dyson. There are se

Xiaonan Shen 232 Dec 31, 2022
TransZero++: Cross Attribute-guided Transformer for Zero-Shot Learning

TransZero++ This repository contains the testing code for the paper "TransZero++: Cross Attribute-guided Transformer for Zero-Shot Learning" submitted

Shiming Chen 6 Aug 16, 2022
ColBERT: Contextualized Late Interaction over BERT (SIGIR'20)

Update: if you're looking for ColBERTv2 code, you can find it alongside a new simpler API, in the branch new_api. ColBERT ColBERT is a fast and accura

Stanford Future Data Systems 637 Jan 08, 2023
This repository contains the data and code for the paper "Diverse Text Generation via Variational Encoder-Decoder Models with Gaussian Process Priors" ([email protected])

GP-VAE This repository provides datasets and code for preprocessing, training and testing models for the paper: Diverse Text Generation via Variationa

Wanyu Du 18 Dec 29, 2022
How Effective is Incongruity? Implications for Code-mix Sarcasm Detection.

Code for the paper: How Effective is Incongruity? Implications for Code-mix Sarcasm Detection - ICON ACL 2021

2 Jun 05, 2022
Towards Debiasing NLU Models from Unknown Biases

Towards Debiasing NLU Models from Unknown Biases Abstract: NLU models often exploit biased features to achieve high dataset-specific performance witho

Ubiquitous Knowledge Processing Lab 22 Jun 14, 2022
Deep learning (neural network) based remote photoplethysmography: how to extract pulse signal from video using deep learning tools

Deep-rPPG: Camera-based pulse estimation using deep learning tools Deep learning (neural network) based remote photoplethysmography: how to extract pu

Terbe Dániel 138 Dec 17, 2022
SegNet model implemented using keras framework

keras-segnet Implementation of SegNet-like architecture using keras. Current version doesn't support index transferring proposed in SegNet article, so

185 Aug 30, 2022
Type4Py: Deep Similarity Learning-Based Type Inference for Python

Type4Py: Deep Similarity Learning-Based Type Inference for Python This repository contains the implementation of Type4Py and instructions for re-produ

Software Analytics Lab 45 Dec 15, 2022
Updated for TTS(CE) = Also Known as TTN V3. The code requires the first server to be 'ttn' protocol.

Updated Updated for TTS(CE) = Also Known as TTN V3. The code requires the first server to be 'ttn' protocol. Introduction This balenaCloud (previously

Remko 1 Oct 17, 2021
MHFormer: Multi-Hypothesis Transformer for 3D Human Pose Estimation

MHFormer: Multi-Hypothesis Transformer for 3D Human Pose Estimation This repo is the official implementation of "MHFormer: Multi-Hypothesis Transforme

Vegetabird 281 Jan 07, 2023
The repository contain code for building compiler using puthon.

Building Compiler This is a python implementation of JamieBuild's "Super Tiny Compiler" Overview JamieBuilds developed a wonderfully educative compile

Shyam Das Shrestha 1 Nov 21, 2021
Performance Analysis of Multi-user NOMA Wireless-Powered mMTC Networks: A Stochastic Geometry Approach

Performance Analysis of Multi-user NOMA Wireless-Powered mMTC Networks: A Stochastic Geometry Approach Thanh Luan Nguyen, Tri Nhu Do, Georges Kaddoum

Thanh Luan Nguyen 2 Oct 10, 2022
Training data extraction on GPT-2

Training data extraction from GPT-2 This repository contains code for extracting training data from GPT-2, following the approach outlined in the foll

Florian Tramer 62 Dec 07, 2022
Semi Supervised Learning for Medical Image Segmentation, a collection of literature reviews and code implementations.

Semi-supervised-learning-for-medical-image-segmentation. Recently, semi-supervised image segmentation has become a hot topic in medical image computin

Healthcare Intelligence Laboratory 1.3k Jan 03, 2023
Deep learning operations reinvented (for pytorch, tensorflow, jax and others)

This video in better quality. einops Flexible and powerful tensor operations for readable and reliable code. Supports numpy, pytorch, tensorflow, and

Alex Rogozhnikov 6.2k Jan 01, 2023