Giter Site home page Giter Site logo

tensorflow.js-image-classification's Introduction

Tensorflow.js Image Classification

Implementing a K-NN classifier using Tensorflow.js

You can try it here

NOTE: This is the result of following the Tensorflow tutorial available at https://www.tensorflow.org/js/tutorials/transfer/image_classification. I suggest you give it a go and experiment with Tensorflow.js yourself!

K-NN Classification

K-Nearest Neighbours is a classification method that uses similarity/dissimilarity metrics to classify new elements. Since it needs labeled samples to classify against, K-NN is a supervised learning method. When classifying a sample, the distance between that and the existing ones is calculated. The class our sample belongs to is that of the closest "training" sample. Additionally, we can order the distances to see how likely it is for our sample to belong to each of the classes (from most to least if the ordering is done in ascending distance).

We start with an empty model We then add some training samples with their labels
Empty graph Graph with training samples
Once trained, we can add our testing sample The nearest training sample determines the class of ours!
Graph with training samples and a testing one Graph with test sample classified

Here we can see that despite not having the prettiest of faces, this sample model classified me as belonging to the "Human" class based on previous samples. In the real world we would optimally want more samples than this, but it does provide a good example.

Tensorflow.js

Tensorflow.js is a Javascript implementation of the popular Tensorflow library used for many Machine Learning applications. It enables us to use off-the-shelf JavaScript models or convert Python TensorFlow models. Moreover, we can retrain models for our data, which is what I have done in this project. In my case I took the MobileNet K-NN classification model and adapted it to be able to distinguish between 4 facial expressions:

  • Happy
  • Sad
  • Angry
  • Serious

By using a webcam, one can add samples to the model, which will predict in real time the label of the frame captured by the camera.

tensorflow.js-image-classification's People

Contributors

vintrae avatar

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.