ml5.js - Friendly Machine Learning for the Web

Welcome to the ml5.js documentation. Here you’ll find everything you need to get up and started with ml5.

Getting Started

Take a ride on the Coding Train to watch Dan Shiffman’s “A Beginner’s Guide to Machine Learning with ml5.js”. Here Dan explains what ml5.js is and where it all comes from.

ml5.js is machine learning for the web in your web browser. Through some clever and exciting advancements, the folks building TensorFlow.js figured out that it is possible to use the web browser’s built in graphics processing unit (GPU) to do calculations that would otherwise run very slowly using central processing unit (CPU). A really nice explanation of what is happening with GPUs can be found here - Why are shaders fast?. ml5 strives to make all these new developments in machine learning on the web more approachable for everyone.

Quickstart

The fastest way to get started exploring the creative possibilities of ml5.js are to either:

  1. Download a ml5.js project boilerplate. You can download a zip file here: ml5 project boilerplate.
    Or…

  2. Open this p5 web editor sketch with ml5.js added.

  3. You can also copy and paste the cdn link to the ml5 library here:

    1. <script src="https://unpkg.com/ml5@0.4.3/dist/ml5.min.js"></script>

Quickstart: Plain JavaScript

Reference the latest version of ml5.js using a script tag in an HTML file as below:

In an index.html file, copy and paste the following and open up that file in your web browser.

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Getting Started with ml5.js</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <script src="https://unpkg.com/ml5@0.4.3/dist/ml5.min.js"></script>
  7. </head>
  8. <body>
  9. <script>
  10. // Your code will go here
  11. // open up your console - if everything loaded properly you should see 0.4.1
  12. console.log('ml5 version:', ml5.version);
  13. </script>
  14. </body>
  15. </html>


Quickstart: Powered with p5.js

If you’re familiar with p5.js, ml5.js has been designed to play very nicely with p5. You can use the following boilerplate code to get started:

In an index.html file, copy and paste the following and open up that file in your web browser.

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Getting Started with ml5.js</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <!-- p5 -->
  7. <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
  8. <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
  10. <!-- ml5 -->
  11. <script src="https://unpkg.com/ml5@0.4.3/dist/ml5.min.js"></script>
  12. </head>
  13. <body>
  14. <script>
  15. // Your code will go here
  16. // open up your console - if everything loaded properly you should see 0.9.0
  17. console.log('ml5 version:', ml5.version);
  18. function setup() {
  19. createCanvas(400, 400);
  20. }
  21. function draw() {
  22. background(200);
  23. }
  24. </script>
  25. </body>
  26. </html>

Join Our Community

Coming soon

Contribute to ml5.js

ml5 is an open source project that values all contributions. ml5 contributions often take the shape of workshops, design contributions, helping to answer people’s questions on Github, flagging bugs in code, fixing bugs, adding new features, and more.

If you’d like to contribute, you’re welcome to browse through the issues in our Github or create a new issue. If you’re still unsure of where to start, feel free to ping us at @ml5js on twitter, hello@ml5js.org

Support

ml5 is always on the look out for grants and funding to support the maintenance and development of the ml5 project (including our educational and community based initiatives). If you are an educational institution, grant funding organization, or otherwise interested in funding the ml5 community of students, researchers, artists, educators, designers, and developers, we’d love to hear from you.

Feel free to reach out at hello@ml5js.org.

Acknowledgements

ml5.js is supported by the time and dedication of open source developers from all over the world. Funding and support is generously provided by a Google Education grant at NYU’s ITP/IMA program.

Many thanks BrowserStack for providing testing support.