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

The most visionary programmers today dream of what a robot could do, just like their counterparts in 1976 dreamed of what personal computers could do. Read more on MistyRobotics.com and enter to win your own Misty. 

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!

Robot Development Platforms: What the heck is ROS and are there any frameworks to make coding a robot easier? Read more on MistyRobotics.com

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 }}