简体   繁体   中英

Confused on how to store 3D matrices in HDF5 file in matlab?

I have multiple 3D matrices that need to be stored in a hdf5 file. I have looked everywhere but i am confused about the process of storing data in hdf5 file. Can i store multiple 3D matrices in a single dataset in hdf5 file or do i have to create separate dataset for each 3D matrix? I need this dataset for training a 3D CNN model. If both ways are possible, which is the best for training purpose?

Additional information: Matrix size is 12x24x12 and a single data takes less than 100 kb storage space. Dataset is created in matlab and the resultant file will be used in python (where the model will be trained).

In matlab you specify -v3.7 to save stuff in hdf5. You save your matrices like this:

mat0 = zeros(12,24,12);
mat1 = ones(12,24,12);
mat2 = 2*ones(12,24,12);
save data.mat mat0 mat1 mat2 -v7.3

In python you read them like this:

import numpy as np
import h5py
f = h5py.File('/home/innereye/data.mat','r')
mat1 = f.get('mat1')
mat1 = np.array(mat1)

you have a lot of material on Stackoverflow about reading mat files with python, for example, here and here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM