javascript
学习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.js或ml5.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網頁 Webpage on the left, results on the right. It looks like the model predicted it correctly. Photo by John Price on Unsplash網頁在左側,結果在右側。 看起來該模型正確預測了它。 John Price在Unsplash上的照片應用領域 (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/并自己看看😋
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 Semin在Unsplash上拍攝的照片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
總結
以上是生活随笔為你收集整理的学习javascript_使用5行JavaScript进行机器学习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 机器学习 可视化_机器学习-可视化
- 下一篇: jQuery利用JSONP解决AJAX跨