Object Detection withTensorflow
by Rayees ahmad
Agenda
▪ Intro
▪ WhatisObject Detection
▪ Stateof Object Detection
▪ Tensorflow Object DetectionAPI
▪ PreparingData
▪ Training &Evaluating
▪ Links
Intro
Use cases
What is ObjectDetection
Object detection =
Object Classification + Object Localization
One model for twotasks?
Objectdetection-outputistheonenumber(index)of aclass
Objectlocalization-outputisthefournumbers-
coordinatesof boundingbox.
Po
bx1
bx2
by1
by2
c1
c2
c3
…
cn
- is object exists
- bounding box
coordinates
- object’s
variables
State of ObjectDetection
Approaches
▪ Classicalapproach(Haarfeatures)-first OD realtimeframework (Viola-Jones)
▪ Deeplearningapproach-nowstateoftheartinOD
▪ OverFeat
▪ R-CNN
▪ FastR-CNN
▪ YOLO
▪ FasterR-CNN
▪ SSDandR-FCN
Deep learning approach
OverFeat -publishedin2013,multi-scalesliding
window algorithm using Convolutional Neural
Networks(CNNs).
al
C.NN - RegionswithCNN features.Threestage
approach:
- Extract possible objects using aregion propos
method(themostpopular onebeingSelective
Search).
- ExtractfeaturesfromeachregionusingaCNN.
- ClassifyeachregionwithSVMs.
Fast R-CNN -Similar to R-CNN, it used Selective
Search to generate object proposals, but instead of
extractingallof themindependentlyandusingSVM
classifiers,it appliedtheCNN onthecompleteimage
and then used both Region of Interest (RoI) Pooling
onthefeaturemapwithafinalfeedforwardnetwork
for classificationandregression.
YOLO-You Only Look Once: a
simple convolutional neural
network approach which has
both great results and high
speed,allowingfor thefirsttime
realtimeobjectdetection.
Deep learning approach
Faster R-CNN -Faster R-CNN added what
theycalledaRegionProposalNetwork(RPN),
inanattempttogetridof theSelectiveSearch
algorithm and makethe model completely
trainableend-to-end.
SSD andR-FCN
Finally, there are two notable papers, Single Shot
Detector(SSD)whichtakesonYOLO byusingmultiple
sized convolutional feature mapsachieving better
results and speed,and Region-based Fully
Convolutional Networks (R-FCN) which takes the
architecture of Faster R-CNN but with only
convolutionalnetworks.
Deep learning approach
Tensorflow Object
Detection API
TF Object Detection API
▪ OpenSourcefrom2017-07-15
▪ Built on top of TensorFlow
▪ Containstrainabledetection models
▪ Contains frozenweights
▪ Contains JupyterNotebook
▪ Makes easyto construct, train anddeploy
object detectionmodels
Getting started
Dependencies:
▪Protobuf2.6
▪Python-tk
▪Pillow1.0
▪lxml
▪TfSlim (included)
▪Jupyternotebook
▪Matplotlib
▪Tensorflow(tensorflow-
gpu)
▪Cython
▪cocoapi
Installation
instruction
Ifmodelwill betrainedlocally-better
to installtensorflow-gpu.
Dependencies for tensorflow-gpu:
▪ NVIDIAGPU withCUDAComputeCapability3.0
(list)
▪ Ubuntu16.04atleast
▪ CUDA® Toolkit9.0
▪ NVIDIAdriversassociatedwithCUDA Toolkit9.0.
▪ cuDNNv7.0
▪ libcupti-dev
Installation
instruction
Latest version of CUDA Toolkit -9.1not
compatible with tensorflow 1.6,need to
install9.0
Creating a dataset
Dataset
▪ Tensorflow Object DetectionAPI usesthe
TFRecord fileformat
▪ Thereisavailable third-partyscripts to convert
PASCAL VOC andOxford Pet Format
▪ Inother caseexplanation of formatavailable in
gitrepo.
▪ Inputdatato create TFRecord -annotated
image
Getting images
Grab from internet
▪ Scrap images from googleor
Pixabay orwhatever
▪ Forbatchdownloading -
Faktun Bulk Image
Downloader
▪ Fordataminingbymultiplying
existingimages -ImageMagic
Create own images
▪ Recordvideowithneeded
object/objects (in640x480)
▪ Process videoandspliton
screenshots -ffmpeg
Tips
▪ Createimageswith different
lights,backgroundandsoon.
▪ If object is able to have
differentforms-betterto
catch themall.
▪ Tryto make30%-50%of
imageswith overlaid object
▪ Tool forimageaugmentation
Labeling (Annotation) an images
Tools
▪ LabelImg
▪ FIAT (FastImageData
AnnotationTool)
▪ input:images
▪ output: .xml files with
boundingboxescoordinates
Creating TFRecord
▪ TensorflowobjectdetectionAPI repocontains folderdataset_toolswith scripts to
covertscommonstructuresof datain TFRecord.
▪ Ifoutputdatahasanotherstructure -hereisexplanation howto convertit
Training
Selecting a model
Tensorflow OD API provides a collection of
detection models pre-trained on the COCO
dataset,theKitti dataset, andtheOpenImages
dataset.
- model name correspondsto aconfigfile that
wasusedto train this model.
- speed -runningtimeinmsper600x600
image
- mAP standsformeanaverageprecision,
which indicates how well the model
performedontheCOCO dataset.
- Outputs types(Boxes,andMasks if
applicable)
Training & Evaluating
# From the tensorflow/models/research directory
python object_detection/eval.py 
--logtostderr 
--pipeline_config_path=${PATH_TO_YOUR_PIPELINE_CONFIG} 
--checkpoint_dir=${PATH_TO_TRAIN_DIR} 
--eval_dir=${PATH_TO_EVAL_DIR}
# From the tensorflow/models/research directory
python object_detection/train.py
--logtostderr
--
pipeline_config_path=/tensorflow/models/object_detection/samples/configs/ssd_mobilenet_v1_p
ets.config
--train_dir=${PATH_TO_ROOT_TRAIN_FOLDER}
Applications Of Object Detection:
• Facial Recognition
• Security:
• Self Driving Cars
Facial Recognition:
A deep learning facial recognition system called the
“DeepFace” has been developed by a group of researchers
in the Facebook, which identifies human faces in a digital
image very effectively. Google uses its own facial
recognition system in Google Photos, which automatically
segregates all the photos based on the person in the
image. There are various components involved in Facial
Recognition like the eyes, nose, mouth and the eyebrows.
Self Driving Cars:
Self-driving cars are the Future, there’s no doubt in
that. But the working behind it is very tricky as it
combines a variety of techniques to perceive their
surroundings, including radar, laser light, GPS,
odometry, and computer vision.
Advanced control systems interpret sensory
information to identify appropriate navigation
paths, as well as obstacles and once the image
sensor detects any sign of a living being in its path,
it automatically stops. This happens at a very fast
rate and is a big step towards Driverless Cars.
Security: Object Detection plays a very important role in Security. Be it face ID of Apple or
the retina scan used in all the sci-fi movies.
It is also used by the government to access the security feed and match it with
their existing database to find any criminals or to detect the robbers’ vehicle.
The applications are limitless.
Links
▪ https://towardsdatascience.com/how-to-train-your-own-object-detector-with-
tensorflows-object-detector-api-bec72ecfe1d9
▪ https://www.kdnuggets.com/2017/10/deep-learning-object-detection-
comprehensive-review.html
▪ http://www.machinelearninguru.com/deep_learning/tensorflow/basics/tfrecord/tfreco
rd.html
▪ https://www.coursera.org/learn/convolutional-neural-networks
▪ https://medium.com/comet-app/review-of-deep-learning-algorithms-for-object-
detection-c1f3d437b852
▪ https://towardsdatascience.com/evolution-of-object-detection-and-localization-
algorithms-e241021d8bad
▪ https://medium.freecodecamp.org/how-to-play-quidditch-using-the-tensorflow-
object-detection-api-b0742b99065d
Demo :
www.eliftech.c
THANK
YOU!!

