Giter Site home page Giter Site logo

1202kbs / object-detection-api-wrapper Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 4.0 5.98 MB

Simple wrapper for Google Object Detection API

Home Page: https://github.com/tensorflow/models/tree/master/object_detection

Jupyter Notebook 72.40% Python 26.71% Protocol Buffer 0.89%
object-detection tensorflow google-api

object-detection-api-wrapper's Introduction

Google Object Detection API Wrapper

Simple wrapper functions for Google Object Detection API.

Instructions

Method 1

  1. Download the repository
  2. Create a 'detection_model_zoo' directory in the extracted repository file
  3. Download model from Tensorflow detection model zoo
  4. Copy the downloaded model into 'detection_model_zoo' directory
  5. Create a file containing the urls of images to be analyzed. This wrapper supports both .csv and .json extensions. (Click link for example format)
  6. Check the Jupyter notebook for further instructions and examples

Method 2

  1. Download the repository
  2. Select the model to use from Tensorflow detection model zoo
  3. Create a file containing the urls of images to be analyzed. This wrapper supports both .csv and .json extensions. (Click link for example format)
  4. Run detect_cm.py in command line with --downloaded False. Check below section for more detail

Running in Command Line

python detect_cm.py --model-name MODEL_NAME --url-file URL_FILE --extension EXTENSION --downloaded DOWNLOADED --do-rescale DO_RESCALE

Example:

python detect_cm.py --model-name faster_rcnn_inception_resnet_v2_atrous_coco_11_06_2017 --url-file Imagenet_sample_images --extension .json --downloaded True --do-rescale False

Required Arguments

  • --model-name : Name of the model to use. No Default
  • --url-file : Name of the url file without .json extension. No Default
  • --extension : Url file file type, .json or .csv. Default: .csv
  • --downloaded : Indicate whether you have already downloaded model .tar file or not. Wrapper will automatically create 'detection_model_zoo' directory and download model file if set to False. Default: False
  • --do-rescale : Indicate whether you want to rescale the images or not. Default: False

Optional Arguments

  • --width-threshold : If rescale is set to True, all the images with width size over width threshold will be rescaled to fit width threshold. Default: 500
  • --json-output-file : Name of the json output file to dump results. Default: output.json
  • --n-threads : Number of threads to use. Default: 64
  • --visualize : Indicate whether you want to visualize the results. Default: False
  • --labels : Path to the label file. Default: object_detection/data/mscoco_label_map.pbtxt

Run python detect_cm.py --help to see a list of all options.

Successful execution will create a .json file which contains the results of object detection. Contents of the .json file can be read into a dictionary of numpy arrarys with json2dict function in helpers.py. For additional functions for visualization or modification of the results of object detection, look into helpers.py.

Running within IDE

  1. Import detect.py
  2. Run detect.object_detect(...)
  3. The object_detect() function takes the same arguments as command line execution. Look into detect.py for more details

If the execution is successful, the function will return a dictionary of numpy arrays containing the object detection results and create a .json file which contains the results of object detection. Contents of the .json file can be read into a dictionary of numpy arrarys with json2dict function in helpers.py. For additional functions for visualization or modification of the results of object detection, look into helpers.py.

Example:


import detect

model_name = 'faster_rcnn_inception_resnet_v2_atrous_coco_11_06_2017'
url_file = 'Imagenet_sample_images'
extension = '.csv'
downloaded = True
do_rescale = True
width_threshold = 1000
visualize = True

res = detect.object_detect(model_name=model_name, url_file=url_file, extension=extension, downloaded=downloaded, do_rescale=do_rescale, width_threshold=width_thresholdm visualize=visualize)

Etc.

  • Check the function docstring in helpers.py for more info
  • .proto files have already been compiled with Protobuf compiler (Protoc)
  • This code has been tested with Tensorflow 1.1 on Windows 10

Helpful Links

Prerequisites

  • Python 3.5.x
  • Tensorflow-gpu >= 1.1
  • Scikit-image
  • Matplotlib
  • Pandas
  • Numpy

Updates

  • 2017/07/04 : Added image rescale function. For some reason, rescaling drops the recognition accuracy by a significant amount, so using this is not recommended until resolved.

object-detection-api-wrapper's People

Contributors

1202kbs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.