GithubHelp home page GithubHelp logo

drinkspiller / teachablemachine-node-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tr7zw/teachablemachine-node-example

19.0 0.0 7.0 37.71 MB

Showing a workaround to get get teachablemachine tf.js models running in node and beeing able to post images

JavaScript 100.00%

teachablemachine-node-example's Introduction

Teachable Machine Node Example

A demonstration of using Teachable Machine, which is intended to run in the browser, in Node. Based on the clever approach by tr7zw in their original demo.

How It Works

  1. A workaround is used to simulate in Node just enough of the browser parts required for Teachable Machine to work.
  2. The script makes Teachable Machine models available through API endpoints defined in the script using Express.
  3. An image posted to an endpoint is parsed and passed to the model. Predictions are made and the endpoint responds to the request with JSON formatted prediction results.

Usage

  1. Clone this repo, cd into it, and run npm install
  2. Edit app.js and add create endpoints associated with a trained model.
  3. Run app server either with npm start or node app.js
  4. Post an image to the endpoint. This has the potential to be a source of frustration โ€” if POSTing the image is not done correctly the application may crash of malfunction. See "Image POST Tips and Notes" and "Post Examples" below.

Image POST Tips and Notes

  • Ensure you are pointing to the right endpoint name on the right port. (e.g. localhost:3000 if posting from the same computer the app is running on, or myhostname:3000 if posting from another computer)
  • Ensure you are supplying the correct path to the image being posted.

POST Examples

Linux/OSX curl -X POST -H "Content-Type: image/jpeg" --data-binary '@./sample_images/person-using-iphone-1194760.jpg' http://localhost:3000/test view a breakdown of this command

Windows PowerShell.exe Invoke-WebRequest -uri http://localhost:3000/test -Method Post -Infile "./sample_images/person-using-iphone-1194760.jpg" -ContentType 'image/jpeg'

Notes

  • The sample model used makes a prediction on whether a supplied image contains a Solo Human, a Solo Phone, or a Human and Phone. I am not the creator of this model. It is used here with permission from the author, lachlanjc, who uses it in this post.
    • Use the model's URL to explore interactively in the Teachable Machine UI or use it in the code for this demo by passing the URL to the addEndpoint() method.
  • node-canvas is a jsdom dependency for canvas/img support
  • Notable changes from the original demo on which this is based:
    • Removes requirement in original demo to monkey patch (comment out) part of the Teachable Machine npm package.
    • Removes custom _arrayBufferToBase64 method in favor of built-in conversion.
    • Dynamically allows for different image Content-Types (i.e. image/jpeg, image/png).
    • Uses eslint with Google style guide configuration for linting.
      • Adds additional comments and JSDOCs.

teachablemachine-node-example's People

Contributors

ralphfurley avatar tr7zw avatar

Stargazers

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