Object detection with Tensorflow Api

  • 1.
  • 2.
    Agenda ▪ Intro ▪ WhatisObjectDetection ▪ Stateof Object Detection ▪ Tensorflow Object DetectionAPI ▪ PreparingData ▪ Training &Evaluating ▪ Links
  • 3.
  • 4.
  • 5.
  • 6.
    Object detection = ObjectClassification + Object Localization
  • 7.
    One model fortwotasks? Objectdetection-outputistheonenumber(index)of aclass Objectlocalization-outputisthefournumbers- coordinatesof boundingbox. Po bx1 bx2 by1 by2 c1 c2 c3 … cn - is object exists - bounding box coordinates - object’s variables
  • 8.
  • 9.
    Approaches ▪ Classicalapproach(Haarfeatures)-first ODrealtimeframework (Viola-Jones) ▪ Deeplearningapproach-nowstateoftheartinOD ▪ OverFeat ▪ R-CNN ▪ FastR-CNN ▪ YOLO ▪ FasterR-CNN ▪ SSDandR-FCN
  • 10.
    Deep learning approach OverFeat-publishedin2013,multi-scalesliding window algorithm using Convolutional Neural Networks(CNNs). al C.NN - RegionswithCNN features.Threestage approach: - Extract possible objects using aregion propos method(themostpopular onebeingSelective Search). - ExtractfeaturesfromeachregionusingaCNN. - ClassifyeachregionwithSVMs.
  • 11.
    Fast R-CNN -Similarto R-CNN, it used Selective Search to generate object proposals, but instead of extractingallof themindependentlyandusingSVM classifiers,it appliedtheCNN onthecompleteimage and then used both Region of Interest (RoI) Pooling onthefeaturemapwithafinalfeedforwardnetwork for classificationandregression. YOLO-You Only Look Once: a simple convolutional neural network approach which has both great results and high speed,allowingfor thefirsttime realtimeobjectdetection. Deep learning approach
  • 12.
    Faster R-CNN -FasterR-CNN added what theycalledaRegionProposalNetwork(RPN), inanattempttogetridof theSelectiveSearch algorithm and makethe model completely trainableend-to-end. SSD andR-FCN Finally, there are two notable papers, Single Shot Detector(SSD)whichtakesonYOLO byusingmultiple sized convolutional feature mapsachieving better results and speed,and Region-based Fully Convolutional Networks (R-FCN) which takes the architecture of Faster R-CNN but with only convolutionalnetworks. Deep learning approach
  • 13.
  • 14.
    TF Object DetectionAPI ▪ OpenSourcefrom2017-07-15 ▪ Built on top of TensorFlow ▪ Containstrainabledetection models ▪ Contains frozenweights ▪ Contains JupyterNotebook ▪ Makes easyto construct, train anddeploy object detectionmodels
  • 15.
    Getting started Dependencies: ▪Protobuf2.6 ▪Python-tk ▪Pillow1.0 ▪lxml ▪TfSlim (included) ▪Jupyternotebook ▪Matplotlib ▪Tensorflow(tensorflow- gpu) ▪Cython ▪cocoapi Installation instruction Ifmodelwillbetrainedlocally-better to installtensorflow-gpu. Dependencies for tensorflow-gpu: ▪ NVIDIAGPU withCUDAComputeCapability3.0 (list) ▪ Ubuntu16.04atleast ▪ CUDA® Toolkit9.0 ▪ NVIDIAdriversassociatedwithCUDA Toolkit9.0. ▪ cuDNNv7.0 ▪ libcupti-dev Installation instruction Latest version of CUDA Toolkit -9.1not compatible with tensorflow 1.6,need to install9.0
  • 16.
  • 17.
    Dataset ▪ Tensorflow ObjectDetectionAPI usesthe TFRecord fileformat ▪ Thereisavailable third-partyscripts to convert PASCAL VOC andOxford Pet Format ▪ Inother caseexplanation of formatavailable in gitrepo. ▪ Inputdatato create TFRecord -annotated image
  • 18.
    Getting images Grab frominternet ▪ Scrap images from googleor Pixabay orwhatever ▪ Forbatchdownloading - Faktun Bulk Image Downloader ▪ Fordataminingbymultiplying existingimages -ImageMagic Create own images ▪ Recordvideowithneeded object/objects (in640x480) ▪ Process videoandspliton screenshots -ffmpeg Tips ▪ Createimageswith different lights,backgroundandsoon. ▪ If object is able to have differentforms-betterto catch themall. ▪ Tryto make30%-50%of imageswith overlaid object ▪ Tool forimageaugmentation
  • 19.
    Labeling (Annotation) animages Tools ▪ LabelImg ▪ FIAT (FastImageData AnnotationTool) ▪ input:images ▪ output: .xml files with boundingboxescoordinates
  • 20.
    Creating TFRecord ▪ TensorflowobjectdetectionAPIrepocontains folderdataset_toolswith scripts to covertscommonstructuresof datain TFRecord. ▪ Ifoutputdatahasanotherstructure -hereisexplanation howto convertit
  • 21.
  • 22.
    Selecting a model TensorflowOD API provides a collection of detection models pre-trained on the COCO dataset,theKitti dataset, andtheOpenImages dataset. - model name correspondsto aconfigfile that wasusedto train this model. - speed -runningtimeinmsper600x600 image - mAP standsformeanaverageprecision, which indicates how well the model performedontheCOCO dataset. - Outputs types(Boxes,andMasks if applicable)
  • 23.
    Training & Evaluating #From the tensorflow/models/research directory python object_detection/eval.py --logtostderr --pipeline_config_path=${PATH_TO_YOUR_PIPELINE_CONFIG} --checkpoint_dir=${PATH_TO_TRAIN_DIR} --eval_dir=${PATH_TO_EVAL_DIR} # From the tensorflow/models/research directory python object_detection/train.py --logtostderr -- pipeline_config_path=/tensorflow/models/object_detection/samples/configs/ssd_mobilenet_v1_p ets.config --train_dir=${PATH_TO_ROOT_TRAIN_FOLDER}
  • 24.
    Applications Of ObjectDetection: • Facial Recognition • Security: • Self Driving Cars
  • 25.
    Facial Recognition: A deeplearning facial recognition system called the “DeepFace” has been developed by a group of researchers in the Facebook, which identifies human faces in a digital image very effectively. Google uses its own facial recognition system in Google Photos, which automatically segregates all the photos based on the person in the image. There are various components involved in Facial Recognition like the eyes, nose, mouth and the eyebrows.
  • 26.
    Self Driving Cars: Self-drivingcars are the Future, there’s no doubt in that. But the working behind it is very tricky as it combines a variety of techniques to perceive their surroundings, including radar, laser light, GPS, odometry, and computer vision. Advanced control systems interpret sensory information to identify appropriate navigation paths, as well as obstacles and once the image sensor detects any sign of a living being in its path, it automatically stops. This happens at a very fast rate and is a big step towards Driverless Cars.
  • 27.
    Security: Object Detectionplays a very important role in Security. Be it face ID of Apple or the retina scan used in all the sci-fi movies. It is also used by the government to access the security feed and match it with their existing database to find any criminals or to detect the robbers’ vehicle. The applications are limitless.
  • 28.
    Links ▪ https://towardsdatascience.com/how-to-train-your-own-object-detector-with- tensorflows-object-detector-api-bec72ecfe1d9 ▪ https://www.kdnuggets.com/2017/10/deep-learning-object-detection- comprehensive-review.html ▪http://www.machinelearninguru.com/deep_learning/tensorflow/basics/tfrecord/tfreco rd.html ▪ https://www.coursera.org/learn/convolutional-neural-networks ▪ https://medium.com/comet-app/review-of-deep-learning-algorithms-for-object- detection-c1f3d437b852 ▪ https://towardsdatascience.com/evolution-of-object-detection-and-localization- algorithms-e241021d8bad ▪ https://medium.freecodecamp.org/how-to-play-quidditch-using-the-tensorflow- object-detection-api-b0742b99065d
  • 29.
  • 30.