gpt4 book ai didi

javascript - BrainJS引用错误: brain is not defined

转载 作者:行者123 更新时间:2023-12-01 00:27:21 27 4
gpt4 key购买 nike

我正在遵循有关如何使用 Brain.js 处理神经网络的教程,当我尝试运行代码时,它给了我一个 ReferenceError: Brain is not Define 我已经通过 npm 安装并且在 HTML 上有 CDN。

const net = new brain.NeuralNetwork({ hiddenLayers: [3] });

const trainingData = [
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] },
{ input: [1, 0], output: [1] },
{ input: [1, 1], output: [0] }
];

net.train(trainingData);

console.log(net.run([0, 0]));

这是index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="//unpkg.com/brain.js"></script>

<script src="index.js"></script>

</head>
<body>

</body>
</html>
````

最佳答案

尝试添加显式协议(protocol) https:// 而不仅仅是使用 //。当我这样做时,你的代码对我有用。

const net = new brain.NeuralNetwork({ hiddenLayers: [3] });

const trainingData = [
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] },
{ input: [1, 0], output: [1] },
{ input: [1, 1], output: [0] }
];

net.train(trainingData);

console.log(net.run([0, 0]));
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://unpkg.com/brain.js"></script>

<script src="index.js"></script>

</head>
<body>

</body>
</html>

关于javascript - BrainJS引用错误: brain is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58867297/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com