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
Code for our ACL 2021 paper - ConSERT: A Contrastive Framework for Self-Supervised Sentence Representation Transfer

ConSERT Code for our ACL 2021 paper - ConSERT: A Contrastive Framework for Self-Supervised Sentence Representation Transfer Requirements torch==1.6.0

Yan Yuanmeng 478 Dec 25, 2022
Adaptive Dropblock Enhanced GenerativeAdversarial Networks for Hyperspectral Image Classification

This repo holds the codes of our paper: Adaptive Dropblock Enhanced GenerativeAdversarial Networks for Hyperspectral Image Classification, which is ac

Feng Gao 17 Dec 28, 2022
DyStyle: Dynamic Neural Network for Multi-Attribute-Conditioned Style Editing

DyStyle: Dynamic Neural Network for Multi-Attribute-Conditioned Style Editing Figure: Joint multi-attribute edits using DyStyle model. Great diversity

74 Dec 03, 2022
code for EMNLP 2019 paper Text Summarization with Pretrained Encoders

PreSumm This code is for EMNLP 2019 paper Text Summarization with Pretrained Encoders Updates Jan 22 2020: Now you can Summarize Raw Text Input!. Swit

Yang Liu 1.2k Dec 28, 2022
Home for cuQuantum Python & NVIDIA cuQuantum SDK C++ samples

Welcome to the cuQuantum repository! This public repository contains two sets of files related to the NVIDIA cuQuantum SDK: samples: All C/C++ sample

NVIDIA Corporation 147 Dec 27, 2022
Learn about quantum computing and algorithm on quantum computing

quantum_computing this repo contains everything i learn about quantum computing and algorithm on quantum computing what is aquantum computing quantum

arfy slowy 8 Dec 25, 2022
DSAC* for Visual Camera Re-Localization (RGB or RGB-D)

DSAC* for Visual Camera Re-Localization (RGB or RGB-D) Introduction Installation Data Structure Supported Datasets 7Scenes 12Scenes Cambridge Landmark

Visual Learning Lab 143 Dec 22, 2022
An Object Oriented Programming (OOP) interface for Ontology Web language (OWL) ontologies.

Enabling a developer to use Ontology Web Language (OWL) along with its reasoning capabilities in an Object Oriented Programming (OOP) paradigm, by pro

TheEngineRoom-UniGe 7 Sep 23, 2022
PyTorch implementation of SimSiam: Exploring Simple Siamese Representation Learning

SimSiam: Exploring Simple Siamese Representation Learning This is a PyTorch implementation of the SimSiam paper: @Article{chen2020simsiam, author =

Facebook Research 834 Dec 30, 2022
unofficial pytorch implement of "Squareplus: A Softplus-Like Algebraic Rectifier"

SquarePlus (Pytorch implement) unofficial pytorch implement of "Squareplus: A Softplus-Like Algebraic Rectifier" SquarePlus Squareplus is a Softplus-L

SeeFun 3 Dec 29, 2021
Covid-19 Test AI (Deep Learning - NNs) Software. Accuracy is the %96.5, loss is the 0.09 :)

Covid-19 Test AI (Deep Learning - NNs) Software I developed a segmentation algorithm to understand whether Covid-19 Test Photos are positive or negati

Emirhan BULUT 28 Dec 04, 2021
A Python implementation of the Locality Preserving Matching (LPM) method for pruning outliers in image matching.

LPM_Python A Python implementation of the Locality Preserving Matching (LPM) method for pruning outliers in image matching. The code is established ac

AoxiangFan 11 Nov 07, 2022
Implement of homography net by pytorch

HomographyNet Implement of homography net by pytorch Brief Introduction This project is based on the work Homography-Net: @article{detone2016deep, t

ronghao_CN 4 May 19, 2022
PRTR: Pose Recognition with Cascade Transformers

PRTR: Pose Recognition with Cascade Transformers Introduction This repository is the official implementation for Pose Recognition with Cascade Transfo

mlpc-ucsd 133 Dec 30, 2022
A plug-and-play library for neural networks written in Python

A plug-and-play library for neural networks written in Python!

Dimos Michailidis 2 Jul 16, 2022
Code for the paper: Sketch Your Own GAN

Sketch Your Own GAN Project | Paper | Youtube Our method takes in one or a few hand-drawn sketches and customizes an off-the-shelf GAN to match the in

677 Dec 28, 2022
Pretrained models for Jax/Haiku; MobileNet, ResNet, VGG, Xception.

Pre-trained image classification models for Jax/Haiku Jax/Haiku Applications are deep learning models that are made available alongside pre-trained we

Alper Baris CELIK 14 Dec 20, 2022
Garbage classification using structure data.

垃圾分类模型使用说明 1.包含以下数据文件 文件 描述 data/MaterialMapping.csv 物体以及其归类的信息 data/TestRecords 光谱原始测试数据 CSV 文件 data/TestRecordDesc.zip CSV 文件描述文件 data/Boundaries.cs

wenqi 1 Dec 10, 2021
Interactive web apps created using geemap and streamlit

geemap-apps Introduction This repo demostrates how to build a multi-page Earth Engine App using streamlit and geemap. You can deploy the app on variou

Qiusheng Wu 27 Dec 23, 2022
Editing a Conditional Radiance Field

Editing Conditional Radiance Fields Project | Paper | Video | Demo Editing Conditional Radiance Fields Steven Liu, Xiuming Zhang, Zhoutong Zhang, Rich

Steven Liu 216 Dec 30, 2022