karpathy / convnetjs

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

How to feed labels into classifier network #97

Open velociwabbit opened 6 years ago

velociwabbit commented 6 years ago

I am really enjoying learning convnet.js and have had some success with your regression models. Congrats to the developers.

However It is unclear how to provide labels for classification. I am using a very simple network (see below)

These are the layers and trainer and if you notice i have passed a 3 dimensional array (i am acually using 10 representing 0-9 digits)

But the trainer iterates as if the y value input is an integer and does a comparison i === y which can never be true in the backward method.

How do you pass 10 labeled binary outputs to the training function?

Also the output of the training function has a cost_loss and loss value which are the same but what does it mean? the loss value can range from a high of 2 or 4 to low of .03... so it is not a % accuracy number... what does it mean and how do i convert it to % accuracy?

Thanks

net.makeLayers(  [  {   type:'input'    , out_sx:1, out_sy:1, out_depth:4} 
                    , {   type:'fc'       , num_neurons:8, activation:'sigmoid' } 
                    , {   type: 'softmax' , num_classes: 3}])
trainer = new convnetjs.SGDTrainer(net, {learning_rate : 0.01, momentum: 0.0, batch_size: 1, l2_decay: 0.001});

 for(var i=0;i< xtrain.length;i++) {
                x.w[0] = (traindata[i][1]-66) / 40
                x.w[1] = (traindata[i][2]-66) / 40
                x.w[2] = (traindata[i][3]-66) / 40
                x.w[3] = (traindata[i][4]-66) / 40

                var stats = trainer.train(x, [ytrainz[i]/ 10, ytrainy[i]/ 10, ytrainx[i] /10])
NoamGaash commented 6 years ago

Hi. Please note the network assumes that each training example has a single class. Therefore, trainer's Y argument sould contain a single integer, representing the class number (in your case - 0, 1 or 2)