brain.js
brain.js copied to clipboard
Train with NeuralNetworkGPU more slower than CPU

What is wrong?
Training with GPU takes too much time ( 2 min for 3000 data )
Where does it happen?
When I try to train with "NeuralNetworkGPU" instead of "NeuralNetwork"
How do we replicate the issue?
you can try to run this code ->
Code:
const abalone = require('./abalone.json');
const {NeuralNetworkGPU} = require('brain.js')
const sexToNumber = (sex) => {
switch(sex) {
case 'F': return 0;
case 'M': return 1;
default: return 0.5
}
}
const preparedData = (data, ratio = 29) => {
return data.map(row => {
const values = Object.values(row).slice(0, -1);
values[0] = sexToNumber(values[0]);
return { input: values, output: [row.rings / ratio] };
})
}
const shuffle = (arr) => arr.sort(() => Math.random() - .5);
const split = (arr, trainRatio = .75) => {
const l = Math.floor(arr.length * trainRatio);
return { train: arr.slice(0, l), test: arr.slice(l) };
}
const prepared = split(shuffle(preparedData(abalone)));
const config = {
iterations: 5000,
log: true,
logPeriod: 20,
};
const net = new NeuralNetworkGPU();
net.train(prepared.train, config);
let totalError = 0;
prepared.test.forEach(item => {
const output = net.run(item.input);
console.log(`Expected: ${item.output * 29} Predicted: ${output * 29}`);
totalError += (output - item.output) ** 2;
});
console.log(totalError / prepared.test.length);
Expected behavior (i.e. solution)
I've RTX 3060Ti & i5-10500 when I try to train with cpu it takes 2-3 sec but when I switch to gpu maybe options same data takes almost 2 min. I believe my GPU is much stronger and faster than my CPU. GPU should more accurate and faster I think
Version information
brain.js: 2.0.0-beta.23 gpu.js: 2.16.0
Nodejs:
node: v16.16.0
Browser:
Brain.js:
brain.js: 2.0.0-beta.23
How important is this (1-5)?
5
Other Comments
Maybe the config is not works on gpu version or I should enable some feature on my gpu. If so, brain.js should at least warn me about this
iterating 20 times each time
abalone.csv U can convert .csv to .json for code if you want
I think I don't have a CPU so it takes an infinite amount of time to train
I have the same thing, only gpu does not work at all, with cpu everything works quietly, I thought it was a problem with nodejs, rewrote to the browser version. Everything is preserved, the browser freezes and everything crashes with gpu, but with cpu everything works. At the same time gpujs itself works fine.
I think I don't have a CPU so it takes an infinite amount of time to train
how the hell your computer can run without a cpu ???