Caffe - Understanding the pre-processing done before feeding images to HDF5

116 views
Skip to first unread message

Devendra Mandan

unread,
Jan 8, 2016, 8:34:53 PM1/8/16
to Caffe Users
I intend to feed my test and train images to caffe through hdf5. But before that some pre-processing is required, so I was looking at the matcaffe_demo function prepare_image, as I would have to do the same pre-processing steps as the pre-trained net.

% ------------------------------------------------------------------------
function images = prepare_image(im)
% ------------------------------------------------------------------------

d
= load('ilsvrc_2012_mean');
IMAGE_MEAN
= d.image_mean;
IMAGE_DIM
= 256;
CROPPED_DIM
= 227;

% resize to fixed input size
im
= single(im);
im
= imresize(im, [IMAGE_DIM IMAGE_DIM], 'bilinear');
% permute from RGB to BGR (IMAGE_MEAN is already BGR)
im
= im(:,:,[3 2 1]) - IMAGE_MEAN;

% oversample (4 corners, center, and their x-axis flips)
images
= zeros(CROPPED_DIM, CROPPED_DIM, 3, 10, 'single');
indices
= [0 IMAGE_DIM-CROPPED_DIM] + 1;
curr
= 1;
for i = indices
 
for j = indices
    images
(:, :, :, curr) = ...
        permute
(im(i:i+CROPPED_DIM-1, j:j+CROPPED_DIM-1, :), [2 1 3]);
    images
(:, :, :, curr+5) = images(end:-1:1, :, :, curr);
    curr
= curr + 1;
 
end
end
center
= floor(indices(2) / 2)+1;
images
(:,:,:,5) = ...
    permute
(im(center:center+CROPPED_DIM-1,center:center+CROPPED_DIM-1,:), ...
   
[2 1 3]);
images
(:,:,:,10) = images(end:-1:1, :, :, curr);

This produces an output of dimensions 227*227*3*10, my question is,
a) what exactly does this 10 signify here? and,
b) can I do something like the following to feed my images to hdf5, if not what is the correct way?

for i=1:n
    image
= fgetl('/path/to/images.txt');
    im
= imread(image);
    im
= prepare_image(im);
    X
[i] = im;

And then, hdf5write('my_data.h5', '/X',X);

So, is this process which going to follow is correct, I am not sure, please correct and help me!



ashenafi menza

unread,
Jan 8, 2016, 10:47:37 PM1/8/16
to Caffe Users
Guys i am new to deep learning and caffe framework. My prof. asked me to do a project that is to Download at least 20 images for each 10 different cities and Train the system and try to recognise. i have tried to read the documentations and some tutorials on deep learning but i dont know how to start it. i managed to install caffe linked with python on mac. i have already the images(training and validation). i need someone to guide me through :)
Reply all
Reply to author
Forward
0 new messages