使用electron+deeplearnjs构建深度学习环境
2017-09-05 15:42
567 查看
前言
目前javascript的功能越来越强大,除了可以用js+html+css来做网页之外,还可以依赖一些框架和库来做app应用,使用html+css+js来做手机应用比较流行的是react native和weex。html+css+js实现桌面应用比较流行的是electron和nw.js。切入今天的主题,使用js来做深度学习。js深度学习库
已经有很多牛人在尝试将js用于深度学习,作为一个前端的开发者,也可以尝试着了解这方面的知识,在目前,这是一个趋势,一切都在向人工智能靠拢。下面是一些js用于机器学习的库:* brain
* playground
* FlappyLearning
* synaptic
* Land Lines
* convnetjs
* thing-translator
* neurojs
* machine_learning
* deepforge
* deeplearnjs
deeplearnjs
deeplearnjs是google开源的一套深度学习库,支持typescript和es6等语法。它提供了很丰富的API,如果了解过tensorflow的人,学习deeplearnjs会感觉很亲切,因为deeplearnjs里面的很多思想和tensorflow是很相似的。deeplearnjs可以在浏览器里面训练机器学习模型,同时支持CPU和GPU。这里需要一个前提是浏览器需要支持WebGL才能使用该库,可以下载最新的chrome浏览器。可以在这里查看官网提供的demo演示。让deeplearnjs在服务端运行
目前deeplearnjs推荐的运行环境的chrome浏览器,但也可以在node上运行deeplearnjs,这儿尝试的一种办法是使用electron+deeplearnjs+node.js的方式。环境搭建步骤:
安装node V8.4.0安装electron v1.8.0 beta ,需要支持WebGL,所以需要高版本的electron。使用命令:npm install electron@beta, or npm i electron@1.8.0
安装deeplearnjs 命令:npm install deeplearn
到目前为止环境已经搭建完成。
测试:
在上面环境搭建目录下,新建文件:package.json
{ "name": "dp", "version": "1.0.0", "description": "", "main": "main.js", "dependencies": { "deeplearn": "^0.1.2" }, "devDependencies": {}, "scripts": { "start":"electron ." }, "author": "", "license": "ISC" }
main.js
const {app, BrowserWindow} = require('electron') const path = require('path') const url = require('url') // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let win function createWindow () { // Create the browser window. win = new BrowserWindow({width: 800, height: 600}) // and load the index.html of the app. win.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true })) // Open the DevTools. // win.webContents.openDevTools() // Emitted when the window is closed. win.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. win = null }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow) // Quit when all windows are closed. app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (win === null) { createWindow() } })
index.html
<!DOCTYPE html> <html> <head> <title>deeplearn demo1</title> </head> <body> <script> const deeplearn=require('deeplearn'); const util=require('util'); const math = new deeplearn.NDArrayMathGPU(); const a=deeplearn.Array1D.new([1,2,3]); const b=deeplearn.Scalar.new(2); math.scope(()=>{ const result=math.add(a,b); document.body.append(util.inspect(result)); }); </script> </body> </html>
运行命令npm run start,然后看见如下界面出现,则环境搭建成功。
可以在此处下载demo直接运行。
相关文章推荐
- 深度学习 1. CNN的构建和解释--最简单的CNN构造(LeNet-5)# By deepLearnToolbox-master
- 深度学习 1. CNN的构建和解释--最简单的CNN构造(LeNet-5)# By deepLearnToolbox-master
- 使用Amazon AWS搭建GPU版tensorflow深度学习环境
- 【Node.js学习笔记】使用Gulp项目自动化构建工具
- 学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch
- DeepLearning tutorial(7)深度学习框架Keras的使用-进阶
- 使用eclipse构建Jos学习环境--(0)
- Linux环境下搭建DeepNet深度学习框架
- Hbase学习全程记录——使用Eclipse构建HBase开发环境
- DeepLearning tutorial(7)深度学习框架Keras的使用-进阶
- [转载]使用electron构建跨平台Node.js桌面应用经验分享
- 学习使用GTK+ 1.构建GTK+编译环境
- 使用Apache Spark和BigDL来构建深度学习驱动的大数据分析
- DeepLearning tutorial(7)深度学习框架Keras的使用-进阶
- RabbitMQ学习之:(十二)在Node.js环境下使用RabbitMQ
- 一步步学习使用node和express开发web应用(一)——node简介、开发环境及构建最简web应用
- DeepNet深度学习框架的使用
- RabbitMQ学习之:(十二)在Node.js环境下使用RabbitMQ
- Python学习1:使用Aptana构建Python开发环境
- 深度学习Caffe平台开发环境准备——2.使用Eclipse的插件PyDev配置Python开发环境