* Run for a certain number of iterations and give back control to Matlab
* Intermingle arbitrary Matlab code to with gradient steps
-An ILSVRC image classification demo is in caffe/matlab/classification_demo.m
+An ILSVRC image classification demo is in caffe/matlab/demo/classification_demo.m
### Build MatCaffe
Build MatCaffe with `make all matcaffe`. After that, you may test it using `make mattest`.
-Common issue: if you run into error messages `libstdc++.so.6:version 'GLIBCXX_3.4.15' not found` during `make mattest`, then it means that your Matlab's runtime libraries does not match your compile-time libraries. You may need to do the following before you start matlab:
+Common issue: if you run into error messages like `libstdc++.so.6:version 'GLIBCXX_3.4.15' not found` during `make mattest`, then it usually means that your Matlab's runtime libraries do not match your compile-time libraries. You may need to do the following before you start Matlab:
export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/usr/local/cuda/lib64
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
-Or the equivalent based on where things are installed on your system, and do `make mattest` again to see if the issue is fixed. Note: this issue is sometimes more complicated since during its startup Matlab may overwrite your `LD_LIBRARY_PATH` environment variable. You can run `!ldd ./matlab/+caffe/private/caffe_.mexa64` in Matlab to see its runtime libraries, and preload your compile-time libraries by exporting them to your `LD_PRELOAD` environment variable.
+Or the equivalent based on where things are installed on your system, and do `make mattest` again to see if the issue is fixed. Note: this issue is sometimes more complicated since during its startup Matlab may overwrite your `LD_LIBRARY_PATH` environment variable. You can run `!ldd ./matlab/+caffe/private/caffe_.mexa64` (the mex extension may differ on your system) in Matlab to see its runtime libraries, and preload your compile-time libraries by exporting them to your `LD_PRELOAD` environment variable.
After successful building and testing, add this package to Matlab search PATH by starting `matlab` from caffe root folder and running the following commands in Matlab command window.
im_data = permute(im_data, [2, 1, 3]); % permute width and height
im_data = single(im_data); % convert to single precision
-We do not provide extra functions for data output as Matlab itself is already quite powerful in output.
+Also, you may take a look at caffe/matlab/demo/classification_demo.m to see how to prepare input by taking crops from an image.
+
+We show in caffe/matlab/hdf5creation how to read and write HDF5 data with Matlab. We do not provide extra functions for data output as Matlab itself is already quite powerful in output.
#### Clear nets and solvers
function [scores, maxlabel] = classification_demo(im, use_gpu)
-% scores = classification_demo(im, use_gpu)
+% [scores, maxlabel] = classification_demo(im, use_gpu)
%
% Image classification demo using BVLC CaffeNet.
%
%
% output
% scores 1000-dimensional ILSVRC score vector
+% maxlabel the label of the highest score
%
% You may need to do the following before you start matlab:
% $ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/usr/local/cuda-5.5/lib64
% Or the equivalent based on where things are installed on your system
%
% Usage:
-% im = imread('../examples/images/cat.jpg');
+% im = imread('../../examples/images/cat.jpg');
% scores = classification_demo(im, 1);
% [score, class] = max(scores);
% Five things to be aware of:
% If you have multiple images, cat them with cat(4, ...)
+% Add caffe/matlab to you Matlab search PATH to use matcaffe
+if exist('../+caffe', 'dir')
+ addpath('..');
+else
+ error('Please run this demo from caffe/matlab/demo');
+end
+
% Set caffe mode
if exist('use_gpu', 'var') && use_gpu
caffe.set_mode_gpu();
% Initialize the network using BVLC CaffeNet for image classification
% Weights (parameter) file needs to be downloaded from Model Zoo.
-model_dir = '../models/bvlc_reference_caffenet/';
+model_dir = '../../models/bvlc_reference_caffenet/';
net_model = [model_dir 'deploy.prototxt'];
net_weights = [model_dir 'bvlc_reference_caffenet.caffemodel'];
-phase = 'test';
+phase = 'test'; % run with phase test (so that dropout isn't applied)
+if ~exist(net_weights, 'file')
+ error('Please download CaffeNet from Model Zoo before you run this demo');
+end
+
+% Initialize a network
net = caffe.Net(net_model, net_weights, phase);
if nargin < 1
% For demo purposes we will use the cat image
- fprintf('using ../examples/images/cat.jpg as input image\n');
- im = imread('../examples/images/cat.jpg');
+ fprintf('using caffe/examples/images/cat.jpg as input image\n');
+ im = imread('../../examples/images/cat.jpg');
end
% prepare oversampled input
% ------------------------------------------------------------------------
function images = prepare_image(im)
% ------------------------------------------------------------------------
-d = load('+caffe/imagenet/ilsvrc_2012_mean.mat');
+d = load('../+caffe/imagenet/ilsvrc_2012_mean.mat');
IMAGE_MEAN = d.image_mean;
IMAGE_DIM = 256;
CROPPED_DIM = 227;