1

My images are 3channel RGB images. I convert each image to vector form. I intend to feed this 'data' to caffe using HDF5 format.

My code to form the HDF5 data is(using matlab)

images=csvread('vectorized_image.txt');
labels_new=csvread('labels.txt');

images=images.';

% reshape images to 4-D: [rows,col,channel,numbers]
trainData=reshape(images,[99 99 3 size(images,2)]);

% permute to [cols,rows,channel,numbers]
%trainData=permute(trainData,[2 1 3 4]);

% permute lables to [labels, number of labels ]

%trainLabels4=permute(label4,[2,1]);
trainLabels=permute(labels_new,[2,1]);

h5create('hand_train.hdf5','/data',size(trainData),'Datatype','double');
  h5create('hand_train.hdf5','/label',size(trainLabels),'Datatype','double');

h5write('hand_train.hdf5','/data',trainData);
h5write('hand_train.hdf5','/label',trainLabels);

The data blob above is of the format (row, col, channel, number_samples). The Data blob should be of form(number_samples,channel,width, height) as per `http://caffe.berkeleyvision.org/doxygen/classcaffe_1_1Blob.html

When i run training with (row, col, channel, number_samples), the code runs. When i run training with (number_samples, channels, row, col, ), the code gives error:

hdf5_data_layer.cpp:53] Check failed: hdf_blobs_[i]->shape(0) == num (7500 vs. 99) 

where 7500 is the number of images in the dataset. What is the correct way to enter the data for HDF5 format?

user27665
  • 673
  • 7
  • 27
  • Possible duplicate of [\[caffe\]: check fails: Check failed: hdf\_blobs\_\[i\]->shape(0) == num (200 vs. 6000)](http://stackoverflow.com/questions/34418027/caffe-check-fails-check-failed-hdf-blobs-i-shape0-num-200-vs-6000) – Shai Jan 11 '17 at 23:31

1 Answers1

1

One lead for this is that Matlab stores data in Fortran order and not in C order, which is what HDF5 uses internally. Have a look at the Matlab documentation for HDF5, it should be pretty explicit about this.

Pierre de Buyl
  • 7,074
  • 2
  • 16
  • 22
  • i tried with h5py which stores data in C order. I found that the format(number_samples,channel,width, height) works fine. – user27665 Jan 15 '17 at 11:30