karpathy / convnetjs

Deep Learning in Javascript. Train Convolutional Neural Networks (or ordinary ones) in your browser.
MIT License
10.8k stars 2.04k forks source link

Convolutional Network not training #120

Closed Bobingstern closed 2 years ago

Bobingstern commented 2 years ago

I'm trying to recreate a readable version of the mnist demo. My implementation uses a 28x28 array to forward into the network with the same layer defs:

layer_defs = [];
layer_defs.push({type:'input', out_sx:24, out_sy:24, out_depth:1});
layer_defs.push({type:'conv', sx:5, filters:8, stride:1, pad:2, activation:'relu'});
layer_defs.push({type:'pool', sx:2, stride:2});
layer_defs.push({type:'conv', sx:5, filters:16, stride:1, pad:2, activation:'relu'});
layer_defs.push({type:'pool', sx:3, stride:3});
layer_defs.push({type:'softmax', num_classes:10});

I don't know how to train the network properly using the Vol class. Whatever I do the network just does not learn and the cost error is always NaN. The forward pass works fine though but the trainer.train does not.

My train function is as follows

function train(data){
  if (stopTraining){return}
  let cop = [...data.input]
  cop.reshape(28, 28)
  cop = transposeArray(cop, cop.length)
  let x = new convnetjs.Vol(cop.length, cop[0].length, 1, 0.0)
  x.w = cop.flat()
  let stats = trainer.train(x, data.output)
  console.log(stats)

}
371148606 commented 2 years ago

您好,我是薛文毅,已收到您的邮件,一会查收,谢谢!!  

Bobingstern commented 2 years ago

I figured it out, it was an issue with my training output layer