首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Github 项目推荐 | 用 JavaScript 实现的神经网络 —— brain.js

Github 项目推荐 | 用 JavaScript 实现的神经网络 —— brain.js

作者头像
AI研习社
发布2018-07-26 15:25:44
1.4K0
发布2018-07-26 15:25:44
举报
文章被收录于专栏:AI研习社AI研习社

Brain.js 是用 JavaScript 写成的神经网络。

Github 链接:

https://github.com/BrainJS/brain.js

示例

这是一个用 Brain.js 实现的异或案例:

//create a simple feed forward neural network with backpropagation
var net = new brain.NeuralNetwork();

net.train([{input: [0, 0], output: [0]},
           {input: [0, 1], output: [1]},
           {input: [1, 0], output: [1]},
           {input: [1, 1], output: [0]}]);

var output = net.run([1, 0]);  // [0.987]

或者

//create a simple recurrent neural network
var net = new brain.recurrent.RNN();

net.train([{input: [0, 0], output: [0]},
           {input: [0, 1], output: [1]},
           {input: [1, 0], output: [1]},
           {input: [1, 1], output: [0]}]);

var output = net.run([0, 0]);  // [0]
output = net.run([0, 1]);  // [1]
output = net.run([1, 0]);  // [1]
output = net.run([1, 1]);  // [0]

不过,一般的开发者应该都不会用神经网络来实现异或的功能吧,所以这里有一个更加实际的例子:训练一个神经网络来识别颜色对比 https://brain.js.org/

更多示例

开发者可以看看这个链接,它解释了如何使用真实世界的数据集来训练一个简单的神经网络:如何使用Brain.js在浏览器中创建一个神经网络。https://scrimba.com/c/c36zkcb

  • 用循环神经网络编写儿童书籍 https://github.com/BrainJS/brain.js/blob/develop/examples/childrens-book.js
  • 简单的字母检测 https://github.com/BrainJS/brain.js/blob/develop/examples/which-letter-simple.js

用法

Node

如果你安装了 Node,你可以用 npm 来安装 brain.js:

npm install brain.js

或者用 yarn:

yarn add brain.js

另外,可以用 bower 来安装 brain.js:

bower install brain.js

浏览器

在浏览器上下载最新的 brain.js(https://raw.githubusercontent.com/harthur-org/brain.js/master/browser.js)。训练模型在计算力上要花很大的价钱,所以最好选择采用离线的方式来训练(或者在 Worker 上),并使用 toFunction() 或 toJSON()选项将预先训练好的网络插入你的网站。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-03-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 AI研习社 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档