• Stars
    star
    165
  • Rank 227,587 (Top 5 %)
  • Language
    Python
  • Created over 6 years ago
  • Updated over 6 years ago

Reviews

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

Repository Details

Object Detection using TensorFlow on a Raspberry Pi

Object Detection Using Tensorflow on the Raspberry Pi

Script for object detection from training new model on dataset to exporting quantized graph

Step 1. Setup

Using docker registry

This is the fastest way to use the repo

# For cpu
docker pull docker.nanonets.com/pi_training
# For gpu
docker pull docker.nanonets.com/pi_training:gpu

OR

Building locally

Docker build script

Should run this script from repository root

# For cpu
docker build -t pi_training -f docker/Dockerfile.training .
docker image tag pi_training docker.nanonets.com/pi_training

# For gpu
docker build -t pi_training:gpu -f docker/Dockerfile.training.gpu .
docker image tag pi_training:gpu docker.nanonets.com/pi_training:gpu

Step 2. Preparing dataset

Dataset for object detection consists of images of objects you want to detect and annotations which are xml files with coordinates of objects inside images in Pascal VOC format. If you have collected images, you can use tool like LabelImg to create dataset.

Copy dataset with images folder containing all training images and annotations folder containing all respective annotations inside data folder in repo which will be mounted by docker as volume

Step 3. Starting training

Tensorboard will be started at port 8000 and run in background You can specify -h parameter to get help for docker script

If you have a GPU instance, you need to install nvidia-docker

# For cpu
sudo docker run -p 8000:8000 -v `pwd`/data:/data docker.nanonets.com/pi_training -m train -a ssd_mobilenet_v1_coco -e ssd_mobilenet_v1_coco_0 -p '{"batch_size":8,"learning_rate":0.003}'
# For gpu
sudo nvidia-docker run -p 8000:8000 -v `pwd`/data:/data docker.nanonets.com/pi_training:gpu -m train -a ssd_mobilenet_v1_coco -e ssd_mobilenet_v1_coco_0 -p '{"batch_size":8,"learning_rate":0.003}'

Usage

The docker instance on startup runs a script run.sh which takes the following parameters:

run.sh [-m mode] [-a architecture] [-h help] [-e experiment_id] [-c checkpoint] [-p hyperparameters]
-h          display this help and exit
-m          mode: should be either `train` or `export`
-p          key value pairs of hyperparameters as json string
-e          experiment id. Used as path inside data folder to run current experiment
-c          applicable when mode is export, used to specify checkpoint to use for export

List of Models (that can be passed to -a):

  1. ssd_mobilenet_v1_coco
  2. ssd_inception_v2_coco
  3. faster_rcnn_inception_v2_coco
  4. faster_rcnn_resnet50_coco
  5. rfcn_resnet101_coco
  6. faster_rcnn_resnet101_coco
  7. faster_rcnn_inception_resnet_v2_atrous_coco
  8. faster_rcnn_nas

Possible hyperparameters to override from -p command in json

Name Type
learning_rate float
batch_size int
train_steps int
eval_steps int

Step 4. Exporting trained model

This command would export trained model in quantized graph that can be used for prediction. You need to specify one of the trained checkpoints from experiment directory that you want to use for prediction with -c command as follows:

# For cpu
sudo docker run -v `pwd`/data:/data docker.nanonets.com/pi_training -m export -a ssd_mobilenet_v1_coco -e ssd_mobilenet_v1_coco_0 -c /data/0/model.ckpt-8998

# For gpu
sudo nvidia-docker run -v `pwd`/data:/data docker.nanonets.com/pi_training:gpu -m export -a ssd_mobilenet_v1_coco -e ssd_mobilenet_v1_coco_0 -c /data/0/model.ckpt-8998

Once your done training the model and have exported it you can move this onto a client device like the Raspberry Pi. For details of how to use on the Raspberry Pi click see https://github.com/NanoNets/TF-OD-Pi-Test

More Repositories

1

nanonets-ocr-sample-python

NanoNets OCR API Example for Python
Python
153
star
2

ocr-with-tesseract

A comprehensive tutorial for OCR in python using Tesseract-OCR and OpenCV
Jupyter Notebook
96
star
3

object-detection-sample-python

NanoNets Object Detection API Example for Python
Jupyter Notebook
65
star
4

number-plate-detection

Automatic License Plate Reader using tensorflow attention OCR
Python
57
star
5

IndianRoadsObjectDetectionDataset

Python
47
star
6

TF-OD-Pi-Test

Tensorflow Object Detection Prediction Running on the Raspberry Pi
Python
36
star
7

ocr-python

OCR library to extract text & tables from PDF files and images. Convert any image or PDF to CSV / TXT / JSON / Searchable PDF.
Jupyter Notebook
23
star
8

nanonets-id-card-digitization

Python demo for ID card digitization using Nanonets
Python
23
star
9

bert-text-moderation

BERT + CNN for toxic comments multi label classification.
Jupyter Notebook
23
star
10

invoice-processing-with-python-nanonets

Invoice Processing with Python and Nanonets
23
star
11

object-detection-sample-golang

NanoNets Object Detection API Example for Golang
Go
12
star
12

nanonets-pedestrian-detection

NanoNets Crowd Counting Detection API Example for Python
Python
10
star
13

SignatureDetectionDataset

Python
8
star
14

object-detection-sample-nodejs

NanoNets Object Detection API Example for Node.js
JavaScript
7
star
15

nnblog

Code for NN blog article
HTML
6
star
16

nanonets-cracked-screen-detection

Nanonets. Build your own Cracked Screen Detection Model
Python
5
star
17

image-classification-sample-python

NanoNets Image Classification API Example for Python
Python
5
star
18

multi-label-classification-sample-python

Nanonets API interface for training MultiLabel Image Classification Problem
Python
4
star
19

object-detection-sample-php

PHP code to integrate Nanonets API into your Project
PHP
4
star
20

fashion_mnist

Repository for training Nanonets model on fashion MNIST dataset
Python
4
star
21

nanonets-car-damage-classification

A simple classifier to find if a car in an image is damaged or not
Python
3
star
22

SyncAirtablePostgres

Utility to sync tables from Airtable to Postgres
Python
3
star
23

docker-models

Guide to Dockerizing Deep Learning Models
Python
3
star
24

tutorials

repo with data and code samples for running object detection, classification jobs using Nanonets API.
Jupyter Notebook
2
star
25

nsfw-api

Nanonets NSFW API
Python
2
star
26

celebrity-detection

Celebrity Face detection and identification for 10 Indian celebrity
Python
1
star
27

ic-js-sdk

NanoNets' Image Classification Node.js SDK.
JavaScript
1
star
28

ocr-js-sdk

NanoNets' Optical Character Recognition Node.js SDK.
JavaScript
1
star
29

tutorials-page

JavaScript
1
star
30

nanonets-python-client

pip package
Python
1
star
31

code-samples

Code Sample for Object Detection
JavaScript
1
star