Simple convnet example 32x32 image train the net to identify which is which e g apple 1 orange 0 script src https cdnjs cloudflare com ajax libs convnetjs 0 3 0 convnet min js script img id apple src https notebook xbdev net var images apple32 png img id orange src https notebook xbdev net var images orange32 png div id probs Probs div script image var layer_defs layer_defs push type input out_sx 32 out_sy 32 out_depth 3 declare size of input output Vol is of size 32x32x3 here layer_defs push type conv sx 5 filters 16 stride 1 pad 2 activation relu the layer will perform convolution with 16 kernels each of size 5x5 the input will be padded with 2 pixels on all sides to make the output Vol of the same size output Vol will thus be 32x32x16 at this point layer_defs push type pool sx 2 stride 2 output Vol is of size 16x16x16 here layer_defs push type conv sx 5 filters 20 stride 1 pad 2 activation relu output Vol is of size 16x16x20 here layer_defs push type pool sx 2 stride 2 output Vol is of size 8x8x20 here layer_defs push type conv sx 5 filters 20 stride 1 pad 2 activation relu output Vol is of size 8x8x20 here layer_defs push type pool sx 2 stride 2 output Vol is of size 4x4x20 here layer_defs push type softmax num_classes 2 output Vol is of size 1x1x10 here net new convnetjs Net net makeLayers layer_defs var trainer new convnetjs SGDTrainer net learning_rate 0 01 l2_decay 0 001 Train apple 1 orange 0 function update var x0 convnetjs img_to_vol document getElementById apple var prob0 net forward x0 trainer train x0 0 var x1 convnetjs img_to_vol document getElementById orange var prob1 net forward x1 trainer train x1 1 let res prob x0 prob0 w 0 x1 prob1 w 0 document getElementById probs innerHTML res setInterval update 200 console log ready script
output Vol is of size 16x16x20 here layer_defs push type pool sx 2 stride 2 output Vol is of size 8x8x20 here layer_defs push type conv sx 5 filters 20 stride 1 pad 2 activation relu output Vol is of size 8x8x20 here layer_defs push type pool sx 2 stride 2 output Vol is of size 4x4x20 here layer_defs push type softmax num_classes 2 output Vol is of size 1x1x10 here net new convnetjs Net net makeLayers layer_defs var trainer new convnetjs SGDTrainer net learning_rate 0 01 l2_decay 0 001 Train apple 1 orange 0 function update var x0 convnetjs img_to_vol document getElementById apple var prob0 net forward x0 trainer train x0 0 var x1 convnetjs img_to_vol document getElementById orange var prob1 net forward x1 trainer train x1 1 let res prob x0 prob0 w 0 x1 prob1 w 0 document getElementById probs innerHTML res setInterval update 200 console log ready script