1

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

Shai
  • 111,146
  • 38
  • 238
  • 371
user630317
  • 31
  • 8

1 Answers1

0

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.

Shai
  • 111,146
  • 38
  • 238
  • 371
  • Thank you, is the blob shape in pycaffe for 3D data is like N,C,H,W,D, in which D stands for depth? – user630317 Jun 24 '18 at 07:38
  • @user630317 it depends how you design the net. – Shai Jun 24 '18 at 07:39
  • @user630317 I suppose it is usually NxCxDxHxW (you first store each slice and then move to the next one). – Shai Jun 24 '18 at 07:40
  • could I ask for each group of image and label should we have separate `.h5` files? for example, if I have `im-01.nii`, `im-02.nii`, ..., and their corresponding label volumes, `lb-01.nii`, `lb-02.nii`, ..., the hdf5 list includes, `im-01.h5`, `im-02.h5`, etc. – user630317 Jun 24 '18 at 09:26
  • There is a conflict here if I am not mistaken, In [VNet](https://github.com/faustomilletari/VNet/blob/master/Prototxt/test_noPooling_ResNet_cinque.prototxt#L2) the order of input shape is `input_shape{dim: 1 dim: 1 dim: 128 dim: 128 dim: 64}`, that means `depth:64` comes to end. – user630317 Jun 24 '18 at 10:32
  • @user630317 if this is the way your net is defined - then go with it. – Shai Jun 24 '18 at 10:34