Coder Social home page Coder Social logo

leondragon / tensorflow-lite-rest-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robmarkcole/tensorflow-lite-rest-server

0.0 1.0 0.0 13.53 MB

Expose tensorflow-lite models via a rest API

License: Apache License 2.0

Python 0.14% Jupyter Notebook 99.86%

tensorflow-lite-rest-server's Introduction

tensorflow-lite-rest-server

Expose tensorflow-lite models via a rest API, and currently object detection is supported. Can be hosted on any of the common platforms including RPi, linux desktop, Mac and Windows.

Setup

In this process we create a virtual environment (venv), then install tensorflow-lite as per these instructions which is platform specific, and finally install the remaining requirements. Note on an RPi (only) it is necessary to manually install pip3, numpy, pillow.

All instructions for mac:

python3.7 -m venv venv
source venv/bin/activate
pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-macosx_10_14_x86_64.whl
pip3 install -r requirements.txt

Models

Models are available here with a short description of the models here. For convenience are the mobilenet_ssd_v2 model is included in this repo and used by default. This model can detect 90 types of object, with object labels listed in labels/coco_labels.txt

Usage

Start the server:

python3 tflite-server.py

You can check that the app is running by visiting http://ip:5000/ from any machine, where ip is the ip address of the host (localhost if querying from the same machine).

Post an image for processing via cURL:

curl -X POST -F image=@tests/people_car.jpg 'http://localhost:5000/v1/vision/detection'

Which should return:

{
  "predictions": [
    {
      "confidence": 0.93359375, 
      "label": "car", 
      "x_max": 619, 
      "x_min": 302, 
      "y_max": 348, 
      "y_min": 120
    }, 
    {
      "confidence": 0.7890625, 
      "label": "person", 
      "x_max": 363, 
      "x_min": 275, 
      "y_max": 323, 
      "y_min": 126
    },
.
.
.
'success': True}

Deepstack & Home Assistant

This API can be used as a drop in replacement for deepstack object detection in Home Assistant.

Development

I am developing on a mac/pi4 using VScode. Install the dev requirements: $ pip3 install -r requirements-dev.txt. Sort requirements with $ /home/pi/.local/bin/isort tflite-server.py. Unfortunately appears black is not supported on pi4 yet.

tensorflow-lite-rest-server's People

Watchers

 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.