简体   繁体   中英

MatConvNet MNIST network for two classes

Is it possible to make MNIST example in matconvnet to work for two classes instead of 10? I changed the cnn_mnist_init.m file to be the following to generate feature vectors for two classes:

net.layers{end+1} = struct('type', 'conv', ...
                   'weights', {{f*randn(1,1,500,2, 'single'), zeros(1,2,'single')}}, ...
                   'stride', 1, ...
                   'pad', 0) ;

But when I run cnn_train I have the following error:

Error in cnn_train>error_multiclass (line 222)
err(2,1) = sum(sum(sum(min(error(:,:,1:5,:),[],3)))) ;

Error in cnn_train>process_epoch (line 302)
error = sum([error, [...

Error in cnn_train (line 153)
[net, stats.train] = process_epoch(opts, getBatch, epoch, train, learningRate, imdb, net) ;

Error in original_image (line 40)
[net, info] = cnn_train(fold, net, imdb, @getBatch, ...

Error in main_original (line 13)
[imdb, net, info] = original_image(fold);

What I did wrong?

The error you are getting in err(2,1) is probably caused because your error vector has a wrong dimension. err(2,1) is the error of false classificated 5 classes you have only two classes. Check the size of the tensor you feed into softmax it should have the dimension [1,1,2=number of classes, batch size]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM