How to enable MatCaffe wrapper for Caffe

1. Go to caffe root directory, for me it is :

 $cd /home/naved/Desktop/caffe-master 

2. Make Matcaffe binaries:

 $ make all matcaffe 

3. Test matcaffe installation:

 $make mattest 

4. Now open ~/.bashrc and check if the following lines are there, otherwise find them in your (it can be different for your case) system and modify accordingly:

export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=/usr/local/cuda/lib64/:$LD_LIBRARY_PATH
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/

# Caffe Root
export CAFFE_ROOT=/home/guo/Desktop/caffe-master

5. Now open matlab FROM TERMINAL ,(NOT using launcher icon! This is important!) e.g.:


6. Run a test code to makes sure it is running properly. Before running the code make sure to add path to the caffe/matlab directory as shown in the example code below:


addpath('/home/guo/Desktop/caffe-master/matlab'); % MAKE SURE TO ADD THIS!

img = imread('ak.png');
img = single(img);

averageImage = [129.1863,104.7624,93.5940] ;

img = cat(3,img(:,:,1)-averageImage(1),...

img = img(:, :, [3, 2, 1]); % convert from RGB to BGR
img = permute(img, [2, 1, 3]); % permute width and height

model = 'VGG_FACE_16_deploy.prototxt';
weights = 'VGG_FACE.caffemodel';
net = caffe.Net(model, weights, 'test'); % create net and load weights

res = net.forward({img});
prob = res{1};

caffe_ft = net.blobs('fc7').get_data();

2 thoughts on “How to enable MatCaffe wrapper for Caffe

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s