Giter Club home page Giter Club logo

raspberrypi-objectdetection-tensorflow's Introduction

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

raspberrypi-objectdetection-tensorflow's People

Contributors

prats226 avatar sjain07 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raspberrypi-objectdetection-tensorflow's Issues

Error on train step

Hi! I have been try to train following the same steps thar README shows up. On docker file, i had to change some lines and i changed the repository link as well (no longer ../models/research/object_detection/train.py but /models/research/object_detection/legacy/train.py on run.sh). When the train process start, the following error apears:
TypeError: Signature mismatch. Keys must be dtype <dtype: 'float32'>, got <dtype: 'string'>.

Can any one help me on this? I can attach more info if someone answer me!
Thanks!

x509: certificate has expired or is not yet valid

Hi,

When I tried to pull docker image, it threw an error.

$ docker pull docker.nanonets.com/pi_training
Using default tag: latest
Error response from daemon: Get https://docker.nanonets.com/v2/: x509: certificate has expired or is not yet valid

wechatimg70

error when running training

hi im getting this error for both docker versions
Docker version 1.13.1, build 092cba3
Docker version 17.12.0

/models/research/object_detection/utils/visualization_utils.py:25: UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

The backend was *originally* set to u'TkAgg' by the following code:
  File "/models/research/object_detection/eval.py", line 50, in <module>
    from object_detection import evaluator
  File "/models/research/object_detection/evaluator.py", line 24, in <module>
    from object_detection import eval_util
  File "/models/research/object_detection/eval_util.py", line 28, in <module>
    from object_detection.metrics import coco_evaluation
  File "/models/research/object_detection/metrics/coco_evaluation.py", line 20, in <module>
    from object_detection.metrics import coco_tools
  File "/models/research/object_detection/metrics/coco_tools.py", line 47, in <module>
    from pycocotools import coco
  File "/models/research/pycocotools/coco.py", line 49, in <module>
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 72, in <module>
    from matplotlib.backends import pylab_setup
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 14, in <module>
    line for line in traceback.format_stack()


  import matplotlib; matplotlib.use('Agg')  # pylint: disable=multiple-statements
INFO:tensorflow:global_step/sec: 0
INFO:tensorflow:global_step/sec: 0
/run.sh: line 118:    27 Killed                  python /models/research/object_detection/train.py --train_dir $TRAIN_DIR --pipeline_config_path "$TRAIN_DIR/pipeline.config"

Ive set up the project per the instructions. Then run,

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}'

any thoughts on why this might happen?

Thanks

access denied

tried running it the way the readme states. got this error:

pi@raspberrypi:~ $ sudo docker pull docker.nanonets.com/pi_training
Using default tag: latest
Error response from daemon: pull access denied for docker.nanonets.com/pi_training, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

docker version:

pi@raspberrypi:~ $ sudo docker --version
Docker version 20.10.6, build 370c289

export_inference_graph.py

can you push export_inference_graph.py please? Even better the /model folder
Also, do you know where to get or how to create object_detection.protos. Trying to run in my env. docker is cool but a pain too sometimes
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.