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

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.


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


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


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.

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;

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!

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

Published at DZone with permission of Niklas Heidloff , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}