大发红黑大战

您的位置 > 大发红黑大战 > 商业智能 > Build a Machine Learning Model in your Browser using TensorFlow.js and Python

Build a Machine Learning Model in your Browser using TensorFlow.js and Python

来源:分析大师 | 2019-06-12 | 发布:

What’s your favourite tool to code machine learning models? This eternal question prompts all sorts of different answers from data scientists. Some prefer RStudio, others have a special affinity towards Jupyter Notebooks. I’m definitely in the latter category.So, when I first came across TensorFlow.js (previously deeplearn.js), my mind was blown. Building a machine learning model in my browser? And using JavaScript? Sounded too good to be true!More than 4.3 billion people use web browser – around 55% of the worlds population. – Wikipedia (March 2019)Not only has Google’s TensorFlow.js democratized machine learning for the masses by bringing it to the browser, But it is also the perfect gateway to machine learning for developers who work regularly with JavaScript.Our web browsers are one of the most easily accessible platforms. And that’s why it makes sense to be able to build applications that are able to not only train machine learning models but are also able to “learn” or “transfer learn” in the browser itself.In this article, we’ll first understand the importance of using TensorFlow.js and it’s different components. We’ll then deep dive straight into building our own machine learning model in the browser using TensorFlow.js. Then we will build an application that will detect your body pose using your computer’s webcam!If you’re new to TensorFlow, you can learn more about it here:I’ll answer this question using a unique approach. I won’t delve into the theoretical aspect of TensorFlow.js and list down pointers on why it’s such an incredible tool.Instead, I will simply show you what you will miss out on if you do not use TensorFlow.js. So, let’s build an application to classify images using your webcam in under 5 minutes. That’s right – we will jump right into the code!And here’s the best part – you do not need to install anything to do this! Just a text editor and a web browser is enough. The below video shows the application we’ll be building:How cool is that? I literally built that in a matter of minutes in my browser. So let’s look at the steps and code to help you build your own image classification model in your web browser.Key points to note in this example:
I love the fact that we didn’t need to install anything in our machine. This example should work on any modern system irrespective of whether it is Linux, Windows or MacOS – this is the power of building models on the web using JavaScript.Now, let’s see the awesome features TensorFlow.js provides and how you can utilize them for deploying machine learning models in your browser.TensorFlow.js is a library for developing and training ML models in JavaScript, and deploying in the browser or on Node.js.TensorFlow.js offers a plethora of features to leverage and play around with.It is an extension of TensorFlow in JavaScript, the programming language behind the logic of almost every website, browser or application that we use on the internet. JavaScript is as versatile as Python so using it to develop machine learning models gives us a lot of advantages:Deploying with TensorFlow.js is a lot easier than the conventional approachTensorFlow.js provides the below major functionalities in its current form:In this article, we will focus on the first two features. We’ll discuss transfer learning and deploying our model in Python in the second part of this series (coming soon!).TensorFlow.js provides two ways to train models (quite similar to what TensorFlow does):Let’s understand both the approaches through the lens of a few examples. After all, the best way to learn a concept is by putting it into practice!First, set up your HTML file:Create a newindex.htmlfile in your computer and write the following code in it:We have created a basic HTML page and loaded Tensorflow.js (line 7) from a cloud URL.A note about installing TensorFlow.js (deeplearn.js)Since TensorFlow.js is made for the browser, the easiest method to install and use TensorFlow.js is to not install it at all. You can simply load it from a URL in your HTML.What if you want to work locally? Well, you can actually use TensorFlow.js inside Jupyter Notebook like you normally do in case of Python or R. There’s a solution in this for everyone!This local approach is slightly longer and takes time so we won’t be using it in this article. If you do want to learn how to do it, you can start by installing ijavascript kernel for Jupyter. Here is a screenshot of how it looks in my Jupyter notebook:Now, the recommended approach to use TensorFlow.js is to load it directly by using the official URL of the library. You just have to add the following line to your HTML file:And done! It really is that straightforward.The Core API is very similar to the TensorFlow Core where we can define models using low-level tensor operations and linear algebra.This is very useful if we want to build custom models or want to build neural networks from scratch. Let’s take up an example of working with tensors in the browser.Start by adding the below code between the <script></script>tags in your index.html file:The<script> tags basically denote JavaScript. Anything we write between these tags would be executed as JavaScript code. Here is how your index.html should look now:In the above code, we are performing basic addition and multiplicat
本文已经过优化显示,查看原文请点击以下链接:

院校点评

  大发红黑大战官网  论坛法律顾问:王进律师   大发红黑大战 版权所有
联系QQ:2881989700  邮箱:service@pinggu.org
合作咨询电话:(010)62719935 广告合作电话:13661292478(刘老师)

投诉电话:(010)68466864 不良信息处理电话:(010)68466864