matlabdeep-learningconv-neural-networkmatconvnet

CNN for Binary classification using MatConvNet


I have started using CNN in MatConvNet with basic binary classification. I have 90 images in that there are total 750 aircraft's and ground truth boxes. Using ground boxes I have extracted all the aircraft image patches as positive samples and make the variables for the input. here is the MATLAB CODE:

Npos =  numel(p_regions);
Npos_train = floor(0.25*Npos); 
Npos_val = floor(0.25*Npos);
Npos_test = floor(0.50*Npos);

imdb.images.set =[ ones( 1, Npos_train ) 2*ones( 1, Npos_val) 3*ones( 1, Npos_test)];
for i=1:Npos
        im= imresize (double(p_regions{i,:}),[50,50]);
    imdb.images.data(:,:,:, i) = im;
    imdb.images.labels(i) = 1;
end
imdb.meta.sets = {'train', 'val', 'test'} ;

In case if I combine aircraft (positive) and non-aircraft (negative) image patches then code will be like this?

Npos_train = floor(0.25* (Npos+Nneg)); 
Npos_val = floor(0.25*(Npos+Nneg));
Npos_test = floor(0.50*(Npos+Nneg));
for i=1:Npos
            im= imresize (double(p_regions{i,:}),[50,50]);
        imdb.images.data(:,:,:, i) = im;
        imdb.images.labels(i) = 1;
    end
for i=1:Nneg
            im= imresize (double(n_regions{i,:}),[50,50]);
        imdb.images.data(:,:,:, I+Npos) = im;
        imdb.images.labels(I+Npos) = 0;
    end
imdb.images.set =[ ones( 1, Npos_train ) 2*ones( 1, Npos_val) 3*ones( 1, Npos_test)];

images.data will be like [All Positives All Negatives ]

images.labels will organize the data [All 1's All 0's ]
and images.set will be images.set =[ ones( 1, Npos_train ) 2*ones( 1, Npos_val) 3*ones( 1, Npos_test)];

Q: The thing which makes me confuse here is: if we want 200 samples for the training. Then how CNN will automatically take positive and negative samples if the data is stored like in images.data and images.labels ?


Solution

  • You should validate this yourself. Take samples of your data and plot the image while printing the corresponding label.

    Even if I tell you now if this code is correct, which I can not by the way because I have no access to the dataset and I can not try your code. However you will have to be able to validate your data anyways along the way to verify that you are learning the right thing. Therefore I would advise you to validate that yourself. It will help you improve your deep learning skills.

    Edit:

    The same index for the data array corresponds to the same index in the labels array. Therefore if the label is 0 for one aircraft it knows it is false and if not it knows it is true.

    The network actually does not know which label correspond to which action, it just learns to discriminate between the two classes. I suggest working through the tutorial of mathconvnet (like this one: http://www.robots.ox.ac.uk/~vgg/practicals/cnn/index.html) to understand these concepts.