vlfeat / matconvnet

MatConvNet: CNNs for MATLAB
Other
1.4k stars 753 forks source link

assertition failed vl_simplenn.m #34

Closed StevenLOL closed 9 years ago

StevenLOL commented 9 years ago

Hi,

After run cnn_mnist.m, I have few net-epoch-n.mat models.

To predict one image on mnist , following the example in http://www.vlfeat.org/matconvnet/pretrained

When calling

net=load('./data/mnist-baseline/net-epoch-5.mat'); res=vl_simplenn(net.net, im); % im is just one mnist image whose size is 28*28

I got the error:

Error using vl_nnsoftmaxloss (line 42) Assertion failed. Error in vl_simplenn (line 164) res(i+1).x = vl_nnsoftmaxloss(res(i).x, l.class) ;

lenck commented 9 years ago

Hi, when you train a model, as a last layer there is usually the softmaxloss which is a softmax followed by logistic loss - the loss which is being optimized. But in order to compute the loss, it needs the ground truth in net.layers{end}.class which is passed as the second parameter in vl_simplenn to vl_nnsoftmaxloss.

However, in general when you want to obtain only class probabilities, you simply change the last layer type to:

net.net.layers{end}.type = 'softmax';

And now your call of vl_simplenn should work...

StevenLOL commented 9 years ago

Thanks, the best CNN toolkit ever.

rng1995 commented 7 years ago

Where should place the command net.net.layers{end}.type = 'softmax'; ? Is it in cnn_cifar.m file or cnn_cifar_init.m or vl_simplenn.m file ?