Git Product home page Git Product logo

ssd_mlengine's Introduction

A Port of SSD: Single Shot MultiBox Detector to Google Cloud Machine Learning Engine.

For more details, please refer to arXiv paper and Keras implementation.

Usage

$ pip install git+https://github.com/monochromegane/starchart.git
$ git clone https://github.com/monochromegane/ssd_mlengine.git
$ starchart train -m ssd_mlengine \
                  -M trainer.task \
                  -s BASIC_GPU \
                  -- \
                  --annotation_path=gs://PATH_TO_ANNOTATION_FILE \
                  --prior_path=gs://PATH_TO_PRIOR_FILE \
                  --weight_path=gs://PATH_TO_WEIGHT_FILE \
                  --images_path=gs://PATH_TO_IMAGES_FILE \
                  --model_dir=TRAIN_PATH/model

When the training is over,

$ starchart expose -m ssd_mlengine

When the prediction API is published,

$ python predict.py -k 1 -c 0.4 -i image.jpg
# {'predictions': [{'key': '1',
#    'objects': [[8.0,        # class
#      0.45196059346199036,   # confidence
#      104.90727233886719,    # xmin
#      97.99836730957031,     # ymin
#      212.12222290039062,    # xmax
#      315.3045349121094]]}]} # ymax

The code of predict.py is like the following:

import argparse
from oauth2client.client import GoogleCredentials
from googleapiclient import discovery
from googleapiclient import errors
from PIL import Image

parser = argparse.ArgumentParser()
parser.add_argument('-k', '--keep_top_k', type=int, default=10)
parser.add_argument('-c', '--confidence_threshold', type=float, default=0.8)
parser.add_argument('-i', '--image', required=True)
args = parser.parse_args()

project = YOUR_PROJECT_ID
model   = 'ssd_mlengine'
version = YOUR_MODEL_VERSION

credentials = GoogleCredentials.get_application_default()
ml = discovery.build('ml', 'v1', credentials=credentials)

size = (300, 300)
img = Image.open(args.image)
original_size = img.size
resized_img = img.resize(size)

data = []
for i in range(size[1]):
    data.append([])
    for j in range(size[0]):
        data[i].append(resized_img.getpixel((j, i)))

body = {'instances': [{'key': '1',
    'data': data,
    'keep_top_k': args.keep_top_k,
    'original_size': original_size,
    'confidence_threshold': args.confidence_threshold
    }]}
request = ml.projects().predict(name='projects/{}/models/{}/versions/{}'.format(project, model, version), body=body)
try:
    response = request.execute()
    output = response['predictions']
    print(output)
except errors.HttpError as err:
    print(err._get_reason())

Preparation

  • A account for Google Cloud Machine Learning Engine
  • Install monochromegane/starchart
  • Put these files to Google Cloud Storage.
    • Ground truth file. You can generate by the code
    • Images file. The source images of ground truth (tar.gz).
    • weights_SSD300.hdf5. Pre-trained weight file. Download from here
    • prior_boxes_ssd300.pkl. Pre-calcuration default boxes. Download from here. And re-packaging for this repository.
      import pickle
      pickle.load(open('prior_boxes_ssd300.pkl', 'rb'))[4332:].dump('prior_boxes_ssd300_min.pkl')

Note

In this implementation, the 38 x 38 split default box via the pool 4 layer has been removed. The Google Cloud ML Engine limits the size of the saved model to 256 MB, as using the full default box exceeds the limit. The default box of 38x38 splitting at the size of 300x300 is small and it seems that there is no influence on object detection.

ssd_mlengine's People

Contributors

monochromegane avatar

Stargazers

tomonari_takahashi avatar Hiroka Zaitsu avatar

Watchers

James Cloos avatar  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.