javascript深度学习智能ai体验brain.js

<!DOCTYPE html>
<html>

<head>
    <meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
    <!-- <script src="//unpkg.com/brain.js"></script> -->
    <script src="brain2.js"></script>
    <title>javascript深度学习智能ai体验brain.js</title>
</head>

<body>
    <h1>javascript深度学习智能ai体验brain.js</h1>
    <div id="democolor"></div>
    <div id="demo"></div>

    <script>
        // 根据RGB学习判断颜色深浅的示例
        // 创建一个神经网络
        const net = new brain.NeuralNetwork();

        // 使用 4 个输入对象训练网络
        net.train([
            // White RGB(255, 255, 255)
            { input: [255 / 255, 255 / 255, 255 / 255], output: { light: 1 } },
            // 浅灰色 (192,192,192)
            { input: [192 / 255, 192 / 255, 192 / 255], output: { light: 1 } },
            // 深灰色 (64, 64, 64)
            { input: [65 / 255, 65 / 255, 65 / 255], output: { dark: 1 } },
            // 黑色 (0, 0, 0)
            { input: [0, 0, 0], output: { dark: 1 } },
            // 纠正一些错误的参数
            {
                "input": [
                    0.5137254901960784,
                    0.10588235294117647,
                    0.8901960784313725
                ],
                "output": {
                    "dark": 1
                }
            },
        ]);

        let htmlstr = ''
        let resarr = []
        for (let i = 0; i < 18; i++) {
            const rgb = [
                Math.round(Math.random() * 255),
                Math.round(Math.random() * 255),
                Math.round(Math.random() * 255),
            ]
            const res = net.run([rgb[0] / 255, rgb[1] / 255, rgb[2] / 255]);
            let fontcolor = '#ffffff'
            let output = 'dark'
            if (res.light > res.dark) {
                fontcolor = '#000000'
                output = 'light'
            }
            resarr.push({ input: rgb.map((el) => el / 255), output: { [output]: 1 } })
            console.log(666.2001, rgb, res)
            htmlstr += '<b style=background-color:RGB(' + rgb.join(',') + ');color:' + fontcolor + '>(' + (i + 1) + ') 文字Abc</b>'
        }
        console.log(666.2002, resarr)
        document.getElementById("democolor").innerHTML = htmlstr

        // 官方示例
        // Create a Neural Network
        const network = new brain.NeuralNetwork();

        // Train the Network with 4 input objects
        network.train([
            { input: [0, 0], output: { zero: 1 } },
            { input: [0, 1], output: { one: 1 } },
            { input: [1, 0], output: { one: 1 } },
            { input: [1, 1], output: { zero: 1 } },
        ]);

        // What is the expected output of [1,0]?
        let result = network.run([1, 0]);

        // Display the probability for "zero" and "one"
        document.getElementById("demo").innerHTML =
            "one: " + result["one"] + "<br>" + "zero: " + result["zero"];
    </script>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿赛工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值