MatConvNet is a MATLAB toolbox implementingConvolutional NeuralNetworks (CNNs) for computer vision applications. It is simple,efficient, and can run and learn state-of-the-art CNNs. Severalexample CNNs are included to classify and encode images.
1. Download MatConvNet
https://github.com/vlfeat/matconvnet
2. Make sure that MATLAB is configured to use your compiler.
3. Compiling the CPU support
Open MATLAB and issue the commands:
> cd <MatConvNet>
> addpath matlab
> vl_compilenn
At this point MatConvNet should start compiling. If all goes well, youare ready to use the library. If not, you can try debugging theproblem by running the complation script again in verbose mode:
> vl_compilenn('verbose', 1)
4.
Compiling the GPU support
Assuming that there is only a single copy of the CUDA toolkitinstalled in your system and that it matches MATLAB's version, compilethe library with:
> vl_compilenn('enableGpu', true)
If you have multiple versions of the CUDA toolkit, or if the scriptcannot find the toolkit for any reason, specify the path to the CUDAtoolkit explicitly. For example, on a Mac this may look like:
> vl_compilenn('enableGpu', true, 'cudaRoot', '/Developer/NVIDIA/CUDA-6.0')
5. Examples
% setup MtConvNet in MATLAB
run matlab/vl_setupnn
% download a pre-trained CNN from the web
urlwrite('http://www.vlfeat.org/sandbox-matconvnet/models/imagenet-vgg-f.mat', ...
'imagenet-vgg-f.mat') ;
net = load('imagenet-vgg-f.mat') ;
% obtain and preprocess an image
im = imread('peppers.png') ;
im_ = single(im) ; % note: 255 range
im_ = imresize(im_, net.normalization.imageSize(1:2)) ;
im_ = im_ - net.normalization.averageImage ;
% run the CNN
res = vl_simplenn(net, im_) ;
% show the classification result
scores = squeeze(gather(res(end).x)) ;
[bestScore, best] = max(scores) ;
figure(1) ; clf ; imagesc(im) ;
title(sprintf('%s (%d), score %.3f',...
net.classes.description{best}, best, bestScore)) ;
reference url:
http://www.vlfeat.org/matconvnet/mfiles/vl_compilenn/
http://www.vlfeat.org/matconvnet/install/
http://www.vlfeat.org/matconvnet/pretrained/