学习javascript_使用5行JavaScript进行机器学习

学习javascript

介绍 (Introduction)

I’d figure instead of putting you (the reader) through reading the entire article, I’ll deliver the promise right now (no JavaScript pun intended).

我想而不是让您(读者)通过阅读整篇文章,而现在就兑现承诺( 没有JavaScript双关语 )

Extremely simple, to the point where it’s almost scary…
极其简单,几乎到令人恐惧的地步……

但是,“ ml5”是什么? (But, what is “ml5”?)

ml5, or ml5.js , is a high-level machine/deep learning framework built on top of — none other than — tensorflow.js.

ml5.jsml5.js是建立在tensorflow.js之上的高级机器/深度学习框架

It’s best to compare ml5.js to Keras; both are high-level APIs that make ML/DL easier than ever and primarily use TensorFlow as their backend framework, but still vary upon their level of abstraction and (of course) programming language.

最好将 ml5.js ml5.js 进行 比较 ; 两者都是使ML / DL变得比以往更容易的高级API,主要使用TensorFlow作为其后端框架,但是它们的抽象级别和(当然)编程语言仍然有所不同。

深入了解 (Looking In Deeper)

Given it’s simplicity & use of JS promises, it might seem as if ml5.js is just sending your input to a server with a pre-trained model. The notion with the pre-trained model is true, but not the server. All computation with the pre-trained model is done on the browser of the user’s computer. Although this may result in inconsistent and/or slower performance based on the JavaScript (e.g. V8 vs SpiderMonkey) engine & user device, this also means that no backend server needs to be created or maintained by the developer to process classification queries.

考虑到它的简单性对JS promise的使用, 似乎 ml5.js只是将您的输入发送到具有预训练模型的服务器上。 具有预训练模型的概念是正确的, 但服务器不是。 带有预训练模型的所有计算都是在用户计算机的浏览器上完成的 。 尽管基于JavaScript(例如V8与SpiderMonkey )引擎和用户设备,这可能导致性能不一致和/或性能降低,但这也意味着开发人员无需创建或维护后端服务器即可处理分类查询。

您实际上如何使用ml5.js? (How do you actually use ml5.js?)

As heavily implied earlier, ml5.js scripts are intended to be embedded in websites, where it is executed via the browser. It’s super simple to get access to the ml5.js API, just use the CDN and plug it in your html <head>:

如前所述, ml5.js脚本旨在嵌入网站中 ,该网站可通过浏览器执行。 访问ml5.js超级简单 API,只需使用CDN并将其插入html <head>

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

From there, you can do some really simple classification tasks. For example, you can pass an image as input to the pre-trained MobileNet and output the prediction of that image on the JavaScript console. Here’s an example HTML webpage for that:

从那里,您可以执行一些非常简单的分类任务。 例如,您可以将图像作为输入传递给预先训练的MobileNet,并在JavaScript控制台上输出该图像的预测。 这是为此的示例HTML网页:

Very simple HTML webpage of just one image
一张图片非常简单HTML网页
Image for post
Webpage on the left, results on the right. It looks like the model predicted it correctly. Photo by John Price on Unsplash
网页在左侧,结果在右侧。 看起来该模型正确预测了它。 John PriceUnsplash上的 照片

应用领域 (Applications)

Let’s take what we had earlier, and turn it into a simple interactive website, shall we? In fact, I’ve already done it: visit https://ml5demo.netlify.app/ and take a look for yourself 😋

让我们将我们以前的内容变成一个简单的交互式网站,对吧? 实际上,我已经做到了:访问https://ml5demo.netlify.app/并自己看看😋

Image for post
Example website that is powered by ` ml5.js`; a simple object detection classifier with a confidence rating. Photo by Sergey Semin on Unsplash
由` ml5.js提供支持的示例网站; 具有置信度等级的简单对象检测分类器。 Sergey SeminUnsplash拍摄的照片

For reference, all code for this is provided in this github repo below (it’s relatively short, anyway).

作为参考,所有此代码均在下面的github存储库中提供(无论如何,它都比较短)。

Given it only takes 5 lines of code to have a working pre-trained classifier in ml5.js, it should be pretty clear that it’s extremely easy to use the library for a functional website like this one. Now’s about the time I remind you again that classification happens on the browser’s machine, not on a remote server! If you visit the site, you find that the website is “loading” for a few seconds first. That’s because the library is actually loading the actual pre-trained MobileNet (with all it’s weights and parameters) onto your browser instance. Cool, indeed!

鉴于仅需5行代码即可在ml5.js拥有一个有效的经过预先训练的分类ml5.js ,因此应该很清楚,对于像这样的功能性网站使用该库非常容易。 现在是时候再次提醒您分类发生在浏览器的计算机上,而不是在远程服务器上! 如果您访问该网站 ,则会发现该网站首先“加载”了几秒钟。 这是因为该库实际上是将实际的经过预先训练的MobileNet(包括所有权重和参数)加载到您的浏览器实例上。 的确很酷!

Other than image classification, ml5.js also supports a plethora of different image-related DL/ML architectures, such as UNET, DCGAN, and FaceAPI. ml5.js is not limited to images either; it supports sound classification models as well as RNNs for text-based data. Finally, if you don’t find what you need from their presets, you could always build a Neural Network from scratch with their API.

除了图像分类, ml5.js 它还支持大量与图像相关的不同DL / ML架构 ,例如UNET,DCGAN和FaceAPI。 ml5.js也不限于图像; 它支持声音分类模型以及基于文本的数据的RNN。 最后,如果您没有从其预设中找到所需的内容,则始终可以使用其API从头开始构建神经网络

潜在 (Potential)

ml5.js holds a lot of potential considering it could be the next “Keras” of deep learning frameworks/libraries. The high-level API makes developing simple classifiers directly onto websites much less daunting compared to using tensorflow.js, and it could mean less time and money spent trying to deploy a classifier model. Still, it goes without saying that deep learning models would entirely depend on the hardware and web engine it runs on.

考虑到它可能是深度学习框架/库的下一个“ Keras”ml5.js具有很大的潜力。 与使用tensorflow.js相比, 高级API使直接在网站上开发简单分类器的tensorflow.js这意味着可以花更少的时间和金钱来部署分类器模型 。 尽管如此,不用说深度学习模型将完全取决于其运行的硬件和Web引擎。

Nonetheless, go give ml5.js a try for yourself and see what you can make out of it!

尽管如此,请ml5.js尝试ml5.js ,看看您能从中得到什么!

翻译自: https://towardsdatascience.com/machine-learning-with-5-lines-of-javascript-5daa0727a25

学习javascript

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值