为什么这个 brain.js 脚本太慢了?
Why this brain.js script is going too laggy?
您好,我正在关注浏览器 brain.js 脚本的示例,这是示例代码:
<script src="brain-controller.js"></script>
<script>
net = new brain.recurrent.LSTM()
net.train([
'doe, a deer, a female deer',
'ray, a drop of golden sun',
'me, a name I call myself',
])
output = net.run('doe') // ', a deer, a female deer'
console.log(output)
</script>
brain-controller.js
是 brain.js 脚本更新,所以请不要使用 CDNJS 脚本!!!这是坏的!所以这也很糟糕并且效果不佳。我不能 运行 nodejs 中的 brainjs 脚本它给了我这个错误:
TypeError: Cannot read property 'LSTM' of undefined
at Object.<anonymous> (C:\Users\alumno_ciclo\bot1.js:1:46)
[90m at Module._compile (internal/modules/cjs/loader.js:1121:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:976:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:884:14)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:67:12)[39m
[90m at internal/main/run_main_module.js:17:47[39m
当我做 npm install brain.js
时,它给我这些错误:
MSBUILD : error MSB3428: No se pudo cargar el componente "VCBuild.exe" de Visual C++. Para corregir este problema, 1) i
nstale .NET Framework 2.0 SDK, 2) instale Microsoft Visual Studio 2005 o 3) agregue la ubicación del componente a la ru
ta de acceso del sistema si está instalado en otro lugar. [C:\Users\usuario\node_modules\gl\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\usuario\node_modules\gl
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN mygamename@0.0.1 No description
npm WARN mygamename@0.0.1 No repository field.
npm WARN mygamename@0.0.1 No license field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gl@4.4.1 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gl@4.4.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\usuario\AppData\Roaming\npm-cache\_logs20-02-07T14_09_02_546Z-debug.log
我该怎么办???
您一定是导入的库不正确。您可以在此处看到您的代码使用 CDN 工作。指定迭代次数(默认为 20,000(参见 here))and/or 错误阈值以获得更快的性能。
function test() {
net = new brain.recurrent.LSTM()
net.train([
'doe, a deer, a female deer',
'ray, a drop of golden sun',
'me, a name I call myself',
], {
iterations: 1500,
log: details => console.log(details),
errorThresh: 0.011
});
output = net.run('doe') // ', a deer, a female deer'
const myOutput = document.querySelector('#myOutput');
myOutput.innerHTML = output;
console.log(output)
}
test();
<script src="//unpkg.com/brain.js"></script>
<div id=myOutput></div>
您好,我正在关注浏览器 brain.js 脚本的示例,这是示例代码:
<script src="brain-controller.js"></script>
<script>
net = new brain.recurrent.LSTM()
net.train([
'doe, a deer, a female deer',
'ray, a drop of golden sun',
'me, a name I call myself',
])
output = net.run('doe') // ', a deer, a female deer'
console.log(output)
</script>
brain-controller.js
是 brain.js 脚本更新,所以请不要使用 CDNJS 脚本!!!这是坏的!所以这也很糟糕并且效果不佳。我不能 运行 nodejs 中的 brainjs 脚本它给了我这个错误:
TypeError: Cannot read property 'LSTM' of undefined
at Object.<anonymous> (C:\Users\alumno_ciclo\bot1.js:1:46)
[90m at Module._compile (internal/modules/cjs/loader.js:1121:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:976:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:884:14)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:67:12)[39m
[90m at internal/main/run_main_module.js:17:47[39m
当我做 npm install brain.js
时,它给我这些错误:
MSBUILD : error MSB3428: No se pudo cargar el componente "VCBuild.exe" de Visual C++. Para corregir este problema, 1) i
nstale .NET Framework 2.0 SDK, 2) instale Microsoft Visual Studio 2005 o 3) agregue la ubicación del componente a la ru
ta de acceso del sistema si está instalado en otro lugar. [C:\Users\usuario\node_modules\gl\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\usuario\node_modules\gl
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN mygamename@0.0.1 No description
npm WARN mygamename@0.0.1 No repository field.
npm WARN mygamename@0.0.1 No license field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gl@4.4.1 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gl@4.4.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\usuario\AppData\Roaming\npm-cache\_logs20-02-07T14_09_02_546Z-debug.log
我该怎么办???
您一定是导入的库不正确。您可以在此处看到您的代码使用 CDN 工作。指定迭代次数(默认为 20,000(参见 here))and/or 错误阈值以获得更快的性能。
function test() {
net = new brain.recurrent.LSTM()
net.train([
'doe, a deer, a female deer',
'ray, a drop of golden sun',
'me, a name I call myself',
], {
iterations: 1500,
log: details => console.log(details),
errorThresh: 0.011
});
output = net.run('doe') // ', a deer, a female deer'
const myOutput = document.querySelector('#myOutput');
myOutput.innerHTML = output;
console.log(output)
}
test();
<script src="//unpkg.com/brain.js"></script>
<div id=myOutput></div>