vlfeat / matconvnet

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

I cannot figure the last layer's right configuration #348

Open alphamarket opened 8 years ago

alphamarket commented 8 years ago

Hey there I have been working on this for almost 2 days. I have a dataset of 256x256 images with 6 output! I cannot figure the last layer, which is how to create a fully connected layer with 6 output?! Any suggestions(or better, an example:grin:)?!


P.S: Why there is no document on layer configurations for matconvnet?! I am literally reverse engineering the examples in the source.

lenck commented 8 years ago

Hi, the dimensionality of the output is set by the number of filters, which is the fourth dimension of the first element of layer weights. The layer configuration is documented in the help string for vl_simplenn with details of the filter sizes in vl_nnconv. Also if you would like to go deeply into detail, the pdf may fulfil your mathematical dreams :)

vedaldi commented 8 years ago

Hi, since this is probably not an issue with the library, could we move this discussion to the new discussion group?

Thanks!

On 13 Dec 2015, at 16:36, Karel Lenc notifications@github.com wrote:

Hi, the dimensionality of the output is set by the number of filters, which is the fourth dimension of the first element of layer weights. The layer configuration is documented in the help string for vl_simplenn http://www.vlfeat.org/matconvnet/mfiles/simplenn/vl_simplenn/ with details of the filter sizes in vl_nnconv http://www.vlfeat.org/matconvnet/mfiles/vl_nnconv/. Also if you would like to go deeply into detail, the pdf http://www.vlfeat.org/matconvnet/matconvnet-manual.pdf may fulfil your mathematical dreams :)

— Reply to this email directly or view it on GitHub https://github.com/vlfeat/matconvnet/issues/348#issuecomment-164276053.

alphamarket commented 8 years ago

Sry... I still cannot figure it out :pensive: I have very little experience with conv networks. it just gives me Matrix dimensions must agree.. The code I am using is as follow:

function [net, info] = script
    clc, clear
    load_data
    imdb = getImdb(trainset_data, trainset_label, testset_data, testset_label);

    opts.train.batchSize = 1;
    opts.train.numEpochs = 30;
    opts.train.learningRate = 0.001 ;

    opts.expDir = fullfile('data','baseline');
    opts.networkType = 'simplenn' ;

    f=1/100 ;
    net.layers = {} ;
    net.layers{end+1} = struct('type', 'conv', ...
                               'weights', {{f*randn(10,10,1,20, 'single'), zeros(1, 20, 'single')}}, ...
                               'stride', 1, ...
                               'pad', 0) ;
    net.layers{end+1} = struct('type', 'pool', ...
                               'method', 'max', ...
                               'pool', [5 5], ...
                               'stride', 5, ...
                               'pad', 0) ;
    net.layers{end+1} = struct('type', 'conv', ...
                               'weights', {{f*randn(10,10,20,6, 'single'), zeros(1,6,'single')}}, ...
                               'stride', 1, ...
                               'pad', 0) ;
    net.layers{end+1} = struct('type', 'softmax') ;

    % Meta parameters
    net.meta.inputSize = [256 256 1] ;
    net.meta.trainOpts.learningRate = 0.001 ;
    net.meta.trainOpts.numEpochs = 20 ;
    net.meta.trainOpts.batchSize = 10 ;

    % Fill in defaul values
    net = vl_simplenn_tidy(net) ;

    [net, info] = cnn_train(net, imdb, getBatch, ...
      opts.train, ...
      'val', find(imdb.images.set == 3)) ;

function fn = getBatch
    fn = @(x,y) getSimpleNNBatch(x,y);

function [images, labels] = getSimpleNNBatch(imdb, batch)
    images = imdb.images.data(:,:,:,batch);
    labels = imdb.images.labels(:,batch);

The format of the output of getImdb() is same as the one in mnist example.

As you can see I have no idea what I am doing! Would you please be kind and post a network configuration that would train inputs with the size of 256x256 and 6 outputs?