% train-images.idx3-ubyte / train-labels.idx1-ubyte
images = loadMNISTImages('train-images.idx3-ubyte');
labels = loadMNISTLabels('train-labels.idx1-ubyte');
% reshape images to 4-D: [rows,col,channel,numbers]
trainData=reshape(images,[28 28 1 size(images,2)]);
% permute to [cols,rows,channel,numbers]
trainData=permute(trainData,[2 1 3 4]);
% permute lables to [labels, number of labels ]
trainLabels=permute(labels,[2,1]);
h5create('train.hdf5','/data',size(trainData),'Datatype','double');
h5create('train.hdf5','/label',size(trainLabels),'Datatype','double');
h5write('train.hdf5','/data',trainData);
images = loadMNISTImages('train-images.idx3-ubyte');
labels = loadMNISTLabels('train-labels.idx1-ubyte');
% reshape images to 4-D: [rows,col,channel,numbers]
trainData=reshape(images,[28 28 1 size(images,2)]);
% permute to [cols,rows,channel,numbers]
trainData=permute(trainData,[2 1 3 4]);
% permute lables to [labels, number of labels ]
trainLabels=permute(labels,[2,1]);
h5create('train.hdf5','/data',size(trainData),'Datatype','double');
h5create('train.hdf5','/label',size(trainLabels),'Datatype','double');
h5write('train.hdf5','/data',trainData);
h5write('train.hdf5','/label',trainLabels);
原文连接:https://github.com/mravendi/caffe-mnist-hdf5