Code Monkey home page Code Monkey logo

teachable-machine-boilerplate's Introduction

Teachable Machine Boilerplate

This is a small boilerplate project that demonstrates how to use tensorflow.js to create projects like Teachable Machine. The code shows how you can create a KNN classifier that can be trained live in the browser on a webcam image. It is intentionally kept very simple so it can provide a starting point for new projects.

Behind the scenes, the image from the webcam is being processed by an activation of MobileNet. This network is trained to recognize all sorts of classes from the imagenet dataset, and is optimized to be really small, making it useable in the browser. Instead of reading the prediction values from the MobileNet network, we instead take the second to last layer in the neural network and feed it into a KNN (k-nearest neighbors) classifier that allows you to train your own classes.

The benefit of using the MobileNet model instead of feeding the pixel values directly into the KNN classifier is that we use the high level abstractions that the neural network has learned in order to recognize the Imagenet classes. This allows us with very few samples to train a classifier that can recognize things like smiles vs frown, or small movements in your body. This technique is called Transfer Learning.

Tensorflow has a built in model for doing this. It's called the KNN Classifier, and this boilerplate code shows how to easily use it.

Use code

To use the code, first install the Javascript dependencies by running

npm install

Then start the local budo web server by running

npm start

This will start a web server on localhost:9966. Try and allow permission to your webcam, and add some examples by holding down the buttons.

Quick Reference - KNN Classifier

A quick overview of the most important function calls in the tensorflow.js KNN Classifier.

  • knnClassifier.create(): Returns a KNNImageClassifier.

  • .addExample(example, classIndex): Adds an example to the specific class training set.

  • .clearClass(classIndex): Clears a specific class for training data.

  • .predictClass(image): Runs the prediction on the image, and returns an object with a top class index and confidence score.

See the full implementation here

Quick Reference - MobileNet

A quick overview of the most important function calls we use from the tensorflow.js model MobileNet.

  • .load(): Loads and returns a model object.

  • .infer(image, endpoint): Get an intermediate activation or logit as Tensorflow.js tensors. Takes an image and the optional endpoint to predict through.

See the full implementation here

teachable-machine-boilerplate's People

Contributors

halfdanj avatar nonoesp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

teachable-machine-boilerplate's Issues

Can I export/import the training data?

Is there a way that I can export/import the training data?
After I trained the class with many images, I want to export(download) the training data and I want to reuse it.

Saving trained model

Is it possible to save the trained model and load it again? If yes could you please share any reference or document links

[Violation] 'requestAnimationFrame' handler took 218ms

When i'm running the model, program is throwing these warning [Violation] 'requestAnimationFrame' handler took 218ms messages. This is happening even when i run the model on GPU machine. Any idea how to improve the performance or what's causing the model to run slowly ? I can observe too much delay sometimes. I am thinking this warning message may be causing the model to run slowly. am i right ?

Loading files without web server

could you please let me know how can i build and load the files without using budo or any other web server?

can i do using the following command ?
browserify main.js --debug | exorcist bundle.js.map > bundle.js

What are the Layers used to KNN input?

[...] MobileNet network, we instead take the second to last layer in the neural network and feed it into a KNN (k-nearest neighbors) classifier that allows you to train your own classes.

I am trying to replicate Teachable Machine in Python with Keras, and I can't understand what layers are used as KNN input.

Can anyone clarify it to me?

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.