Build apps with pre-trained TensorFlow.js models

Original article can be found here (source): Artificial Intelligence on Medium

Build apps with pre-trained TensorFlow.js models

When building an app with machine learning, we first need to train a model, which is not always easy to do and can take some time.

TensorFlow.js provides pre-trained models, that we can import directly into our apps and start using. Like image classification, object detection, hand pose recognition, …

So basically, we can build an app that use machine learning, without doing machine learning.

One weekend, after watching too many Friends episodes on Netflix (and heard too many times “how you doin’” from Joey), I wrote a little app, using the pre-trained speech recognition model.

Basically, you speak your phone number, digit by digit, and the app guess the right digits from the audio (sorry, it does not handle all the phone number formats 🙃)

To do that, I didn’t had to train a model. Just to:

Import the pre-trained model from TensorFlow.js

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/speech-commands"></script>

Instanciate the recognizer

And call the listen method of the recognizer to start listening through Web audio API (directly in the browser). After each word we say, the callback receive a score for each words known by the model. The word with the highest score is most likely to be the one we said.
So we can use it.

And that’s all. Here is an app doing speech recognition, with few lines of codes.

Of course, the list of pre-trained TensorFlow.js models is limited, but we can already do a lot of cool things with them 🙂

Source code https://github.com/prudywsh/phone_number_speech_recognition_tfjs

TensorFlow.js speech recognition pre-trained model https://github.com/tensorflow/tfjs-models/tree/master/speech-commands