DEV Community

Cover image for ML5 ALIVE!
gfish94
gfish94

Posted on • Updated on

ML5 ALIVE!

ML5.js

ML5.js is a machine learning library built on top of TensorFlow.js. It aims to be more approachable than TensorFlow.js. It accomplishes this by abstracting away the higher level mathematics involved in understanding TensorFlow or machine learning at large.

Getting Started

<script src="https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
Enter fullscreen mode Exit fullscreen mode

ML5.js does not run in node.js, which the developers hope to remedy now that TensorFlow.js has node support. First thing is first you need to load the script into your html. From there you can start coding in your environment of choice.

For my adventure into ML5.js, I followed the tutorial for the image classifier and used the MobileNet model.

// Initialize the Image Classifier method with MobileNet
const classifier = ml5.imageClassifier('MobileNet', modelLoaded);

// When the model is loaded
function modelLoaded() {
  console.log('Model Loaded!');
}

// Make a prediction with a selected image
classifier.classify(document.getElementById('image'), (err, results) => {
  console.log(results);
});
Enter fullscreen mode Exit fullscreen mode

When the classifier is provided an image, it will send a get request to the model provided and return a result object with the labeled output.

ML5 comes with many other image based functionality. PoseNet is a model that allows the algorithm to detect the poses of one or multiple people, this data can be used for such things as tracking virtual avatars or motion capture animation. BodyPix is a model that takes an image of a person and differentiate between the background of the image as well as categorize the human form into 24 different body parts. Pix2pix is a model that can take a line art and render it in color. Ml5 also has features for sound recognition and text generators.

Machine learning as a creative outlet

Experimenting with Ml5.js — extrasleepy

Ever since I completed the Machine Learning Literacy workshop back in February (at the School for Poetic Computation), I've been wanting to put together a project using Machine Learning. I finally finished something I call Land of Lumps .&nbsp; Land of Lumps is an experimental comic strip

favicon extrasleepy.com

The above link shows another user's adventure with ML5. They created a series of comics called Land of Lumps. In the comic, they have two characters- the first representing the user's input and the second representing the machine's response. The short experimental comic shows off the interworking of how the machine interprets language.

Here is a comic I made using the comic generator provided by the creator, Andrew Kleindolph.

Image description

Conclusion

All in all ML5 is a robust library with many functions that are all simple to learn and easy to implement. This seems to be the dev team's whole mission statement, to make machine learning easy and accessible to the broader community. ML5.js is an open source library build on top of TensorFlow. It abstracts away a lot of the complexity of TensorFlow allowing for it to be accessible to nearly anyone. ML5 also does not have any external dependencies allowing it to be extremely quick to set-up and try out. In conclusion, ML5 is a great library for anyone to try their hands at machine learning.

Helpful Resources

Top comments (0)