Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Three Awesome TensorFlow.js Models for Visual Recognition

DZone's Guide to

Three Awesome TensorFlow.js Models for Visual Recognition

Explore three TensorFlow.js models for visual recognition.

· AI Zone ·
Free Resource

Bias comes in a variety of forms, all of them potentially damaging to the efficacy of your ML algorithm. Read how Alegion's Chief Data Scientist discusses the source of most headlines about AI failures here.

Last week, I open sourced a web application called Blue Cloud Mirror, which is a game where players need to show five specific emotions and do five specific poses in two levels. The faster, the better.

You can play the game online; it only takes a minute. All you need is a webcam and a Chrome browser.

The game uses three different TensorFlow.js models for Visual Recognition. The code is executed in browsers to run predictions, which are pretty fast.

Faces

Face-api.js can detect faces, find face similarities and detect face landmarks. Try the online demo.

Emotions

Face_classification predicts emotions and can identify genders. The output of face-api.js is passed into this model. Try the online demo.

Poses

Posenet can detect 17 key points of bodies and works for single persons and multiple persons. Try the online demo.

Using the Models in Vue.js

The usage of the models in Vue.js is pretty straight forward. Here is the code to load and run the emotions model.

<script>
import * as tf from "@tensorflow/tfjs";

export default {
  name: "emotionmodel",
  data() {
    return {
      model: {}
    };
  },
  mounted() {
    let url = "models/emotion/model.json";
    tf.loadModel(url).then(result => {
      this.model = result;
...
   var r = this.model.predict(input);
   var result = r.dataSync();
   var tresult = tf.tensor(result);
   var label_index = tf.argMax(tresult).dataSync()[0];
   var label_percent = result[label_index].toFixed(4) * 100;
...
</script>

If you want to run everything from your local machine, run these commands:

$ git clone https://github.com/IBM/blue-cloud-mirror.git
$ cd blue-cloud-mirror/game
$ yarn install
$ yarn run serve

This is a screenshot of level one of the game where five different emotions need to be shown.

Thanks, and let me know what you think in the comments section!

Your machine learning project needs enormous amounts of training data to get to a production-ready confidence level. Get a checklist approach to assembling the combination of technology, workforce and project management skills you’ll need to prepare your own training data.

Topics:
artificial intelligence ,tensorflow.js ,visual recognition ,vue.js ,tutorial ,tensorflow.js models

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}