Available at: http://www.vlfeat.org/matconvnet/
My goal is to use this toolbox to classify cars into four classes: Sedan, Minivan, SUV and pickup. I already have the data from my prior work (http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6558793).
My plan is to first use transfer learning i. e. to use one of the deep networks pre-trained with imagenet data to extract features and use an SVM classifier to do the actual classification. I plan to do this with Matlab 2016a on Windows 10 PC equipped with GeForce GTX 960. I am aware that Matlab also has deep learning support in its Neural Network toolbox, I am going with MatConNet in hopes that it will stay more cutting edge.
The code below is derived from http://www.mathworks.com/company/newsletters/articles/deep-learning-for-computer-vision-with-matlab.html and http://www.vlfeat.org/matconvnet/quick/
clear; close all; clc; %Load the pre-trained net net = load('imagenet-vgg-f.mat'); net = vl_simplenn_tidy(net) ; %Remove the last layer (softmax layer) net.layers = net.layers(1 : end - 1); %% This deals with reading the data and getting the ground truth class labels %All files are are inside the root root = 'C:\Users\ninad\Dropbox\Ninad\Lasagne\data\c200x200\'; Files = dir(fullfile(root, '*.bmp')); %Load the map which stores the class information load MakeModels.mat for i = 1 : length(Files) waitbar (i/ length(Files)); % Read class from the map Q = Files(i).name(end - 18 : end - 4); Qout = MakeModels(Q); Files(i).class = Qout.Type; % Preprocess the data and get it ready for the CNN im = imread(fullfile(root, Files(i).name)); im_ = single(im); % note: 0-255 range im_ = imresize(im_, net.meta.normalization.imageSize(1:2)); im_ = bsxfun(@minus, im_, net.meta.normalization.averageImage); % run the CNN to compute the features feats = vl_simplenn(net, im_) ; Files(i).feats = squeeze(feats(end).x); end %% Classifier training %Select training data fraction trainFraction = 0.5; randomsort = randperm(length(Files)); trainSamples = randomsort(1 : trainFraction * length(Files)); testSamples = randomsort(trainFraction * length(Files)+1 : end); Labels = [Files.class]; Features = [Files.feats]; trainingFeatures = Features( :, trainSamples); trainingLabels = Labels( :, trainSamples); classifier = fitcecoc(trainingFeatures', trainingLabels); %% Carry out the validation with rest of the data testFeatures = Features( :, testSamples); testLabels = Labels( :, testSamples); predictedLabels = predict(classifier, testFeatures'); confMat = confusionmat(testLabels, predictedLabels); % Convert confusion matrix into percentage form confMat = bsxfun(@rdivide,confMat,sum(confMat,2)) % Display the mean accuracy mean(diag(confMat))