【问题标题】:format for data for HDF5 input to caffeHDF5 输入到 caffe 的数据格式
【发布时间】:2017-05-26 17:36:45
【问题描述】:

我的图像是 3 通道 RGB 图像。我将每个图像转换为矢量形式。 我打算使用 HDF5 格式将此“数据”提供给 caffe。

我形成 HDF5 数据的代码是(使用 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);

上面的数据块的格式是(行、列、通道、数字样本)。根据 `http://caffe.berkeleyvision.org/doxygen/classcaffe_1_1Blob.html

当我使用 (row, col, channel, number_samples) 运行训练时,代码会运行。当我使用 (number_samples, channels, row, col, ) 运行训练时,代码给出错误:

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

其中 7500 是数据集中的图像数量。 输入 HDF5 格式数据的正确方法是什么?

【问题讨论】:

标签: format caffe hdf5


【解决方案1】:

这方面的一个原因是,Matlab 以 Fortran 顺序存储数据,而不是 HDF5 内部使用的 C 顺序。查看 HDF5 的 Matlab 文档,它应该对此非常明确。

【讨论】:

  • 我尝试使用以 C 顺序存储数据的 h5py。我发现格式(number_samples,channel,width,height)工作正常。
猜你喜欢
  • 2016-07-31
  • 2017-02-24
  • 2017-02-22
  • 2016-10-28
  • 2017-01-21
  • 2017-02-11
  • 2017-07-18
  • 2018-04-08
相关资源
最近更新 更多