Hand Tracking in JS

In this series of posts, I'll try to cover and document some of my early explorations in computer vision and how far we have come. In this initial post, I'll focus on hand tracking with a port of this model to JS.

Problem Statement

The problem of hand tracking in computer vision is fairly easy to state: given an image, draw boxes whenever there are hands. For example, in the following picture there is a clear hand raised by this person.


I found this neat pre-trained model here and gave it a try. Converting it to the tensorflow web format was fairly straightforward:

    --saved_model_tags=serve hand_inference_graph/frozen_inference_graph.pb 

You can find the tool's output model here.


With a trained model, tensorflow makes loading it extremely easy:

        const MODEL_URL = `/static/hands/tensorflowjs_model.pb`;
        const WEIGHTS_URL = `/static/hands/weights_manifest.json`;
        const {loadFrozenModel} = tf;
        const model = loadFrozenModel(MODEL_URL, WEIGHTS_URL);

With a little bit of UI code around it, making the inferecence is simple too:

Live demo

Surprisingly, this model in tensorflow js performs reasonably well. Here is an example of it running against your webcamera feed:

Pretty cool, isn't it?