How to create HDF5 database of 3D data for pycaffe?

454 Views Asked by At

My question may sound easy, however, I have difficulty in creating an Hdf5 dataset from my 3d medical images that have been saved in nii format for both images and manual segmentation (label files). My questions are:

  1. The blob shape in pycaffe is N*C*W*H, is it different order in matcaffe? for example in pycaffe the data blob shape will be 1*1*60*320*320 for a grayscale volume with width and height 320-by-320 and 60 slices. I tried to use a Matlab code to create HDF5 dataset for the 3D data, and the order of blob in hdf5info file is 320*320*60*1*1 for both data and label. How should I change the orders in the Matlab code to be readable in Pycaffe?
  2. Is there any python code for creating the hdf5 database for 3D data?
  3. if I create the hdf5 data in Matlab and use the list the pycaffe, will it raise issue?

Thanks

1

There are 1 best solutions below

6
Shai On

Matlab arranges elements in ND arrays from the first dimension to the last (like fortran), while caffe and hdf5 stores the arrays from last dimension to first ("col-major").
This answer explains how to simply modify Matlab's code to write "col-major" arrays to HDF5 files.
You might also find this answer useful for your problem.